protected static void UpdateAnimation(float deltaTime, CharacterAnimationComponent animationData, BaseCharacterEntity characterEntity, Transform transform) { if (characterEntity.isRecaching) { return; } // Update current velocity animationData.updatingTime += deltaTime; if (animationData.updatingTime >= UPDATE_VELOCITY_DURATION) { if (!animationData.previousPosition.HasValue) { animationData.previousPosition = transform.position; } animationData.currentVelocity = (transform.position - animationData.previousPosition.Value) / animationData.updatingTime; animationData.previousPosition = transform.position; animationData.updatingTime = 0f; } tempCharacterModel = characterEntity.CharacterModel; if (tempCharacterModel != null) { tempCharacterModel.UpdateAnimation(characterEntity.IsDead(), animationData.currentVelocity, characterEntity.MoveAnimationSpeedMultiplier); } }
protected virtual void LoadCharacters() { // Remove all models characterModelContainer.RemoveChildren(); CharacterModelByEntityId.Clear(); // Remove all cached data PlayerCharacterDataByEntityId.Clear(); // Clear character selection CacheCharacterSelectionManager.Clear(); CacheCharacterList.HideAll(); // Show list of characters that can be create PlayerCharacterData firstData = null; List <BasePlayerCharacterEntity> selectableCharacters = GetCreatableCharacters(); CacheCharacterList.Generate(selectableCharacters, (index, characterEntity, ui) => { // Cache player character to dictionary, we will use it later PlayerCharacterDataByEntityId[characterEntity.EntityId] = characterEntity.playerCharacters; // Prepare data BaseCharacter playerCharacter = characterEntity.playerCharacters[0]; PlayerCharacterData playerCharacterData = new PlayerCharacterData(); playerCharacterData.SetNewPlayerCharacterData(characterEntity.characterTitle, playerCharacter.DataId, characterEntity.EntityId); // Hide all model, the first one will be shown later BaseCharacterModel characterModel = playerCharacterData.InstantiateModel(characterModelContainer); CharacterModelByEntityId[playerCharacterData.EntityId] = characterModel; characterModel.gameObject.SetActive(false); characterModel.UpdateAnimation(false, MovementState.IsGrounded); // Setup UI if (ui != null) { UICharacter uiCharacter = ui.GetComponent <UICharacter>(); uiCharacter.Data = playerCharacterData; CacheCharacterSelectionManager.Add(uiCharacter); } if (index == 0) { firstData = playerCharacterData; } }); // Select first entry if (CacheCharacterSelectionManager.Count > 0) { CacheCharacterSelectionManager.Select(0); } else { OnSelectCharacter(firstData); } }
protected virtual void LoadCharacters() { CacheCharacterSelectionManager.Clear(); // Unenabled buttons buttonStart.gameObject.SetActive(false); buttonDelete.gameObject.SetActive(false); // Remove all models characterModelContainer.RemoveChildren(); CharacterModelById.Clear(); // Remove all cached data PlayerCharacterDataById.Clear(); // Show list of created characters List <PlayerCharacterData> selectableCharacters = PlayerCharacterDataExtension.LoadAllPersistentCharacterData(); for (int i = selectableCharacters.Count - 1; i >= 0; --i) { PlayerCharacterData selectableCharacter = selectableCharacters[i]; if (selectableCharacter == null || !GameInstance.PlayerCharacters.ContainsKey(selectableCharacter.DataId)) { selectableCharacters.RemoveAt(i); } } selectableCharacters.Sort(new PlayerCharacterDataLastUpdateComparer().Desc()); CacheCharacterList.Generate(selectableCharacters, (index, characterData, ui) => { // Cache player character to dictionary, we will use it later PlayerCharacterDataById[characterData.Id] = characterData; // Setup UIs UICharacter uiCharacter = ui.GetComponent <UICharacter>(); uiCharacter.Data = characterData; // Select trigger when add first entry so deactivate all models is okay beacause first model will active BaseCharacterModel characterModel = characterData.InstantiateModel(characterModelContainer); if (characterModel != null) { CharacterModelById[characterData.Id] = characterModel; characterModel.gameObject.SetActive(false); characterModel.SetEquipWeapons(characterData.EquipWeapons); characterModel.SetEquipItems(characterData.EquipItems); characterModel.UpdateAnimation(false, MovementState.IsGrounded); CacheCharacterSelectionManager.Add(uiCharacter); } }); }