Ejemplo n.º 1
0
        public static void AddDispose(Timer td, bool cb = false)
        {
            if (td == null)
            {
                return;
            }
            if (td.dispose)
            {
                return;
            }
            if (td.td == null)
            {
                return;
            }

            if (cb)
            {
                if (td.td.doSomething != null)
                {
                    td.td.doSomething(td.td.param);
                }
                else if (td.td.luaDoSth != null)
                {
                    LuaManager.CallFunc_VX(td.td.luaDoSth, td.td.param, 0);
                }
            }

            td.SetDispose();
            if (disposeQueue.Contains(td.td))
            {
                return;
            }

            if (td.td.luaDoSth != null)
            {
                LuaManager.CallFunc_VX(td.td.luaDoSth, td.td.param, 1);
            }

            td.td.doSomething = null;
            td.td.param       = null;
            td.td.luaDoSth    = null;
            td.td.StopAllCoroutines();
            td.td.gameObject.SetActive(false);
            td.td.timer = null;
            disposeQueue.Enqueue(td.td);
            td.td = null;
        }
Ejemplo n.º 2
0
        private void OnSceneWasLoaded()
        {
            if (!alive)
            {
                return;
            }
            if (loadStatus == LoadSceneStatus.END)
            {
                {
                    loadStatus   = LoadSceneStatus.NONE;
                    sceneLoading = false;

                    LuaContext.RefreshDelegateMap();

#if LUASCRIPT
                    if (luaLoadOverFunc == null)
                    {
                        luaLoadOverFunc = LuaManager.GetFunction("SceneManager.ListenLoadOver");
                    }

                    if (luaLoadOverFunc != null)
                    {
                        LuaManager.CallFunc_VX(luaLoadOverFunc, next);
                    }
#endif
                }
            }
            else if (loadStatus == LoadSceneStatus.BEGIN)
            {
                if (!sceneLoading)
                {
                    sceneLoading = true;

                    if (next != null)
                    {
                        Load();
                    }
                }
            }

            ClearSceneAsset();

            Resources.UnloadUnusedAssets();
            System.GC.Collect();
        }
Ejemplo n.º 3
0
        private void OnDoubleClick(GameObject gameObject, int id)
        {
            if (listenOnDoubleClick && !UIManager.IsFocusEventLocked(uiID, id))
            {
#if JSSCRIPT
                jsRepresentClass.CallFunctionByFunName("OnDoubleClick", gameObject, id);
#elif LUASCRIPT
                if (lua_OnDoubleClick == null)
                {
                    lua_OnDoubleClick = LuaManager.GetFunction(name + ".OnDoubleClick");
                }
                if (lua_OnDoubleClick != null)
                {
                    LuaManager.CallFunc_V(lua_OnDoubleClick, gameObject, id);
                }
#endif
            }
        }
Ejemplo n.º 4
0
        private void OnTooltip(GameObject gameObject, bool show, int id)
        {
            if (listenOnTooltip && !UIManager.IsFocusEventLocked(uiID, id))
            {
#if JSSCRIPT
                jsRepresentClass.CallFunctionByFunName("OnTooltip", gameObject, show, id);
#elif LUASCRIPT
                if (lua_OnTooltip == null)
                {
                    lua_OnTooltip = LuaManager.GetFunction(name + ".OnTooltip");
                }
                if (lua_OnTooltip != null)
                {
                    LuaManager.CallFunc_V(lua_OnTooltip, gameObject, show, id);
                }
#endif
            }
        }
Ejemplo n.º 5
0
        private void OnKey(GameObject gameObject, KeyCode key, int id)
        {
            if (listenOnKey && !UIManager.IsFocusEventLocked(uiID, id))
            {
#if JSSCRIPT
                jsRepresentClass.CallFunctionByFunName("OnKey", gameObject, key, id);
#elif LUASCRIPT
                if (lua_OnKey == null)
                {
                    lua_OnKey = LuaManager.GetFunction(name + ".OnKey");
                }
                if (lua_OnKey != null)
                {
                    LuaManager.CallFunc_V(lua_OnKey, gameObject, key, id);
                }
#endif
            }
        }
