private void Update() { if (callbacksProducing.Count == 0) { return; } //lock (lockObj) { callbacksConsuming.AddRange(callbacksProducing); foreach (var c in callbacksConsuming) { callbacksProducing.Remove(c); } foreach (var cb in callbacksConsuming) { //if (cb.Target != null) { cb(); } } callbacksConsuming.Clear(); UICommonWait.Hide(); } }
protected override void InitComponents() { UICommonWait.Show(); Task.Run(async() => { if (!LibClient.AClientApp.bConnected) { await LibClient.AClientApp.StartClient(); } UEventListener.Instance.AddProducingAction(() => { UICommonWait.Hide(); }); }); inputUsername = FindWidget <InputField>("inputUsername"); if (!string.IsNullOrEmpty(CachedUsername)) { inputUsername.text = CachedUsername; } inputPassword = FindWidget <InputField>("inputPassword"); btnLogin = FindWidget <Button>("btnLogin"); btnLogin.onClick.AddListener(() => { Task.Run(async() => { if (!LibClient.AClientApp.bConnected) { await LibClient.AClientApp.StartClient(); } if (!LibClient.AClientApp.bConnected) { UEventListener.Instance.AddProducingAction(() => { btnLogin.enabled = true; UICommonWait.Hide(); }); AOutput.Log($"连接失败!"); return; } UEventListener.Instance.AddProducingAction(OnLogin); }); btnLogin.enabled = false; }); var btnRegister = FindWidget <Button>("btnRegister"); btnRegister.onClick.AddListener((UnityEngine.Events.UnityAction)(() => { base.OnUnloadThis(); AHotBase.LoadUI <UIRegister>(); })); RegisterEvent(UEvents.Login, OnLoginCb); }
protected override void InitComponents() { UICommonWait.Show(); Task.Run(async() => { if (!LibClient.AClientApp.bConnected) { await LibClient.AClientApp.StartClient(); } UEventListener.Instance.AddProducingAction(() => { UICommonWait.Hide(); }); }); inputUsername = FindWidget <InputField>("inputUsername"); if (!string.IsNullOrEmpty(CachedUsername)) { inputUsername.text = CachedUsername; } inputPassword = FindWidget <InputField>("inputPassword"); btnLogin = FindWidget <Button>("btnLogin"); btnLogin.onClick.AddListener(() => { Task.Run(async() => { if (!LibClient.AClientApp.bConnected) { await LibClient.AClientApp.StartClient(); } if (!LibClient.AClientApp.bConnected) { AOutput.Log($"连接失败!"); return; } UEventListener.Instance.AddProducingAction(OnLogin); }); btnLogin.enabled = false; }); var btnRegister = FindWidget <Button>("btnRegister"); btnRegister.onClick.AddListener(() => { OnUnloadThis(); LoadAnotherUI <UIRegister>(); }); UEventListener.Instance.OnRegisterEvent(UEvents.LoginFailed, OnLoginFailedCb); UEventListener.Instance.OnRegisterEvent(UEvents.EnterGame, OnEnterGameCb); UEventListener.Instance.OnRegisterEvent(UEvents.ServerDisconnected, OnServerDisconnectedCb); }
public static void LoadUI <T>(Action <T> action = null) where T : AHotBase, new() { UICommonWait.Show(); var path = "UI/" + typeof(T).Name; UHotAssetBundleLoader.Instance.OnDownloadResources(() => { UICommonWait.Hide(); LoadClass <T>(path, action); }, path); }
private void AddGame <T>(string gameLabel) where T : AHotBase, new() { _dGames.Add(gameLabel, () => { var gamename = typeof(T).Name; UICommonWait.Show(); UHotAssetBundleLoader.Instance.OnDownloadResources(() => { UICommonWait.Hide(); LoadGame <T>("Game/" + gamename); }, "game/" + gamename); }); }
protected override void InitComponents() { UICommonWait.Show(); WebSocketConnector.Instance.OnInit(Utils.WebSocketURL + "username="******"&token=" + UILogin.token , (openEvt) => { UICommonWait.Hide(); LoadAnotherUI <UMUIMain>(); }, (msgEvt) => { }, (errorEvt) => { UIAlert.Show("WSError:" + errorEvt.Message); }, (closeMsg) => { UICommonWait.Hide(); }); }
private void Update() { if (callbacksProducing.Count == 0) { return; } callbacksConsuming.AddRange(callbacksProducing); foreach (var c in callbacksConsuming) { callbacksProducing.Remove(c); } foreach (var cb in callbacksConsuming) { cb(); } callbacksConsuming.Clear(); UICommonWait.Hide(); }
private void Update() { if (callbacks.Count == 0) { return; } lock (lockObj) { foreach (var cb in callbacks) { //if (cb.Target != null) { cb(); } } callbacks.Clear(); UICommonWait.Hide(); } }
public void OnClose() { if (!bConnected) { return; } bConnected = false; this.closeAction = null; UnityEngine.Debug.Log("ws close on purpose."); if (ws != null) { UICommonWait.Show(); new Task(() => { ws.Close(); callbackAdd.Add(() => { UICommonWait.Hide(); }); }).Start(); } }
protected override void InitComponents() { btnDailyCheck = FindWidget <Button>("btnDailyCheck"); btnDailyCheck.onClick.AddListener(() => { AClientApis.OnDailyCheck(); }); var textUsername = FindWidget <Text>("textUsername"); textUsername.text = CakeClient.GetCake("pinfo", CakeAvatar.myID).GetStringValue(ParamNameDefs.AvatarName); textGold = FindWidget <Text>("textGold"); textGold.text = "0"; textDiamond = FindWidget <Text>("textDiamond"); textDiamond.text = "0"; var btnLogout = FindWidget <Button>("btnLogout"); btnLogout.onClick.AddListener(() => { AClientApp.OnDisconnect(); OnUnloadThis(); LoadAnotherUI <UIMinerLogin>(); }); var btnPay = FindWidget <Button>("btnPay"); btnPay.onClick.AddListener(() => { //AClientApis.OnPay(1); AClientApis.OnCreateOrder(1); }); var btnExchange = FindWidget <Button>("btnExchange"); btnExchange.onClick.AddListener(() => { AClientApis.OnExchange(1); }); OnParamUpdateCb(null); RegisterEvent(UEvents.ParamUpdate, OnParamUpdateCb); RegisterEvent(UEvents.EventCreateOrder, OnCreateOrderCb); //var map01 = LoadClass<UMinerMap>("UI/MinerMap/Map01"); AClientApis.OnGetSdata(""); OnRegistAction(str => { UICommonWait.Hide(); var astrs = str.Split(' '); switch (astrs[0]) { case "ProvideContent": UIAlert.Show("ProvideContent " + str); break; case "FailedTransactions": UIAlert.Show("FailedTransactions " + str); break; case "UpdateTransactions": UIAlert.Show("UpdateTransactionss " + str); break; } }); }
public void OnInit(string wsurl, Action <EventArgs> openAction, Action <MessageEventArgs> msgAction , Action <ErrorEventArgs> errorAction, Action <string> closeAction) { if (bConnecting || bConnected) { return; } this.closeAction = closeAction; ws = new WebSocket(wsurl); ws.OnOpen += (sender, e) => { UnityEngine.Debug.Log("OnOpen:" + wsurl); bConnecting = false; bConnected = true; lock (lockObj) { callbackAdd.Add(() => { UICommonWait.Hide(); openAction(e); }); } receive = true; }; ws.OnMessage += (sender, e) => { if (e.Data == "ping") { receive = true; } else { UnityEngine.Debug.Log("OnMessage:" + (e.IsText ? e.Data : e.RawData.Length.ToString())); lock (lockObj) { callbackAdd.Add(() => { msgAction(e); var amsg = e.Data.Split('?'); if (amsg.Length > 1) { OnResponse(amsg[0], amsg[1]); } }); } } }; ws.OnError += (sender, e) => { UnityEngine.Debug.Log("OnError:" + e.Message); lock (lockObj) { callbackAdd.Add(() => { errorAction(e); }); } }; ws.OnClose += (sender, e) => { bConnecting = false; bConnected = false; closeAction?.Invoke(e.Reason); UnityEngine.Debug.Log("OnClose:" + e.Reason); }; bConnecting = true; UnityEngine.Debug.Log("ws.Connect() " + wsurl); UICommonWait.Show(); new Thread(new ThreadStart(() => { try { ws.Connect(); } catch { UnityEngine.Debug.Log("connect failed:" + wsurl); } })).Start(); }
protected override void InitComponents() { mycard = FindWidget <RawImage>("mycard"); mycard.gameObject.SetActive(false); var btn = mycard.gameObject.AddComponent <Button>(); btn.onClick.AddListener(() => { if (whosTurn != UILogin.CachedUsername) { UICommonTips.AddTip("还没轮到你出牌。"); return; } mycard.color = Color.grey; WebSocketConnector.Instance.OnRemoteCall("roomOp", ""); }); othercard = FindWidget <RawImage>("othercard"); othercard.gameObject.SetActive(false); var bgpath = new string[] { "Images/Pai/bg1", "Images/Pai/bg2" }; UHotAssetBundleLoader.Instance.OnDownloadResources(() => { mycard.texture = UHotAssetBundleLoader.Instance.OnLoadAsset <Texture2D>(bgpath[random.Next(bgpath.Length)]); othercard.texture = UHotAssetBundleLoader.Instance.OnLoadAsset <Texture2D>(bgpath[random.Next(bgpath.Length)]); }, bgpath); textMyCardCount = FindWidget <Text>("textMyCardCount"); textMyCardCount.text = "0"; textMyAvatarname = FindWidget <Text>("textMyAvatarname"); textMyAvatarname.text = URemoteData.AvatarName; textMyLevel = FindWidget <Text>("textMyLevel"); ShowLevel(); textOtherCardCount = FindWidget <Text>("textOtherCardCount"); textOtherCardCount.text = "0"; textOtherLevel = FindWidget <Text>("textOtherLevel"); textOtherAvatarname = FindWidget <Text>("textOtherAvatarname"); RegisterReturnButton(); btnJoinRoom = FindWidget <Button>("btnJoinRoom"); btnJoinRoom.onClick.AddListener(() => { WebSocketConnector.Instance.OnRemoteCall("joinRoom", "老牛赶大车"); }); cardcell = FindWidget <Transform>("cardcell"); cardcell.gameObject.SetActive(false); otherinfo = FindWidget <Transform>("otherinfo"); otherinfo.gameObject.SetActive(false); URemoteData.ListeningParam(InfoNameDefs.AvatarLevel, ShowLevel); UICommonWait.Show(); WebSocketConnector.Instance.OnInit(Utils.WebSocketURL + UILogin.CachedUsernameAndTokenArguments, evt => { UICommonWait.Hide(); }, msgEvt => { }, errEvt => { }, closeEvt => { }); WebSocketConnector.Instance.OnRegisterResponse("enter", OnJoinRoomCB); WebSocketConnector.Instance.OnRegisterResponse("cardsync", OnCardsSync); WebSocketConnector.Instance.OnRegisterResponse("result", OnResult); WebSocketConnector.Instance.OnRegisterResponse("dismissed", OnDismissed); }
protected override void InitComponents() { UICommonWait.Show(); Task.Run(async() => { if (!LibClient.AClientApp.bConnected) { await LibClient.AClientApp.StartClient(); } UWebSender.Instance.AddProducingAction(() => { UICommonWait.Hide(); }); }); inputUsername = FindWidget <InputField>("inputUsername"); if (!string.IsNullOrEmpty(CachedUsername)) { inputUsername.text = CachedUsername; } inputPassword = FindWidget <InputField>("inputPassword"); var btnLogin = FindWidget <Button>("btnLogin"); btnLogin.onClick.AddListener(() => { Task.Run(async() => { if (!LibClient.AClientApp.bConnected) { await LibClient.AClientApp.StartClient(); } if (!LibClient.AClientApp.bConnected) { AOutput.Log($"连接失败!"); return; } UWebSender.Instance.AddProducingAction(OnLogin); }); btnLogin.enabled = false; }); var btnRegister = FindWidget <Button>("btnRegister"); btnRegister.onClick.AddListener(() => { OnUnloadThis(); LoadAnotherUI <UIRegister>(); }); if (!string.IsNullOrEmpty(token)) { inputPassword.text = "******"; btnLogin.enabled = false; UStaticWebRequests.OnWebRequest("Login/CheckToken", "username="******"&token=" + token, jobj => { OnSelectAvatar(); }, jfail => { btnLogin.enabled = true; inputPassword.text = ""; token = ""; }); } }