Exemple #1
0
        /// <summary>
        /// Close the room
        /// </summary>
        /// <param name="roomToChangeLeftoverPlayersTo"></param>
        public void Close(Room roomToChangeLeftoverPlayersTo)
        {
            //TODO: close the room, move players to a new room or lobby or something

            foreach (var player in players)
            {
                player.ChangeRoom(roomToChangeLeftoverPlayersTo);
            }

            foreach (var routine in rootRoutines)
            {
                GameState.RemoveRoutine(routine);
            }
            rootRoutines = null;

            foreach (var act in m_Actors)
            {
                NetworkView.RemoveView(act.viewID.guid);
                GameObject.Destroy(act.gameObject);
            }
            m_Actors = null;

            foreach (var gobj in roomObjects)
            {
                GameObject.Destroy(gobj.Value.gameObject);
            }

            roomObjects = null;
            m_Players = null;
            phases = null;

            GC.Collect();
        }
Exemple #2
0
        public void MyTestInitialize()
        {
            _client = new TestablePNet();
            _client.TestableHook.StartUpdateThread();

            _testRoom = Room.CreateRoom("test room");
            _testRoom2 = Room.CreateRoom("test room 2");
        }
Exemple #3
0
        public void MyTestInitialize()
        {
            _client = new TestablePNet();
            _client.TestableHook.StartUpdateThread();

            _client.OnRoomChange += s => _client.FinishedRoomChange();
            PNetServer.OnPlayerConnected += player => player.ChangeRoom(_testRoom);

            _testRoom = Room.CreateRoom("test room");

            _client.Connect(TestablePNet.GetTestConnectionConfig());
            Thread.Sleep(250);
            _player = PNetServer.AllPlayers().First(f => f != null && f != Player.Server);
        }
Exemple #4
0
        /// <summary>
        /// Load a gameobject from a file
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="roomToInstantiateIn"></param>
        /// <param name="position"> </param>
        /// <param name="rotation"> </param>
        /// <param name="allowNetworkInstantiateIfHasNetworkView"></param>
        /// <param name="visibleToAll">makes all players in the room subscribed to the object</param>
        /// <param name="owner">owner of the loaded object if network instantiated.  By default, it is the server</param>
        /// <returns></returns>
        public static GameObject Load(string filePath, Room roomToInstantiateIn, bool allowNetworkInstantiateIfHasNetworkView = false, Vector3? position = null, Quaternion? rotation = null, bool visibleToAll = true, Player owner = null)
        {
            var dser = new GameObject();
            dser.Room = roomToInstantiateIn;
            var awakes = new List<Action>();
            var config = new YamlConfig();
            var actualFilePath = Path.Combine(ResourceFolder, filePath + ".prefab");

            config.AddActivator<GameObject>(() =>
            {
                //be returning an object we've already created, the AddComponent will work properly
                return dser;
            });

            //config.AddActivator < List<ComponentTracker>>(() =>
            //{
            //    return dser.components;
            //});

            var trackers = new Stack<GameObject.ComponentTracker>();

            config.AddActivator<GameObject.ComponentTracker>(() =>
            {
                var ntrack = new GameObject.ComponentTracker();
                trackers.Push(ntrack);
                return ntrack;
            });

            foreach (Type t in GetComponentTypes())
            {
                Type tLocal = t;
                if (tLocal == typeof(NetworkView) && !allowNetworkInstantiateIfHasNetworkView)
                {
                    Debug.LogWarning("[Resources.Load] file {0} has a NetworkView component on it, but was run as to not network instantiate. It will not be networked.", actualFilePath);
                }
                GameObject dser1 = dser;
                config.AddActivator(tLocal, () =>
                {
                    Action awake;
                    var ntrack = trackers.Pop();
                    var ret = dser1.DeserializeAddComponent(tLocal, out awake, ntrack);
                    awakes.Add(awake);
                    return ret;
                });
            }

            var serializer = new YamlSerializer(config);
            serializer.DeserializeFromFile(actualFilePath, typeof(GameObject));

            if (dser.Resource == null)
                dser.Resource = filePath;

            if (position.HasValue)
                dser.Position = position.Value;
            if (rotation.HasValue)
                dser.Rotation = rotation.Value;

            roomToInstantiateIn.OnGameObjectAdded(dser);

            foreach (var awake in awakes)
                if (awake != null) awake();
            
            dser.OnComponentAfterDeserialization();

            if (allowNetworkInstantiateIfHasNetworkView && dser.GetComponent<NetworkView>() != null)
                roomToInstantiateIn.ResourceNetworkInstantiate(dser, visibleToAll, owner);

            return dser;
        }
Exemple #5
0
        /// <summary>
        /// change the player to the specified room
        /// </summary>
        /// <param name="room"></param>
        public void ChangeRoom(Room room)
        {
            newRoom = room;

            if (currentRoom != null)
                currentRoom.RemovePlayer(this);

            var message = PNetServer.peer.CreateMessage();
            message.Write(RPCUtils.ChangeRoom);
            message.Write(room.name);

            connection.SendMessage(message, NetDeliveryMethod.ReliableOrdered, Channels.STATIC_UTILS);
        }
Exemple #6
0
 internal void FireLeaveRoom(Room roomLeaving)
 {
     if (LeavingRoom != null)
         LeavingRoom(roomLeaving);
 }
Exemple #7
0
        /// <summary>
        /// change the player to the specified room
        /// </summary>
        /// <exception cref="ThreadStateException">if GameState.InvokeRequired</exception>
        /// <param name="room"></param>
        public void ChangeRoom(Room room)
        {
            if (GameState.InvokeRequired)
                throw new ThreadStateException("Cannot change rooms on unless on gamestate's update thread");

            newRoom = room;

            if (CurrentRoom != null)
                CurrentRoom.RemovePlayer(this);
            CurrentRoom = null;

            var message = PNetServer.peer.CreateMessage();
            message.Write(RPCUtils.ChangeRoom);
            message.Write(room.Name);

            connection.SendMessage(message, NetDeliveryMethod.ReliableOrdered, Channels.STATIC_UTILS);
        }
Exemple #8
0
 internal Player()
 {
     CurrentRoom = null;
     
 }