示例#1
0
            internal void onEvent(State state, Action action, float progress)
            {
                mAction   = action;
                mState    = state;
                mProgress = progress;
                switch (mState)
                {
                case State.Completed:
                    ResLoad.setVersionPart(mThis.mNewVersion, mParts);
                    Log.i("patch task ok! name=" + mName, Log.Tag.Update);
                    if (mCallback != null)
                    {
                        mCallback(this);
                    }
                    //移除任务
                    mThis.closeTask(mName);
                    break;

                default:
                    if (mCallback != null)
                    {
                        mCallback(this);
                    }
                    break;
                }
            }
示例#2
0
        void Create()
        {
            JObject    data = JsonConvert.DeserializeObject(param) as JObject;
            string     res  = data["path"].ToString();
            GameObject go   = ResLoad.get(res).gameObject();

            OnLoadFinish(go, data);
        }
示例#3
0
 public ResLoad(ResLoad rl)
 {
     mItem     = rl.mItem;
     mUniqueID = mItem.mUniqueID;
     if (mItem.mReside == ResideType.Ref)
     {
         ++mItem.mRef;
     }
 }
示例#4
0
 internal PatchTask(string name, int[] parts)
 {
     if (mThis == null)
     {
         throw new Exception("disable new PatchTask by yourself");
     }
     mParts = parts;
     mName  = name;
     Log.i("creat patch task name=" + mName + ",parts=" + ResLoad.intArray2Str(parts), Log.Tag.Update);
 }
示例#5
0
        public void ReloadResource()
        {
            Log.i("ResMgr Reset!!!", Log.Tag.RES);
            ResLoad.clearCach();
            ResLoad.init(this);

            /*if (mUseLua)
             * {
             *  LuaRoot.dirty = true;
             *  GetComponent<LuaRoot>().Init();
             * }*/
        }
示例#6
0
        public Dictionary <int, TableBase> build()
        {
            Dictionary <int, TableBase> dic = new Dictionary <int, TableBase>();

            if (TableMgr.TestModel)
            {
                //文件以.txt结尾
                string    path  = string.Format("Table/{0}", recoderType.Name);
                TextAsset ta    = ResLoad.get(path).asset <TextAsset>();
                string[]  datas = ta.text.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < datas.Length; ++i)
                {
                    if (string.IsNullOrEmpty(datas[i]) || datas[i][0] != '{')
                    {
                        continue;
                    }
                    try
                    {
                        TableBase record = JsonUtility.FromJson(datas[i], recoderType) as TableBase;
                        dic.Add(record.id, record);
                    }
                    catch (Exception e)
                    {
                        Log.e("fmt error:" + datas [i] + ",path=" + path);
                    }
                }
                ResLoad.clearByPath(path);
            }
            else
            {
                //文件以.bytes结尾,否则字符串处理可能有错
                string    path = string.Format("Table/{0}", recoderType.Name);
                TextAsset ta   = ResLoad.get(path).asset <TextAsset>();
                byte[]    data = ta.bytes;
                using (MemoryStream ms = new MemoryStream(ta.bytes))
                {
                    BinaryReader r     = new BinaryReader(ms);
                    int          count = r.ReadInt32();  //记录数
                    string       head  = r.ReadString(); //表头
                    int[]        idx   = TypeReader(head);
                    for (int i = 0; i < count; ++i)
                    {
                        TableBase record = Activator.CreateInstance(recoderType) as TableBase;
                        record.read(r, idx);
                        dic.Add(record.id, record);
                    }
                }
                ResLoad.clearByPath(path);
            }
            return(dic);
        }
示例#7
0
        void RunScript(string file)
        {
            Log.i("runScript path=" + file, Log.Tag.Sitcom);
            if (string.IsNullOrEmpty(file))
            {
                Log.e("sitcom table error sitcomid=" + mSitcomId, Log.Tag.Sitcom);
                return;
            }

            using (ResLoad ld = ResLoad.get(file))
            {
                RunScript(ld.asset <TextAsset> ());
            }
        }
