예제 #1
0
        protected override void OnInit(object userData)
        {
            base.OnInit(userData);

            luaEnv = LuaManager.luaEnv; //此处要从LuaManager上获取 全局只有一个

            scriptEnv = luaEnv.NewTable();

            LuaTable meta = luaEnv.NewTable();

            meta.Set("__index", luaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();

            string prefabName = name;

            if (prefabName.Contains("(Clone)"))
            {
                prefabName = prefabName.Split(new string[] { "(Clone)" }, StringSplitOptions.RemoveEmptyEntries)[0] + "View";
            }

            onInit         = scriptEnv.GetInPath <OnInitHandler>(prefabName + ".OnInit");
            onOpen         = scriptEnv.GetInPath <OnOpenHandler>(prefabName + ".OnOpen");
            onClose        = scriptEnv.GetInPath <OnCloseHandler>(prefabName + ".OnClose");
            onBeforDestroy = scriptEnv.GetInPath <OnBeforDestroyHandler>(prefabName + ".OnBeforDestroy");

            scriptEnv.Set("self", this);
            if (onInit != null)
            {
                onInit(userData);
            }
        }
예제 #2
0
        /// -----------------------------------------------------------------
        /// <summary>
        /// </summary>
        // -----------------------------------------------------------------
        public bool AddCloseHandler(OnCloseHandler handler)
        {
            lock (m_closeRegistry)
                m_closeRegistry.Add(handler);

            return(true);
        }
예제 #3
0
        protected override void OnInit(object userData)
        {
            base.OnInit(userData);
            luaEnv = LuaManager.luaEnv; //此处要从LuaManager上获取 全局只有一个
            if (luaEnv == null)
            {
                return;
            }

            string prefabName = name;

            if (prefabName.Contains("(Clone)"))
            {
                prefabName = prefabName.Split(new string[] { "(Clone)" }, StringSplitOptions.RemoveEmptyEntries)[0] + "View";
            }
            //根据这个ui面板的名字监听 注意预制件上的名称要和lua脚本名称一致
            onInit        = luaEnv.Global.GetInPath <OnInitHandler>(prefabName + ".OnInit");
            onOnpe        = luaEnv.Global.GetInPath <OnOpenHandler>(prefabName + ".OnOpen");
            onClose       = luaEnv.Global.GetInPath <OnCloseHandler>(prefabName + ".OnClose");
            onBeforDestry = luaEnv.Global.GetInPath <OnBeforDestryHandler>(prefabName + ".OnBeforDestry");

            if (onInit != null)
            {
                onInit(transform, userData);
            }
        }
예제 #4
0
        protected override void OnInit()
        {
            base.OnInit();

            luaEnv = LuaManager.luaEnv;//从LuaManager上获取 全局只有一个
            if (luaEnv == null)
            {
                return;
            }

            scriptEnv = luaEnv.NewTable();

            LuaTable meta = luaEnv.NewTable();

            meta.Set("__index", luaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();

            string name = "UI_TaskView";

            onInit   = scriptEnv.GetInPath <OnInitHandler>(name + ".OnInit");
            onOpen   = scriptEnv.GetInPath <OnOpenHandler>(name + ".OnOpen");
            onClose  = scriptEnv.GetInPath <OnCloseHandler>(name + ".OnClose");
            onBefore = scriptEnv.GetInPath <OnBeforeHandler>(name + ".OnBefore");
            scriptEnv.Set("self", this);
            onInit?.Invoke(UIFormTransform, Close);
        }
예제 #5
0
        public static void WsRemoveOnClose(uint objectId, OnCloseHandler callback)
        {
            if (!JslibInterop.onCloseHandlers.ContainsKey(objectId))
            {
                return;
            }

            JslibInterop.onCloseHandlers[objectId] -= callback;
        }
예제 #6
0
        public static void WsAddOnClose(uint objectId, OnCloseHandler callback)
        {
            if (!JslibInterop.onCloseHandlers.ContainsKey(objectId))
            {
                JslibInterop.onCloseHandlers[objectId] = null;
            }

            JslibInterop.onCloseHandlers[objectId] += callback;
        }
예제 #7
0
        protected override void OnBeforeDestroy()
        {
            base.OnBeforeDestroy();
            onBefore?.Invoke();

            onInit   = null;
            onOpen   = null;
            onClose  = null;
            onBefore = null;
        }
예제 #8
0
    public void CloseSelf()
    {
        Accessor.OverlayViewManager.HideCurrent();

        if (OnNextClose != null)
        {
            OnNextClose();
            OnNextClose = null;
        }
    }
예제 #9
0
    protected void Close(WindowResult result = WindowResult.None)
    {
        Managers.UiManager.Instance.Close(Type);
        if (OnClose != null)
        {
            OnClose(this, result);
        }

        this.OnClose = null;
        compontCache?.Clear();
    }
예제 #10
0
 protected override void OnBeforDestroy()
 {
     base.OnBeforDestroy();
     //备注 调用销毁的话,经常会造成Unity崩溃
     if (onBeforDestroy != null)
     {
         onBeforDestroy();
     }
     onInit         = null;
     onOpen         = null;
     onClose        = null;
     onBeforDestroy = null;
 }
예제 #11
0
        protected override void OnBeforDestroy()
        {
            base.OnBeforDestroy();
            if (onBeforDestroy != null)
            {
                onBeforDestroy();
            }

            onInit         = null;
            onOpen         = null;
            onClose        = null;
            onBeforDestroy = null;

            int len = m_LuaComs.Length;

            for (int i = 0; i < len; i++)
            {
                LuaCom com = m_LuaComs[i];
                com.Trans = null;
                com       = null;
            }
            //卸载图片资源
            // int len = m_LuaComs.Length;
            // for (int i = 0; i < len; i++)
            // {
            //     LuaCom com = m_LuaComs[i];
            //
            //     switch (com.Type)
            //     {
            //         case LuaComType.Button:
            //         case LuaComType.Image:
            //         case LuaComType.YouYouImage:
            //             {
            //                 Image img = com.Trans.GetComponent<Image>();
            //                 img.sprite = null;
            //             }
            //             break;
            //         case LuaComType.RawImage:
            //             {
            //                 RawImage img = com.Trans.GetComponent<RawImage>();
            //                 img.texture = null;
            //             }
            //             break;
            //     }
            //
            //     com.Trans = null;
            //     com = null;
            // }
        }
        protected override void OnBeforeDestroy()
        {
            base.OnBeforeDestroy();
            if (onBeforeDestroy != null)
            {
                onBeforeDestroy();
            }
            onInit          = null;
            onOpen          = null;
            onClose         = null;
            onBeforeDestroy = null;

            //卸载图片资源
            int len = m_LuaComs.Length;

            for (int i = 0; i < len; i++)
            {
                LuaCom com = m_LuaComs[i];

                switch (com.Type)
                {
                case LuaComponentType.Button:
                case LuaComponentType.Image:
                case LuaComponentType.YouYouImage:
                {
                    Image ima = com.Trans.GetComponent <Image>();
                    ima.sprite = null;
                }
                break;

                case LuaComponentType.RawImage:
                {
                    RawImage ima = com.Trans.GetComponent <RawImage>();
                    ima.texture = null;
                }
                break;
                }
                com.Trans = null;
                com       = null;
            }
        }
예제 #13
0
        /// <summary>
        /// 删除
        /// </summary>
        protected override void OnBeforDestry()
        {
            base.OnBeforDestry();
            if (onBeforDestry != null)
            {
                onBeforDestry();
            }
            onInit        = null;
            onOnpe        = null;
            onClose       = null;
            onBeforDestry = null;

            //卸载图片资源
            int len = m_LuaComs.Length;

            for (int i = 0; i < len; i++)
            {
                LuaCom com = m_LuaComs[i];
                com.Trans = null;
                com       = null;
            }
        }
예제 #14
0
        /// -----------------------------------------------------------------
        /// <summary>
        /// </summary>
        // -----------------------------------------------------------------
        public bool AddCloseHandler(OnCloseHandler handler)
        {
            lock (m_closeRegistry)
                m_closeRegistry.Add(handler);

            return true;
        }
예제 #15
0
        public bool Start()
        {
            if (!check())
            {
                return(false);
            }

            //			opendSocks5Client.OnDataReceived += OpendSocks5Client_OnDataReceived;
            opendSocks5Client.OnDisconnected += OpendSocks5Client_OnDisconnected;

            logger.Info(this.GetHashCode() + "=>" + (opendSocks5Client.Client.Sock.LocalEndPoint as IPEndPoint) + "<->" + (opendSocks5Client.Client.Sock.RemoteEndPoint as IPEndPoint));

            CachedTasks = new[] {
                Task.Run(() =>
                {
                    while (true)
                    {
                        LoopTranClient();
                    }
                    logger.Info("opendSocks5Client:" + opendSocks5Client.Connected + "");
                }, source.Token)
                .ContinueWith((x, y) =>
                {
                    var args = (y as List <object>);

                    logger.Info("closing client");
                    if (x.IsFaulted)
                    {
                        args.Add(x.Exception);
                    }
                }, tmpArgs),

                Task.Run(() =>
                {
                    while (!this.breakLoopTrace)
                    {
                        LoopTran();
                    }

                    logger.Info("opendSocket:" + this.opendSocket.Connected + "");
                }, source.Token)
                .ContinueWith((x, y) =>
                {
                    var args = (y as List <object>);

                    //(args[1] as Socks5Client)?.Close();
                    logger.Info("closing socket");
                    //OnCloseHandler?.Invoke(this, new AdapterOnCloseEventArgs()
                    //{
                    //	S = (args[0] as Socket),
                    //	Client = (args[1] as Socks5Client),
                    //	Adapter = this

                    //});
                    if (x.IsCanceled)
                    {
                    }
                    else if (x.IsFaulted)
                    {
                        args.Add(x.Exception);
                    }
                }, tmpArgs)
            };

            Task.WhenAll(CachedTasks).ContinueWith(x =>
            {
                this.opendSocket.Shutdown(SocketShutdown.Both);
                this.opendSocks5Client.Client.Sock.Shutdown(SocketShutdown.Both);
                this.opendSocket.Close();
                this.opendSocks5Client.Close();
                OnCloseHandler?.Invoke(this, new AdapterOnCloseEventArgs()
                {
                    S       = this.opendSocket,
                    Client  = this.opendSocks5Client,
                    Adapter = this
                });
            });


            return(true);
        }
예제 #16
0
        protected override void OnInit(object userData)
        {
            base.OnInit(userData);

            luaEnv = LuaManager.luaEnv; //此处要从LuaManager上获取 全局只有一个

            scriptEnv = luaEnv.NewTable();

            LuaTable meta = luaEnv.NewTable();

            meta.Set("__index", luaEnv.Global);
            scriptEnv.SetMetaTable(meta);
            meta.Dispose();

            string prefabName = name;

            if (prefabName.Contains("(Clone)"))
            {
                prefabName = prefabName.Split(new string[] { "(Clone)" }, StringSplitOptions.RemoveEmptyEntries)[0] + "View";
            }

            onInit          = scriptEnv.GetInPath <OnInitHandler>(prefabName + ".OnInit");
            onOpen          = scriptEnv.GetInPath <OnOpenHandler>(prefabName + ".OnOpen");
            onClose         = scriptEnv.GetInPath <OnCloseHandler>(prefabName + ".OnClose");
            onBeforeDestroy = scriptEnv.GetInPath <OnBeforeDestroyHandler>(prefabName + ".OnBeforeDestroy");

            scriptEnv.Set("self", this);
            //LuaTable t = LuaManager.ReturnNewTable("UI_TaskView");
            //Debug.Log(t == null);
            //t.Set("name", this.gameObject.name);

            //LuaTable model = luaEnv.Global.GetInPath<LuaTable>("UI_TaskView");
            //LuaTable t = luaEnv.NewTable();
            //t.SetMetaTable(model);
            ////model.Dispose();
            //t.Set("name", this.gameObject.name);


            LuaTable tmodel = luaEnv.Global.GetInPath <LuaTable>(prefabName);

            tmodel.Set("__index", tmodel);

            t = luaEnv.NewTable();
            t.SetMetaTable(tmodel);

            t.Set("name", this.gameObject.name);

            ta = t.GetInPath <TableFunc>("PrintName");
            ta(t);

            //ta = t.GetInPath<TableFunc>("UI_TaskView" + ".PrintName");
            //Debug.Log(ta == null);
            //if (ta == null)
            //{
            //    onClose = t.GetInPath<OnCloseHandler>("UI_TaskView" + ".Pme");
            //    Debug.Log("onClose");
            //    Debug.Log(onClose == null);
            //    OnClose();
            //}
            //ta(t);


            if (onInit != null)
            {
                onInit(transform, userData);
            }
        }
예제 #17
0
        public async Task ConnectWebSocket(OnMessageHandler onMessageHandler, OnConnectHandler onConnectHandler = null, OnCloseHandler onCloseHandler = null)
        {
            await Task.Run(async() =>
            {
                if (!Guid.TryParse(wsToken, out _))
                {
                    throw new ArgumentException("tokenの値が不正です, UUID形式で入力してください");
                }

                sakuraioSocket = new ClientWebSocket();
                try
                {
                    await sakuraioSocket.ConnectAsync(new Uri("wss://api.sakura.io/ws/v1/" + wsToken), CancellationToken.None);
                }
                catch (System.Net.WebSockets.WebSocketException)
                {
                    throw new WebSocketException("WebSocketの接続に失敗しました");
                }

                // 特に指定がなければ呼ばない
                onConnectHandler?.Invoke(true);

                while (sakuraioSocket.State == WebSocketState.Open)
                {
                    var buff = new ArraySegment <byte>(new byte[MessageBufferSize]);
                    var ret  = await sakuraioSocket.ReceiveAsync(buff, CancellationToken.None);

                    if (!ret.EndOfMessage)
                    {
                        continue;
                    }

                    var frameString = (new UTF8Encoding()).GetString(buff.Take(ret.Count).ToArray());
                    Console.WriteLine(frameString);

                    var cmsg = DeserializeChannelMessage(frameString);
                    if (cmsg == null)
                    {
                        continue;
                    }

                    onMessageHandler(cmsg);
                }
                onCloseHandler?.Invoke();
            });
        }
예제 #18
0
 /// -----------------------------------------------------------------
 /// <summary>
 /// </summary>
 // -----------------------------------------------------------------
 public bool RemoveCloseHandler(OnCloseHandler handler)
 {
     lock (m_closeRegistry)
         return(m_closeRegistry.Remove(handler));
 }
예제 #19
0
 /// -----------------------------------------------------------------
 /// <summary>
 /// </summary>
 // -----------------------------------------------------------------
 public bool RemoveCloseHandler(OnCloseHandler handler)
 {
     lock (m_closeRegistry)
         return m_closeRegistry.Remove(handler);
 }