Exemple #1
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);
        }
Exemple #2
0
        /// <summary>
        /// This method is checking every certain amount of seconds for new loaded streamed areas to update data that is waiting for a streamed terrain to be loaded.
        /// </summary>
        /// <returns></returns>
        protected IEnumerator CheckForStreamingBufferedUpdates()
        {
            while (true)
            {
                BaseUNNetworkData.CheckForStreamedData();

                yield return(new WaitForSeconds(STREAM_UPDATE_CHECK_INTERVAL_SECONDS));
            }
        }
        /// <summary>
        /// Unpack the data
        /// </summary>
        public override void UnPack()
        {
            base.UnPack();

            var       terrains = UNTerrain.terrains;
            Terrain   terrain;
            UNTerrain unTerrainComponent;

            for (int i = 0; i < terrains.Count; i++)
            {
                unTerrainComponent = terrains[i];
                terrain            = unTerrainComponent.terrain;

                if (terrain.name == terrainID)
                {
                    if (eventType == PacketType.HealthUpdate)
                    {
                        BaseUNNetworkData data = null;

                        if (!bufferedData.Contains(this))
                        {
                            bufferedData.Add(this);
                            data = this;
                        }
                        else
                        {
                            for (int b = 0; b < bufferedData.Count; b++)
                            {
                                if (this.Equals(bufferedData[b]))
                                {
                                    data = bufferedData[b];
                                    break;
                                }
                            }
                        }

                        if (data != null)
                        {
                            if (data.minHealth == -1 && data.maxHealth == -1)
                            {
                                TreeInstance          treeInstance         = terrain.terrainData.GetTreeInstance(data.treeInstanceID);
                                HarvestableTIPoolItem harvestableComponent = terrain.terrainData.treePrototypes[treeInstance.prototypeIndex].prefab.GetComponent <HarvestableTIPoolItem>();

                                if (harvestableComponent != null)
                                {
                                    data.minHealth = harvestableComponent.minHealth;
                                    data.maxHealth = harvestableComponent.maxHealth;
                                }
                            }

                            data.health = health;
                        }
                    }

                    break;
                }
                else if (i == terrains.Count - 1)
                {
                    BaseUNNetworkData.WaitingForStreamData.Add(this);
                }
            }
        }