protected virtual void OnDisable()
 {
     if (activeGameMode == this)
     {
         activeGameMode = null;
     }
 }
Beispiel #2
0
    public GameModeBase LoadGameMode(Type t)
    {
        if (!t.IsSubclassOf(typeof(GameModeBase)))
        {
            Debug.Log("type is not a game mode");
            return(null);
        }

        GameModeBase preGm = mGameMode;

        mGameMode = (GameModeBase)Activator.CreateInstance(t);
        if (mGameMode == null)
        {
            Debug.LogError("Load Game Mode " + t.FullName + " fail");
            return(null);
        }
        mGameMode.Init();

        if (preGm != null)
        {
            preGm.OnRelease();
        }

        return(mGameMode);
    }
    void OnEnable()
    {
        SerializedProperty mgrGameModesArray = serializedObject.FindProperty("allGameModes");

        mgrGameModesArray.ClearArray();
        mgrGameModesArray.arraySize = 0;


        //Find the GUID of all assets in the gameModeFolder
        string[] allGameModesGUIDs = AssetDatabase.FindAssets("", new string[] { gameModeFolder });

        foreach (string GUID in allGameModesGUIDs)
        {
            //Get the asset path from the GUID
            string assetPath = AssetDatabase.GUIDToAssetPath(GUID);

            //Load the asset
            GameModeBase gameMode = AssetDatabase.LoadAssetAtPath <GameModeBase>(assetPath);

            mgrGameModesArray.arraySize++;
            mgrGameModesArray.GetArrayElementAtIndex(mgrGameModesArray.arraySize - 1).objectReferenceValue = gameMode;
        }

        serializedObject.ApplyModifiedPropertiesWithoutUndo();
    }
    public override void Disconnected(BoltConnection connection)
    {
        base.Disconnected(connection);

        Debug.Log("Player connected. Connection: " + connection);
        GameModeBase.GetActiveGameMode().SV_OnPlayerDisconnected(connection);
    }
Beispiel #5
0
 protected virtual void Awake()
 {
     if (_gameMode == null)
     {
         _gameMode = this;
     }
     DontDestroyOnLoad(this.gameObject);
 }
Beispiel #6
0
    private void OnConfigLoaded()
    {
        Debug.Log("config loaded");
        Game = (NormalMode)GameModeBase.CreateGameMode("Normal");
        Game.Init();
        Game.StartGame();

        Destroy(gameObject);
    }
Beispiel #7
0
        /// <summary>
        /// Load Game Mode and initialize components.
        /// </summary>
        private void SetupGameMode()
        {
            m_currentModeBase = PhotonNetwork.CurrentRoom.GetGameMode();
            m_currentModeBase.HandlePlayer();

            OnReceivedGameMode?.Invoke(m_currentModeBase);

            m_currentModeBase.OnConditionReached += OnMatchEnd;
        }
Beispiel #8
0
    private static void HandleGameModeAssets()
    {
        //This will be called when unity reloads scripts


        //Make sure the GameModes folder exists
        CreateFolder(GameModeMgrEditor.gameModeFolder);


        //Find the GUID of all assets in the gameModeFolder
        string[] allGameModesGUIDs = AssetDatabase.FindAssets("", new string[] { GameModeMgrEditor.gameModeFolder });

        GameModeBase[] allGameModes = new GameModeBase[allGameModesGUIDs.Length];

        int GUIDIndex = 0;

        foreach (string GUID in allGameModesGUIDs)
        {
            //Get the asset path from the GUID
            string assetPath = AssetDatabase.GUIDToAssetPath(GUID);

            //Load the asset
            GameModeBase gameMode = AssetDatabase.LoadAssetAtPath <GameModeBase>(assetPath);

            //Make sure the script hasnt been deleted
            if (gameMode != null)
            {
                //Add it to the array
                allGameModes[GUIDIndex] = gameMode;
            }
            else
            {
                //The script has been deleted. Delete the asset file as well
                Debug.Log("Missing script file for GameMode '" + System.IO.Path.GetFileNameWithoutExtension(assetPath) + "', deleting.");
                AssetDatabase.DeleteAsset(assetPath);
            }

            GUIDIndex++;
        }


        //Find all classes that inherit GameModeBase
        foreach (System.Type type in GameMode.GameMode.GetAllClassesInheritingClass <GameModeBase>(false))
        {
            //Make sure this GameMode class has its own asset file
            if (allGameModes.Any(gameMode => gameMode != null && gameMode.name == type.Name))
            {
                //Debug.Log(type.Name + " has an asset file.");
            }
            else
            {
                Debug.Log("Discovered new GameMode class '" + type.Name + "'. Creating a settings asset in " + GameModeMgrEditor.gameModeFolder);

                CreateGameModeAsset(type);
            }
        }
    }
