//Action is a invokeable container for Mehod or function method
//that doesnt return anything. They can accept inputs based on the generals
//that you template on. If you need a return check out the Func Class
//example:
Action YourActionProperty = new Action(()=>{/*do something*/});
//or
Action YourActionProperty = ()=>{/*do something*/};
//or
Action<int/*Or some other types followed by others comma seperated*/>
YourParamitarizedActionProperty =
(x/*Each Param will be to the comma seperated types*/)=>
{/*do some with the inputs*/});
// you can invloke them by calling their invokes.
YourActionProperty.Invoke();
YourParamitarizedActionProperty.Invoke(5);
//The last is the basic sycronous way. For a aysnc call uses
YourActionProperty.BeginInvoke();
YourParamitarizedActionProperty.BeginInvoke(5);
//although awaiting is not required should you need to await a aysnc call use
YourActionProperty.EndInvoke();
//You can also fill them with defined methods in a class if you wish,
//but the signatures must match.
Action YourActionDefinedProperty = YourDefinedMethod;
void YourDefinedMethod()
{
//do something
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class ActionDemo : MonoBehaviour {
void Start(){
Action<string> SampleAction; //action dont need an explicit delegate to be declared (Action is special kind of delegate which takes parameters but returns nothing)
SampleAction = PrintMsg;
SampleAction += delegate(string s) {Debug.Log("from anonymous method : "+s);} ; //using anonymous method
SampleAction += s => Debug.Log("using lambda expression : "+s); //using lambda expression
SampleAction ("Hello shrinath");
}
void PrintMsg(string msg1){
Debug.Log ("msg : " + msg1);
}
}