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; } }
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); }
private static void UpdateUsernamesAppearance() { Chat chat = ChatUtil.GetChat(); MainCameraComponent cameraComponent = CameraUtil.GetMainCameraComponent(); InChatPanelComponent inChatPanelComponent = (InChatPanelComponent)UIPanelUtil.GetUIPanel(PanelType.IN_CHAT); for (int i = 0; i < inChatPanelComponent.CharactersUsername.Length; i++) { UIText uiText = inChatPanelComponent.CharactersUsername[i]; Character referenceCharacter = chat.Characters[i]; uiText.text = chat.CharacterConfiguration.BaseName; UIUtil.FormatUIText(uiText, referenceCharacter); uiText.fontSize = chat.CharacterConfiguration.UsernameSize; uiText.color = chat.CharacterConfiguration.UsernameColor; } }
private static void UpdateUsernamesPosition() { Chat chat = ChatUtil.GetChat(); MainCameraComponent cameraComponent = CameraUtil.GetMainCameraComponent(); InChatPanelComponent inChatPanelComponent = (InChatPanelComponent)UIPanelUtil.GetUIPanel(PanelType.IN_CHAT); for (int i = 0; i < inChatPanelComponent.CharactersUsername.Length; i++) { UIText uiText = inChatPanelComponent.CharactersUsername[i]; Character referenceCharacter = chat.Characters[i]; uiText.transform.SetParent(inChatPanelComponent.CharacterUsernamesHolder); Vector2 worldPosition = chat.Characters[i].Position + Vector2.up * referenceCharacter.PCharacter.Render.sprite.bounds.size; Vector2 offset = chat.CharacterConfiguration.UsernameOffset; uiText.transform.position = cameraComponent.Camera.WorldToScreenPoint(worldPosition + offset); } }
void Update() { SimulationUtil.ManageStateChanging(); State currentState = SimulationUtil.GetCurrentState(); SimulationUtil.UpdateTick(); switch (currentState) { case State.INTIALIZE: AccessUtil.LoadAccess(); SimulationUtil.InitializeSimulation(); CameraUtil.InitializeMainCameraComponent(); UIUtil.InitializeUI(); SimulationUtil.SetState(State.LOGIN); break; case State.LOGIN: { if (Simulation.Backend != null) { SimulationUtil.SetState(State.CONNECTING); } } break; case State.IN_CHAT: { if (!ClientUtil.IsConnected()) { UnityEngine.Debug.Log("Disconnected"); if (Simulation.Backend != null && Simulation.Backend.HasExited) { Simulation.Backend = null; } SimulationUtil.SetState(State.LOGIN); break; } if (SimulationUtil.Tick()) { FollowerUtil.UpdateFollowers(); } ChatUtil.UpdateChat(); } break; case State.LOGIN_SETTINGS: break; case State.CONNECTING: { if (!SimulationUtil.Tick()) { break; } UnityEngine.Debug.Log("Connecting"); if (ClientUtil.IsConnected()) { SimulationUtil.SetState(State.HUB); UnityEngine.Debug.Log("Connection complete !"); } } break; case State.HUB: { Client.ReadMessages = true; if (SimulationUtil.Tick()) { FollowerUtil.UpdateFollowers(); } } break; } UIUtil.UpdateUI(); }