Ejemplo n.º 1
0
        void Create()
        {
            JObject    data = JsonConvert.DeserializeObject(param) as JObject;
            string     res  = data["path"].ToString();
            GameObject go   = ResLoad.get(res).gameObject();

            OnLoadFinish(go, data);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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> ());
            }
        }
Ejemplo n.º 4
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));
     }
 }
Ejemplo n.º 5
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;
                }
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }