コード例 #1
0
    private void Update()
    {
        if (OnStateChange == null)
        {
            return;
        }

        if (Input.GetAxis("Horizontal") == 0 || (groundSensor.State()))
        {
            onGround = true;
            PlayerFSM.Instance.ChangeState(new Idle());
        }

        if (Input.GetAxis("Horizontal") != 0)
        {
            PlayerFSM.Instance.ChangeState(new WalkState(Input.GetAxis("Horizontal")));
        }

        if (Input.GetAxis("Vertical") > 0 && onGround)
        {
            onGround = false;
            groundSensor.Disable(0.2f);
            PlayerFSM.Instance.ChangeState(new Jump());
        }

        if (PlayerFSM.Instance.ValidUpdate)
        {
            OnStateChange.Invoke(PlayerFSM.Instance.CurrentState);
            PlayerFSM.Instance.Reset();
        }
    }
コード例 #2
0
        private void Chrome_FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
        {
            var url = e.Url;

            try
            {
                string path = $"{System.Environment.CurrentDirectory}\\jquery-3.2.1.min.js";
                if (File.Exists(path))
                {
                    chrome.ExecuteScriptAsync(File.ReadAllText($"{System.Environment.CurrentDirectory}\\jquery-3.2.1.min.js"));
                }
                else
                {
                    using (var client = new WebClient())
                    {
                        client.DownloadFile("https://code.jquery.com/jquery-3.2.1.min.js", path);
                    }
                }
            }
            catch (Exception ex)
            {
                OnStateChange.Invoke(Enums.StateLogType.TaoBaoCouponUploadFail, $"jquey加载失败{ex.Message}");
            }
            if (url.Contains(COUPON_DOWNLOAD_URL))
            {
                Download();
            }
        }
コード例 #3
0
ファイル: Life.cs プロジェクト: Vlam1r/Game-of-Life
        public void Next()
        {
            if (!Interactive)
            {
                return;
            }
            HashSet <Cell> tmp = new HashSet <Cell>();

            foreach (Cell c in currentState)
            {
                if (survival[aliveNeighbors(c)])
                {
                    tmp.Add(c);
                }
                foreach (Cell n in c.Neighbors)
                {
                    if (!currentState.Contains(n) && birth[aliveNeighbors(n)])
                    {
                        tmp.Add(n);
                    }
                }
            }
            states.Add(tmp);
            OnStateChange.Invoke();
        }
コード例 #4
0
ファイル: Life.cs プロジェクト: Vlam1r/Game-of-Life
 public void Reset()
 {
     x      = y = 0; zoom = pb.Width / 20;
     states = new List <HashSet <Cell> >();
     states.Add(new HashSet <Cell>());
     OnStateChange.Invoke();
 }
コード例 #5
0
        void SetStateById(int stateId, bool force)
        {
            if (stateId < 0 || stateId >= states.Length)
            {
                return;
            }
            if (!force && currentStateId == stateId)
            {
                return;                                          // skip - item is already in this state
            }
            previousStateId = currentStateId;
            currentStateId  = stateId;

            if (OnStateChange != null)
            {
                OnStateChange.Invoke();                            // call OnStateChange event
            }
            if (StateGroup != null && StateGroup.IsInitialized)
            {
                StateGroup.ItemStateChanged(itemName);                                                     // call ItemStateChanged for exist and initialized group
            }
            // update state UI
            for (int i = 0; i < states.Length; i++)
            {
                StateOffForce(i);
            }
            StateOn(currentStateId);
        }
コード例 #6
0
        protected void Patch(byte[] delta)
        {
            serializer.Patch(delta);

            if (OnStateChange != null)
            {
                OnStateChange.Invoke(this, new StateChangeEventArgs <T>(serializer.GetState()));
            }
        }
コード例 #7
0
ファイル: Life.cs プロジェクト: Vlam1r/Game-of-Life
 private void Pb_MouseWheel(object sender, MouseEventArgs e)
 {
     if (!Interactive)
     {
         return;
     }
     zoom = Math.Max(5, zoom + Math.Sign(e.Delta));
     OnStateChange.Invoke();
 }
コード例 #8
0
        public void SetState(byte[] encodedState)
        {
            serializer.SetState(encodedState);

            if (OnStateChange != null)
            {
                OnStateChange.Invoke(this, new StateChangeEventArgs <T>(serializer.GetState(), true));
            }
        }
