Skip to content

Instantly share code, notes, and snippets.

@ITEnot
Last active March 8, 2019 01:29
Show Gist options
  • Save ITEnot/aac78359c9c11180cfbe191eac5e0b82 to your computer and use it in GitHub Desktop.
Save ITEnot/aac78359c9c11180cfbe191eac5e0b82 to your computer and use it in GitHub Desktop.
public class GunsAnimSync : NetworkBehaviour
{
public delegate void RemoteFuncDelegate(string funcName, string objName);
[SyncEvent]
public event RemoteFuncDelegate EventInvoke;
[SerializeField]
public GunsClass[] _gunsList;
public List<Guns> syncGuns = new List<Guns>();
private void Start()
{
if (isLocalPlayer) {
foreach (GunsClass gun in _gunsList) {
var gunStr = new Guns(gun.transform.name, gun);
syncGuns.Add(gunStr);
}
}
EventInvoke += NetworkSync_EventInvoke;
}
public struct Guns
{
public string className;
public object gun;
public Guns(string _className, object _gun)
{
className = _className;
gun = _gun;
}
}
public void NetworkSync_EventInvoke(string funcName, string objName)
{
if (isLocalPlayer)
return;
var invObj = _gunsList.FirstOrDefault(t => t.name == objName);
invObj.Invoke(funcName, 0);
}
[Command]
public void CmdSendInvokeRequest(string funcName, string objName)
{
EventInvoke(funcName, objName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment