コード例 #1
0
        /// <summary>
        /// Removes a WorldObject on clients.
        /// </summary>
        /// <param name="data"></param>
        private void ClientRemoveWorldObject(WorldObjectData data)
        {
            WorldObject wo = ReturnWorldObject(data);

            //If WorldObject was found.
            if (wo != null)
            {
                /* Update WorldObject with new data. This is because
                 * even though the WorldObject is removed, it may have
                 * already existed in the scene thus cannot
                 * be destroyed, but rather hidden. Updating
                 * the WorldObject will hide the WorldObject and if it does
                 * need to be destroyed that will occur after
                 * the update. */
                wo.UpdateData(data);

                //If was spawned then destroy WorldObject.
                if (data.Instantiated)
                {
                    Destroy(wo.gameObject);
                }
            }
            //Not found.
            else
            {
                Debug.LogError("Could not find WorldObject data in WorldObjects collection. This can occur when added or removed WorldObjects are not properly handled on clients.");
            }
        }
コード例 #2
0
        public void RemoveWorldObject(WorldObject wo)
        {
            WorldObjectData data = wo.ReturnData();

            //WorldObject was modified so do a dirty update.
            UpdateDirty(wo, DirtyUpdateReasons.Removed);

            //If spawned.
            if (data.Instantiated)
            {
                //Only remove from WorldObjects if spawned.
                _worldObjects.Remove(data.Key);

                /* If spawned WorldObject then add key to cache.
                 * Cannot cache WorldObjects placed in editor(not spawned) as
                 * they aren't actually destroyed, and remain
                 * in scene. */
                _cachedKeys.Push(data.Key);

                /* This is a spawned WorldObject so it's safe to destroy;
                 * new clients do not need to know about spawned WorldObjects
                 * which were destroyed before they joined. */
                Destroy(wo.gameObject);
            }

            RpcRemoveWorldObject(new WorldObjectData[] { data });
        }
コード例 #3
0
        /// <summary>
        /// Returns WorldObject associated with data.
        /// </summary>
        /// <param name="data"></param>
        private WorldObject ReturnWorldObject(WorldObjectData data)
        {
            WorldObject result;

            _worldObjects.TryGetValue(data.Key, out result);

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Updates a WorldObject on clients.
        /// </summary>
        /// <param name="data"></param>
        private void ClientUpdateWorldObject(WorldObjectData data)
        {
            WorldObject wo = ReturnWorldObject(data);

            //If WorldObject was found.
            if (wo != null)
            {
                wo.UpdateData(data);
            }
            //Not found.
            else
            {
                Debug.LogError("Could not find WorldObject data in WorldObjects collection. This can occur when added or removed WorldObjects are not properly handled on clients.");
            }
        }
コード例 #5
0
        public static void WriteWorldObjectData(this NetworkWriter writer, WorldObjectData data)
        {
            writer.WriteInt32((int)data.ObjectType);
            writer.WriteUInt32(data.Key);
            writer.WriteBoolean(data.Instantiated);

            //Ïsland type.
            if (data is IslandObjectData od)
            {
                writer.WriteByte((byte)od.TreeState);
            }

            //Tree type.
            if (data is TreeObjectData op)
            {
                writer.WriteByte((byte)op.TreeState);
            }
        }
コード例 #6
0
        public void InitializeWorldObject(WorldObject wo, WorldObjectTypes objectType)
        {
            if (wo == null || wo.gameObject == null)
            {
                Debug.LogError("You must first InstantiateWorldObject, and use the result within InitializeWorldObject.");
                return;
            }

            WorldObjectData data = wo.ReturnData();

            data.SetKey(ReturnNextKey());
            data.SetObjectType(objectType);
            data.SetInstantiated(true);
            //Update WorldObjects data with newly generated data.
            wo.UpdateData(data);
            //Add to WorldObjects collection.
            _worldObjects[data.Key] = wo;
            //WorldObject was modified so do a dirty update.
            UpdateDirty(wo, DirtyUpdateReasons.Instantiated);
            //Generate new added WorldObject and send to clients.
            AddedWorldObjectData addedWorldObject = new AddedWorldObjectData(wo.transform.position, wo.transform.rotation, data);

            RpcAddWorldObject(new AddedWorldObjectData[] { addedWorldObject });
        }
コード例 #7
0
 public override void UpdateData(WorldObjectData data)
 {
     Data = (TreeObjectData)data;
     ApplyStateVisuals();
 }
コード例 #8
0
 /// <summary>
 /// Updates this object's data.
 /// </summary>
 public virtual void UpdateData(WorldObjectData data)
 {
 }
コード例 #9
0
 public AddedWorldObjectData(Vector3 position, Quaternion rotation, WorldObjectData data)
 {
     Position = position;
     Rotation = rotation;
     Data     = data;
 }