Beispiel #9
0
        /// <summary>
        /// Loads the given Game Mode and sets it as the active one.
        /// </summary>
        /// <param name="gameModeDefinition">The Game Mode to load.</param>
        protected virtual void SetGameMode(GameModeDefinition gameModeDefinition)
        {
            if (this.GameMode)
            {
                Destroy(this.GameMode.gameObject);
            }
            GameObject gameMode = Instantiate(gameModeDefinition.gameModeHandler.gameObject, transform);

            this.GameMode = gameMode.GetComponent <GameModeBase>();
        }
Beispiel #10
0
    public static void StartGameMode(GameModeBase newGameMode)
    {
        if (currentPhase != Phase.Lobby)
        {
            Debug.LogWarning("Attempted to start gamemode when not in lobby!");
            return;
        }

        SetActiveGameMode(newGameMode);
    }
Beispiel #11
0
        /// <summary>
        /// Creates Dropdown Options as string.
        /// </summary>
        private void SetGameMode()
        {
            var modes = GameModeBase.GetAll();

            for (var i = 0; i < modes.Count; i++)
            {
                modes[i] = string.Concat(modes[i].Select(x => char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
            }

            ModeDropDown.AddOptions(modes);
        }
Beispiel #12
0
    // Use this for initialization
    protected virtual void Awake()
    {
        activeGameMode = this;
        gameState      = GameState.GameLoading;
        DontDestroyOnLoad(this.gameObject);

        //TODO: Make next two lines less hard coded
        playerPawnPrefab   = Resources.Load("PlayerPawnPrefab") as GameObject;
        resultScreenPrefab = Resources.Load("UI/ResultScreen") as GameObject;

        InitPlayerController();
    }
 static public int get_gameState(IntPtr l)
 {
     try {
         GameModeBase self = (GameModeBase)checkSelf(l);
         pushValue(l, true);
         pushEnum(l, (int)self.gameState);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int PauseGame(IntPtr l)
 {
     try {
         GameModeBase self = (GameModeBase)checkSelf(l);
         self.PauseGame();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #15
0
    public override void initialize(MapData mapData)
    {
        base.initialize(mapData);

        this.gameMode = GameObject.FindObjectOfType <GameModeBase>();
        if (this.gameMode == null)
        {
            throw new Exception("No GameObject with a component of GameModeBase or a derived type could be located!");
        }
        this.gameMode.init(this);

        this.setResources(Team.SURVIVORS_1, this.campaignData.startingResources);
    }
Beispiel #16
0
        private void OnValidate()
        {
            var modes = GameModeBase.GetAll();

            foreach (var mode in modes)
            {
                var modeExists = Hints.FindIndex(x => x.Mode == mode) != -1;
                if (!modeExists)
                {
                    Hints.Add(new Hint(mode));
                }
            }
        }
 static public int EndGame(IntPtr l)
 {
     try {
         GameModeBase  self = (GameModeBase)checkSelf(l);
         System.String a1;
         checkType(l, 2, out a1);
         self.EndGame(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #18
0
    public override void onRightClick(Player player)
    {
        base.onRightClick(player);

        GameModeBase gm = Director.singleton.getCurrentGameMode();

        if (gm != null && gm is GameModeCallForHelp)
        {
            GameModeCallForHelp gmch = (GameModeCallForHelp)gm;
            if (gmch.getState() == GameModeCallForHelp.EnumState.FIND_RADIO)
            {
                gmch.setItem(this);
            }
        }
    }
Beispiel #19
0
    public void ChangeScene(string sname, GameModeInitData initData = null, Action onSceneFinished = null)
    {
        if (!SceneInfoDict.ContainsKey(sname))
        {
            return;
        }
        string SceneName = SceneInfoDict[sname].SceneName;

        mResLoader.LoadLevelSync("Scene/" + SceneName, LoadSceneMode.Single, delegate(Scene scene, LoadSceneMode mode) {
            Type t          = SceneInfoDict[sname].GameModeType;
            GameModeBase gm = LoadGameMode(t, initData);

            gm.GameFinishedCallback = onSceneFinished;
        });
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        if (newGameMode == null)
        {
            newGameMode = GameModeMgr.activeGameMode;
        }

        newGameMode = (GameModeBase)EditorGUILayout.ObjectField("Set GameMode to", newGameMode, typeof(GameModeBase), false);

        if (GUILayout.Button("Set GameMode"))
        {
            GameModeMgr.SetActiveGameMode(newGameMode);
        }
    }
        /// <summary>
        /// Changes game mode to the specified one.
        /// </summary>
        /// <param name="command">The Mode command.</param>
        private void ChangeGameMode(Command command)
        {
            var modeNameArgument = command.GetArgument <string>(0);

            var modeNameParseResult = Enum.TryParse(modeNameArgument, true, out GameModeType modeType);

            if (!modeNameParseResult)
            {
                _consoleManager.WriteLine($"$rInvalid mode type ($R{modeNameArgument}$r)");
                return;
            }

            _commandsManager.RemoveCommandHandlers(CommandGroup.GameMode);
            _mode = _modeFactory.Create(modeType);
            _mode.LoadContent(Content);
        }
Beispiel #22
0
    private void Awake()
    {
        Director.singleton = this;

        if (this.zombiePrefab == null)
        {
            throw new Exception("Zombie prefab field can not be null!");
        }
        else if (!this.zombiePrefab.GetComponent <ZombieBase>())
        {
            throw new Exception("Zombie prefab must contain a ZombieBase component!");
        }

        if (this.difficulty == null)
        {
            throw new Exception("Difficulty field can not be null!");
        }

        // Create the zombie list and put any zombies that were placed via the inspector into the list.
        this.allZombiesList = new List <ZombieBase>();
        foreach (ZombieBase zombie in GameObject.FindObjectsOfType <ZombieBase>())
        {
            this.allZombiesList.Add(zombie);
        }

        // Construct a queue of all of the spawn areas.
        this.spawnAreaQueue = new Queue <ZombieSpawnArea>();
        foreach (ZombieSpawnArea sa in GameObject.FindObjectsOfType <ZombieSpawnArea>())
        {
            if (sa.enabled && sa.gameObject.activeInHierarchy)
            {
                this.spawnAreaQueue.Enqueue(sa);
            }
        }
        this.spawnAreaQueue.Shuffle();

        // Setup the game mode.
        this.gameMode = GameObject.FindObjectOfType <GameModeBase>();
        if (this.gameMode == null)
        {
            Debug.LogWarning("No GameMode set in inspector!");
        }
        else
        {
            this.gameMode.initGameMode(this);
        }
    }
 static public int BindLuaGameMode(IntPtr l)
 {
     try {
         GameModeBase  self = (GameModeBase)checkSelf(l);
         SLua.LuaTable a1;
         checkType(l, 2, out a1);
         System.String a2;
         checkType(l, 3, out a2);
         var ret = self.BindLuaGameMode(a1, a2);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #24
0
    private static void CreateGameModeAsset(System.Type type)
    {
        //Create a new asset file

        //Create the actual object to save as an asset
        GameModeBase gameMode = CreateInstance(type) as GameModeBase;

        //Save the object as an asset
        string path = GameModeMgrEditor.gameModeFolder + "/" + type.Name + ".asset";

        AssetDatabase.CreateAsset(gameMode, path);

        //Save changes to assets
        AssetDatabase.SaveAssets();

        //Refresh assets to make sure its visible in the inspector
        AssetDatabase.Refresh();
    }
Beispiel #25
0
    /// <summary>
    /// Forcefully set the current gamemode. Use this for debugging
    /// </summary>
    /// <param name="newGameMode">The gamemode to start</param>
    public static void SetActiveGameMode(GameModeBase newGameMode)
    {
        if (activeGameMode != null)
        {
            activeGameMode.GameExit();
        }

        activeGameMode = newGameMode;

        if (newGameMode != null)
        {
            newGameMode.Start();

            AssignTeams();

            StartCountdown();
        }
    }
Beispiel #26
0
    protected virtual void OnDestroy()
    {
        if (luaGameMode != null)
        {
            if (luaGameMode.luaTable != null)
            {
                LuaFunction luaOnDestroy = luaGameMode.luaTable["_OnDestroy"] as LuaFunction;
                if (luaOnDestroy != null)
                {
                    luaOnDestroy.call(luaGameMode.luaTable);
                }
                else
                {
                    Debug.LogError("[GameModeBase]:: Can not load OnDestroy function from " + luaGameMode.luaFileName);
                }
            }
        }

        _gameMode = null;
    }
        /// <summary>
        /// Initializes a new instance of the <see cref="GUICore"/> class.
        /// </summary>
        /// <param name="consoleManager">The console manager instance.</param>
        /// <param name="commandsManager">The commands manager instance.</param>
        public GUICore(ConsoleManager consoleManager, CommandsManager commandsManager)
        {
            _consoleManager  = consoleManager;
            _commandsManager = commandsManager;

            _graphics = new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth  = (int)Constants.WindowSize.X,
                PreferredBackBufferHeight = (int)Constants.WindowSize.Y
            };

            _modeFactory = new GameModeFactory(_consoleManager, _commandsManager);
            _mode        = _modeFactory.Create(GameModeType.Editor);

            _inputManager = new InputManager();

            Content.RootDirectory = "Content";
            IsMouseVisible        = true;

            SetCommandHandlers();
        }
Beispiel #28
0
    // Use this for initialization
    void Start()
    {
        ScreenBuf            = new Texture2D(64, 64);
        ScreenBuf.filterMode = FilterMode.Point;

        ScreenBuf.wrapMode = TextureWrapMode.Clamp;

        Renderer rend = Target.GetComponent <Renderer>();

        rend.material.mainTexture = ScreenBuf;

        for (int y = 0; y < ScreenBuf.height; y++)
        {
            for (int x = 0; x < ScreenBuf.width; x++)
            {
                float dx = x - 32;
                float dy = y - 32;
                float dz = Mathf.Sqrt(dx * dx + dy * dy);

                Color color = ((dz > 32) ? Color.white : Color.gray);
                ScreenBuf.SetPixel(x, y, color);
            }
        }

        ScreenBuf.Apply();

        currentMode = new TitleGameMode(TitleTexture);

        Globals.FontTex    = FontTexture;
        Globals.JackTex    = JackTexture;
        Globals.MakuTex    = MakuTexture;
        Globals.BeetleTex  = BeetleTexture;
        Globals.PortalTex  = PortalTexture;
        Globals.CreditsTex = CreditsTexture;
        Globals.TitleTex   = TitleTexture;

        Globals.BeetleSpriteTex = BeetleSpriteTexture;
        Globals.ClueCoin1Tex    = ClueCoin1Texture;
        Globals.ClueCoin2Tex    = ClueCoin2Texture;
    }
Beispiel #29
0
 internal void on_SetGameModeBase(GameModeBase gameModeBase, string mapURL) =>
 SetGameModeBase?.Invoke(gameModeBase, mapURL);
Beispiel #30
0
 /// <summary>
 /// free static game mode instance object. this only be invoked from OnDestroy funtion of LuaGameModeBase script
 /// </summary>
 public void FreeGameMode()
 {
     _gameMode = null;
 }