initial commit
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
public static class EditorGUIHelper
|
||||
{
|
||||
private static Styles s_Styles;
|
||||
private class Styles
|
||||
{
|
||||
public GUIStyle header = "ShurikenModuleTitle";
|
||||
public GUIStyle headerCheckbox = "ShurikenCheckMark";
|
||||
|
||||
internal Styles()
|
||||
{
|
||||
header.font = (new GUIStyle("Label")).font;
|
||||
header.border = new RectOffset(15, 7, 4, 4);
|
||||
header.fixedHeight = 22;
|
||||
header.contentOffset = new Vector2(20f, -2f);
|
||||
}
|
||||
}
|
||||
|
||||
static EditorGUIHelper()
|
||||
{
|
||||
s_Styles = new Styles();
|
||||
}
|
||||
|
||||
public static bool Header(SerializedProperty group, SerializedProperty enabledField)
|
||||
{
|
||||
var display = group == null || group.isExpanded;
|
||||
var enabled = enabledField != null && enabledField.boolValue;
|
||||
var title = group == null ? "Unknown Group" : ObjectNames.NicifyVariableName(group.displayName);
|
||||
|
||||
Rect rect = GUILayoutUtility.GetRect(16f, 22f, s_Styles.header);
|
||||
GUI.Box(rect, title, s_Styles.header);
|
||||
|
||||
Rect toggleRect = new Rect(rect.x + 4f, rect.y + 4f, 13f, 13f);
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
s_Styles.headerCheckbox.Draw(toggleRect, false, false, enabled, false);
|
||||
|
||||
Event e = Event.current;
|
||||
if (e.type == EventType.MouseDown)
|
||||
{
|
||||
if (toggleRect.Contains(e.mousePosition) && enabledField != null)
|
||||
{
|
||||
enabledField.boolValue = !enabledField.boolValue;
|
||||
e.Use();
|
||||
}
|
||||
else if (rect.Contains(e.mousePosition) && group != null)
|
||||
{
|
||||
display = !display;
|
||||
group.isExpanded = !group.isExpanded;
|
||||
e.Use();
|
||||
}
|
||||
}
|
||||
return display;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b995f06a3ed14d449823cf7ab1c5a58
|
||||
timeCreated: 1454681943
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
public static class FieldFinder<T>
|
||||
{
|
||||
public static FieldInfo GetField<TValue>(Expression<Func<T, TValue>> selector)
|
||||
{
|
||||
Expression body = selector;
|
||||
if (body is LambdaExpression)
|
||||
{
|
||||
body = ((LambdaExpression)body).Body;
|
||||
}
|
||||
switch (body.NodeType)
|
||||
{
|
||||
case ExpressionType.MemberAccess:
|
||||
return (FieldInfo)((MemberExpression)body).Member;
|
||||
default:
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39e54cb37a3a81a40b248f1cc25c4619
|
||||
timeCreated: 1454073160
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityStandardAssets.CinematicEffects
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(MinAttribute))]
|
||||
internal sealed class MinDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
MinAttribute attribute = (MinAttribute) base.attribute;
|
||||
|
||||
if (property.propertyType == SerializedPropertyType.Integer)
|
||||
{
|
||||
int v = EditorGUI.IntField(position, label, property.intValue);
|
||||
property.intValue = (int)Mathf.Max(v, attribute.min);
|
||||
}
|
||||
else if (property.propertyType == SerializedPropertyType.Float)
|
||||
{
|
||||
float v = EditorGUI.FloatField(position, label, property.floatValue);
|
||||
property.floatValue = Mathf.Max(v, attribute.min);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.LabelField(position, label.text, "Use Min with float or int.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c615a85f13c6764fa4496d1d7f75f52
|
||||
timeCreated: 1453220014
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user