Exemplo n.º 1
0
        //加载用户模组
        private IEnumerator GameInitUserMods()
        {
            //加载mod文件夹下所有模组
            string modFolderPath = GamePathManager.GetResRealPath("mod", "");

            if (Directory.Exists(modFolderPath))
            {
                DirectoryInfo direction = new DirectoryInfo(modFolderPath);
                FileInfo[]    files     = direction.GetFiles("*.ballance", SearchOption.TopDirectoryOnly);
                for (int i = 0, c = files.Length; i < c; i++)
                {
                    ModManager.LoadGameMod(GamePathManager.GetResRealPath("mod", files[i].Name), false);

                    GameInitSetUIProgressValue(0.6f + i / (float)c * 0.2f);
                    UIProgressText.text = "Loading " + files[i].Name;
                }
            }

            //根据用户设置启用对应模组
            string[] enableMods = ModManager.GetModEnableStatusList();
            foreach (string packageName in enableMods)
            {
                GameMod m = ModManager.FindGameMod(packageName);
                if (m != null)
                {
                    ModManager.InitializeLoadGameMod(m);

                    yield return(new WaitUntil(m.IsLoadComplete));
                }
            }

            UIProgressText.text = "Loading";
            GameInitSetUIProgressValue(0.8f);
            yield break;
        }
Exemplo n.º 2
0
 public GameLevel(string path, IModManager modManager)
 {
     FilePath   = path;
     Name       = GamePathManager.GetFileNameWithoutExt(path);
     _TAG       = "GameLevel:" + Name;
     ModManager = modManager;
 }
