コード例 #1
0
        private static void UpdateCharacterStates(Character character)
        {
            Chat chat = GetChat();

            Vector2 worldBottomLeft   = Vector2.zero;
            Vector2 worldBottomCenter = Vector2.zero;
            Vector2 worldBottomRight  = Vector2.zero;

            switch (character.State)
            {
            case CharacterState.IDLE:
            {
                character.IdleCurrentTime += Time.deltaTime / character.IdleTime;
                if (character.IdleCurrentTime >= 1)
                {
                    character.IdleCurrentTime = 0;

                    CameraUtil.GetScreenToWorldPointBoundaires(ref worldBottomLeft, ref worldBottomCenter, ref worldBottomRight);

                    character.DestinationXPosition = Random.Range(worldBottomLeft.x, worldBottomRight.x);

                    character.State = CharacterState.WALK;
                }
            }
            break;

            case CharacterState.WALK:
            {
                int direction;

                if (character.DestinationXPosition > character.Position.x)
                {
                    character.PCharacter.Controller.CurrentAction = PControllerActionType.TRANSLATE_RIGHT;
                    direction = 1;
                }
                else
                {
                    character.PCharacter.Controller.CurrentAction = PControllerActionType.TRANSLATE_LEFT;
                    direction = -1;
                }

                PCharacter.PCharacterInstanceUtil.FaceToMoveDirection(character.PCharacter);

                Vector2 newPosition = character.Position;

                newPosition.x     += direction * character.MoveSpeed * Time.deltaTime;
                character.Position = newPosition;

                if (Mathf.Abs(character.Position.x - character.DestinationXPosition) < .1f)
                {
                    character.State    = CharacterState.IDLE;
                    character.IdleTime = Random.Range(chat.CharacterConfiguration.IdleTime.x, chat.CharacterConfiguration.IdleTime.y);
                }
            }
            break;
            }
        }
コード例 #2
0
        private static void UpdateChatGround()
        {
            Chat chat = GetChat();
            MainCameraComponent mainCameraComponent = CameraUtil.GetMainCameraComponent();

            Vector2 middleWorldPos = Vector2.zero;
            Vector2 leftWorldPos   = Vector2.zero;
            Vector2 rightWorldPos  = Vector2.zero;

            CameraUtil.GetScreenToWorldPointBoundaires(ref leftWorldPos, ref middleWorldPos, ref rightWorldPos);

            float distanceBtweenScreenBounds = Vector2.Distance(leftWorldPos, rightWorldPos);

            middleWorldPos += Vector2.up * chat.GroundYOfset;
            chat.Ground.transform.position   = middleWorldPos;
            chat.Ground.transform.localScale = Vector2.one + (Vector2.right * distanceBtweenScreenBounds);
        }