Exemplo n.º 1
0
 public void RemoveObserver(ResourceObserver ob)
 {
     if (null != ob)
     {
         this.RemoveObserver(ob.id);
     }
 }
Exemplo n.º 2
0
 public ResourceObserver AsyncLoadAsset(string path, System.Action<string, ResourceObserver> cb)
 {
     ResourceObserver ret = this.GetLoadedResState(path);
     if (null == ret)
     {
         ret = m_loader.AsyncLoadAsset(path, (string resPath, ResourceObserver resOb) => {
             if (null == this.GetResObserver(path) && null != ret && ret.isValid)
             {
                 m_resObservers.Add(ret.path, ret);
             }
             else
             {
                 ret.Release();
             }
             if (null != cb)
             {
                 cb(resPath, resOb);
             }
         });
     }
     else
     {
         if (null != cb)
         {
             Core.ins.timer.Add(() => {
                 cb(path, ret);
             }, 0);
         }
     }
     return ret;
 }
Exemplo n.º 3
0
 public ResourceObserver GetLoadedResState(string path)
 {
     ResourceObserver resState = this.GetResObserver(path);
     if (null == resState || !resState.isLoaded)
         return null;
     return resState;
 }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 public void RemoveResObserver(ResourceObserver ob)
 {
     if (null != ob && null != ob.resState)
     {
         ob.resState.RemoveObserver(ob.id);
     }
 }
Exemplo n.º 6
0
        public ResourceObserver AddObserver(System.Action <string, ResourceObserver> cb)
        {
            ++m_lastObserverId;
            ResourceObserver ob = new ResourceObserver(cb);

            ob.id       = m_lastObserverId;
            ob.resState = this;
            m_observers.Add(ob.id, ob);
            return(ob);
        }
Exemplo n.º 7
0
        public ResourceObserver CoLoadAsset(string path)
        {
            ResourceObserver ret = this.GetResObserver(path);
            if (null == ret)
            {
                ret = m_loader.CoLoadAsset(path);
                m_resObservers.Add(ret.path, ret);

            }
            return ret;
        }
Exemplo n.º 8
0
 protected ResourceObserver GetResObserver(string path)
 {
     ResourceObserver ret = null;
     m_resObservers.TryGetValue(path, out ret);
     if (null != ret && !ret.isValid)
     {
         m_resObservers.Remove(path);
         ret = null;
     }
     return ret;
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 public ResourceObserver LoadAsset(string path)
 {
     ResourceObserver ret = this.GetLoadedResState(path);
     if (null == ret)
     {
         ret = m_loader.LoadAsset(path);
         if (null != ret && ret.isValid && null == GetResObserver(path))
         {
             m_resObservers.Add(ret.path, ret);
         }
         else
         {
             ret.Release();
             ret = this.GetLoadedResState(path);
         }
     }
     return ret;
 }
Exemplo n.º 11
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);
        }