コード例 #9
0
    public void SetCurrentState(State state)
    {
        Debug.Log("state: " + state);
        var prev = Cur;

        Cur = state;
        if (OnStateChange != null)
        {
            OnStateChange.Invoke(prev, state);
        }
    }
コード例 #10
0
ファイル: Life.cs プロジェクト: Vlam1r/Game-of-Life
 public void Previous()
 {
     if (!Interactive)
     {
         return;
     }
     if (!Reversible)
     {
         return;
     }
     states.RemoveAt(states.Count - 1);
     OnStateChange.Invoke();
 }
コード例 #11
0
ファイル: Life.cs プロジェクト: Vlam1r/Game-of-Life
 public void Random()
 {
     states = new List <HashSet <Cell> >();
     states.Add(new HashSet <Cell>());
     foreach (Cell c in visibleTiles)
     {
         if (rnd.Next(0, 4) == 0)
         {
             currentState.Add(c);
         }
     }
     OnStateChange.Invoke();
 }
コード例 #12
0
ファイル: UIStateGroup.cs プロジェクト: liyuwanglyw/MiniGame
 /*
  *      Func: SetStateForItems (state, itemsNames)
  *      Set state for several items
  *
  *      (start code)
  *      GetComponent<UIStateGroup>().SetStateForItems(UIStateItem.STATE_ACTIVE, new string [] {"item (1)", "item (3)"});
  *      (end code)
  *
  *      Parameters:
  *              state - state name
  *              itemsNames - string array of <UIStateItem> items names
  */
 public void SetStateForItems(string state, string [] itemsNames)
 {
     if (OnStateChange != null)
     {
         OnStateChange.Invoke();                            // call OnStateChange event
     }
     for (int i = 0; i < itemsNames.Length; i++)
     {
         UIStateItem StateItem = GetItem(itemsNames[i]) as UIStateItem;
         if (StateItem != null)
         {
             StateItem.SetState(state);
         }
     }
 }
コード例 #13
0
ファイル: UIStateGroup.cs プロジェクト: liyuwanglyw/MiniGame
 /*
  *      Func: SetStateForAllItems (state)
  *      Set state for all items
  *
  *      (start code)
  *      GetComponent<UIStateGroup>().SetStateForAllItems(UIStateItem.STATE_INACTIVE);
  *      (end code)
  *
  *      Parameters:
  *              state - state name
  */
 public void SetStateForAllItems(string state)
 {
     if (OnStateChange != null)
     {
         OnStateChange.Invoke();                            // call OnStateChange event
     }
     for (int i = 0; i < items.Length; i++)
     {
         UIStateItem StateItem = items[i] as UIStateItem;
         if (StateItem != null)
         {
             StateItem.SetState(state);
         }
     }
 }
コード例 #14
0
ファイル: Life.cs プロジェクト: Vlam1r/Game-of-Life
 private void Pb_MouseMove(object sender, MouseEventArgs e)
 {
     if (!Interactive)
     {
         return;
     }
     if (e.Button != MouseButtons.Left)
     {
         return;
     }
     moving = true;
     x     += ((float)delta.X - e.X) / zoom;
     y     += ((float)delta.Y - e.Y) / zoom;
     delta  = e.Location;
     OnStateChange.Invoke();
 }
コード例 #15
0
ファイル: Life.cs プロジェクト: Vlam1r/Game-of-Life
        private void Pb_MouseUp(object sender, MouseEventArgs e)
        {
            if (!Interactive)
            {
                return;
            }
            if (moving)
            {
                moving = false; return;
            }
            int i = (int)Math.Floor((e.X + x * zoom - pb.Width / 2) / zoom), j = (int)Math.Floor((e.Y + y * zoom - pb.Height / 2) / zoom);

            if (currentState.Contains(new Cell(i, j)))
            {
                currentState.Remove(new Cell(i, j));
            }
            else
            {
                currentState.Add(new Cell(i, j));
            }
            OnStateChange.Invoke();
        }