Exemplo n.º 3
0
        private IEnumerator LoadGameInitUI()
        {
            gameInitMod = ModManager.LoadGameMod(GamePathManager.GetResRealPath("core", "core.gameinit.ballance"), false);
            gameInitMod.IsModInitByGameinit = true;

            yield return(StartCoroutine(gameInitMod.LoadInternal()));

            if (gameInitMod.LoadStatus != GameModStatus.InitializeSuccess)
            {
                GameErrorManager.ThrowGameError(GameError.GameInitPartLoadFailed, "加载 GameInit 资源包失败 ");
                StopAllCoroutines();
            }

            gameInitUI = GameManager.UIManager.InitViewToCanvas(gameInitMod.GetPrefabAsset("UIGameInit.prefab"), "GameInitUI").gameObject;

            GameManager.UIManager.MaskBlackSet(false);

            UIProgress      = gameInitUI.transform.Find("UIProgress").GetComponent <RectTransform>();
            UIProgressValue = gameInitUI.transform.Find("UIProgress/UIValue").GetComponent <RectTransform>();
            UIProgressText  = gameInitUI.transform.Find("Text").GetComponent <Text>();
            IntroAnimator   = gameInitUI.GetComponent <Animator>();
            TextError       = gameInitUI.transform.Find("TextError").GetComponent <Text>();

            loadedGameInitUI = true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 加载模组包中的音乐资源
        /// </summary>
        /// <param name="assets">资源路径(模组包:音乐路径)</param>
        /// <returns></returns>
        public AudioClip LoadAudioResource(string assets)
        {
            string[] names = assets.Split(':');

            GameMod mod = ModManager.FindGameModByAssetStr(names[0]);

            if (mod == null)
            {
                GameLogger.Warning(TAG, "无法加载声音文件 {0} ,因为未找到模组包 {1}", assets, names[0]);
                GameErrorManager.LastError = GameError.NotRegister;
                return(null);
            }
            if (mod.LoadStatus != GameModStatus.InitializeSuccess)
            {
                GameLogger.Warning(TAG, "无法加载声音文件 {0} ,因为模组包 {1} ({2}) 未初始化", assets, names[0], mod.Uid);
                GameErrorManager.LastError = GameError.NotInitialize;
                return(null);
            }

            AudioClip clip = mod.GetAsset <AudioClip>(names[1]);

            if (clip != null)
            {
                clip.name = GamePathManager.GetFileNameWithoutExt(names[1]);
            }
            else
            {
                GameLogger.Warning(TAG, "未找到声音文件 {0} ,在模组包 {1}", assets, names[0]);
                GameErrorManager.LastError = GameError.AssetsNotFound;
            }

            return(clip);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 加载模组包
        /// </summary>
        /// <param name="packagePath">模组包路径</param>
        /// <param name="initialize">是否立即初始化模组包</param>
        /// <returns>返回模组包UID</returns>
        public GameMod LoadGameMod(string packagePath, bool initialize = true)
        {
            GameMod mod = FindGameModByPath(packagePath);

            if (mod != null)
            {
                GameLogger.Warning(TAG, "Mod \"{0}\" already registered, skip", packagePath);
                return(mod);
            }

            //路径处理
            if (StringUtils.IsUrl(packagePath))
            {
                GameLogger.Error(TAG, "不支持从 URL 加载模组包 \"{0}\" ,请将其先下载至 streamingAssetsPath 后再加载。", packagePath);
                return(null);
            }
            //处理路径至mod文件夹路径
            if (!File.Exists(packagePath) && !GamePathManager.IsAbsolutePath(packagePath))
            {
                packagePath = GamePathManager.GetResRealPath("mod", packagePath);
            }
            if (!File.Exists(packagePath))
            {
                GameLogger.Error(TAG, "Mod file \"{0}\" not exists", packagePath);
                return(null);
            }

            mod = new GameMod(packagePath, this);
            if (!mod.Init())
            {
                return(null);
            }
            if (!gameMods.Contains(mod))
            {
                gameMods.Add(mod);
            }

            GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_REGISTERED, "*", mod.PackageName, mod);
            GameLogger.Log(TAG, "Register mod \"{0}\"", packagePath);

            if (initialize)
            {
                mod.Load(this);
            }

            return(mod);
        }
Exemplo n.º 6
0
        private GameActionCallResult OnCallLoadLevel(params object[] param)
        {
            if (levelLoadStatus == LevelLoadStatus.Loading || levelLoadStatus == LevelLoadStatus.UnLoading)
            {
                GameErrorManager.LastError = GameError.InProgress;
                return(GameActionCallResult.CreateActionCallResult(false));
            }
            if (levelLoadStatus != LevelLoadStatus.NotLoad)
            {
                GameErrorManager.LastError = GameError.AlredayLoaded;
                return(GameActionCallResult.CreateActionCallResult(false));
            }

            string pathOrName = (string)param[0];
            string levelPath  = "";
            int    number;

            if (int.TryParse(pathOrName, out number))
            {
                if (number < 15)
                {
                    levelPath = GamePathManager.GetResRealPath("core", "levels/Level" + number + ".ballance");
                }
            }
            else
            {
                if (GamePathManager.IsAbsolutePath(pathOrName))
                {
                    levelPath = pathOrName;
                }
                else
                {
                    levelPath = GamePathManager.GetResRealPath("level", pathOrName);
                }
            }

            EnterLoader();
            StartCoroutine(LoadLevel(levelPath));
            return(GameActionCallResult.CreateActionCallResult(true));
        }
Exemplo n.º 7
0
        //加载所有关卡信息
        private IEnumerator GameInitLevels()
        {
            //加载levels文件夹下所有模组
            string levelFolderPath = GamePathManager.GetResRealPath("level", "");

            if (Directory.Exists(levelFolderPath))
            {
                DirectoryInfo direction = new DirectoryInfo(levelFolderPath);
                FileInfo[]    files     = direction.GetFiles("*.ballance", SearchOption.AllDirectories);
                for (int i = 0, c = files.Length; i < c; i++)
                {
                    ModManager.RegisterLevel(files[i].FullName);

                    GameInitSetUIProgressValue(0.8f + i / (float)c * 0.2f);
                    UIProgressText.text = "Loading " + files[i].Name;
                }
            }

            UIProgressText.text = "Loading";
            GameInitSetUIProgressValue(1);
            yield break;
        }
Exemplo n.º 8
0
        /// <summary>
        /// 通过包名加载模组包
        /// </summary>
        /// <param name="packageName">模组包包名</param>
        /// <param name="initialize">是否立即初始化模组包</param>
        /// <returns>返回模组包UID</returns>
        public GameMod LoadGameModByPackageName(string packageName, bool initialize = true)
        {
            GameMod mod = FindGameMod(packageName);

            if (mod != null)
            {
                GameLogger.Warning(TAG, "Mod \"{0}\" already registered, skip", packageName);
                return(mod);
            }

            string pathInMods = GamePathManager.GetResRealPath("mod", packageName + ".ballance");
            string pathInCore = GamePathManager.GetResRealPath("core", packageName + ".ballance");

            string pathInEditorMods = GamePathManager.DEBUG_MOD_FOLDER + "/" + packageName;

            if (false)
            {
            }
#if UNITY_EDITOR
            //编辑器直接加载模组
            else if (DebugSettings.Instance.ModLoadInEditor && File.Exists(pathInEditorMods + "/ModDef.xml"))
            {
                mod = LoadModInEditor(pathInEditorMods, packageName);
            }
#endif
            else if (File.Exists(pathInMods))
            {
                mod = new GameMod(pathInMods, this, packageName);
            }
            else if (File.Exists(pathInCore))
            {
                mod = new GameMod(pathInCore, this, packageName);
            }
#if UNITY_EDITOR
            else if (DebugSettings.Instance.ModLoadInEditor == false && File.Exists(pathInEditorMods + "/ModDef.xml"))
            {
                mod = LoadModInEditor(pathInEditorMods, packageName);
            }
#endif
            else
            {
                GameLogger.Warning(TAG, "无法通过包名加载模组包 {0} ,未找到文件", packageName);
                GameErrorManager.LastError = GameError.FileNotFound;
                return(null);
            }

            if (!mod.Init())
            {
                return(null);
            }
            if (!gameMods.Contains(mod))
            {
                gameMods.Add(mod);
            }

            GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_MOD_REGISTERED, "*", mod.PackageName, mod);
            GameLogger.Log(TAG, "Register mod \"{0}\" {1}", packageName, (mod.IsEditorPack ? "(Editor Pack)" : ""));

            if (initialize)
            {
                mod.Load(this);
            }

            return(mod);
        }
