Skip to content

Instantly share code, notes, and snippets.

View saint-angels's full-sized avatar
💭
crawling

Michael saint-angels

💭
crawling
View GitHub Profile
1 image + 1 audio = video
ffmpeg -loop 1 -i image.jpg -i audio.wav -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4
@saint-angels
saint-angels / RandomWeighted.cs
Created December 27, 2019 07:15
Weighted Random
private int RandomWeighted(List<int> weights)
{
int accumulatedWeigts = 0;
for (int i = 0; i < weights.Count; i++)
{
accumulatedWeigts += weights[i];
weights[i] = accumulatedWeigts;
}
//If accumulated weights is 0, choose random index. Otherwise, logic would always select 1st element
@saint-angels
saint-angels / PointsConnections.cs
Created June 16, 2018 08:44
Lines connecting UI points. Unity
for (int pIdx = 0; pIdx < points.Count - 1; pIdx++)
{
RectTransform point1 = points[pIdx];
RectTransform point2 = points[pIdx + 1];
Vector2 midpoint = (point2.position - point1.position) / 2 + point1.position;
float xDifference = point2.position.x - point1.position.x;
float yDifference = point2.position.y - point1.position.y;
float distance = (point2.position - point1.position).magnitude;
float angle = Mathf.Acos(Mathf.Abs(xDifference)/ distance) * 57.2958f;
@saint-angels
saint-angels / CurvedText.cs
Created April 9, 2016 16:37
Curve UI Text elements in Unity
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
[RequireComponent(typeof(RectTransform))]
public class CurvedText : BaseMeshEffect
{
@saint-angels
saint-angels / ListComponent.cs
Created March 25, 2016 14:11
You probably have a bunch of components that you want to keep a constantly updated list of too. Maybe all your enemies, or maybe all your bullets. (For Unity3D engine, from http://garry.tv/2015/06/14/unity-tips/)
using UnityEngine;
using System.Collections.Generic;
public abstract class ListComponent<T> : MonoBehaviour where T : MonoBehaviour
{
public static List<T> InstanceList = new List<T>();
protected virtual void OnEnable()
{
InstanceList.Add( this as T );
@saint-angels
saint-angels / SingletonComponent.cs
Last active March 25, 2016 14:10
Useful Components for Unity3D engine. You probably have a component somewhere where you only want one of them and you probably want to get access to it from everywhere for some reason. So we added SingletonComponent. from http://garry.tv/2015/06/14/unity-tips/
using UnityEngine;
public abstract class SingletonComponent<T> : SingletonComponent where T : MonoBehaviour
{
public static T Instance
{
get { return instance; }
}
private static T instance = default( T );