Last active
August 29, 2015 14:27
-
-
Save is8r/db707c69b9b840fddc14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
public class CustomEventArgs : EventArgs { | |
public string message; | |
} | |
public delegate void CustomEventHandler(object sender, CustomEventArgs e); | |
public class EventTest : MonoBehaviour { | |
[SerializeField] public event CustomEventHandler OnCustomEventHandler; | |
public void OnEvent () { | |
CustomEventArgs args = new CustomEventArgs(); | |
args.message = "Fuga"; | |
if (OnCustomEventHandler != null) OnCustomEventHandler (this, args); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
public class Receiver : MonoBehaviour { | |
void Start () { | |
this.gameObject.GetComponent<EventTest> ().OnCustomEventHandler += OnCustomEventHandler; | |
this.gameObject.GetComponent<EventTest> ().OnCustomEventHandler += delegate(object sender, CustomEventArgs e) | |
{ | |
print ("OnCustomEventHandler: "+ e.message); | |
}; | |
} | |
void OnCustomEventHandler (object sender, CustomEventArgs e) { | |
print ("OnCustomEventHandler: "+ e.message); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.Events; | |
[System.Serializable] | |
public class CustomUnityEvent : UnityEvent<string>{}; | |
public class EventTest : MonoBehaviour { | |
[SerializeField] public CustomUnityEvent OnCustomUnityEvent; | |
public void OnEvent () { | |
if(OnCustomUnityEvent != null) OnCustomUnityEvent.Invoke ("Fuga"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Receiver : MonoBehaviour { | |
void Start () { | |
this.gameObject.GetComponent<EventTest> ().OnCustomUnityEvent.AddListener(OnCustomUnityEventHandler); | |
this.gameObject.GetComponent<EventTest> ().OnCustomUnityEvent.AddListener(delegate(string s){ | |
print ("OnUnityEvent.AddListener: " + s); | |
}); | |
} | |
void OnCustomUnityEventHandler (string s) { | |
print ("OnCustomUnityEventHandler: "+ s); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
[RequireComponent(typeof (Receiver))] | |
public class EventTest : MonoBehaviour { | |
private Receiver receiver; | |
void OnEvent { | |
receiver = this.gameObject.GetComponent<Receiver> () as Receiver; | |
receiver.Hoge ("Fuga"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Receiver : MonoBehaviour { | |
public void Hoge (string s) { | |
print ("Hoge: "+s); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
public class EventTest : MonoBehaviour { | |
[SerializeField] public event EventHandler OnEventHandler; | |
public void OnEvent () { | |
if (OnEventHandler != null) OnEventHandler (this, EventArgs.Empty); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System; | |
public class Receiver : MonoBehaviour { | |
void Start () { | |
this.gameObject.GetComponent<EventTest> ().OnEventHandler += OnEventHandler; | |
this.gameObject.GetComponent<EventTest> ().OnEventHandler += delegate(object sender, EventArgs e) | |
{ | |
print ("OnEventHandler: "+ e); | |
}; | |
} | |
void OnEventHandler (object sender, EventArgs e) { | |
print ("OnEventHandler: "+ e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.EventSystems; | |
public class EventTest : MonoBehaviour { | |
public void OnEvent () { | |
ExecuteEvents.Execute<IReciever>(this.gameObject, null, (x,y)=>x.OnExecuteEventsHandler("Fuga")); | |
ExecuteEvents.Execute<IReciever>( | |
target: this.gameObject, | |
eventData: null, | |
functor: (x,y) => x.OnExecuteEventsHandler("Fuga")); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine.EventSystems; | |
public interface IReciever : IEventSystemHandler { | |
void OnExecuteEventsHandler(string s); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Receiver : MonoBehaviour, IReciever { | |
public void OnExecuteEventsHandler (string s) | |
{ | |
Debug.Log("OnExecuteEventsHandler: " + s); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.Events; | |
public class EventTest : MonoBehaviour { | |
public UnityEvent OnUnityEvent; | |
public void OnEvent () { | |
if(OnUnityEvent != null) OnUnityEvent.Invoke (); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Receiver : MonoBehaviour { | |
void Start () { | |
this.gameObject.GetComponent<EventTest> ().OnUnityEvent.AddListener(OnUnityEventHandler); | |
this.gameObject.GetComponent<EventTest> ().OnUnityEvent.AddListener(delegate(){ | |
print ("OnUnityEvent.AddListener"); | |
}); | |
} | |
void OnUnityEventHandler () { | |
print ("OnUnityEventHandler"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.gameObject.BroadcastMessage(methodName, argument); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.gameObject.SendMessage(methodName, argument); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment