Beispiel #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);
        }
Beispiel #2
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();
        }