void RegistNewAutonomousObject(ClientDataContainer client, ReplicatiorBase replicatior, string PrefabName)
 {
     RegistNewReplicationObject(replicatior, PrefabName);
     replicatior.OwnerNetId = client.NetworkId;
     client.AutonomousObjects.Add(replicatior);
     OnNewAutonomousObjectAdded?.Invoke(replicatior);
 }
    void CreateAutonomousPrefab(string PrefabName, string ObjName, Vector3 pos, Vector3 eular, string ParentObjName, ClientDataContainer Owner)
    {
        string     path = "Prefabs/" + PrefabName;
        GameObject Pobj = (GameObject)Resources.Load(path), parentobj = GameObject.Find(ParentObjName), obj;

        if (parentobj != null)
        {
            obj = Instantiate(Pobj, pos, Quaternion.Euler(eular.x, eular.y, eular.z), parentobj.transform);
        }
        else
        {
            obj = Instantiate(Pobj, pos, Quaternion.Euler(eular.x, eular.y, eular.z));
        }
        ReplicatiorBase replicatior = obj.GetComponent <ReplicatiorBase>();

        if (replicatior == null)
        {
            Debug.Log("CreatingAutonomousPrefab Request Refused! Attach Replicator To Prefab!");
            Destroy(obj);
            return;
        }

        RegistNewAutonomousObject(Owner, replicatior, PrefabName);
        ClientDataList.ForEach((c) =>
        {
            if (c.TcpSocket != Owner.TcpSocket)
            {
                SendTcpPacket(c, encoding.GetBytes("NewRepObj," + PrefabName + "," + Serializer.Vector3ToString(pos) + "," + Serializer.Vector3ToString(eular) + "," + ParentObjName + "," + replicatior.Id));
            }
            else
            {
                SendTcpPacket(c, encoding.GetBytes("AutoObjAdded," + ObjName + "," + replicatior.Id));
            }
        });
    }
    /// <summary>
    /// Create Gameobject replicated On all Client. On LocalHost, Object beact as LocalPrefab. On Client, Object beact as NetworkPrefab. <!warning> Prefab must contain Replicator!
    /// </summary>
    /// <paramref name="LocalPrefabName"/> Local Replicated Object. Search in Resources/Prefabs/...
    /// <param name="NetworkPrefabName"> Replicated Object On Networking. Search in Resources/Prefabs/... </param>
    /// <param name="pos"></param>
    /// <param name="eular"></param>
    /// <param name="ParentObjName"></param>
    /// <returns></returns>
    public GameObject CreateNetworkPrefab(string LocalPrefabName, string NetworkPrefabName, Vector3 pos, Vector3 eular, string ParentObjName)
    {
        string     path = "Prefabs/" + LocalPrefabName;
        GameObject Pobj = (GameObject)Resources.Load(path), parentobj = GameObject.Find(ParentObjName), obj;

        if (parentobj != null)
        {
            obj = Instantiate(Pobj, pos, Quaternion.Euler(eular.x, eular.y, eular.z), parentobj.transform);
        }
        else
        {
            obj = Instantiate(Pobj, pos, Quaternion.Euler(eular.x, eular.y, eular.z));
        }
        ReplicatiorBase replicatior = obj.GetComponent <ReplicatiorBase>();

        if (replicatior == null)
        {
            Debug.Log("CreatingNetworkPrefab Request Refused! Attach Replicator To Prefab!");
            Destroy(obj);
            return(null);
        }
        RegistNewReplicationObject(replicatior, NetworkPrefabName);
        ClientDataList.ForEach((c) =>
        {
            SendTcpPacket(c, encoding.GetBytes("NewRepObj," + NetworkPrefabName + "," + Serializer.Vector3ToString(pos) + "," +
                                               Serializer.Vector3ToString(eular) + "," + ParentObjName + "," + replicatior.Id + "," + replicatior.OwnerNetId));
        });
        return(obj);
    }
Example #4
0
 public void DestroyAutonomousObject(ReplicatiorBase replicatior)
 {
     SendTcpPacket(encoding.GetBytes("DestAutoObj," + replicatior.Id));
     RepObjPairs.Remove(replicatior.Id);
     AutonomausObjects.Remove(replicatior);
     Destroy(replicatior.gameObject);
 }
 void RegistNewReplicationObject(ReplicatiorBase replicatior, string PrefabName)
 {
     RepObjects.Add(replicatior);
     replicatior.Id            = ObjIdBuffer;
     replicatior.RepPrefabName = PrefabName;
     RepObjPairs.Add(ObjIdBuffer++, replicatior);
     OnNewRepObjectAdded?.Invoke(replicatior);
 }
 /// <summary>
 /// Replicate Object as RepPrefabObj
 /// </summary>
 /// <param name="replicatior"></param>
 /// <param name="RepPrefabName"></param>
 public void StartReplicateObject(ReplicatiorBase replicatior, string RepPrefabName)
 {
     RegistNewReplicationObject(replicatior, RepPrefabName);
     ClientDataList.ForEach((c) =>
     {
         SendTcpPacket(c, encoding.GetBytes("NewRepObj," + RepPrefabName + "," + Serializer.Vector3ToString(replicatior.transform.position) + "," +
                                            Serializer.Vector3ToString(replicatior.transform.eulerAngles) + "," + replicatior.transform.parent.gameObject.name + "," + replicatior.Id + "," + replicatior.OwnerNetId));
     });
 }
