Beispiel #1
0
    IEnumerator Start()
    {
        Debug.LogWarning("Game Start : " + System.DateTime.Now);
        // 加载配置
        Setting.Load();
        // 构造公共模块
        Console.Instance();
        Logger.Instance();
        ResMgr.Instance();
        ConfigMgr.Instance();
        LuaMgr.Instance();
        Debug.LogWarning("Res Start : " + System.DateTime.Now);
        // 初始化公共模块
        // 初始化资源管理器
        yield return(StartCoroutine(ResMgr.Instance().Init()));

        Debug.LogWarning("Config Start : " + System.DateTime.Now);
        // 初始化配置数据管理器
        yield return(StartCoroutine(ConfigMgr.Instance().Init()));

        Debug.LogWarning("Lua Start : " + System.DateTime.Now);
        // 初始化脚本管理器,启动脚本,开始逻辑
        yield return(StartCoroutine(LuaMgr.Instance().Init()));

        Debug.LogWarning("Game Start Done : " + System.DateTime.Now);

#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX
        Screen.SetResolution(Setting.GetInt("WindowWidth", 1024),
                             Setting.GetInt("WindowHeight", 768), false);
#endif
    }
Beispiel #2
0
        /// <summary>
        /// 增加UI层
        /// </summary>
        public UILayer AddLayer(string layerName, float nextZ, object uiData = null)
        {
            if (mAllLayers.ContainsKey(layerName))
            {
                Debug.LogWarning(layerName + ": already exist");

                mAllLayers [layerName].transform.localPosition    = Vector3.zero;
                mAllLayers [layerName].transform.localEulerAngles = Vector3.zero;
                mAllLayers [layerName].transform.localScale       = Vector3.one;

                mAllLayers [layerName].Enter(uiData);
            }
            else
            {
                GameObject prefab = ResMgr.Instance().LoadUIPrefabSync(layerName);

                GameObject uiLayer = NGUITools.AddChild(mParentTrans.gameObject, prefab, nextZ);

                uiLayer.transform.localPosition    = Vector3.forward * nextZ;
                uiLayer.transform.localEulerAngles = Vector3.zero;
                uiLayer.transform.localScale       = Vector3.one;

                uiLayer.gameObject.name = layerName;

                mAllLayers.Add(layerName, uiLayer.GetComponent <UILayer> ());
                uiLayer.GetComponent <UILayer> ().Enter(uiData);
            }


            return(mAllLayers [layerName]);
        }
Beispiel #3
0
    /// <summary>
    /// 异步清理场景资源
    /// </summary>
    /// <returns></returns>
    IEnumerator CleanScene()
    {
        ResMgr.Instance().Unload();
        this.curLogicResObjDict.Clear();
        this.curLogicResObjDict = null;
        Debug.LogWarning("Unload in SceneMgr");
        AsyncOperation req = Resources.UnloadUnusedAssets();

        yield return(req);

        System.GC.Collect();
    }
Beispiel #4
0
 public virtual void CheckDependences()
 {
     this.dependences = ResMgr.Instance().GetDependences(base.SceneName);
     for (int i = 0; i < this.dependences.Length; ++i)
     {
         string dependence = this.dependences[i];
         if (!ResMgr.Instance().IsLoadedAssetBundle(dependence))
         {
             ResMgr.Instance().LoadRes(dependence);
         }
     }
 }
Beispiel #5
0
 public override bool IsDone()
 {
     // 如果有依赖,要先判断依赖是否已经加载完成
     if (this.dependences != null)
     {
         for (int i = 0; i < this.dependences.Length; ++i)
         {
             if (!ResMgr.Instance().IsLoadedAssetBundle(this.dependences[i]))
             {
                 return(false);
             }
         }
     }
     // 判断自己是否加载完成
     if (base.LoadDoneCallback == null)
     {
         // 依赖资源,不需要LoadDone回调
         if (this.assetbundle != null)
         {
             return(true);
         }
         if (this.www.isDone)
         {
             this.assetbundle = this.www.assetBundle;
             this.www.Dispose();
             this.www = null;
             return(true);
         }
         return(false);
     }
     else
     {
         // 直接资源,需要LoadDone回调,所以需要从AssetBundle中提取资源对象
         if (this.assetbundleReq != null)
         {
             // 只有从assetbundle中提取出最终的资源对象,才算加载完成,保证所有的IO操作都是异步的
             return(this.assetbundleReq.isDone);
         }
         else
         {
             if (this.www.isDone)
             {
                 this.assetbundle = this.www.assetBundle;
                 // 从assetbundle中提取资源对象
                 string resPath = string.Format(ResMgr.AssetBundleFormation, base.ResName);
                 this.assetbundleReq = this.assetbundle.LoadAssetAsync(resPath);
                 this.www.Dispose();
                 this.www = null;
             }
             return(false);
         }
     }
 }
