예제 #1
0
        public static void AddScriptListener(int rMessageType, int rFilter, string scriptClassName, string scriptMethodName, bool rImmediate, bool staticBinding = true)
        {
#if JSSCRIPT
#elif LUASCRIPT
            LuaManager.Require(scriptClassName);
            LuaFunction func = LuaManager.GetFunction(scriptMethodName);
            if (func == null)
            {
                Debugger.LogError("register script listener func is null->" + scriptClassName + "^" + scriptMethodName);
                return;
            }
#endif

            MessageDispatcher.AddListener(rMessageType, rFilter, (message) =>
            {
#if JSSCRIPT
                JsRepresentClass jsRepresent = JsRepresentClassManager.Instance.AllocJsRepresentClass(JSClassName, staticBinding);

                if (message != null)
                {
                    jsRepresent.CallFunctionByFunName(JSMethodName, message.Data);
                }
#elif LUASCRIPT
                LuaManager.CallFunc_VX(func, message.Data);
#endif
            }, rImmediate);
        }
예제 #2
0
        private void OnDisable()
        {
            if (uiData == null)
            {
                return;
            }
            UIManager.ResetUIAlpha(this);

            scriptShowUICall = null;
            UISpriteData data = null;

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

#if JSSCRIPT
            jsRepresentClass.CallFunctionByFunName("OnDisable", this);
#elif LUASCRIPT
            if (lua_OnDisable == null)
            {
                lua_OnDisable = LuaManager.GetFunction(name + ".OnDisable");
            }
            if (lua_OnDisable != null)
            {
                LuaManager.CallFunc_V(lua_OnDisable, this);
            }
#endif
        }
예제 #3
0
 internal void OnMessageCallBack(string result)
 {
     if (lua_OnMessage == null)
     {
         lua_OnMessage = LuaManager.GetFunction("MessageBox.OnMessage");
     }
     if (lua_OnMessage != null)
     {
         LuaManager.CallFunc_V(lua_OnMessage, result);
     }
 }
예제 #4
0
 internal void OnDialogCallBack(string result)
 {
     if (lua_OnDialog == null)
     {
         lua_OnDialog = LuaManager.GetFunction("MessageBox.OnDialog");
     }
     if (lua_OnDialog != null)
     {
         LuaManager.CallFunc_V(lua_OnDialog, result);
     }
 }
예제 #5
0
        public static Timer LuaCreateTimer(float interval, int count, int param)
        {
            if (interval <= 0)
            {
                return(null);
            }

            if (callLuaFunc == null)
            {
                callLuaFunc = LuaManager.GetFunction("TimerMgr.Back");
            }

            if (callLuaFunc == null)
            {
                return(null);
            }

            TD td;

            if (disposeQueue.Count > 0)
            {
                disposeQueue.Dequeue(out td);
                if (td != null)
                {
                    td.gameObject.SetActive(true);
                }
            }
            else
            {
                GameObject go = new GameObject();
                Object.DontDestroyOnLoad(go);
                td    = go.AddComponent <TD>();
                td.id = ++idx;
            }
            if (td == null)
            {
                return(null);
            }

            td.interval    = interval;
            td.count       = (short)count;
            td.doSomething = null;
            td.luaDoSth    = callLuaFunc;
            td.param       = param;


            Timer t = new Timer();

            t.td     = td;
            td.timer = t;

            td.StartTimer();
            return(t);
        }
예제 #6
0
        private void OnAdditiveSceneLoaded(string name)
        {
#if LUASCRIPT
            if (luaAdditiveLoadOverFunc == null)
            {
                luaAdditiveLoadOverFunc = LuaManager.GetFunction("SceneManager.ListenAdditiveLoadOver");
            }

            if (luaAdditiveLoadOverFunc != null)
            {
                LuaManager.CallFunc_VX(luaAdditiveLoadOverFunc, name);
            }
#endif
        }
예제 #7
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();
        }
예제 #8
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
            }
        }
예제 #9
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
            }
        }
예제 #10
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
            }
        }
예제 #11
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
            }
        }
예제 #12
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
            }
        }
예제 #13
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
            }
        }
예제 #14
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
            }
        }
예제 #15
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
        }
예제 #16
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);
                }
            }
        }
예제 #17
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
            }
        }
예제 #18
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();
        }
예제 #19
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());
                });
            });
        }
예제 #20
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");
            }
        }
예제 #21
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));
        }
예제 #22
0
 internal static void SetHttpBackProtoBufCall(string className, string funcName)
 {
     LuaManager.Require(className);
     protoBufCall = LuaManager.GetFunction(funcName);
 }
예제 #23
0
 internal void SetLuaRecvCallFunc(string className, string funcName)
 {
     LuaManager.Require(className);
     recvMsgCall = LuaManager.GetFunction(funcName);
 }
예제 #24
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);
        }