Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 5d63fff

Browse files
Implemented event example
1 parent f1b822e commit 5d63fff

Some content is hidden

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

44 files changed

+7687
-0
lines changed
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
public class TypedRaiseButton
8+
{
9+
public TypedRaiseButton(Type type, Action<object> callback)
10+
{
11+
_type = type;
12+
_callback = callback;
13+
}
14+
15+
private readonly Type _type;
16+
private readonly Action<object> _callback;
17+
18+
private MutableObject _value = new MutableObject();
19+
20+
public void Draw()
21+
{
22+
if (_type == typeof(bool))
23+
{
24+
_value = EditorGUILayout.Toggle("Debug Value", _value);
25+
26+
RaiseButton((bool)_value);
27+
}
28+
else if (_type == typeof(byte))
29+
{
30+
_value = EditorGUILayout.IntField("Debug Value", _value);
31+
32+
RaiseButton((byte)_value);
33+
}
34+
else if (_type == typeof(char))
35+
{
36+
_value = EditorGUILayout.TextField("Debug Value", _value);
37+
38+
RaiseButton((char)_value);
39+
}
40+
else if (_type == typeof(double))
41+
{
42+
_value = EditorGUILayout.DoubleField("Debug Value", _value);
43+
44+
RaiseButton((double)_value);
45+
}
46+
else if (_type == typeof(float))
47+
{
48+
_value = EditorGUILayout.FloatField("Debug Value", _value);
49+
50+
RaiseButton((float)_value);
51+
}
52+
else if (_type == typeof(int))
53+
{
54+
_value = EditorGUILayout.IntField("Debug Value", _value);
55+
56+
RaiseButton((int)_value);
57+
}
58+
else if (_type == typeof(long))
59+
{
60+
_value = EditorGUILayout.LongField("Debug Value", _value);
61+
62+
RaiseButton((long)_value);
63+
}
64+
else if (_type == typeof(UnityEngine.Object))
65+
{
66+
_value = EditorGUILayout.ObjectField("Debug Value", _value, _type, true);
67+
68+
RaiseButton((UnityEngine.Object)_value);
69+
}
70+
else if (_type == typeof(sbyte))
71+
{
72+
_value = EditorGUILayout.IntField("Debug Value", _value);
73+
74+
RaiseButton((sbyte)_value);
75+
}
76+
else if (_type == typeof(short))
77+
{
78+
_value = EditorGUILayout.IntField("Debug Value", _value);
79+
80+
RaiseButton((short)_value);
81+
}
82+
else if (_type == typeof(string))
83+
{
84+
_value = EditorGUILayout.TextField("Debug Value", _value);
85+
86+
RaiseButton((string)_value);
87+
}
88+
else if (_type == typeof(uint))
89+
{
90+
_value = EditorGUILayout.LongField("Debug Value", _value);
91+
92+
RaiseButton((uint)(long)_value);
93+
}
94+
else if (_type == typeof(ushort))
95+
{
96+
_value = EditorGUILayout.IntField("Debug Value", _value);
97+
98+
RaiseButton((ushort)(int)_value);
99+
}
100+
else
101+
{
102+
EditorGUILayout.LabelField("Can't draw debug value field for " + _type);
103+
}
104+
}
105+
private void RaiseButton(object value)
106+
{
107+
if (GUILayout.Button("Raise"))
108+
{
109+
_callback.Invoke(value);
110+
}
111+
}
112+
private partial class MutableObject
113+
{
114+
public MutableObject() { }
115+
}
116+
private partial class MutableObject
117+
{
118+
public MutableObject(bool value)
119+
{
120+
_boolValue = value;
121+
}
122+
123+
private bool _boolValue;
124+
125+
public static implicit operator bool(MutableObject obj)
126+
{
127+
return obj._boolValue;
128+
}
129+
public static implicit operator MutableObject(bool value)
130+
{
131+
return new MutableObject(value);
132+
}
133+
}
134+
private partial class MutableObject
135+
{
136+
public MutableObject(int value)
137+
{
138+
_intValue = value;
139+
}
140+
141+
private int _intValue;
142+
143+
public static implicit operator int(MutableObject obj)
144+
{
145+
return obj._intValue;
146+
}
147+
public static implicit operator MutableObject(int value)
148+
{
149+
return new MutableObject(value);
150+
}
151+
}
152+
private partial class MutableObject
153+
{
154+
public MutableObject(float value)
155+
{
156+
_floatValue = value;
157+
}
158+
159+
private float _floatValue;
160+
161+
public static implicit operator float(MutableObject obj)
162+
{
163+
return obj._floatValue;
164+
}
165+
public static implicit operator MutableObject(float value)
166+
{
167+
return new MutableObject(value);
168+
}
169+
}
170+
private partial class MutableObject
171+
{
172+
public MutableObject(string value)
173+
{
174+
_stringValue = value;
175+
}
176+
177+
private string _stringValue;
178+
179+
public static implicit operator string(MutableObject obj)
180+
{
181+
return obj._stringValue;
182+
}
183+
public static implicit operator char(MutableObject obj)
184+
{
185+
if (obj._stringValue == null)
186+
return default(char);
187+
188+
if (obj._stringValue.Length > 0)
189+
return obj._stringValue[0];
190+
191+
return default(char);
192+
}
193+
public static implicit operator MutableObject(string value)
194+
{
195+
return new MutableObject(value);
196+
}
197+
}
198+
private partial class MutableObject
199+
{
200+
public MutableObject(double value)
201+
{
202+
_doubleValue = value;
203+
}
204+
205+
private double _doubleValue;
206+
207+
public static implicit operator double(MutableObject obj)
208+
{
209+
return obj._doubleValue;
210+
}
211+
public static implicit operator MutableObject(double value)
212+
{
213+
return new MutableObject(value);
214+
}
215+
}
216+
private partial class MutableObject
217+
{
218+
public MutableObject(long value)
219+
{
220+
_longValue = value;
221+
}
222+
223+
private long _longValue;
224+
225+
public static implicit operator long(MutableObject obj)
226+
{
227+
return obj._longValue;
228+
}
229+
public static implicit operator MutableObject(long value)
230+
{
231+
return new MutableObject(value);
232+
}
233+
}
234+
private partial class MutableObject
235+
{
236+
public MutableObject(UnityEngine.Object value)
237+
{
238+
_objectValue = value;
239+
}
240+
241+
private UnityEngine.Object _objectValue;
242+
243+
public static implicit operator UnityEngine.Object(MutableObject obj)
244+
{
245+
return obj._objectValue;
246+
}
247+
public static implicit operator MutableObject(UnityEngine.Object value)
248+
{
249+
return new MutableObject(value);
250+
}
251+
}
252+
}

