public virtual void Run(params object[] param) { if (_isRunning) { CLog.LogError("GameRunner,id=" + _id + " is running,can not run again!"); return; } _isRunning = true; GameCfg gameCfg = GameConfig.GetGameCfg(this._id); if (GO == null) { GO = new GameObject(gameCfg.name); GameObject.DontDestroyOnLoad(GO); } Transform uiTrans = AppManager.Instance.GameStarter.transform.FindChild(gameCfg.ui + "_Template"); if (uiTrans != null) { GameObject ui = GameObject.Instantiate(uiTrans.gameObject); CTLTools.AddChildToParent(ui, GO, false); ui.transform.Find("UICamera").GetComponent <Camera>().depth = gameCfg.uiDepth; ui.SetActive(true); ui.name = "UI"; } else { CLog.LogError("can not find UI template in GameStarter!UI:" + gameCfg.ui); } STContainer = GO.AddComponent <SingletonContainer>(); STContainer.ResourceMgr.Init(GameConfig.IsResourceLoadMode, string.Format("Assets/{0}/Res", gameCfg.rootDir)); STContainer.LuaClient.BindGame(gameCfg.id); STContainer.LuaClient.StartGame(); }
public virtual void BindGame(int id) { //在Eidtor下时,添加lua的游戏路径(相对路径) ((LuaMultiLoader)this.luaFileUtils).BindGame(id); #if UNITY_EDITOR GameCfg gameCfg = GameConfig.GetGameCfg(id); string path = string.Format("{0}/{1}/Lua", Application.dataPath, gameCfg.rootDir); if (!Directory.Exists(path)) { string msg = string.Format("luaDir path not exists: {0}", path); throw new LuaException(msg); } AddSearchPath(path); #endif }
public static void Load() { TextAsset txt = Resources.Load <TextAsset>(GameSetting); string files = txt.text; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(files); foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { XmlElement element = (XmlElement)node; if (node.Name == "Resource") { IsResourceLoadMode = element.GetAttribute("isResourcesLoadMode") == "true"; } else if (node.Name == "HotUpdate") { IsHotUpdateMode = element.GetAttribute("isHotUpdate") == "true"; } else if (node.Name == "Debug") { IsDebugInfo = element.GetAttribute("isDebugInfo") == "true"; IsDebugWarn = element.GetAttribute("isDebugWarn") == "true"; IsDebugError = element.GetAttribute("isDebugError") == "true"; } else if (node.Name == "Server") { ServerUrl = element.GetAttribute("url"); PkgUpdateUrl = element.GetAttribute("pkgUpdateUrl"); } else if (node.Name == "Version") { ShowVersion = element.GetAttribute("showVersion"); PkgVersion = int.Parse(element.GetAttribute("pkgVersion")); VersionCodeFile = element.GetAttribute("versionCodeFile"); VersionDataFile = element.GetAttribute("versionDataFile"); VersionPkgFile = element.GetAttribute("versionPkgFile"); } else if (node.Name == "Games") { foreach (XmlElement child in node.ChildNodes) { GameCfg cfg = new GameCfg(child); _mapGame.Add(cfg.id, cfg); } } } }
private void Awake() { GameObject.DontDestroyOnLoad(gameObject); AppManager.Instance.SetGameStarter(gameObject); if (Debug.isDebugBuild) { gameObject.AddComponent <ConsoleLogger>(); } GameConfig.Load(); CLog.Init(); List <GameCfg> games = GameConfig.GetGames(); for (int i = 0; i < games.Count; i++) { GameCfg cfg = games[i]; Type type = Type.GetType(cfg.runClass); IRunner runner = (IRunner)Activator.CreateInstance(type, cfg.id); AppManager.Instance.RegisterRunner(runner); } AppManager.Instance.Run(1); //AppManager.Instance.Run(2); }