Example #7
0
 void AddNewReplicatedObject(ReplicatiorBase replicatior, int Id, byte OwnerId)
 {
     replicatior.Id             = Id;
     replicatior.OwnerNetId     = OwnerId;
     replicatior.LocalHostNetId = NetworkId;
     RepObjPairs.Add(Id, replicatior);
     if (OnNewRepObjectAdded != null)
     {
         OnNewRepObjectAdded.Invoke(replicatior);
     }
 }
Example #8
0
 public void RequestRPCOnOtherClient(ReplicatiorBase RPCTarget, string MethodName, string arg, byte ClientId)
 {
     if (ClientId == NetworkId)
     {
         ProcessRPC(RPCTarget.Id, MethodName, arg);
     }
     else
     {
         SendTcpPacket(encoding.GetBytes("RPCOC," + ClientId + "," + RPCTarget.Id + "," + MethodName + "," + arg));
     }
 }
Example #9
0
    void AddAdmittedAutonomousObject(string ObjName, int ObjId)
    {
        GameObject obj = GameObject.Find(ObjName);

        if (obj == null)
        {
            return;
        }

        ReplicatiorBase replicatior = obj.GetComponent <ReplicatiorBase>();

        AddNewReplicatedObject(replicatior, ObjId, NetworkId);
        AutonomausObjects.Add(replicatior);
        if (OnNewAutonomousObjectAdmitted != null)
        {
            OnNewAutonomousObjectAdmitted.Invoke(replicatior);
        }

        Debug.Log("New Autonomous Object : " + ObjName);
    }
Example #10
0
    GameObject CreateReplicatedPrefab(string PrefabName, Vector3 pos, Vector3 eular, string ParentObj, int ObjId, byte OwnerId)
    {
        if (RepObjPairs.TryGetValue(ObjId, out ReplicatiorBase r))
        {
            return(null);
        }
        string     path = "Prefabs/" + PrefabName;
        GameObject Pobj = (GameObject)Resources.Load(path), parentobj = GameObject.Find(ParentObj), obj;

        if (parentobj != null)
        {
            obj = Instantiate(Pobj, pos, Quaternion.Euler(eular.x, eular.y, eular.z), parentobj.transform);
        }
        else
        {
            obj = Instantiate(Pobj, pos, Quaternion.Euler(eular.x, eular.y, eular.z));
        }
        ReplicatiorBase replicatior = obj.GetComponent <ReplicatiorBase>();

        AddNewReplicatedObject(replicatior, ObjId, OwnerId);
        return(obj);
    }
Example #11
0
 void NewObjCreated(ReplicatiorBase replicatior)
 {
     replicatior.gameObject.transform.FindChild("man-astronaut_Rig").FindChild("Geometry").FindChild("man-astronaut").gameObject.GetComponent <Renderer>().material.color = Mats[replicatior.LocalHostNetId];
 }
Example #12
0
 public void RequestRPCMultiCast(ReplicatiorBase RPCTarget, string MethodName, string arg)
 {
     SendTcpPacket(encoding.GetBytes("RPCMC," + RPCTarget.Id + "," + MethodName + "," + arg));
 }
Example #13
0
 /// <summary>
 /// Send creating autonomous object request to server <!waring!> Autonomous Object must have One and Only Name!
 /// </summary>
 /// <param name="replicatior">Autonomous obj</param>
 /// <param name="ObjName">Identity of autonomous obj</param>
 /// <param name="ReplicatedPrefabName">Name of prefab replicated on others</param>
 /// <param name="pos">replicated prefab initial position</param>
 /// <param name="eular">replicated prefab initial eularAngle</param>
 /// <param name="ParentName">replicated prefab initial parent name</param>
 public void RequestCreatingNewAutonomousObject(ReplicatiorBase replicatior, string ReplicatedPrefabName, Vector3 pos, Vector3 eular, string ParentName)
 {
     SendTcpPacket(encoding.GetBytes("NewAutoObj," + ReplicatedPrefabName + "," + replicatior.gameObject.name + "," + Serializer.Vector3ToString(pos) +
                                     "," + Serializer.Vector3ToString(eular) + "," + ParentName));
 }