Exemple #1
0
 public void Instantiate(string path, NetworkView newView, Vector3 location, Quaternion rotation)
 {
     Console.WriteLine("{0} instantiated", path);
     Instantiates.Add(path, newView);
 }
Exemple #2
0
        private void ProcessUtils(NetIncomingMessage msg)
        {
            var utilId = msg.ReadByte();

            if (utilId == RPCUtils.TimeUpdate)
            {
                throw new NotImplementedException("RPCUtils.TimeUpdate");
            }
            else if (utilId == RPCUtils.Instantiate)
            {
                //read the path...
                var resourcePath = msg.ReadString();
                var viewId = NetworkViewId.Deserialize(msg);
                var ownerId = msg.ReadUInt16();

                var position = new Vector3();
                position.OnDeserialize(msg);
                var rotation = new Quaternion();
                rotation.OnDeserialize(msg);

                var view = NetworkViewManager.Create(viewId, ownerId);

                try
                {
                    EngineHook.Instantiate(resourcePath, view, position, rotation);
                }
                catch(Exception e)
                {
                    Debug.LogError(this, "[EngineHook.Instantiate] {0}", e);
                }

                Debug.Log(this, "Created {0}", view);

                view.DoOnFinishedCreation();
                
                FinishedInstantiate(viewId);
            }
            else if (utilId == RPCUtils.Remove)
            {

                var viewId = new NetworkViewId();
                viewId.OnDeserialize(msg);
                byte reasonCode;
                if (!msg.ReadByte(out reasonCode))
                    reasonCode = 0;

                NetworkView find;
                if (NetworkViewManager.Find(viewId, out find))
                {
                    find.DoOnRemove(reasonCode);
                }
                else
                {
                    Debug.LogError(this, "Attempted to remove {0}, but it could not be found", viewId);
                }
            }
            else if (utilId == RPCUtils.ChangeRoom)
            {
                var newRoom = msg.ReadString();

                Debug.LogInfo(this, "Changing to room {0}", newRoom);

                if (OnRoomChange != null)
                {
                    try
                    {
                        OnRoomChange(newRoom);
                    }
                    catch(Exception e)
                    {
                        Debug.LogError(this, "[OnChangeRoom] {0}", e);
                    }
                }

                if (Configuration.DeleteNetworkInstantiatesOnRoomChange)
                {
                    NetworkViewManager.DestroyAllViews();
                }
            }
            else if (utilId == RPCUtils.AddView)
            {
                var addToId = NetworkViewId.Deserialize(msg);
                var idToAdd = NetworkViewId.Deserialize(msg);
                string customFunction;
                msg.ReadString(out customFunction);


                NetworkView view;
                if (NetworkViewManager.Find(addToId, out view))
                {
                    var newView = NetworkViewManager.Create(idToAdd, view.OwnerId);

                    try
                    {
                        EngineHook.AddNetworkView(view, newView, customFunction);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(this, "[EngineHook.AddNetworkView] {0}", e);
                    }
                }
                else
                {
                    Debug.LogError(this, "Attempted to add a network view to id {0}, but it could not be found");
                }
            }
            else if (utilId == RPCUtils.SetPlayerId)
            {
                var playerId = msg.ReadUInt16();
                PlayerId = playerId;
                Debug.LogInfo(this, "Setting player id to " + playerId);
            }
        }