示例#8
0
 public static bool setImage(Image image, string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         return(false);
     }
     using (ResLoad rl = ResLoad.get(path))
     {
         if (null == rl.asset <GameObject>())
         {
             return(false);
         }
         return(setImage(image, rl));
     }
 }
示例#9
0
        public static bool setImage(Image image, ResLoad rl)
        {
            if (image == null)
            {
                return(false);
            }
            AssetRef ar = image.GetComponent <AssetRef> ();

            if (ar == null)
            {
                ar = image.gameObject.AddComponent <AssetRef> ();
            }
            ar.copyRef(rl.depends());
            image.sprite = ar.mAsset as Sprite;
            return(true);
        }
示例#10
0
 internal void addRef()
 {
     if (mDepends == null)
     {
         return;
     }
     for (int i = 0, max = mDepends.Length; i < max; ++i)
     {
         string key = mDepends [i];
         if (string.IsNullOrEmpty(key))
         {
             continue;
         }
         ResLoad.addAssetRef(key);
     }
 }
示例#11
0
 internal static void decRef(string[] depends)
 {
     if (depends == null)
     {
         return;
     }
     for (int i = 0, max = depends.Length; i < max; ++i)
     {
         string key = depends [i];
         if (string.IsNullOrEmpty(key))
         {
             continue;
         }
         ResLoad.decAssetRef(key);
     }
 }
示例#12
0
        static void loadCommonAB()
        {
            mShaders.Clear();
            ResLoad.get("common/font", ResideType.InGame).assetBundle();
            AssetBundle ab = ResLoad.get("common/shader", ResideType.InGame).assetBundle();

            if (ab != null)
            {
                Object[] objs = ab.LoadAllAssets();
                for (int i = 0, max = objs.Length; i < max; ++i)
                {
                    Shader sd = objs [i] as Shader;
                    mShaders [sd.name] = sd;
                }
            }
        }
示例#13
0
        IEnumerator Start()
        {
            yield return(new WaitForSeconds(mStartDelay));

            if (mUseLua)
            {
                gameObject.AddComponent <LuaRoot>();
            }
            Application.targetFrameRate = 60;
            Application.runInBackground = true;
            if (EventSystem.current != null)
            {
                DontDestroyOnLoad(EventSystem.current.gameObject);
            }
            ResLoad.init(this);
            GameStart();
        }
示例#14
0
        public void Play(string clipRes, OnComplite onComplete, bool unscaleTime)
        {
            anim = gameObject.GetComponent <Animation>();
            if (anim == null)
            {
                anim = gameObject.AddComponent <Animation>();
            }
            AnimationClip ac = ResLoad.get(clipRes).asset <AnimationClip>();

            anim.AddClip(ac, ac.name);
            if (unscaleTime)
            {
                StartCoroutine(Play(ac.name, onComplete));
            }
            else
            {
                anim.Play(ac.name);
            }
        }
示例#15
0
        public Window GetWindow(string name, bool create = false, string id = null)
        {
            Window win = null;
            string key = id == null ? name : name + id;

            if (mWindows.TryGetValue(key, out win))
            {
                return(win);
            }
            if (create)
            {
                GameObject go = ResLoad.get(mWinResMap [name]).gameObject();
                if (go == null)
                {
                    return(null);
                }
                go.transform.SetParent(mWinRoot, false);

                /*//======================
                 * RectTransform rt = go.transform as RectTransform;
                 * Vector2 offsetMin = rt.offsetMin;
                 * Vector2 offsetMax = rt.offsetMax;
                 * rt.SetParent(WindowMgr.single.mWinRoot);
                 * rt.localPosition = Vector3.zero;
                 * rt.localScale = Vector3.one;
                 * //必须设置,否则setParent后,prefab原来的size被改变了
                 * rt.offsetMin = offsetMin;
                 * rt.offsetMax = offsetMax;
                 * //=======================*/
                win           = go.GetComponent <Window>();
                win.winName   = key;
                mWindows[key] = win;
                mZOrder.Add(win);
                WindowMgr.single.UpdateZOrder();
                return(win);
            }
            return(null);
        }
