/// <summary>
        /// Requests the server to spawn the gameObject across all clients and register it as a network entity
        /// </summary>
        public void RequestNetworkSpawn(GameObject obj, Vector3 pos, Quaternion rot)
        {
            int index = networkPrefabSpawner.GetPrefabIndex(obj);

            if (index < 0)
            {
                Debug.LogError("Unregistered prefab on Network Spawn Prefabs");
                return;
            }

            using (DarkRiftWriter writer = DarkRiftWriter.Create())
            {
                writer.Write((ushort)index);
                writer.Write(pos.x);
                writer.Write(pos.y);
                writer.Write(pos.z);
                if (rot == Quaternion.identity)
                {
                    using (Message message = Message.Create(Tags.spawnObjectTag, writer))
                    {
                        client.SendMessage(message, SendMode.Reliable);
                    }
                }
                else
                {
                    Vector3 rot_ = rot.eulerAngles;
                    writer.Write(rot_.x);
                    writer.Write(rot_.y);
                    writer.Write(rot_.z);
                    using (Message message = Message.Create(Tags.spawnObjectWithRotTag, writer))
                    {
                        client.SendMessage(message, SendMode.Reliable);
                    }
                }
            }
        }
示例#2
0
 public void FixedUpdate()
 {
     // Gets message/packet from Data.cs and sends them to all clients
     if (!client.SendMessage(dataClass.Get(), mode))
     {
         if (mode == DarkRift.SendMode.Reliable)
         {
             UnityEngine.Debug.LogWarning("Packet lost when using TCP/IP.");
         }
         else
         {
             UnityEngine.Debug.Log("Packet lost when using UDP.");
         }
     }
 }