Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
            }
        }
Beispiel #3
0
        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);
                }
            });
        }
        public void ApplyToCharacterModel(BaseCharacterModel characterModel)
        {
            if (characterModel == null)
            {
                Debug.LogWarning("[EquipmentModelContainerSetter] Cannot find character model");
                return;
            }
            bool hasChanges = false;
            bool isFound    = false;
            List <EquipmentContainer> equipmentContainers = new List <EquipmentContainer>(characterModel.equipmentContainers);

            for (int i = 0; i < equipmentContainers.Count; ++i)
            {
                EquipmentContainer equipmentContainer = equipmentContainers[i];
                if (equipmentContainer.transform == transform)
                {
                    isFound    = true;
                    hasChanges = true;
                    equipmentContainer.equipSocket  = name;
                    equipmentContainer.defaultModel = defaultModel;
                    equipmentContainer.transform    = transform;
                    equipmentContainers[i]          = equipmentContainer;
                    break;
                }
            }
            if (!isFound)
            {
                hasChanges = true;
                EquipmentContainer newEquipmentContainer = new EquipmentContainer();
                newEquipmentContainer.equipSocket  = name;
                newEquipmentContainer.defaultModel = defaultModel;
                newEquipmentContainer.transform    = transform;
                equipmentContainers.Add(newEquipmentContainer);
            }
            if (hasChanges)
            {
                characterModel.equipmentContainers = equipmentContainers.ToArray();
            }
        }