示例#16
0
        public static AnimationCurve Get(string assetName, string acName)
        {
            AnimationCurve ac  = null;
            string         key = assetName + acName;

            if (mCach.TryGetValue(key, out ac))
            {
                return(ac);
            }

            GameObject go     = ResLoad.get("AC/" + assetName).gameObject();
            AC         acMono = go.GetComponent <AC> ();

            for (int i = 0; i < acMono._acs.Count; ++i)
            {
                ACItem aci = acMono._acs[i];
                key         = assetName + aci.name;
                mCach [key] = aci.ac;
            }
            ac = mCach [key];
            DestroyObject(go);
            return(ac);
        }
示例#17
0
            internal void asyncLoad <T>(ResLoad loader, OnLoadFinish onLoadFinish) where T : UnityEngine.Object
            {
                if (mAsset != null)
                {
                    if (null != onLoadFinish)
                    {
                        onLoadFinish(loader);
                    }
                    return;
                }

                if (mCallData == null)
                {
                    mCach[mKey] = this;
                    mCallData   = new CallData(loader, onLoadFinish);
                    mMono.StartCoroutine(yieldLoad(typeof(T)));
                }
                else
                {
                    CallData cd = new CallData(loader, onLoadFinish);
                    cd.next   = mCallData;
                    mCallData = cd;
                }
            }
示例#18
0
        public static HeadInfo Bind(Transform trans, object data)
        {
            if (mMount == null)
            {
                return(null);                          //for test
            }
            HeadInfo hi = null;

            if (mHeadInfos.Count > 0 && mHeadInfos[0].target == null)
            {
                hi = mHeadInfos[0];
                hi.gameObject.SetActive(true);
            }
            else
            {
                GameObject go = ResLoad.get("UI/HeadInfo", ResideType.InScene).gameObject();
                go.transform.SetParent(mMount, false);
                hi = go.GetComponent <HeadInfo>();
                mHeadInfos.Add(hi);
            }
            hi.target = trans;
            hi.Init(data);
            return(hi);
        }
示例#19
0
 void OnDestroy()
 {
     GameExit();
     ResLoad.deinit();
     Log.deinit();
 }
示例#20
0
 public CallData(ResLoad loader, OnLoadFinish func)
 {
     this.loader = loader;
     this.func   = func;
 }
示例#21
0
        public Audio Play(int soundId, GameObject source, SwitchType switchType = SwitchType.Fade, string tag = null)
        {
            if (soundId == 0)
            {
                return(null);
            }

            // 背景音乐关闭
            if (soundId <= 100 && false == mMusicOn)
            {
                return(null);
            }

            // 音效关闭
            if (soundId > 100 && false == mEffectOn)
            {
                return(null);
            }

            //该背景音乐正在播放
            if (soundId <= 100 && mCurMusic != null && mCurMusic.tb.id == soundId)
            {
                return(mCurMusic);
            }

            TBSound tb = TableMgr.single.GetDataByKey(typeof(TBSound), soundId) as TBSound;

            if (null == tb)
            {
                return(null);
            }
            GameObject src;

            if (source == null)
            {//2d声音/
                src = new GameObject(soundId.ToString());
                if (tag != null)
                {
                    src.tag = tag;
                }
                src.transform.parent        = transform;
                src.transform.localPosition = Vector3.zero;
            }
            else
            {
                src = new GameObject(soundId.ToString());
                if (tag != null)
                {
                    src.tag = tag;
                }
                src.transform.parent        = source.transform;
                src.transform.localPosition = Vector3.zero;
            }

            Audio audio = new Audio();

            audio.switchType = switchType;
            audio.tb         = tb;
            audio.trans      = src.transform;
            audio.state      = StateType.Waitting;
            if (tb.id <= 100)
            {
                if (mCurMusic != null)
                {
                    mCurMusic.Stop();
                }
                mCurMusic   = audio;
                mCurMusicId = soundId;
            }

            //异步的引用计数会出错,可能src对象销毁了asset才加载进来
            ResLoad rl = ResLoad.get(tb.asset, ResideType.Ref);

            src.AddComponent <AudioRef>().resLoad = rl;
            OnLoadAssetFinish(rl.asset <AudioClip>(), src, audio, null);
            return(audio);
        }