Ejemplo n.º 6
0
        private void OnDrag(GameObject gameObject, Vector2 delta, int id)
        {
            if (listenOnDrag && !UIManager.IsFocusEventLocked(uiID, id))
            {
#if JSSCRIPT
                jsRepresentClass.CallFunctionByFunName("OnDrag", gameObject, delta, id);
#elif LUASCRIPT
                if (lua_OnDrag == null)
                {
                    lua_OnDrag = LuaManager.GetFunction(name + ".OnDrag");
                }
                if (lua_OnDrag != null)
                {
                    LuaManager.CallFunc_V(lua_OnDrag, gameObject, delta, id);
                }
#endif
            }
        }
Ejemplo n.º 7
0
        private void OnScroll(GameObject gameObject, float delta, int id)
        {
            if (listenOnSroll && !UIManager.IsFocusEventLocked(uiID, id))
            {
#if JSSCRIPT
                jsRepresentClass.CallFunctionByFunName("OnScroll", gameObject, delta, id);
#elif LUASCRIPT
                if (lua_OnScroll == null)
                {
                    lua_OnScroll = LuaManager.GetFunction(name + ".OnScroll");
                }
                if (lua_OnScroll != null)
                {
                    LuaManager.CallFunc_V(lua_OnScroll, gameObject, delta, id);
                }
#endif
            }
        }
Ejemplo n.º 8
0
        private void OnSelect(GameObject gameObject, bool selected, int id)
        {
            if (listenOnSelect && !UIManager.IsFocusEventLocked(uiID, id))
            {
#if JSSCRIPT
                jsRepresentClass.CallFunctionByFunName("OnSelect", gameObject, selected, id);
#elif LUASCRIPT
                if (lua_OnSelect == null)
                {
                    lua_OnSelect = LuaManager.GetFunction(name + ".OnSelect");
                }
                if (lua_OnSelect != null)
                {
                    LuaManager.CallFunc_V(lua_OnSelect, gameObject, selected, id);
                }
#endif
            }
        }
Ejemplo n.º 9
0
        private void OnHover(GameObject gameObject, bool isOver, int id)
        {
            if (listenOnHover && !UIManager.IsFocusEventLocked(uiID, id))
            {
#if JSSCRIPT
                jsRepresentClass.CallFunctionByFunName("OnHover", gameObject, isOver, id);
#elif LUASCRIPT
                if (lua_OnHover == null)
                {
                    lua_OnHover = LuaManager.GetFunction(name + ".OnHover");
                }
                if (lua_OnHover != null)
                {
                    LuaManager.CallFunc_V(lua_OnHover, gameObject, id);
                }
#endif
            }
        }
Ejemplo n.º 10
0
        internal UIFrame(int id, string name, List <string> atlas, List <string> texs)
        {
            _name = name;
            uiID  = id;

            if (atlas != null)
            {
                short index = -1;
                for (int i = 0, count = atlas.Count; i < count; i++)
                {
                    index = GetAtlasIndex(atlas[i]);
                    if (index < 0)
                    {
                        Debugger.LogError("ui atlas is invalid->" + atlas[i]);
                    }
                    else
                    {
                        atlases.Add(index);
                    }
                }
            }

            if (texs != null)
            {
                short index = -1;
                for (int i = 0, count = texs.Count; i < count; i++)
                {
                    index = GetTextureIndex(texs[i]);
                    if (index < 0)
                    {
                        Debugger.LogError("ui texture is invalid->" + texs[i]);
                    }
                    else
                    {
                        textures.Add(index);
                    }
                }
            }


#if LUASCRIPT
            LuaManager.Require("UI/" + name);
#endif
        }
