Exemple #1
0
 public void MoveTo(Vector2Int sourceLogicalPosition, Vector2Int targetLogicalPosition)
 {
     SnapToLastTargetIfStillAnimating();
     _previousLogicalPosition = sourceLogicalPosition;
     _animationTargetPosition = targetLogicalPosition;
     _animationState          = EntityAnimationState.Moving;
 }
Exemple #2
0
 public void Bump(Vector2Int sourceLogicalPosition, Vector2Int affectedPosition)
 {
     SnapToLastTargetIfStillAnimating();
     _previousLogicalPosition   = sourceLogicalPosition;
     _animationAffectedPosition = affectedPosition;
     _animationState            = EntityAnimationState.Bumping;
 }
Exemple #3
0
 public void FallOut(Vector2Int sourceLogicalPosition, Vector2Int targetLogicalPosition)
 {
     SnapToLastTargetIfStillAnimating();
     _previousLogicalPosition = sourceLogicalPosition;
     _animationStartRotation  = transform.rotation;
     _animationTargetPosition = targetLogicalPosition;
     _animationState          = EntityAnimationState.FallingOut;
 }
Exemple #4
0
        public void Bump(Position sourceLogicalPosition, Position affectedPosition)
        {
            InitialPosition  = _unityGridInfoProvider.GetCellCenterWorld(sourceLogicalPosition);
            AffectedPosition = _unityGridInfoProvider.GetCellCenterWorld(affectedPosition);
            _animator.Play("GenericBump", 0, 0f);

            _animationState = EntityAnimationState.Bumping;
        }
Exemple #5
0
        public void MoveTo(Position sourceLogicalPosition, Position targetLogicalPosition)
        {
            InitialPosition  = _unityGridInfoProvider.GetCellCenterWorld(sourceLogicalPosition);
            AffectedPosition = _unityGridInfoProvider.GetCellCenterWorld(targetLogicalPosition);
            _animator.Play("GenericMove", 0, 0f);

            _animationState = EntityAnimationState.Moving;
        }
Exemple #6
0
 public void FallIn(Vector2Int sourceLogicalPosition, GameEntity targetEntity)
 {
     SnapToLastTargetIfStillAnimating();
     _previousLogicalPosition = sourceLogicalPosition;
     _animationStartRotation  = transform.rotation;
     _animationTargetPosition = targetEntity.EntityData.LogicalPosition;
     _entityToBecomeParent    = targetEntity;
     GetComponent <SpriteRenderer>().sortingOrder += 1;
     _animationState = EntityAnimationState.FallingIn;
 }
Exemple #7
0
        public void MoveTo(Position sourceLogicalPosition, Position targetLogicalPosition)
        {
            InitialPosition  = _unityGridInfoProvider.GetCellCenterWorld(sourceLogicalPosition);
            AffectedPosition = _unityGridInfoProvider.GetCellCenterWorld(targetLogicalPosition);
            if (_animator == null)
            {
                Debug.LogWarning("missing animator; start executed = " + _startExecuted);
            }
            else
            {
                _animator.Play("GenericMove", 0, 0f);
            }

            _animationState = EntityAnimationState.Moving;
        }
    public override BaseState Clone()
    {
        EntityAnimationState cloneObj = new EntityAnimationState();

        cloneObj.durationTick   = this.durationTick;
        cloneObj.name           = this.name;
        cloneObj.animantioName  = this.animantioName;
        cloneObj.animationSpeed = this.animationSpeed;
        cloneObj.loopCount      = this.loopCount;
        foreach (KeyValuePair <int, StateLink> kv in m_links)
        {
            StateLink link = new StateLink();
            link.linkID                   = kv.Value.linkID;
            link.linkStateName            = kv.Value.linkStateName;
            cloneObj.m_links[link.linkID] = link;
        }
        return(cloneObj);
    }
