|
8 | 8 |
|
9 | 9 | namespace MackySoft.SerializeReferenceExtensions.Example {
|
10 | 10 |
|
11 |
| - public class Example : MonoBehaviour { |
| 11 | + public class Example : MonoBehaviour { |
12 | 12 |
|
13 |
| - // The type that implements ICommand will be displayed in the popup. |
14 |
| - [SerializeReference, SubclassSelector] |
15 |
| - ICommand m_Command; |
| 13 | + // The type that implements ICommand will be displayed in the popup. |
| 14 | + [SerializeReference, SubclassSelector] |
| 15 | + ICommand m_Command; |
16 | 16 |
|
17 |
| - // Collection support |
18 |
| - [SerializeReference, SubclassSelector] |
19 |
| - ICommand[] m_Commands = Array.Empty<ICommand>(); |
| 17 | + // Collection support |
| 18 | + [SerializeReference, SubclassSelector] |
| 19 | + ICommand[] m_Commands = Array.Empty<ICommand>(); |
20 | 20 |
|
21 | 21 | void Start () {
|
22 |
| - m_Command?.Execute(); |
| 22 | + m_Command?.Execute(); |
23 | 23 |
|
24 |
| - foreach (ICommand command in m_Commands) { |
25 |
| - command?.Execute(); |
| 24 | + foreach (ICommand command in m_Commands) { |
| 25 | + command?.Execute(); |
26 | 26 | }
|
27 | 27 | }
|
28 | 28 |
|
29 |
| - // Nested type support |
| 29 | + // Nested type support |
30 | 30 | [Serializable]
|
31 |
| - public class NestedCommand : ICommand { |
32 |
| - public void Execute () { |
33 |
| - Debug.Log("Execute NestedCommand"); |
| 31 | + public class NestedCommand : ICommand { |
| 32 | + public void Execute () { |
| 33 | + Debug.Log("Execute NestedCommand"); |
34 | 34 | }
|
35 | 35 | }
|
36 | 36 |
|
37 |
| - } |
| 37 | + } |
38 | 38 |
|
39 |
| - public interface ICommand { |
40 |
| - void Execute (); |
| 39 | + public interface ICommand { |
| 40 | + void Execute (); |
41 | 41 | }
|
42 | 42 |
|
43 |
| - [Serializable] |
44 |
| - public class DebugCommand : ICommand { |
45 |
| - [SerializeField] |
46 |
| - string m_Message; |
47 |
| - public void Execute () { |
48 |
| - Debug.Log(m_Message); |
| 43 | + [Serializable] |
| 44 | + public class DebugCommand : ICommand { |
| 45 | + [SerializeField] |
| 46 | + string m_Message; |
| 47 | + public void Execute () { |
| 48 | + Debug.Log(m_Message); |
49 | 49 | }
|
50 | 50 | }
|
51 | 51 |
|
52 |
| - [Serializable] |
53 |
| - public class InstantiateCommand : ICommand { |
| 52 | + [Serializable] |
| 53 | + public class InstantiateCommand : ICommand { |
54 | 54 |
|
55 |
| - [SerializeField] |
| 55 | + [SerializeField] |
56 | 56 | GameObject m_Prefab;
|
57 | 57 |
|
58 | 58 | public void Execute () {
|
59 |
| - UnityEngine.Object.Instantiate(m_Prefab,Vector3.zero,Quaternion.identity); |
| 59 | + UnityEngine.Object.Instantiate(m_Prefab,Vector3.zero,Quaternion.identity); |
60 | 60 | }
|
61 | 61 | }
|
62 | 62 |
|
63 |
| - // Menu override support |
64 |
| - [AddTypeMenu("Example/Add Type Menu Command")] |
65 |
| - [Serializable] |
66 |
| - public class AddTypeMenuCommand : ICommand { |
67 |
| - public void Execute () { |
68 |
| - Debug.Log("Execute AddTypeMenuCommand"); |
| 63 | + // Menu override support |
| 64 | + [AddTypeMenu("Example/Add Type Menu Command")] |
| 65 | + [Serializable] |
| 66 | + public class AddTypeMenuCommand : ICommand { |
| 67 | + public void Execute () { |
| 68 | + Debug.Log("Execute AddTypeMenuCommand"); |
69 | 69 | }
|
70 | 70 | }
|
71 | 71 |
|
|
0 commit comments