コード例 #16
0
ファイル: Life.cs プロジェクト: Vlam1r/Game-of-Life
 public void Import(StreamReader sr)
 {
     byte[] raw = new byte[sr.BaseStream.Length];
     sr.BaseStream.Read(raw, 0, (int)sr.BaseStream.Length);
     string[] data = Convert.ToBase64String(raw).Replace('C', '-').Replace('D', ',').Split('A');
     x      = float.Parse(data[0]);
     y      = float.Parse(data[1]);
     zoom   = float.Parse(data[2]) * pb.Width;
     states = new List <HashSet <Cell> >();
     states.Add(new HashSet <Cell>());
     for (int i = 3; i < data.Length - 1; i++)
     {
         if (data[i] == "F")
         {
             states.Add(new HashSet <Cell>()); continue;
         }
         currentState.Add(new Cell(
                              int.Parse(data[i].Split('B')[0]),
                              int.Parse(data[i].Split('B')[1])));
     }
     states.RemoveAt(states.Count - 1);
     OnStateChange.Invoke();
 }
コード例 #17
0
ファイル: UIStateGroup.cs プロジェクト: liyuwanglyw/MiniGame
 /*
  *      Func: SetStateExceptItems (state, excludeItemsNames)
  *      Set state for all items excluding given items names
  *
  *      (start code)
  *      GetComponent<UIStateGroup>().SetStateExceptItems(UIStateItem.STATE_ACTIVE, new string [] {"item (1)", "item (3)"});
  *      (end code)
  *
  *      Parameters:
  *              state - state name
  *              excludeItemsNames - string array of <UIStateItem> items names to exclude
  */
 public void SetStateExceptItems(string state, string [] excludeItemsNames)
 {
     if (OnStateChange != null)
     {
         OnStateChange.Invoke();                            // call OnStateChange event
     }
     for (int i = 0; i < items.Length; i++)
     {
         bool isExclude = false;
         for (int j = 0; j < excludeItemsNames.Length; j++)
         {
             if (excludeItemsNames[j] == items[i].itemName)
             {
                 isExclude = true;
                 break;
             }
         }
         if (isExclude)
         {
             continue;
         }
         (items[i] as UIStateItem).SetState(state);
     }
 }
コード例 #18
0
 protected void Patch(byte[] delta, int offset)
 {
     serializer.Patch(delta, offset);
     OnStateChange?.Invoke(serializer.GetState(), false);
 }
コード例 #19
0
 protected void ChangeState(Type type)
 {
     OnStateChange?.Invoke(null, type);
 }
コード例 #20
0
 public void NotifyStateChange(GameState state, RoundPlayerState roundState = null, Player roundCurrentPlayer = null)
 {
     OnStateChange?.Invoke(state, roundState, roundCurrentPlayer);
 }
コード例 #21
0
 public static void RaiseOnStateChange() => OnStateChange?.Invoke();