Ejemplo n.º 11
0
        private void OnEnable()
        {
            if (uiData == null)
            {
                return;
            }

            if (lowLayerAlpha < 1)
            {
                UIManager.SetLessLayerUIAlpha(layer, lowLayerAlpha);
            }

            UIManager.ProcessUIAlpha(this);

            UISpriteData data = null;

            for (int i = 0, count = uiData.sprites.Count; i < count; i++)
            {
                data = uiData.sprites[i];
                SetAtlas(data, true);
            }

            UITextureData utd = null;

            for (int i = 0, count = uiData.textures.Count; i < count; i++)
            {
                utd = uiData.textures[i];
                SetTexture(utd, true);
            }

#if JSSCRIPT
            jsRepresentClass.CallFunctionByFunName("OnEnable", this);
#elif LUASCRIPT
            if (lua_OnEnable == null)
            {
                lua_OnEnable = LuaManager.GetFunction(name + ".OnEnable");
            }
            if (lua_OnEnable != null)
            {
                LuaManager.CallFunc_V(lua_OnEnable, this);
            }
#endif
        }
Ejemplo n.º 12
0
        private void LoadAssetOver()
        {
            if (uiData == null)
            {
                Create();
            }
            else
            {
                ProcessShow(true);
                Prepare();

                if (lua_OnShowOver == null)
                {
                    lua_OnShowOver = LuaManager.GetFunction(name + ".OnShowOver");
                }
                if (lua_OnShowOver != null)
                {
                    LuaManager.CallFunc_V(lua_OnShowOver, this);
                }
            }
        }
Ejemplo n.º 13
0
        private void BeginUpdate(List <int> updateList, List <long> totalList)
        {
            canUpdate = true;

            totalSize = 0;
            for (int i = 0, count = totalList.Count; i < count; i++)
            {
                totalSize += totalList[i];
            }

            Debugger.LogError("download version->" + totalSize + "^" + updateList.Count + "^" + totalList.Count);
            curSize = 0;
            if (updateList.Count > 0)
            {
                if (totalSize > 0)
                {
                    totalNum       = updateList.Count;
                    needUpdateList = updateList;

                    canUpdate = false;
                    LuaInterface.LuaFunction func = LuaManager.GetFunction("OnResourceNeedUpdate");
                    if (func != null)
                    {
                        LuaManager.CallFunc_VX(func, totalNum, totalSize);
                    }
                    else
                    {
                        Debug.LogError("script function 'OnResourceNeedUpdate' is null");
                    }
                }
#if UNITY_EDITOR
                else
                {
                    Debugger.LogError("update files is invalid");
                }
#endif
            }
        }
Ejemplo n.º 14
0
        private static IEnumerator _HttpGetSendBackString(string url, string ob, string className, string functionName)
        {
            WWW www = new WWW(url + "?" + ob);

            yield return(www);

            if (www.error != null)
            {
                Debugger.LogError("http get send error->" + www.error);
            }
            else
            {
                if (www.bytes != null)
                {
                    string data = System.Text.Encoding.UTF8.GetString(www.bytes);

                    if (!string.IsNullOrEmpty(data))
                    {
#if JSSCRIPT
                        JsRepresentClass jsRepresentClass =
                            JsRepresentClassManager.Instance.AllocJsRepresentClass(className, true);
                        jsRepresentClass.CallFunctionByFunName(functionName, data);
#elif LUASCRIPT
                        LuaManager.Require(className);
                        LuaInterface.LuaFunction func = LuaManager.GetFunction(functionName);
                        LuaManager.CallFunc_VX(func, data);
#endif
                    }
                }
                else
                {
                    Debugger.LogError("http get response data is null");
                }
            }

            www.Dispose();
        }
Ejemplo n.º 15
0
 internal void SetLuaRecvCallFunc(string className, string funcName)
 {
     LuaManager.Require(className);
     recvMsgCall = LuaManager.GetFunction(funcName);
 }
