protected static void ResponseRPC(int executeID, byte[] mArray) { object[] _array = mArray.DeserializeObject <object[]>(); int propertyID = (int)_array[0]; object[] parameters = (object[])_array[1]; //=====================================================================================================================// NeutronObject obj = neutronObjects[propertyID]; //=====================================================================================================================// RPCBehaviour[] scriptComponents = obj.GetComponentsInChildren <RPCBehaviour>(); //=====================================================================================================================// for (int i = 0; i < scriptComponents.Length; i++) { RPCBehaviour mInstance = scriptComponents[i]; MethodInfo Invoker = mInstance.HasRPC(executeID, out string message); if (Invoker != null) { Invoker.Invoke(mInstance, new object[] { new NeutronReader((byte[])parameters[0]) }); break; } else if (message != string.Empty) { LoggerError(message); } } }
protected static void HandleNavMeshAgent(int ownerID, Vector3 inputPoint) { NeutronObject obj = neutronObjects[ownerID]; if (obj.agent != null) { Neutron.Enqueue(() => obj.agent.SetDestination(inputPoint), ref monoBehaviourActions); } }
protected static void HandleNavMeshResync(int ownerID, Vector3 pos, Vector3 rot) { NeutronObject obj = neutronObjects[ownerID]; if (obj.agent != null) { obj.navMeshResync.position = pos.ToVector3(); obj.navMeshResync.rotation = rot.ToVector3(); } }
protected static void HandlePlayerDisconnected(byte[] player) { Player playerDisconnected = player.DeserializeObject <Player>(); //===================================================================================\\ NeutronObject obj = neutronObjects[playerDisconnected.ID]; //===================================================================================\\ Neutron.Enqueue(() => Destroy(obj.gameObject), ref monoBehaviourActions); //===================================================================================\\ neutronObjects.Remove(obj.Infor.ownerID); }
public void Awake() { if (TryGetComponent <NeutronObject>(out NeutronObject obj)) { isMine = obj; } else { isMine = transform.root.GetComponent <NeutronObject>(); } if (isMine == null && Neutron.NeutronObject == null) { Debug.LogError("RPC Behaviour depends it NeutronObject. Try Add"); } }
protected static void HandleJsonProperties(int ownerID, string properties) { NeutronObject obj = neutronObjects[ownerID]; //======================================================================\\ if (obj != null) { if (obj.myProperties != null) { JsonUtility.FromJsonOverwrite(properties, obj.myProperties); } else { Debug.LogError("Unable to find NeutronSyncBehaviour object!"); } } }
protected static void SendRPC(NeutronObject mThis, int RPCID, ValidationPacket validationType, object[] parameters, SendTo sendTo, bool cached, ProtocolType protocolType, Broadcast broadcast) { using (NeutronWriter writer = new NeutronWriter()) { object[] bArray = { mThis.Infor.ownerID, parameters }; //==========================================================================================================// writer.WritePacket(Packet.RPC); writer.WritePacket(broadcast); writer.Write(RPCID); writer.WritePacket(sendTo); writer.WritePacket(validationType); writer.Write(cached); writer.Write(bArray.Serialize()); //==========================================================================================================// Send(writer.GetBuffer(), protocolType); } }