Beispiel #6
0
    /// <summary>
    /// 进入场景
    /// </summary>
    /// <param name="loadingSceneName">Loading场景名字,忽略路径,name.scene格式</param>
    /// <param name="loadingSceneDoneCallback">Loading场景加载完成回调,给予自定义Loading场景显示逻辑入口</param>
    /// <param name="sceneName">真正要加载的场景名,格式同loadingSceneName</param>
    /// <param name="logicResNames">逻辑资源名,这里只必要资源,即场景进入后所需的必要资源</param>
    /// <param name="loadSceneDoneCallback">场景加载完成回调,一般用于场景逻辑初始化</param>
    /// <param name="loadSceneUpdateProgressCallback">场景加载进度回调,用于Loading显示</param>
    public void EnterScene(string loadingSceneName, LoadSceneDoneCallback loadingSceneDoneCallback,
                           string sceneName, string[] logicResNames, LoadSceneDoneCallback loadSceneDoneCallback, LoadSceneUpdateProgressCallback loadSceneUpdateProgressCallback)
    {
        this.curSceneName                = sceneName;
        this.curLogicResNames            = logicResNames;
        this.curLoadingSceneDoneCallback = loadingSceneDoneCallback;
        this.curLoadSceneDoneCallback    = loadSceneDoneCallback;
        this.curUpdateProgressCallback   = loadSceneUpdateProgressCallback;

        // 4.释放中间资源
        ResMgr.Instance().Unload();
        // 1.加载Loading场景
        ResMgr.Instance().LoadScene(loadingSceneName, false, OnLoadingSceneDone, null);
    }
Beispiel #7
0
    /// <summary>
    /// Loading场景加载完成回调
    /// </summary>
    /// <param name="sceneName">Loading场景名,没啥意义</param>
    void OnLoadingSceneDone(string sceneName)
    {
        if (this.curLoadingSceneDoneCallback != null)
        {
            this.curLoadingSceneDoneCallback(null);
        }

        // 2.加载主场景
        this.curTotalProgress = 50;
        ResMgr.Instance().LoadScene(this.curSceneName, true, OnLoadSceneDone, OnLoadSceneUpdateProgress);
        // 3.加载逻辑资源
        if (this.curLogicResNames != null && this.curLogicResNames.Length > 0)
        {
            this.curTotalProgress += this.curLogicResNames.Length;
            for (int i = 0; i < this.curLogicResNames.Length; ++i)
            {
                ResMgr.Instance().LoadRes(this.curLogicResNames[i], OnLoadLogicResDone);
            }
        }
    }
Beispiel #8
0
 public override bool IsDone()
 {
     if (this.dependences != null)
     {
         for (int i = 0; i < this.dependences.Length; ++i)
         {
             if (!ResMgr.Instance().IsLoadedAssetBundle(this.dependences[i]))
             {
                 return(false);
             }
         }
     }
     if (this.op != null)
     {
         return(this.op.isDone);
     }
     else
     {
         if (this.www.isDone)
         {
             this.assetbundle = this.www.assetBundle;
             string scene = base.SceneName.Substring(0, base.SceneName.LastIndexOf('.'));
             if (this.additive)
             {
                 this.op = Application.LoadLevelAdditiveAsync(scene);
             }
             else
             {
                 this.op = Application.LoadLevelAsync(scene);
             }
             this.www.Dispose();
             this.www = null;
         }
         return(false);
     }
 }