Ejemplo n.º 16
0
        private void DownloadVersionFile(string url, byte[] data, System.Object obj)
        {
            if (data == null)
            {
                if (Config.Detail_Debug_Log())
                {
                    Debug.LogError("download version data failed");
                }

                LuaInterface.LuaFunction func = LuaManager.GetFunction("OnDownloadVersionDataFailed");
                if (func != null)
                {
                    LuaManager.CallFunc_VX(func);
                }
                else
                {
                    Debug.LogError("script function 'OnDownloadVersionDataFailed' is null");
                }

                return;
            }

            if (Config.Detail_Debug_Log())
            {
                Debug.Log("download version");
            }

            GameUtils.BytesMD5Value(data, (md5Str) =>
            {
                if (Config.Detail_Debug_Log())
                {
                    Debug.Log("download version 1->" + md5Str + "^" + vfc.Md5);
                }
                if (md5Str != vfc.Md5.ToLower())
                {
                    Debugger.LogError("versionInfo file is invalid->" + md5Str + "^" + vfc.Md5);
                    return;
                }

                versionInfoData = new byte[data.Length];
                System.Array.Copy(data, versionInfoData, data.Length);
                ResLoader.RemoveImpurity(data, (arr) =>
                {
                    GameUtils.MemoryStreamClear();
                    GameUtils.ms.Write(data, 0, data.Length);
                    GameUtils.ms.Position = 0;

                    versionInfo = VersionInfo.Deserialize(GameUtils.ms);

                    if (Config.Detail_Debug_Log())
                    {
                        Debugger.Log("download version 2->" + versionInfo.Files.Count);
                    }

                    versionFileData            = new VersionFileData();
                    versionFileData.fileLocate = new List <byte>();

                    nameToRelation.Clear();

                    VersionInfoToData(versionInfo, (byte)FileLocate.None);

                    totalNum = 0;

                    StartCoroutine(BeginCheckUpdateFiles());
                });
            });
        }
Ejemplo n.º 17
0
        private void CheckVersion(string url, byte[] data, System.Object obj)
        {
            if (data == null)
            {
                if (Config.Detail_Debug_Log())
                {
                    Debug.LogError("download check version data failed");
                }

                LuaInterface.LuaFunction func = LuaManager.GetFunction("OnDownloadCheckVersionDataFailed");
                if (func != null)
                {
                    LuaManager.CallFunc_VX(func);
                }
                else
                {
                    Debug.LogError("script function 'OnDownloadCheckVersionDataFailed' is null");
                }

                return;
            }

            GameUtils.MemoryStreamClear();
            GameUtils.ms.Write(data, 0, data.Length);
            GameUtils.ms.Position = 0;

            vfc           = VersionForCheck.Deserialize(GameUtils.ms);
            updateVersion = false;
            if (Config.Detail_Debug_Log())
            {
                Debugger.Log("versionInfo->" + (versionInfo == null) + "^" + vfc.Version);
            }
            if (versionInfo != null)
            {
                Debugger.Log("vi->" + versionInfo.Version);
            }
            else if (streamingAssetVersionInfo != null)
            {
                versionInfo = streamingAssetVersionInfo;

                versionFileData            = new VersionFileData();
                versionFileData.fileLocate = new List <byte>();

                nameToRelation.Clear();

                VersionInfoToData(versionInfo, (byte)FileLocate.StreamingAsset);
            }

            if (versionInfo == null || vfc.Version != versionInfo.Version)
            {
                Debugger.LogError("version not match, need update.");
                updateVersion = true;
                GameUtils.StringBuilderClear();
                GameUtils.stringBuilder.Append(remoteAssetPath);
                GameUtils.stringBuilder.Append(versionInfoFileName);
                GameUtils.stringBuilder.Append(GameUtils.GetSuffixOfURL());
                StartCoroutine(ResLoader.BeginDownload(GameUtils.stringBuilder.ToString(), DownloadVersionFile, null, updatePBar));
            }
            else
            {
                canUpdate = true;
                Debugger.Log("update nothing");
            }
        }
Ejemplo n.º 18
0
        /*
         * internal void Connect(InnerNetNode node)
         * {
         * }
         */

#if LUASCRIPT
        //internal struct RecvData
        //{
        //    internal InnerNetNode node;
        //    internal NetAdapter.DeserializationData data;
        //}

        internal void SetLuaRecvCallFunc(string className, string funcName)
        {
            LuaManager.Require(className);
            recvMsgCall = LuaManager.GetFunction(funcName);
            //Debugger.Log("set lua call->" + (recvMsgCall == null));
        }
Ejemplo n.º 19
0
 internal static void SetHttpBackProtoBufCall(string className, string funcName)
 {
     LuaManager.Require(className);
     protoBufCall = LuaManager.GetFunction(funcName);
 }
Ejemplo n.º 20
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);
        }