コード例 #22
0
    private void SetupEvents()
    {
        On("open", (e) =>
        {
            Debug.Log("Connection made to the server");
        });

        On("register", (e) =>
        {
            clientID = e.data["id"].ToString().RemoveQuotes();
            Debug.LogFormat("our client id ({0})", clientID);
        });

        On("addPlayer", (e) =>
        {
            Debug.Log("add player serverobj=" + MultiplayerManager.serverObject.transform);

            Vector3 playersScale              = new Vector3(0.9f, 0.9f, 0.9f);
            Vector3 currentPositionPlayer1    = MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1 ? new Vector3(2f, 0.3f, 1.8f):new Vector3(-1.07f, 0.73f, 1.27f);
            Quaternion currentRotationPlayer1 = Quaternion.Euler(0, -180f, 0);
            Vector3 currentPositionPlayer2    = MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1 ? new Vector3(2f, 0.3f, -2.5f):new Vector3(-1.27f, 0.73f, -4.22f);
            Quaternion currentRotationPlayer2 = Quaternion.Euler(0, 0, 0);

            if (LobbyState.cameraState.Equals(LobbyState.AR_OFF))
            {
                currentPositionPlayer1 = oldPlayer1Position;
                currentPositionPlayer2 = oldPlayer2Position;
                currentRotationPlayer1 = oldPlayer1Rotation;
                currentRotationPlayer2 = oldPlayer2Rotation;
            }
            string id = e.data["id"].ToString().RemoveQuotes();

            GameObject obj = Instantiate(playersObjects.Count == 0 ? playerPrefab1 : playerPrefab2, MultiplayerManager.serverObject.transform);
            obj.name       = string.Format("Player({0})", id);
            NetworkIdentity netIdentity = obj.GetComponent <NetworkIdentity>();
            netIdentity.SetControllerID(id);
            Debug.Log("id controlling" + netIdentity.GetID());
            netIdentity.SetSocketReference(this);
            obj.transform.SetParent(MultiplayerManager.serverObject.transform);
            if (netIdentity.IsControlling())
            {
                GameObject j = Instantiate(jostickPrefab, MultiplayerManager.serverObject.transform);
                j.name       = string.Format("Jostick({0})", id);
                jostick      = j.GetComponentInChildren <FixedJoystick>();
                btns         = j.GetComponentsInChildren <Button>();

                if (!LobbyState.cameraState.Equals(LobbyState.AR_OFF))
                {
                    Debug.Log("game lobby");
                    lobbyGameManagerContainer = GameObject.FindGameObjectWithTag("GameLobbyManager");
                    lobbyGameManager          = lobbyGameManagerContainer.AddComponent <LobbyGameManager>() as LobbyGameManager;
                }
            }
            if (playersObjects.Count == 0)//player1
            {
                netIdentity.transform.localPosition = currentPositionPlayer1;
                netIdentity.transform.localRotation = currentRotationPlayer1;
                netIdentity.transform.localScale    = playersScale;
                Debug.Log("player 1 position=" + currentPositionPlayer1);
            }
            else//player2
            {
                netIdentity.transform.localPosition = currentPositionPlayer2;
                netIdentity.transform.localRotation = currentRotationPlayer2;
                netIdentity.transform.localScale    = playersScale;
            }
            playersObjects.Add(id, netIdentity);
        });
        On("addBall", (e) =>
        {
            Vector3 currentBallPosition = MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1? new Vector3(2f, 3f, -0.5f): new Vector3(-1.11f, 2.5f, -1.62f);
            Vector3 ballScale           = MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1 ? new Vector3(2.4f, 2.4f, 2.4f):new Vector3(0.32f, 0.32f, 0.32f);
            Quaternion ballRotation     = Quaternion.Euler(0, 0f, 0);
            Debug.Log("ball camera state=" + LobbyState.cameraState);
            if (LobbyState.cameraState.Equals(LobbyState.AR_OFF))
            {
                currentBallPosition = oldBallPosition;
            }
            string id = e.data["id"].ToString().RemoveQuotes();
            ballObj   = ballPrefab;
            if (MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1)
            {
                ballObj = ballPrefab;
            }
            else if (MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL2)
            {
                ballObj = beachBallPrefab;
            }
            GameObject obj            = Instantiate(ballObj, MultiplayerManager.serverObject.transform);
            obj.name                  = string.Format("Ball({0})", id);
            ObjectNetwork netIdentity = obj.GetComponent <ObjectNetwork>();
            obj.transform.SetParent(MultiplayerManager.serverObject.transform);
            netIdentity.transform.localPosition = currentBallPosition;
            netIdentity.transform.localScale    = ballScale;
            netIdentity.transform.localRotation = ballRotation;
            netIdentity.SetControllerID(id);
            netIdentity.SetSocketReference(this);
            ballObject = netIdentity;
            PlayerManager.SetBall(ballObject);
            Debug.Log("add ball");
        });
        On("addGate", (e) =>
        {
            Vector3 gatesScale              = MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1 ?new Vector3(1.32f, 0.87f, 1f):new Vector3(1.22f, 0.35f, 0.8f);
            Vector3 currentPositionGate1    = MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1 ? new Vector3(1.8f, 0.29f, 10.4f):new Vector3(-1f, 0.72f, 14.3f);
            Quaternion currentRotationGate1 = Quaternion.Euler(0, 90, 0);
            Vector3 currentPositionGate2    = MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1 ? new Vector3(1.8f, 0.29f, -11f) :new Vector3(-0.98f, 0.72f, -16f);
            Quaternion currentRotationGate2 = Quaternion.Euler(0, -90, 0);

            Gate gate                 = new Gate();
            string id                 = e.data["id"].ToString().RemoveQuotes();
            GameObject obj            = Instantiate(gateObjects.Count == 0 ? gatePrefab1 : gatePrefab2, MultiplayerManager.serverObject.transform);
            obj.name                  = string.Format("Gate({0})", id);
            ObjectNetwork netIdentity = obj.GetComponent <ObjectNetwork>();
            netIdentity.SetControllerID(id);
            netIdentity.SetSocketReference(this);
            obj.transform.SetParent(MultiplayerManager.serverObject.transform);

            if (gateObjects.Count == 0)//gate 1
            {
                obj.transform.localPosition = currentPositionGate1;
                obj.transform.localRotation = currentRotationGate1;
                obj.transform.localScale    = gatesScale;
            }
            else//gate 2
            {
                obj.transform.localPosition = currentPositionGate2;
                obj.transform.localRotation = currentRotationGate2;
                obj.transform.localScale    = gatesScale;
                lobbyGameManager.SetBallNet(netIdentity);
                lobbyGameManager.SetPlayers(playersObjects);
                lobbyGameManager.InitGame(resultGameContainer, scoreUi, MultiplayerManager.serverObject.transform);
            }
            gateObjects.Add(id, netIdentity);
            Debug.Log("add gate ( " + id + ") to GameLobby");
        });

        On("addScoreUI", (e) => {
            if (playersObjects[clientID].IsControlling())
            {
                scoreUi      = Instantiate(scoreUiPrefab, MultiplayerManager.serverObject.transform);
                scoreUi.name = string.Format("ScoreUI({0})", clientID);
                scoreUi.transform.SetParent(MultiplayerManager.serverObject.transform);
                Image avatarPlayer1 = scoreUi.transform.Find("ScoreUI").Find("BackgroundPlayer1").Find("AvatarPlayer1").Find("Image1").GetComponent <Image>();
                Image avatarPlayer2 = scoreUi.transform.Find("ScoreUI").Find("BackgroundPlayer2").Find("AvatarPlayer2").Find("Image2").GetComponent <Image>();
                string avatar1      = users[playersObjects.Keys.ElementAt(0)].avatar;
                string avatar2      = users[playersObjects.Keys.ElementAt(1)].avatar;
                avatar.DisplayAvatar(avatarPlayer1, avatar1);
                avatar.DisplayAvatar(avatarPlayer2, avatar2);
            }
        });

        On("updateAnim", (e) =>
        {
            string id   = e.data["id"].ToString().RemoveQuotes();
            string anim = e.data["anim"].ToString().RemoveQuotes();

            NetworkIdentity netIdentity = playersObjects[id];
            netIdentity.transform.GetComponent <Animator>().SetTrigger(anim);
        });
        On("updatePosition", (e) =>
        {
            if (LobbyState.currentState.Equals(LobbyState.GAME))
            {
                //  Debug.Log("in update positin");
                string id = e.data["id"].ToString().RemoveQuotes();

                float x1 = e.data["rotation"]["x"].f;
                float y1 = e.data["rotation"]["y"].f;
                float z1 = e.data["rotation"]["z"].f;

                float x2 = e.data["position"]["x"].f;
                float y2 = e.data["position"]["y"].f;
                float z2 = e.data["position"]["z"].f;


                NetworkIdentity netIdentity            = playersObjects[id];
                netIdentity.transform.localEulerAngles = new Vector3(x1, y1, z1);
                netIdentity.transform.localPosition    = new Vector3(x2, y2, z2);

                //     Debug.Log("recive position (" + x2 + "," + y2 +","+ z2 + ")");
            }
        });


        On("updateBallPosition", (e) =>
        {
            string id = e.data["id"].ToString().RemoveQuotes();
            float x2  = e.data["position"]["x"].f;
            float y2  = e.data["position"]["y"].f;
            float z2  = e.data["position"]["z"].f;


            //  Debug.Log("player id=" + id + "recive ball position (" + x2 + ", " + y2 + "," + z2 + ")");
            ObjectNetwork netIdentity           = ballObject;
            netIdentity.transform.localPosition = new Vector3(x2, y2, z2);
        });
        On("playerKickBall", (e) =>
        {
            Debug.Log("master not");
            KickBall kickBall    = new KickBall();
            kickBall.direction   = new Position();
            kickBall.ballID      = e.data["ballID"].ToString().RemoveQuotes();
            kickBall.direction.x = e.data["direction"]["x"].f;
            kickBall.direction.y = e.data["direction"]["y"].f;
            kickBall.direction.z = e.data["direction"]["z"].f;
            kickBall.force       = e.data["force"].f;
            Debug.Log("not masterr =(" + kickBall.direction.x + "," + kickBall.direction.y + "," + kickBall.direction.z + ")");
            Vector3 direction = new Vector3(kickBall.direction.x, kickBall.direction.y, kickBall.direction.z);
            ballObject.GetComponent <Rigidbody>().velocity = direction.normalized * kickBall.force;
            Debug.Log("not masterr =(" + kickBall.direction.x + "," + kickBall.direction.y + "," + kickBall.direction.z + ")");
        });

        On("loadGame", (e) =>
        {
            Debug.Log("Loading game level " + MainMenuManager.currentLevelGame);
            if (MainMenuManager.currentLevelGame == SceneList.TEST)
            {
                SceneManagementManager.Instance.LoadLevel(SceneList.TEST, (levelName) =>
                {
                    invitationContainer.SetActive(false);
                });
            }
            if (MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL1)
            {
                SceneManagementManager.Instance.LoadLevel(SceneList.MULTIPLAYER_LEVEL1, (levelName) =>
                {
                    invitationContainer.SetActive(false);
                });
            }
            else if (MainMenuManager.currentLevelGame == SceneList.MULTIPLAYER_LEVEL2)
            {
                SceneManagementManager.Instance.LoadLevel(SceneList.MULTIPLAYER_LEVEL2, (levelName) =>
                {
                    invitationContainer.SetActive(false);
                });
            }
        });
        On("allPlayersLoadedLevelGame", (e) => {
            SceneManagementManager.isAllPlayersLoadedLevel = true;
        });
        On("allPlayersDetectedMarker", (e) =>
        {
            Debug.Log("All players detected marker");
            MultiplayerManager.isAllPlayersDetectedMarker = true;
        });

        On("lobbyUpdate", (e) =>
        {
            string state            = e.data["state"].ToString().RemoveQuotes();
            LobbyState.currentState = state;
            Debug.Log("lobby update:" + state);
            if (state.Equals(LobbyState.PLAYER_LEFT_GAME))
            {
                DestroyServerObject();
                string name = e.data["name"].ToString().RemoveQuotes();
                OnGameStateChange.Invoke(e, "", name);
                OnStateChange.Invoke(e, "", "");
                Debug.Log("update state:" + state);
            }
            else
            {
                if (state.Equals(LobbyState.GAME_OVER))
                {
                    DestroyServerObject();

                    Emit("removePlayerFromLobby");
                }

                OnGameStateChange.Invoke(e, "", "");
                OnStateChange.Invoke(e, "", "");
            }
        });

        On("updateTurn", (e) =>
        {
            string playerTurn = e.data["playerTurn"].ToString().RemoveQuotes();
            lobbyGameManager.UpdateTurn(playerTurn);
        });
        On("goalUI", (e) =>
        {
            string player = e.data["player"].ToString().RemoveQuotes();
            float score   = e.data["score"].f;

            Debug.Log("scoreUi ui player =" + player);
            Debug.Log("score=" + score);
            //pause game
            LobbyGameManager.isStartGame = false;
            GoalUI.SetActive(true);
            StartCoroutine(Wait(player, score));//wait 1 seconds
        });
        On("updateScore", (e) =>
        {
            string player = e.data["player"].ToString().RemoveQuotes();
            float score   = e.data["score"].f;
            lobbyGameManager.UpdateScore(player, score);
        });
        On("initPosition", (e) =>
        {
            if (LobbyState.currentState != LobbyState.GAME_OVER)
            {
                lobbyGameManager.InitPosition();
            }
        });
        On("initUsers", (e) => {
            users.Clear();
        });
        On("saveUser", (e) => {
            User user   = new User();
            user.id     = e.data["id"].ToString().RemoveQuotes();
            user.name   = e.data["username"].ToString().RemoveQuotes();
            user.avatar = e.data["avatar"].ToString().RemoveQuotes();
            user.played = e.data["played"].f;
            user.won    = e.data["won"].f;
            user.socket = this;
            user.lobby  = 0;
            users.Add(user.id, user);

            Debug.Log("Player loged in (  id: " + user.id + ", name: " + user.name + ", played= " + user.played + ")");
            if (LobbyState.currentState == LobbyState.UNCONECCTED_USERS)
            {
                Emit("invitationAddPlayer");
            }
        });
        On("signInUpMessage", (e) =>
        {
            Debug.Log("signInUpMessage");
            bool result    = e.data["result"].b;
            string message = e.data["message"].ToString().RemoveQuotes();
            Debug.Log("result=" + result + "mess=" + message);
            OnSignInUpMessage.Invoke(result, message);
        });
        On("signIn", (e) => {
            OnSignInComplete.Invoke();
        });
        On("invitationInit", (e) =>
        {
            GameObject[] invitations = invitationContainer.GetComponents <GameObject>();
            foreach (GameObject obj in invitations)
            {
                Destroy(obj);
            }
        });
        On("removeInvitation", (e) =>
        {
            Debug.Log("removeInvitation");
            string id   = e.data["id"].ToString().RemoveQuotes();
            string name = e.data["name"].ToString().RemoveQuotes();
            users.Remove(id);
            Destroy(MainMenuManager.allInvitationObj[id]);
            MainMenuManager.allInvitationObj.Remove(id);
            if (MainMenuManager.allInvitationObj.Count() == 0)
            {
                Debug.Log("count=" + MainMenuManager.allInvitationObj.Count());

                Emit("lobbyUpdate");
                //OnStateChange.Invoke(e, LobbyState.UNCONECCTED_USERS, "");
            }
        });
        On("invitationPlayer", (e) =>
        {
            Debug.Log("invitationPlayer");
            OnStateChange(e, LobbyState.SEND_INVITATION, "");
            User player            = new User();
            player.id              = e.data["id"].ToString().RemoveQuotes();
            player.name            = e.data["name"].ToString().RemoveQuotes();
            users[player.id].lobby = player.lobby;
            MainMenuManager.OnSendInvitation(player, invitationPrefab, invitationContainer.transform);
        });
        On("receiveInvitation", (e) =>
        {
            float lobby           = e.data["lobby"].f;
            string sendername     = e.data["sendername"].ToString().RemoveQuotes();
            string level          = e.data["level"].ToString().RemoveQuotes();
            users[clientID].lobby = lobby;
            Debug.Log("Recive invitation to join lobby: " + lobby + "," + level);
            MainMenuManager.currentLevelGame = level;
            OnStateChange(e, LobbyState.RECEIVE_INVITATION, sendername);
            Debug.Log("state:" + e.data["state"].ToString());
        });
        On("denyInvitation", (e) =>
        {
            LobbyState.isdeny = true;
            string username   = e.data["username"].ToString().RemoveQuotes();
            MainMenuManager.userInvitation = username;
            username = "******" + username + ")";
            Transform invitationObject = invitationContainer.transform.Find(username);
        });
        On("updateUsername", (e) =>
        {
            bool isError = e.data["err"].b;
            string msg   = e.data["msg"].ToString().RemoveQuotes();
            string name  = e.data["name"].ToString().RemoveQuotes();
            if (!isError)
            {
                users[clientID].name = name;
            }
            UpdateUsernameEnd.Invoke(isError, msg, name);
        });
        On("updatePassword", (e) =>
        {
            bool isError = e.data["err"].b;
            string msg   = e.data["msg"].ToString().RemoveQuotes();

            UpdatePasswordEnd.Invoke(isError, msg);
        });
        On("updateAvatar", (e) =>
        {
            bool isError  = e.data["err"].b;
            string msg    = e.data["msg"].ToString().RemoveQuotes();
            string avatar = e.data["avatar"].ToString().RemoveQuotes();
            if (!isError)
            {
                users[clientID].avatar = avatar;
            }
            UpdateAvatarEnd.Invoke(isError, msg);
        });
        On("disconnected", (e) =>
        {
            string id      = e.data["id"].ToString().RemoveQuotes();
            GameObject obj = playersObjects[id].gameObject;
            Destroy(obj);              //remove from game
            playersObjects.Remove(id); //remove from memory
        });
    }
