Пример #1
0
        public ResourceScene CoLoadScene(string path, bool isAddition)
        {
            if (!isAddition)
            {
                Dictionary <string, ResourceScene> tmpScens = new Dictionary <string, ResourceScene>(m_resScenes);
                foreach (string item in tmpScens.Keys)
                {
                    if (item == path)
                    {
                        continue;
                    }
                    this.UnloadScene(item);
                }
            }

            ResourceState resState = new ResourceState(this);
            ulong         reqId    = this.GenReqId();

            resState.req = ResourceRequest.CreateAsyncRequest(m_resLoader, path, this.ResLoadSceneEndCall, reqId);
            ResourceScene resScene = new ResourceScene(resState);

            resScene.TryLoadAsset();

            m_resScenes.Add(resScene.sceneName, resScene);
            return(resScene);
        }
Пример #2
0
        public ResourceObserver LoadAsset(string path)
        {
            ResourceObserver retOb    = null;
            ResourceState    resState = this.GetResState(path);

            /*
             * resState.req.isLoaded will be loading or isLoaded.
             * if it fail, it will be remove by funciton ResLoadEndCall
             */
            if (null != resState && null != resState.req && resState.req.isLoaded)
            {
                retOb = resState.AddObserver(null);
            }
            else
            {
                UnityEngine.Object ret = m_resLoader.Load(path);
                if (null != ret)
                {
                    if (null == resState)
                    {
                        resState = new ResourceState(this);
                        ulong reqId = this.GenReqId();
                        resState.req = ResourceRequest.CreateRequest(m_resLoader, path, ret, reqId);
                        m_resStates.Add(path, resState);
                        retOb = resState.AddObserver(null);
                    }
                    else
                    {
                        retOb = resState.AddObserver(null);
                        resState.req.SetRes(ret);
                    }
                }
            }
            return(retOb);
        }
Пример #3
0
        protected ResourceState GetResState(string path)
        {
            ResourceState ret = null;

            m_resStates.TryGetValue(path, out ret);
            return(ret);
        }
Пример #4
0
        public void ResLoadEndCall(ResourceRequest req)
        {
            ResourceState resState = this.GetResState(req.path);

            if (null != resState && null != resState.req && req.id == resState.req.id)
            {
                foreach (ResourceObserver ob in resState.GetObservers())
                {
                    if (null != ob.cb)
                    {
                        ob.cb(req.path, ob);
                        ob.ResetCb();
                    }
                }
                if (!req.isLoaded)
                {
                    m_resStates.Remove(req.path);
                }
                else
                {
                    this.CheckUnloadRes(req.path, req.id);
                }
            }
            else
            {
                req.UnloadRes();
            }
        }
Пример #5
0
        public ResourceState GetLoadedResState(string path)
        {
            ResourceState resState = this.GetResState(path);

            if (null == resState || !resState.isLoaded)
            {
                return(null);
            }
            return(resState);
        }
Пример #6
0
        public void CheckUnloadRes(string path, ulong id)
        {
            ResourceState resState = this.GetResState(path);

            if (null != resState &&
                null != resState.req &&
                resState.req.id == id &&
                resState.req.isDone &&
                resState.observerCount <= 0 &&
                resState.refCount <= 0)
            {
                m_resStates.Remove(path);
                resState.req.UnloadRes();
                resState.req = null;
            }
        }
Пример #7
0
        public ResourceObserver CoLoadAsset(string path)
        {
            ResourceState resState = this.GetResState(path);

            if (null == resState)
            {
                resState = new ResourceState(this);
                ulong reqId = this.GenReqId();
                resState.req = ResourceRequest.CreateAsyncRequest(m_resLoader, path, this.ResLoadEndCall, reqId);
                m_resStates.Add(path, resState);
                resState.req.AsyncLoad();
            }
            ResourceObserver ret = resState.AddObserver(null);

            return(ret);
        }
Пример #8
0
        public void AsyncLoadScene(string path, bool isAddition, System.Action <ResourceScene.LoadResult, string> cb)
        {
            if (!isAddition)
            {
                Dictionary <string, ResourceScene> tmpScens = new Dictionary <string, ResourceScene>(m_resScenes);
                foreach (string item in tmpScens.Keys)
                {
                    if (item == path)
                    {
                        continue;
                    }
                    this.UnloadScene(item);
                }
            }

            ResourceScene resScene = this.GetResScene(path);

            if (null != resScene)
            {
                resScene.isAddition = isAddition;

                // 不存在Fail和Released的情况,因为函数逻辑会马上把这些情况的resScene移出m_resScenes
                // 不存在Inited的情况,因为所有的resScene一创建马上就TryLoadAssset了
                if (resScene.isLoading)
                {
                    if (null != resScene.cb)
                    {
                        resScene.cb(ResourceScene.LoadResult.Cancel, resScene.sceneName);
                        resScene.SetCb(cb);
                    }
                }
                else if (resScene.isLoaded)
                {
                    resScene.ReloadScene(cb);
                }
            }
            else
            {
                ResourceState resState = new ResourceState(this);
                ulong         reqId    = this.GenReqId();
                resState.req = ResourceRequest.CreateAsyncRequest(m_resLoader, path, this.ResLoadSceneEndCall, reqId);
                resScene     = new ResourceScene(resState);
                resScene.SetCb(cb);
                m_resScenes.Add(resScene.sceneName, resScene);
                resScene.TryLoadAsset();
            }
        }
Пример #9
0
        public ResourceObserver AsyncLoadAsset(string path, System.Action <string, ResourceObserver> cb)
        {
            ResourceState resState = this.GetResState(path);

            if (null == resState)
            {
                resState = new ResourceState(this);
                ulong reqId = this.GenReqId();
                resState.req = ResourceRequest.CreateAsyncRequest(m_resLoader, path, this.ResLoadEndCall, reqId);
                m_resStates.Add(path, resState);
                resState.req.AsyncLoad();
            }
            else
            {
                // 模拟异步
                Core.ins.timer.Add(() => { this.ResLoadEndCall(resState.req); }, 0);
            }
            ResourceObserver ret = resState.AddObserver(cb);

            return(ret);
        }
Пример #10
0
 public ResourceScene(ResourceState resState)
 {
     m_state     = State.Inited;
     m_resState  = resState;
     m_resLoader = resState.loader;
 }
Пример #11
0
 // 重置数据,一般不调用
 public void ResetAll()
 {
     this.ResetCb();
     id       = 0;
     resState = null;
 }