Assets/SO Architecture/Editor/Inspectors/TypedRaiseButton.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.

Assets/SO Architecture/Examples.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/SO Architecture/Examples/Objects.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInternal: {fileID: 0}
8+
m_GameObject: {fileID: 0}
9+
m_Enabled: 1
10+
m_EditorHideFlags: 0
11+
m_Script: {fileID: 11500000, guid: 7a78c7052899406438e9fc79486b45c0, type: 3}
12+
m_Name: OnPlayerDamaged
13+
m_EditorClassIdentifier:
14+
DeveloperDescription:

Assets/SO Architecture/Examples/Objects/OnPlayerDamaged.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInternal: {fileID: 0}
8+
m_GameObject: {fileID: 0}
9+
m_Enabled: 1
10+
m_EditorHideFlags: 0
11+
m_Script: {fileID: 11500000, guid: f9377ffeb64ba30478a995a8ffc78ae8, type: 3}
12+
m_Name: Player Health
13+
m_EditorClassIdentifier:
14+
DeveloperDescription: 'It''s important to remember that Scriptable Objects will
15+
not reset when you exit playmode. This means that player health is not automatically
16+
reset
17+
18+
19+
Simply have a separate object that contains the starting health of your player,
20+
and make sure the health component resets on awake'
21+
_value: -60

Assets/SO Architecture/Examples/Objects/Player Health.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInternal: {fileID: 0}
8+
m_GameObject: {fileID: 0}
9+
m_Enabled: 1
10+
m_EditorHideFlags: 0
11+
m_Script: {fileID: 11500000, guid: f9377ffeb64ba30478a995a8ffc78ae8, type: 3}
12+
m_Name: Player Move Speed
13+
m_EditorClassIdentifier:
14+
DeveloperDescription:
15+
_value: 0.2

Assets/SO Architecture/Examples/Objects/Player Move Speed.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)