コード例 #23
0
 public void SetGameState(GameState gameState)
 {
     GameState = gameState;
     OnStateChange?.Invoke();
 }
コード例 #24
0
 /// <summary>
 /// The state change event notification
 /// </summary>
 private void NotifyStateChanged() => OnStateChange?.Invoke(CurrentTheme);
コード例 #25
0
        public void LoadCoupon()
        {
            OnStateChange?.Invoke(Enums.StateLogType.MoGuJieGetCouponStart, "开始加载蘑菇街优惠券");
            var cids     = MoGuJie.Method.AllCategory;
            var pageSize = 100;
            var models   = new List <Coupon>();

            foreach (var cid in cids)
            {
                if (!EnableRun)
                {
                    return;
                }

                try
                {
                    //获取第一页
                    var result = mgj.GetItemList(channels, cid, pageNo: 1, pageSize: pageSize);
                    //已经初始化过了,就不往下加载了
                    if (result.Total > 0)
                    {
                        models.AddRange(result.Items);
                        //获取
                        if (!onlyFirstPage)
                        {
                            for (int i = 2; i <= result.TotalPage; i++)
                            {
                                var result2 = mgj.GetItemList(channels, cid, pageNo: i, pageSize: pageSize);
                                models.AddRange(result2.Items);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemBase.WriteLog(ex.Message, "MoGuJie");
                }
            }


            OnStateChange?.Invoke(Enums.StateLogType.MoGuJieGetCouponComplated, "加载蘑菇街优惠券加载完成");
            var dirInfo = new System.IO.DirectoryInfo($"{Config.RuningPath}\\temp");

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }
            foreach (var item in channels)
            {
                var pModel   = models.Where(s => s.UserID == item.UserID).ToList();
                var path     = $"{Config.RuningPath}\\temp\\蘑菇街_{item.Name}_{DateTime.Now:yyyyMMddHHmm}.json";
                var fileInfo = new System.IO.FileInfo(path);
                System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(pModel));


                try
                {
                    OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbStart, $"蘑菇街 代理{item.Name} 提交开始");
                    var files = new Dictionary <string, string>();
                    files.Add("file", path);

                    var upload = new Api.BuyUploadApi(files).CreateRequestReturnUrls();
                    var update = new Api.BuyApi("ImportItems", "MoGuJie", new { Url = upload[0] }).CreateRequestReturnBuyResult <object>();

                    if (update.State == "Success")
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbComplated, $"蘑菇街 代理{item.Name} 提交完成");
                        try
                        {
                            System.IO.File.Delete(path);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbError, update.Message);
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        Bll.Buy.LoopCheckCouponUserTemps(item.UserID, Enums.Platform.MGJ);
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbComplated, $"蘑菇街 代理{item.Name} 提交完成");
                    }
                    catch (Exception)
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbError, $"蘑菇街 代理{item.Name} 提交超时");
                    }
                }
                finally
                {
                    try
                    {
                        System.IO.File.Delete(path);
                    }
                    catch (Exception ex)
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponDeleteTemp, $"蘑菇街 代理{item.Name} 提交有误");
                    }
                }
            }

            onlyFirstPage = true;

            var task = new Task(() =>
            {
                Thread.Sleep(5 * 60 * 1000);
                mgj.RefeashToken();
                LoadCoupon();
            });

            task.Start();
        }
コード例 #26
0
 public void InvokeStateChanged(short par_state)
 {
     bSwwWsState = (BSwwWsState)par_state;
     OnStateChange?.Invoke(par_state);
 }
コード例 #27
0
 public static void StateChanged(PlayerLocomotion.PLOC_State newState)
 {
     Current = newState;
     OnStateChange?.Invoke(newState);
 }
コード例 #28
0
 public void TriggerStateChange()
 {
     ChangeState();
     OnStateChange?.Invoke(this, EventArgs.Empty);
 }
コード例 #29
0
ファイル: JobExecutor.cs プロジェクト: tomyqg/STM32CANFlasher
 void RunningStrat(JobEventType Type, string Message)
 {
     OnStateChange?.Invoke(this, Type, _NoRunning, JobRunning, Message);
 }
コード例 #30
0
 public void SetState(byte[] encodedState, int offset)
 {
     serializer.SetState(encodedState, offset);
     OnStateChange?.Invoke(serializer.GetState(), true);
 }