Exemple #9
0
    public void LoadFSMTemplate(XmlNode fsmNode)
    {
        Assembly assembly = Assembly.GetExecutingAssembly();

        if (fsmNode == null || fsmNode.Name != "FSM")
        {
            return;
        }
        object fsmObj = assembly.CreateInstance(fsmNode.Attributes.GetNamedItem("type").Value);

        if (fsmObj != null)
        {
            BaseFSM bfsm = fsmObj as BaseFSM;
            bfsm.name = fsmNode.Attributes.GetNamedItem("name").Value;
            switch (bfsm.type)
            {
            case EFSM_TYPE.EFSM_DEFAULT_FSM:
            {
            }
            break;

            case EFSM_TYPE.EFSM_ENTITY_FSM:
            {
            } break;
            }
            //先将所有节点生成一遍,再设置连接关系
            XmlNodeList stateNodes = fsmNode.ChildNodes;
            for (int i = 0; i < stateNodes.Count; i++)
            {
                XmlNode stateNode = stateNodes[i];
                if (stateNode.Name != null && stateNode.Name == "StateNode")
                {
                    //string t = typeof(EntityAnimationState).ToString();
                    //object stateObj = assembly.CreateInstance(t);
                    object stateObj = assembly.CreateInstance(stateNode.Attributes.GetNamedItem("type").Value);
                    if (stateObj != null)
                    {
                        BaseState state = stateObj as BaseState;
                        state.name   = stateNode.Attributes.GetNamedItem("name").Value;
                        state.curFSM = bfsm;
                        int duration = 0;
                        int.TryParse(stateNode.Attributes.GetNamedItem("duration").Value, out duration);
                        state.durationTick = duration;
                        switch (state.type)
                        {
                        case EStateType.EStateType_LoginEntiy:
                        {
                        }
                        break;

                        case EStateType.EStateType_EntityAnimation:
                        {
                            EntityAnimationState animState = state as EntityAnimationState;
                            animState.animantioName = stateNode.Attributes.GetNamedItem("AnimationType").Value;
                            float speed = 0;
                            float.TryParse(stateNode.Attributes.GetNamedItem("AnimationSpeed").Value, out speed);
                            animState.animationSpeed = speed;
                            int loopCount = 0;
                            int.TryParse(stateNode.Attributes.GetNamedItem("loopCount").Value, out loopCount);
                            animState.loopCount = loopCount;
                        }
                        break;
                        }
                        for (int j = 0; j < stateNode.ChildNodes.Count; j++)
                        {
                            XmlNode linkNode = stateNode.ChildNodes[j];
                            object  linkObj  = assembly.CreateInstance("StateLink");
                            if (linkObj != null)
                            {
                                StateLink link    = linkObj as StateLink;
                                object    linkKey = Enum.Parse(typeof(EActionType), linkNode.Attributes.GetNamedItem("actionId").Value);
                                if (linkKey != null)
                                {
                                    link.linkID        = (int)linkKey;
                                    link.linkStateName = linkNode.Attributes.GetNamedItem("linkStateName").Value;
                                    state.links.Add((int)linkKey, link);
                                }
                            }
                            bfsm.AddStateNode(state);
                        }
                    }
                }
            }
            object defaultNode = bfsm.FindChildState(fsmNode.Attributes.GetNamedItem("defaultNode").Value);
            if (defaultNode != null)
            {
                bfsm.defaultNode = defaultNode as BaseState;
            }
            //设置连接关系
            //foreach (XmlNode stateNode in fsmNode.ChildNodes)
            for (int i = 0; i < stateNodes.Count; i++)
            {
                XmlNode   stateNode = stateNodes[i];
                BaseState state     = bfsm.FindChildState(stateNode.Attributes.GetNamedItem("name").Value);
                object    outstate  = bfsm.FindChildState(stateNode.Attributes.GetNamedItem("outState").Value);
                if (outstate != null)
                {
                    state.timeOutState = outstate as BaseState;
                }
            }
            //添加到FSM表
            m_fsmTemplates[bfsm.name] = bfsm;
        }
    }
