Exemplo n.º 1
0
        public static Thread RunAsync(Action begin, Action end)
        {
            if (!GameCommon.IsMainThread())
            {
                if (begin != null)
                {
                    begin();
                }
                if (end != null)
                {
                    end();
                }
                return(null);
            }

            Initialize();
            while (numThreads >= maxThreads)
            {
                Thread.Sleep(1);
            }

            Interlocked.Increment(ref numThreads);
            TaskItem item;

            {
                item = GenTaskItem();
                item.Init(begin, end);
            }

            ThreadPool.QueueUserWorkItem(RunAction, item);
            return(null);
        }
Exemplo n.º 2
0
        public static int SetParent(int parent, int child, bool reset)
        {
            Transform ptrans = GetTransform(parent);

            if (!ptrans)
            {
                return(-1);
            }

            Transform ctrans = GetTransform(child);

            if (!ctrans)
            {
                return(-2);
            }

            ctrans.parent = ptrans;

            if (reset)
            {
                GameCommon.ResetTrans(ctrans);
            }

            return(0);
        }
Exemplo n.º 3
0
        public static void ResetTrans(int id)
        {
            Transform trans = GetTransform(id);

            if (!trans)
            {
                return;
            }

            GameCommon.ResetTrans(trans);
        }
Exemplo n.º 4
0
 private static void Initialize()
 {
     if (!initialized)
     {
         if (GameCommon.IsMainThread())
         {
             if (!Application.isPlaying)
             {
                 return;
             }
             initialized = true;
             var g = new GameObject("ThreadTask");
             UnityEngine.Object.DontDestroyOnLoad(g);
             _current = g.AddComponent <ThreadTask>();
         }
     }
 }
Exemplo n.º 5
0
        void Start()
        {
            if (inited)
            {
                return;
            }
            inited = true;

            GameCommon.Init();

            ThreadTask.RunAsync(() => { }, null);

            Object.DontDestroyOnLoad(gameObject);
            Application.runInBackground = true;

            BeforeInit();

            Init();
        }
Exemplo n.º 6
0
        private void Create()
        {
            status = UIStatus.Creating;
            ResLoader.LoadByName(name, (asset, param) =>
            {
                if (asset == null)
                {
                    return;
                }
                GameObject goo = ((GameObject)Object.Instantiate(asset));
                goo.name       = name;
                uiData         = goo.GetComponent <UIData>();
                if (uiData == null)
                {
                    Debugger.LogError("ui prefab has no UIData->" + name);
                    return;
                }

                for (int i = 0, count = uiData.events.Count; i < count; i++)
                {
                    RegisterEvent(uiData.events[i]);
                }

                for (int i = 0, count = uiData.labels.Count; i < count; i++)
                {
                    uiData.labels[i].label.font = comFont;
                }

                m_transform        = uiData.transform;
                m_transform.parent = UIManager.GetUIRoot();

                GameCommon.ResetTrans(m_transform);
                UIPanel[] panels = m_transform.GetComponents <UIPanel>();
                if (panels.Length > 0)
                {
                    uiData.panels.AddRange(panels);
                }
                panels = m_transform.GetComponentsInChildren <UIPanel>();
                if (panels.Length > 0)
                {
                    uiData.panels.AddRange(panels);
                }

                if (layer >= 0)
                {
                    UIPanel panel = null;
                    for (int i = 0, count = uiData.panels.Count; i < count; i++)
                    {
                        panel = uiData.panels[i];
                        panel.sortingOrder = panel.depth;
                    }
                }

                UIManager.UICreateCall(id, this);


#if JSSCRIPT
                jsRepresentClass.CallFunctionByFunName("OnCreate", this);
#elif LUASCRIPT
                if (lua_OnCreate == null)
                {
                    lua_OnCreate = LuaManager.GetFunction(name + ".OnCreate");
                }
                if (lua_OnCreate != null)
                {
                    LuaManager.CallFunc_V(lua_OnCreate, this);
                }
#endif

                UIManager.RegisterUILayer(layer, this);

                if (hasBG)
                {
                    GameObject go    = new GameObject();
                    go.layer         = m_transform.gameObject.layer;
                    Transform strans = go.transform;
                    strans.parent    = m_transform;
                    GameCommon.ResetTrans(strans);
                    strans.localScale = new Vector3(2000, 2000, 1);
                    UIColorSprite ucs = go.AddComponent <UIColorSprite>();
                    ucs.depth         = -1;
                    ucs.SetShaderEnum(UIColorSprite.ShaderEnum.SH2, true);
                    ucs.SetColor(bgColor);

                    if (bgCollider)
                    {
                        go.AddComponent <BoxCollider>();
                    }
                }

                if (status != UIStatus.Creating)
                {
                    Debugger.Log("create show ui after disable");
                    ProcessShow(false);
                    ClearAtlas();
                    ClearTextures();
                    return;
                }

                Prepare();

                if (lua_OnShowOver == null)
                {
                    lua_OnShowOver = LuaManager.GetFunction(name + ".OnShowOver");
                }
                if (lua_OnShowOver != null)
                {
                    LuaManager.CallFunc_V(lua_OnShowOver, this);
                }
            }, null);
        }