Skip to content

Commit f8afe49

Browse files
committed
Introduced "Variables" namespace
1 parent 07c5043 commit f8afe49

File tree

81 files changed

+2224
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2224
-14
lines changed
File renamed without changes.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace StephanHooft.Variables.EditorScripts
5+
{
6+
/// <summary>
7+
/// A custom <see cref="PropertyDrawer"/> for the <see cref="BoolReference"/>.
8+
/// </summary>
9+
[CustomPropertyDrawer(typeof(BoolReference))]
10+
public class BoolReferenceDrawer : PropertyDrawer
11+
{
12+
private readonly string[] popupOptions =
13+
{ "Use Local Value", "Use BoolVariable" };
14+
15+
private GUIStyle popupStyle;
16+
17+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
18+
{
19+
if (popupStyle == null)
20+
{
21+
popupStyle = new(GUI.skin.GetStyle("PaneOptions"));
22+
popupStyle.imagePosition = ImagePosition.ImageOnly;
23+
}
24+
label = EditorGUI.BeginProperty(position, label, property);
25+
position = EditorGUI.PrefixLabel(position, label);
26+
27+
EditorGUI.BeginChangeCheck();
28+
29+
var useLocalValue = property.FindPropertyRelative("useLocalValue");
30+
var localValue = property.FindPropertyRelative("localValue");
31+
var variable = property.FindPropertyRelative("variable");
32+
33+
var buttonRect = new Rect(position);
34+
buttonRect.yMin += popupStyle.margin.top;
35+
buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
36+
position.xMin = buttonRect.xMax;
37+
38+
var indent = EditorGUI.indentLevel;
39+
EditorGUI.indentLevel = 0;
40+
41+
var index = useLocalValue.boolValue
42+
? 0
43+
: 1;
44+
var result = EditorGUI.Popup(buttonRect, index, popupOptions, popupStyle);
45+
useLocalValue.boolValue = result == 0;
46+
var propertyToShow = useLocalValue.boolValue
47+
? localValue
48+
: variable;
49+
EditorGUI.PropertyField(position, propertyToShow, GUIContent.none);
50+
if (EditorGUI.EndChangeCheck())
51+
property.serializedObject.ApplyModifiedProperties();
52+
53+
EditorGUI.indentLevel = indent;
54+
EditorGUI.EndProperty();
55+
}
56+
}
57+
}

Editor/Variables/BoolReferenceDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace StephanHooft.Variables.EditorScripts
5+
{
6+
/// <summary>
7+
/// A custom <see cref="PropertyDrawer"/> for the <see cref="ColorReference"/>.
8+
/// </summary>
9+
[CustomPropertyDrawer(typeof(ColorReference))]
10+
public class ColorReferenceDrawer : PropertyDrawer
11+
{
12+
private readonly string[] popupOptions =
13+
{ "Use Local Value", "Use ColorVariable" };
14+
15+
private GUIStyle popupStyle;
16+
17+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
18+
{
19+
if (popupStyle == null)
20+
{
21+
popupStyle = new(GUI.skin.GetStyle("PaneOptions"));
22+
popupStyle.imagePosition = ImagePosition.ImageOnly;
23+
}
24+
label = EditorGUI.BeginProperty(position, label, property);
25+
position = EditorGUI.PrefixLabel(position, label);
26+
27+
EditorGUI.BeginChangeCheck();
28+
29+
var useLocalValue = property.FindPropertyRelative("useLocalValue");
30+
var localValue = property.FindPropertyRelative("localValue");
31+
var variable = property.FindPropertyRelative("variable");
32+
33+
var buttonRect = new Rect(position);
34+
buttonRect.yMin += popupStyle.margin.top;
35+
buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
36+
position.xMin = buttonRect.xMax;
37+
38+
var indent = EditorGUI.indentLevel;
39+
EditorGUI.indentLevel = 0;
40+
41+
var index = useLocalValue.boolValue
42+
? 0
43+
: 1;
44+
var result = EditorGUI.Popup(buttonRect, index, popupOptions, popupStyle);
45+
useLocalValue.boolValue = result == 0;
46+
var propertyToShow = useLocalValue.boolValue
47+
? localValue
48+
: variable;
49+
EditorGUI.PropertyField(position, propertyToShow, GUIContent.none);
50+
if (EditorGUI.EndChangeCheck())
51+
property.serializedObject.ApplyModifiedProperties();
52+
53+
EditorGUI.indentLevel = indent;
54+
EditorGUI.EndProperty();
55+
}
56+
}
57+
}

