Ejemplo n.º 1
0
        public static void set(Arg arg)
        {
            string @string = arg.GetString(0);

            if (string.IsNullOrEmpty(@string))
            {
                Debug.Log("Invalid gamemode");
            }
            BaseGameMode     baseGameMode     = null;
            GameObjectRef    gameObjectRef    = null;
            GameModeManifest gameModeManifest = GameModeManifest.Get();

            Debug.Log("total gamemodes : " + gameModeManifest.gameModePrefabs.Count);
            foreach (GameObjectRef gameModePrefab in gameModeManifest.gameModePrefabs)
            {
                BaseGameMode component = gameModePrefab.Get().GetComponent <BaseGameMode>();
                if (component.shortname == @string)
                {
                    baseGameMode  = component;
                    gameObjectRef = gameModePrefab;
                    Debug.Log("Found :" + component.shortname + " prefab name is :" + component.PrefabName + ": rpath is " + gameModePrefab.resourcePath + ":");
                    break;
                }
                Debug.Log("search name " + @string + "searched against : " + component.shortname);
            }
            if (baseGameMode == null)
            {
                Debug.Log("Unknown gamemode : " + @string);
                return;
            }
            BaseGameMode activeGameMode = BaseGameMode.GetActiveGameMode(true);

            if ((bool)activeGameMode)
            {
                if (baseGameMode.shortname == activeGameMode.shortname)
                {
                    Debug.Log("Same gamemode, resetting");
                }
                if (activeGameMode.permanent)
                {
                    Debug.LogError("This game mode is permanent, you must reset the server to switch game modes.");
                    return;
                }
                activeGameMode.ShutdownGame();
                activeGameMode.Kill();
                BaseGameMode.SetActiveGameMode(null, true);
            }
            BaseEntity baseEntity = GameManager.server.CreateEntity(gameObjectRef.resourcePath, Vector3.zero, Quaternion.identity);

            if ((bool)baseEntity)
            {
                Debug.Log("Spawning new game mode : " + baseGameMode.shortname);
                baseEntity.Spawn();
            }
            else
            {
                Debug.Log("Failed to create new game mode :" + baseGameMode.PrefabName);
            }
        }
Ejemplo n.º 2
0
    public static void CreateGameMode(string overrideMode = "")
    {
        BaseGameMode activeGameMode = GetActiveGameMode(true);

        if ((bool)activeGameMode)
        {
            activeGameMode.ShutdownGame();
            activeGameMode.Kill();
            SetActiveGameMode(null, true);
        }
        string text = Server.gamemode;

        Debug.Log("Gamemode Convar :" + text);
        if (!string.IsNullOrEmpty(overrideMode))
        {
            text = overrideMode;
        }
        if (string.IsNullOrEmpty(text))
        {
            Debug.Log("No Gamemode.");
            if (BaseGameMode.GameModeChanged != null)
            {
                BaseGameMode.GameModeChanged(null);
            }
        }
        else
        {
            BaseEntity baseEntity = GameManager.server.CreateEntity("assets/prefabs/gamemodes/" + text + ".prefab", Vector3.zero, Quaternion.identity);
            if ((bool)baseEntity)
            {
                baseEntity.Spawn();
            }
            else
            {
                Debug.Log("Failed to create gamemode : " + text);
            }
        }
    }