Ejemplo n.º 1
0
    private void PlayerAccepted(NetworkingPlayer player)
    {
        Debug.Log($"Player: {player.InstanceGuid} accepted.");

        if (Players.ContainsKey(player.InstanceGuid))
        {
            return;
        }
        var teamID = 0;

        if (Players.Count % 2 > 0)
        {
            teamID = 1;
        }

        var playerModel = new PlayerModel()
        {
            ID        = player.InstanceGuid,
            PlayerID  = (int)player.NetworkId,
            TeamID    = teamID,
            Name      = $"player{(int)player.NetworkId}",
            NetworkID = player.NetworkId
        };

        Players.Add(playerModel.ID, playerModel);
        RPCInterface.PlayerJoinedGame(playerModel);
    }
        /// <summary>
        /// Initializes a new instance of the class <see cref="MixedRealityExtensionApp"/>
        /// </summary>
        /// <param name="globalAppId">The global id of the app.</param>
        /// <param name="ownerScript">The owner mono behaviour script for the app.</param>
        internal MixedRealityExtensionApp(string globalAppId, MonoBehaviour ownerScript, IMRELogger logger = null)
        {
            GlobalAppId     = globalAppId;
            _ownerScript    = ownerScript;
            EventManager    = new MWEventManager(this);
            _assetLoader    = new AssetLoader(ownerScript, this);
            _userManager    = new UserManager(this);
            _actorManager   = new ActorManager(this);
            SoundManager    = new SoundManager(this);
            _commandManager = new CommandManager(new Dictionary <Type, ICommandHandlerContext>()
            {
                { typeof(MixedRealityExtensionApp), this },
                { typeof(Actor), null },
                { typeof(AssetLoader), _assetLoader },
                { typeof(ActorManager), _actorManager }
            });

            RPC         = new RPCInterface(this);
            RPCChannels = new RPCChannelInterface();
            // RPC messages without a ChannelName will route to the "global" RPC handlers.
            RPCChannels.SetChannelHandler(null, RPC);
#if ANDROID_DEBUG
            Logger = logger ?? new UnityLogger(this);
#else
            Logger = logger ?? new ConsoleLogger(this);
#endif
        }
Ejemplo n.º 3
0
    private void PlayerDisconnected(NetworkingPlayer player)
    {
        Debug.Log($"Player: {player.NetworkId} disconnected.");

        if (Players.ContainsKey(player.InstanceGuid))
        {
            var playerModel = Players[player.InstanceGuid];
            Players.Remove(player.InstanceGuid);
            RPCInterface.PlayerLeftGame(playerModel.TeamID, playerModel.PlayerID, playerModel.NetworkID);
        }
    }
