Example #1
0
 /// <summary>
 /// Send event to the correct location
 /// </summary>
 /// <param name="instance">the data instance</param>
 public virtual void SendEvent(UNNetworkData <T1> instance)
 {
     if (isServer || !isAuth)
     {
         SendToOthers(instance);
     }
 }
Example #2
0
        /// <summary>
        /// Update item damage and handle synchorization.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="health"></param>
        protected void OnItemDamaged(HarvestableTIPoolItem item, int damage)
        {
            if (!item.isCollider)
            {
                return;
            }

            BaseUNNetworkData data    = null;
            BaseUNNetworkData current = null;

            for (int i = 0; i < bufferedData.Count; i++)
            {
                current = bufferedData[i];

                if (current.treeInstanceID == item.uid && current.terrainID == item.terrain.name)
                {
                    current.health -= damage;
                    data            = current;

                    break;
                }
            }

            if (data == null)
            {
                data = UNNetworkData <T1> .Pack <T1, T2>(item.terrain, item.uid, item.health, PacketType.HealthUpdate);

                bufferedData.Add(data as T2);
            }

            SendEvent(data as T2);
        }
Example #3
0
        /// <summary>
        /// Create equal state which checks whether those 2 instances of NetworkData are equal
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            UNNetworkData <T> instance = obj as UNNetworkData <T>;

            if (obj == null)
            {
                return(false);
            }

            bool result = instance.terrainID == this.terrainID && instance.treeInstanceID == this.treeInstanceID;

            return(result);
        }
Example #4
0
        /// <summary>
        /// The constructor of this class, initiate basic events.
        /// </summary>
        public UNNetworkManager(MonoBehaviour managerInstance)
        {
            manager = this;

            TerrainPoolItem.OnTreeInstanceRestored += (Terrain terrain, int id) =>
            {
                UNNetworkData <T1> instance;
                instance = UNNetworkData <T1> .Pack <T1, T2>(terrain, id, 0, PacketType.HealthUpdate);

                var similarItem = bufferedData.TryGet(instance as T2);
                bufferedData.Remove(similarItem);

                //SendEvent(instance);
            };

            HarvestableTIPoolItem.OnItemDamagedEvent += OnItemDamaged;
            HarvestableTIPoolItem.OnItemPooledEvent  += OnHarvestableTreeInstancePooled;

            managerInstance.StartCoroutine(CheckForStreamingBufferedUpdates());

            Awake();
        }
Example #5
0
 /// <summary>
 /// Send to the server the data.
 /// </summary>
 /// <param name="terrainName">the terrain name (terrain.name)</param>
 /// <param name="instanceID">the tree instance</param>
 /// <param name="destroy">you want to destroy/ restore the tree?</param>
 public virtual void SendToServer(UNNetworkData <T1> instance)
 {
     instance.SendToServer();
 }
Example #6
0
 /// <summary>
 /// Send to all other connections.
 /// </summary>
 /// <param name="terrainName">the terrain name (terrain.name)</param>
 /// <param name="instanceID">the tree instance</param>
 /// <param name="destroy">you want to destroy/ restore the tree?</param>
 public virtual void SendToOthers(UNNetworkData <T1> instance)
 {
     instance.SendToOthers();
 }
Example #7
0
 /// <summary>
 /// Send to all of the clients.
 /// </summary>
 /// <param name="terrainName">the terrain name (terrain.name)</param>
 /// <param name="instanceID">the tree instance</param>
 /// <param name="destroy">you want to destroy/ restore the tree?</param>
 public virtual void SendToClients(UNNetworkData <T1> instance)
 {
     instance.SendToClients();
 }
Example #8
0
 /// <summary>
 /// Send to certain connection the data
 /// </summary>
 /// <param name="connection">the connection</param>
 /// <param name="terrainName">the terrain name (terrain.name)</param>
 /// <param name="instanceID">the tree instance</param>
 /// <param name="destroy">you want to destroy/ restore the tree?</param>
 public virtual void SendToConnection(T1 connection, UNNetworkData <T1> instance)
 {
     instance.SendToConnection(connection);
 }