Exemple #10
0
        void Update()
        {
            if (_animationState == EntityAnimationState.Inactive)
            {
                return;
            }
            if (_animationState == EntityAnimationState.Moving)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action

                Vector3 previousWorldPosition   = _gridInfoProvider.GetCellCenterWorld(_previousLogicalPosition);
                Vector3 animationTargetPosition = _gridInfoProvider.GetCellCenterWorld(_animationTargetPosition);
                Vector3 interpolatedPosition
                    = Vector3.Lerp(previousWorldPosition, animationTargetPosition, _timeSinceStartedAnimation / DefaultAnimationDuration);
                transform.position = interpolatedPosition;
                bool finished = _timeSinceStartedAnimation > DefaultAnimationDuration;
                if (finished)
                {
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                }
            }
            else if (_animationState == EntityAnimationState.FallingIn)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action

                Vector3 previousWorldPosition   = _gridInfoProvider.GetCellCenterWorld(_previousLogicalPosition);
                Vector3 animationTargetPosition = _gridInfoProvider.GetCellCenterWorld(_animationTargetPosition);
                float   progress = _timeSinceStartedAnimation / FallInAnimationDuration;
                Vector3 interpolatedPosition
                    = Vector3.Lerp(previousWorldPosition, animationTargetPosition, progress);
                Vector3    interpolatedScale    = Vector3.Lerp(new Vector3(1, 1, 1), new Vector3(0.5f, 0.5f, 0.5f), progress);
                Quaternion interpolatedRotation = Quaternion.Lerp(_animationStartRotation, Quaternion.Euler(0, 0, 180), progress);
                transform.position   = interpolatedPosition;
                transform.localScale = interpolatedScale;
                transform.rotation   = interpolatedRotation;
                bool finished = progress >= 1;
                if (finished)
                {
                    transform.parent           = _entityToBecomeParent.transform;
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                    _entityToBecomeParent      = null;
                }
            }
            else if (_animationState == EntityAnimationState.FallingOut)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action

                Vector3 previousWorldPosition   = _gridInfoProvider.GetCellCenterWorld(_previousLogicalPosition);
                Vector3 animationTargetPosition = _gridInfoProvider.GetCellCenterWorld(_animationTargetPosition);
                float   progress = _timeSinceStartedAnimation / FallInAnimationDuration;
                Vector3 interpolatedPosition
                    = Vector3.Lerp(previousWorldPosition, animationTargetPosition, progress);
                Vector3    interpolatedScale    = Vector3.Lerp(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1, 1, 1), progress);
                Quaternion interpolatedRotation = Quaternion.Lerp(_animationStartRotation, Quaternion.identity, progress);
                transform.position   = interpolatedPosition;
                transform.localScale = interpolatedScale;
                transform.rotation   = interpolatedRotation;
                bool finished = progress >= 1;
                if (finished)
                {
                    _animationState = EntityAnimationState.Inactive;
                    GetComponent <SpriteRenderer>().sortingOrder -= 1;
                    _timeSinceStartedAnimation = 0f;
                    _entityToBecomeParent      = null;
                }
            }
            else if (_animationState == EntityAnimationState.Bumping)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;
                Vector3 previousWorldPosition = _gridInfoProvider.GetCellCenterWorld(_previousLogicalPosition);
                Vector3 middleWayToTarget     = (previousWorldPosition + _gridInfoProvider.GetCellCenterWorld(_animationAffectedPosition)) / 2;
                Vector3 interpolatedPosition
                    = Vector3Utilities.LerpThereAndBack(previousWorldPosition, middleWayToTarget, _timeSinceStartedAnimation / DefaultAnimationDuration);
                transform.position = interpolatedPosition;
                bool finished = _timeSinceStartedAnimation > DefaultAnimationDuration;
                if (finished)
                {
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                }
            }
            else if (_animationState == EntityAnimationState.BeingKnockedOut)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action
                float      progress             = _timeSinceStartedAnimation / DefaultAnimationDuration;
                Quaternion interpolatedRotation = Quaternion.Lerp(_animationStartRotation, Quaternion.Euler(0, 0, 180), progress);
                transform.rotation = interpolatedRotation;
                bool finished = progress >= 1;
                if (finished)
                {
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                }
            }
            else if (_animationState == EntityAnimationState.StandingUp)
            {
                _timeSinceStartedAnimation += Time.smoothDeltaTime;                 // deltaTime could be unnaturally big
                // because of calculations done when player performs an action
                float      progress             = _timeSinceStartedAnimation / DefaultAnimationDuration;
                Quaternion interpolatedRotation = Quaternion.Lerp(_animationStartRotation, Quaternion.identity, progress);
                transform.rotation = interpolatedRotation;
                bool finished = progress >= 1;
                if (finished)
                {
                    _animationState            = EntityAnimationState.Inactive;
                    _timeSinceStartedAnimation = 0f;
                }
            }
        }
Exemple #11
0
 public void StandUp()
 {
     SnapToLastTargetIfStillAnimating();
     _animationStartRotation = transform.rotation;
     _animationState         = EntityAnimationState.StandingUp;
 }
Exemple #12
0
 public void KnockOut()
 {
     SnapToLastTargetIfStillAnimating();
     _animationStartRotation = transform.rotation;
     _animationState         = EntityAnimationState.BeingKnockedOut;
 }
Exemple #13
0
 public void StandUp()
 {
     _animationState = EntityAnimationState.StandingUp;
 }
Exemple #14
0
        public void KnockOut()
        {
            BodyAnimator.Play("DropUpsideDown");

            _animationState = EntityAnimationState.BeingKnockedOut;
        }
Exemple #15
0
 public void FinishedAnimating()
 {
     Progress        = 0f;
     _animationState = EntityAnimationState.Inactive;
     InitialPosition = transform.position;
 }