Ejemplo n.º 4
0
    public void PlayerChangeTeams(string playerGUID)
    {
        if (Players.ContainsKey(playerGUID))
        {
            var player    = Players[playerGUID];
            var newTeamID = 0;
            if (player.TeamID == 0)
            {
                newTeamID = 1;
            }

            player.TeamID = newTeamID;
            RPCInterface.PlayerChangeTeams(player);

            SharedEvents.OnPlayerChangedTeam?.Invoke(player);
        }
    }
        /// <summary>
        /// Initializes a new instance of the class <see cref="MixedRealityExtensionApp"/>
        /// </summary>
        /// <param name="globalAppId">A string uniquely identifying the MRE behind the server URL. Used for generating
        /// consistent user IDs when user tracking is enabled.</param>
        /// <param name="ephemeralAppId">A string uniquely identifying the MRE instance in the shared space across
        /// all clients. Used for generating user IDs when user tracking is disabled.</param>
        /// <param name="ownerScript">The owner mono behaviour script for the app.</param>
        internal MixedRealityExtensionApp(string globalAppId, string ephemeralAppId, Node ownerScript, IMRELogger logger = null)
        {
            GlobalAppId    = globalAppId;
            EphemeralAppId = ephemeralAppId;
            _ownerScript   = ownerScript;
            EventManager   = new MWEventManager(this);
            _assetLoader   = new AssetLoader(ownerScript, this);
            _userManager   = new UserManager(this);
            _actorManager  = new ActorManager(this);

            if (Constants.UsePhysicsBridge)
            {
                PhysicsBridge = new PhysicsBridge();
            }

            SoundManager     = new SoundManager(this);
            AnimationManager = new AnimationManager(this);
            _commandManager  = new CommandManager(new Dictionary <Type, ICommandHandlerContext>()
            {
                { typeof(MixedRealityExtensionApp), this },
                { typeof(Actor), null },
                { typeof(AssetLoader), _assetLoader },
                { typeof(ActorManager), _actorManager },
                { typeof(AnimationManager), AnimationManager }
            });

            var cacheRoot = new Node()
            {
                Name = "MRE Cache"
            };

            _ownerScript.AddChild(cacheRoot);
            cacheRoot.SetProcess(false);
            _assetManager = new AssetManager(this, cacheRoot);

            RPC         = new RPCInterface(this);
            RPCChannels = new RPCChannelInterface();
            // RPC messages without a ChannelName will route to the "global" RPC handlers.
            RPCChannels.SetChannelHandler(null, RPC);
#if ANDROID_DEBUG
            Logger = logger ?? new UnityLogger(this);
#else
            Logger = logger ?? new ConsoleLogger(this);
#endif
        }
        /// <summary>
        /// Initializes a new instance of the class <see cref="MixedRealityExtensionApp"/>
        /// </summary>
        /// <param name="globalAppId">The global id of the app.</param>
        /// <param name="ownerScript">The owner mono behaviour script for the app.</param>
        internal MixedRealityExtensionApp(string globalAppId, MonoBehaviour ownerScript)
        {
            GlobalAppId     = globalAppId;
            _ownerScript    = ownerScript;
            EventManager    = new MWEventManager(this);
            _assetLoader    = new AssetLoader(ownerScript, this);
            _userManager    = new UserManager(this);
            _actorManager   = new ActorManager(this);
            SoundManager    = new SoundManager(this);
            _commandManager = new CommandManager(new Dictionary <Type, ICommandHandlerContext>()
            {
                { typeof(MixedRealityExtensionApp), this },
                { typeof(Actor), null },
                { typeof(AssetLoader), _assetLoader },
                { typeof(ActorManager), _actorManager }
            });

            RPC = new RPCInterface(this);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the class <see cref="MixedRealityExtensionApp"/>
        /// </summary>
        /// <param name="globalAppId">The global id of the app.</param>
        /// <param name="ownerScript">The owner mono behaviour script for the app.</param>
        internal MixedRealityExtensionApp(string globalAppId, MonoBehaviour ownerScript, IMRELogger logger = null)
        {
            GlobalAppId   = globalAppId;
            _ownerScript  = ownerScript;
            EventManager  = new MWEventManager(this);
            _assetLoader  = new AssetLoader(ownerScript, this);
            _userManager  = new UserManager(this);
            _actorManager = new ActorManager(this);

            UsePhysicsBridge = Constants.UsePhysicsBridge;

            if (UsePhysicsBridge)
            {
                _physicsBridge = new PhysicsBridge();
            }

            SoundManager     = new SoundManager(this);
            AnimationManager = new AnimationManager(this);
            _commandManager  = new CommandManager(new Dictionary <Type, ICommandHandlerContext>()
            {
                { typeof(MixedRealityExtensionApp), this },
                { typeof(Actor), null },
                { typeof(AssetLoader), _assetLoader },
                { typeof(ActorManager), _actorManager },
                { typeof(AnimationManager), AnimationManager }
            });

            var cacheRoot = new GameObject("MRE Cache");

            cacheRoot.transform.SetParent(_ownerScript.gameObject.transform);
            cacheRoot.SetActive(false);
            _assetManager = new AssetManager(this, cacheRoot);

            RPC         = new RPCInterface(this);
            RPCChannels = new RPCChannelInterface();
            // RPC messages without a ChannelName will route to the "global" RPC handlers.
            RPCChannels.SetChannelHandler(null, RPC);
#if ANDROID_DEBUG
            Logger = logger ?? new UnityLogger(this);
#else
            Logger = logger ?? new ConsoleLogger(this);
#endif
        }