Exemplo n.º 9
0
        //加载主函数
        private IEnumerator GameInitCore()
        {
            GameLogger.Log(TAG, "Gameinit start");

            yield return(new WaitUntil(IsGameInitUILoaded));

            //播放音乐和动画
            if (GameManager.Mode == GameMode.Game)
            {
                IntroAnimator.Play("IntroAnimation");
                IntroAudio.Play();
            }

            //选择加载包模式
            switch (GameManager.Mode)
            {
            case GameMode.Game: currentLoadMask = GameModRunMask.GameBase; break;

            case GameMode.Level: currentLoadMask = GameModRunMask.Level | GameModRunMask.LevelLoader; break;

            case GameMode.LevelEditor: currentLoadMask = GameModRunMask.LevelEditor | GameModRunMask.Level; break;

            case GameMode.MinimumDebug: currentLoadMask = GameModRunMask.GameBase; break;

            case GameMode.LoaderDebug: currentLoadMask = GameModRunMask.Level | GameModRunMask.LevelLoader; break;

            case GameMode.CoreDebug: currentLoadMask = GameModRunMask.GameCore; break;
            }

            UIProgressText.text = "Loading";

            //加载 core.gameinit.txt 获得要加载的模块
            string gameInitTxt = "";

#if UNITY_EDITOR // 编辑器中直接加载
            TextAsset gameInitEditorAsset = null;
            if (DebugSettings.Instance.GameInitLoadInEditor &&
                (gameInitEditorAsset =
                     UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(
                         GamePathManager.DEBUG_MOD_FOLDER + "/core.gameinit.txt")) != null)
            {
                gameInitTxt = gameInitEditorAsset.text;
                GameLogger.Log(TAG, "Load gameinit table in Editor : \n" + gameInitTxt);
            }
#else
            if (false)
            {
            }
#endif
            else
            {
                //加载 gameinit
                string          gameinit_txt_path = GamePathManager.GetResRealPath("gameinit", "");
                UnityWebRequest request           = UnityWebRequest.Get(gameinit_txt_path);
                yield return(request.SendWebRequest());

                if (!string.IsNullOrEmpty(request.error))
                {
                    GameErrorManager.ThrowGameError(GameError.GameInitReadFailed, "加载 GameInit.txt  " + gameinit_txt_path + " 时发生错误:" + request.error);
                    yield break;
                }

                gameInitTxt = request.downloadHandler.text;
            }

            //加载包
            yield return(StartCoroutine(GameInitPackages(gameInitTxt)));

            //加载模组
            yield return(StartCoroutine(GameInitUserMods()));

            //加载关卡信息
            yield return(StartCoroutine(GameInitLevels()));

            UIProgressText.text = "Loading";

            //加载游戏内核管理器
            GameManager.RegisterManager(typeof(LevelLoader), false);
            GameManager.RegisterManager(typeof(LevelManager), false);
            GameManager.ICManager = (ICManager)GameManager.RegisterManager(typeof(ICManager), false);

            BaseManager ballManager = GameCloneUtils.CloneNewObjectWithParent(
                GameManager.FindStaticPrefabs("BallManager"),
                GameManager.GameRoot.transform).GetComponent <BaseManager>();
            BaseManager camManager = GameCloneUtils.CloneNewObjectWithParent(
                GameManager.FindStaticPrefabs("CamManager"),
                GameManager.GameRoot.transform).GetComponent <BaseManager>();

            GameManager.RegisterManager(ballManager, false);
            GameManager.RegisterManager(camManager, false);

            //初始化管理器
            GameManager.RequestAllManagerInitialization();

            //正常情况下,等待动画播放完成
            if (GameManager.Mode == GameMode.Game)
            {
                yield return(new WaitUntil(IsGameInitAnimPlayend));

                //hide cp
                GameManager.UIManager.UIFadeManager.AddFadeOut(GameObject.Find("GlobalCopyrightText").GetComponent <Text>(), 1.3f, true);

                IntroAnimator.Play("IntroAnimationHide");
                IntroAudio.Stop();

                yield return(new WaitForSeconds(0.8f));
            }

            yield return(new WaitUntil(GameManager.IsManagersInitFinished));

            //初始化模组启动代码(游戏初始化完成)
            ModManager.ExecuteModEntry(GameModEntryCodeExecutionAt.AtStart);

            yield return(new WaitUntil(GameManager.IsManagersInitFinished));

            //分发接管事件
            int hC = GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_GAME_INIT_TAKE_OVER_CONTROL, "*", (BooleanDelegate)GameInitContinueInit);
            if (hC == 0)//无接管
            {
                if (GameInitContinueInit())
                {
                    //正常模式,加载menulevel
                    GameManager.NotifyGameCurrentScenseChanged(GameCurrentScense.MenuLevel);

                    yield return(new WaitUntil(ModManager.IsNoneModLoading));

                    int initEventHandledCount = GameManager.GameMediator.DispatchGlobalEvent(GameEventNames.EVENT_ENTER_MENULEVEL, "*");
                    GameManager.GameMediator.UnRegisterGlobalEvent(GameEventNames.EVENT_ENTER_MENULEVEL);

                    if (initEventHandledCount == 0)
                    {
                        GameErrorManager.ThrowGameError(GameError.HandlerLost, "未找到 EVENT_ENTER_MENULEVEL 的下一步事件接收器\n此错误出现原因可能是配置不正确");
                        GameLogger.Warning(TAG, "None EVENT_GAME_INIT_FINISH handler was found, the game will not continue.");
                    }
                    else
                    {
                        GameInitHideGameInitUi(true);
                    }
                }
            }
            else
            {
                GameInitHideGameInitUi(true);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 注册 SoundPlayer
        /// </summary>
        /// <param name="audioClip">音频源文件</param>
        /// <returns></returns>
        public AudioSource RegisterSoundPlayer(GameSoundType type, AudioClip audioClip, bool playOnAwake = false, bool activeStart = true, string name = "")
        {
            AudioSource audioSource = Instantiate(audioSourcePrefab, gameObject.transform).GetComponent <AudioSource>();

            audioSource.clip            = audioClip;
            audioSource.playOnAwake     = playOnAwake;
            audioSource.gameObject.name = "AudioSource_" + type + "_" + (name == "" ? GamePathManager.GetFileNameWithoutExt(audioClip.name) : name);

            if (!activeStart)
            {
                audioSource.gameObject.SetActive(false);
            }

            RegisterAudioSource(type, audioSource);
            return(audioSource);
        }