예제 #1
0
 void Start()
 {
     if (isServer)
     {
         idCount++;
         id = idCount;
     }
     if (isPlayer)
     {
         id = 0;
     }
     objSync  = new ObjectSync(id, prefabId);
     position = new PositionSync(id, transform.position);
     rotation = new RotationSync(id, transform.rotation);
     if (!isServer)
     {
         ViewerManager.instance.synchronizables.Add(this);
     }
     if (isServer)
     {
         StartCoroutine(SyncPos());
         StartCoroutine(SyncRot());
         NetworkManager.instance.SendJSON("newenemy", JsonUtility.ToJson(objSync));
     }
 }
예제 #2
0
        public void Receive_Position(SocketIOEvent e)
        {
            PositionSync position = JsonUtility.FromJson <PositionSync> (e.data.ToString());

            for (int i = 0; i < synchronizables.Count; i++)
            {
                if (synchronizables [i].id == position.id)
                {
                    if (synchronizables [i].syncPosition)
                    {
                        synchronizables [i].transform.position = new Vector3(position.posX, position.posY, position.posZ);
                    }
                }
            }
        }