View HVECEncoder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using Unity.Collections; | |
using UnityEditor.Media; | |
using UnityEditor.Recorder.Encoder; | |
class HVECEncoder : IEncoder | |
{ | |
Process process; | |
public void OpenStream(IEncoderSettings settings, RecordingContext ctx) |
View HSLandHSV.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
/// <summary> | |
/// Represents a color with hue, saturation, and lightness. | |
/// </summary> | |
readonly struct HSL | |
{ | |
public Color Color => HSV.FromHSL(this).Color; | |
public readonly float H; |
View GetExtensionMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from https://stackoverflow.com/a/299526 | |
static IEnumerable<MethodInfo> GetExtensionMethods(Assembly assembly, Type extendedType) | |
{ | |
return assembly | |
.GetTypes() | |
.Where(type => type.IsSealed && !type.IsGenericType && !type.IsNested) | |
.SelectMany(type => type.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)) | |
.Where(method => method.IsDefined(typeof(ExtensionAttribute), false) && | |
method.GetParameters()[0].ParameterType == extendedType); | |
} |
View GetMainWindowPosition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This contains no error checking, which you want for such fragile code. | |
// You also probably want to cache `mainWindow` if you call this often. | |
static Rect GetMainWindowPosition() | |
{ | |
var containerWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ContainerWindow"); | |
var showModeField = containerWindowType.GetField("m_ShowMode", BindingFlags.Instance | BindingFlags.NonPublic); | |
var mainWindow = Resources.FindObjectsOfTypeAll(containerWindowType).First(window => (int)showModeField.GetValue(window) == 4); | |
var positionProperty = mainWindow.GetType().GetProperty("position", BindingFlags.Instance | BindingFlags.Public); | |
return (Rect)positionProperty.GetValue(mainWindow, null); | |
} |
View GetMainEditorWindow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Object GetMainEditorWindow() | |
{ | |
var containerWindowType = typeof(EditorWindow).Assembly.GetType("UnityEditor.ContainerWindow"); | |
var showModeField = containerWindowType.GetField("m_ShowMode", BindingFlags.Instance | BindingFlags.NonPublic); | |
return Resources | |
.FindObjectsOfTypeAll(containerWindowType) | |
.First(window => (int)showModeField.GetValue(window) == 4); | |
} |
View Draggable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
/// <summary> | |
/// Attribute to add to Vector3 and Vector3[] fields to make them draggable in the scene. | |
/// </summary> | |
public class Draggable : PropertyAttribute | |
{ | |
} |
View GetPropertiesWithAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example usage inside Editor.OnSceneGUI for Vector3 fields: | |
// | |
// foreach (var property in GetPropertiesWithAttribute<MyCustomAttribute>(serializedObject)) | |
// { | |
// Handles.Label(property.vector3Value, property.name); | |
// } | |
static IEnumerable<SerializedProperty> GetPropertiesWithAttribute<TAttribute>(SerializedObject serializedObject) | |
{ | |
var targetObjectType = serializedObject.targetObject.GetType(); |
View RandomPointOnUnitCircle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Vector2 RandomPointOnUnitCircle() | |
{ | |
var angle = Random.Range(0f, Mathf.PI * 2); | |
var x = Mathf.Sin(angle); | |
var y = Mathf.Cos(angle); | |
return new Vector2(x, y); | |
} |
View StateMachine.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public class StateMachine | |
{ | |
public interface IState | |
{ | |
public void OnEnter(); | |
public void OnExit(); | |
} |
NewerOlder