Editor/Variables/ColorReferenceDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace StephanHooft.Variables.EditorScripts
5+
{
6+
/// <summary>
7+
/// A custom <see cref="PropertyDrawer"/> for the <see cref="DoubleReference"/>.
8+
/// </summary>
9+
[CustomPropertyDrawer(typeof(DoubleReference))]
10+
public class DoubleReferenceDrawer : PropertyDrawer
11+
{
12+
private readonly string[] popupOptions =
13+
{ "Use Local Value", "Use DoubleVariable" };
14+
15+
private GUIStyle popupStyle;
16+
17+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
18+
{
19+
if (popupStyle == null)
20+
{
21+
popupStyle = new(GUI.skin.GetStyle("PaneOptions"));
22+
popupStyle.imagePosition = ImagePosition.ImageOnly;
23+
}
24+
label = EditorGUI.BeginProperty(position, label, property);
25+
position = EditorGUI.PrefixLabel(position, label);
26+
27+
EditorGUI.BeginChangeCheck();
28+
29+
var useLocalValue = property.FindPropertyRelative("useLocalValue");
30+
var localValue = property.FindPropertyRelative("localValue");
31+
var variable = property.FindPropertyRelative("variable");
32+
33+
var buttonRect = new Rect(position);
34+
buttonRect.yMin += popupStyle.margin.top;
35+
buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
36+
position.xMin = buttonRect.xMax;
37+
38+
var indent = EditorGUI.indentLevel;
39+
EditorGUI.indentLevel = 0;
40+
41+
var index = useLocalValue.boolValue
42+
? 0
43+
: 1;
44+
var result = EditorGUI.Popup(buttonRect, index, popupOptions, popupStyle);
45+
useLocalValue.boolValue = result == 0;
46+
var propertyToShow = useLocalValue.boolValue
47+
? localValue
48+
: variable;
49+
EditorGUI.PropertyField(position, propertyToShow, GUIContent.none);
50+
if (EditorGUI.EndChangeCheck())
51+
property.serializedObject.ApplyModifiedProperties();
52+
53+
EditorGUI.indentLevel = indent;
54+
EditorGUI.EndProperty();
55+
}
56+
}
57+
}

Editor/Variables/DoubleReferenceDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace StephanHooft.Variables.EditorScripts
5+
{
6+
/// <summary>
7+
/// A custom <see cref="PropertyDrawer"/> for the <see cref="FloatReference"/>.
8+
/// </summary>
9+
[CustomPropertyDrawer(typeof(FloatReference))]
10+
public class FloatReferenceDrawer : PropertyDrawer
11+
{
12+
private readonly string[] popupOptions =
13+
{ "Use Local Value", "Use FloatVariable" };
14+
15+
private GUIStyle popupStyle;
16+
17+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
18+
{
19+
if (popupStyle == null)
20+
{
21+
popupStyle = new(GUI.skin.GetStyle("PaneOptions"));
22+
popupStyle.imagePosition = ImagePosition.ImageOnly;
23+
}
24+
label = EditorGUI.BeginProperty(position, label, property);
25+
position = EditorGUI.PrefixLabel(position, label);
26+
27+
EditorGUI.BeginChangeCheck();
28+
29+
var useLocalValue = property.FindPropertyRelative("useLocalValue");
30+
var localValue = property.FindPropertyRelative("localValue");
31+
var variable = property.FindPropertyRelative("variable");
32+
33+
var buttonRect = new Rect(position);
34+
buttonRect.yMin += popupStyle.margin.top;
35+
buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
36+
position.xMin = buttonRect.xMax;
37+
38+
var indent = EditorGUI.indentLevel;
39+
EditorGUI.indentLevel = 0;
40+
41+
var index = useLocalValue.boolValue
42+
? 0
43+
: 1;
44+
var result = EditorGUI.Popup(buttonRect, index, popupOptions, popupStyle);
45+
useLocalValue.boolValue = result == 0;
46+
var propertyToShow = useLocalValue.boolValue
47+
? localValue
48+
: variable;
49+
EditorGUI.PropertyField(position, propertyToShow, GUIContent.none);
50+
if (EditorGUI.EndChangeCheck())
51+
property.serializedObject.ApplyModifiedProperties();
52+
53+
EditorGUI.indentLevel = indent;
54+
EditorGUI.EndProperty();
55+
}
56+
}
57+
}

Editor/Variables/FloatReferenceDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace StephanHooft.Variables.EditorScripts
5+
{
6+
/// <summary>
7+
/// A custom <see cref="PropertyDrawer"/> for the <see cref="IntReference"/>.
8+
/// </summary>
9+
[CustomPropertyDrawer(typeof(IntReference))]
10+
public class IntReferenceDrawer : PropertyDrawer
11+
{
12+
private readonly string[] popupOptions =
13+
{ "Use Local Value", "Use IntVariable" };
14+
15+
private GUIStyle popupStyle;
16+
17+
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
18+
{
19+
if (popupStyle == null)
20+
{
21+
popupStyle = new(GUI.skin.GetStyle("PaneOptions"));
22+
popupStyle.imagePosition = ImagePosition.ImageOnly;
23+
}
24+
label = EditorGUI.BeginProperty(position, label, property);
25+
position = EditorGUI.PrefixLabel(position, label);
26+
27+
EditorGUI.BeginChangeCheck();
28+
29+
var useLocalValue = property.FindPropertyRelative("useLocalValue");
30+
var localValue = property.FindPropertyRelative("localValue");
31+
var variable = property.FindPropertyRelative("variable");
32+
33+
var buttonRect = new Rect(position);
34+
buttonRect.yMin += popupStyle.margin.top;
35+
buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
36+
position.xMin = buttonRect.xMax;
37+
38+
var indent = EditorGUI.indentLevel;
39+
EditorGUI.indentLevel = 0;
40+
41+
var index = useLocalValue.boolValue
42+
? 0
43+
: 1;
44+
var result = EditorGUI.Popup(buttonRect, index, popupOptions, popupStyle);
45+
useLocalValue.boolValue = result == 0;
46+
var propertyToShow = useLocalValue.boolValue
47+
? localValue
48+
: variable;
49+
EditorGUI.PropertyField(position, propertyToShow, GUIContent.none);
50+
if (EditorGUI.EndChangeCheck())
51+
property.serializedObject.ApplyModifiedProperties();
52+
53+
EditorGUI.indentLevel = indent;
54+
EditorGUI.EndProperty();
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)