Update Example.cs
This commit is contained in:
parent
f719b189f1
commit
5eca08b18d
@ -8,64 +8,64 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace MackySoft.SerializeReferenceExtensions.Example {
|
namespace MackySoft.SerializeReferenceExtensions.Example {
|
||||||
|
|
||||||
public class Example : MonoBehaviour {
|
public class Example : MonoBehaviour {
|
||||||
|
|
||||||
// The type that implements ICommand will be displayed in the popup.
|
// The type that implements ICommand will be displayed in the popup.
|
||||||
[SerializeReference, SubclassSelector]
|
[SerializeReference, SubclassSelector]
|
||||||
ICommand m_Command;
|
ICommand m_Command;
|
||||||
|
|
||||||
// Collection support
|
// Collection support
|
||||||
[SerializeReference, SubclassSelector]
|
[SerializeReference, SubclassSelector]
|
||||||
ICommand[] m_Commands = Array.Empty<ICommand>();
|
ICommand[] m_Commands = Array.Empty<ICommand>();
|
||||||
|
|
||||||
void Start () {
|
void Start () {
|
||||||
m_Command?.Execute();
|
m_Command?.Execute();
|
||||||
|
|
||||||
foreach (ICommand command in m_Commands) {
|
foreach (ICommand command in m_Commands) {
|
||||||
command?.Execute();
|
command?.Execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nested type support
|
// Nested type support
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class NestedCommand : ICommand {
|
public class NestedCommand : ICommand {
|
||||||
public void Execute () {
|
public void Execute () {
|
||||||
Debug.Log("Execute NestedCommand");
|
Debug.Log("Execute NestedCommand");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ICommand {
|
|
||||||
void Execute ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
public interface ICommand {
|
||||||
public class DebugCommand : ICommand {
|
void Execute ();
|
||||||
[SerializeField]
|
}
|
||||||
string m_Message;
|
|
||||||
public void Execute () {
|
[Serializable]
|
||||||
Debug.Log(m_Message);
|
public class DebugCommand : ICommand {
|
||||||
|
[SerializeField]
|
||||||
|
string m_Message;
|
||||||
|
public void Execute () {
|
||||||
|
Debug.Log(m_Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class InstantiateCommand : ICommand {
|
public class InstantiateCommand : ICommand {
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject m_Prefab;
|
GameObject m_Prefab;
|
||||||
|
|
||||||
public void Execute () {
|
public void Execute () {
|
||||||
UnityEngine.Object.Instantiate(m_Prefab,Vector3.zero,Quaternion.identity);
|
UnityEngine.Object.Instantiate(m_Prefab,Vector3.zero,Quaternion.identity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Menu override support
|
// Menu override support
|
||||||
[AddTypeMenu("Example/Add Type Menu Command")]
|
[AddTypeMenu("Example/Add Type Menu Command")]
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class AddTypeMenuCommand : ICommand {
|
public class AddTypeMenuCommand : ICommand {
|
||||||
public void Execute () {
|
public void Execute () {
|
||||||
Debug.Log("Execute AddTypeMenuCommand");
|
Debug.Log("Execute AddTypeMenuCommand");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user