コード例 #1
0
    private void Update()
    {
        // Ensure current state is not null
        Debug.Assert(currentAnimState != null, "Current animation state is null", gameObject);

        CurrentState = animation[currentAnimState.AnimationName];

        // Update current state and check if the current state  needs to transition to a new state
        var result = currentAnimState?.OnStateUpdate(this, CurrentState == null ? false : CurrentState.enabled);

        if (result != null)
        {
            currentAnimState = result.Target;
            currentAnimState.OnStateEnter(this);

            Debug.Assert(!string.IsNullOrEmpty(currentAnimState.AnimationName), "Animation name can not be null or empty.");

            CurrentState = animation[currentAnimState.AnimationName];

            // Set the time of the state to the EnterTime if specified
            if (animation[currentAnimState.AnimationName] != null)
            {
                animation.Play(currentAnimState.AnimationName);
                CurrentState.normalizedTime = result.HasExitTime ? result.EnterTime : CurrentState.normalizedTime;
            }
        }

        if (CurrentState != null)
        {
            LastUpdateTime = CurrentState.normalizedTime;
        }
    }
コード例 #2
0
    private void Start()
    {
        currentAnimState = AnimationManager.Instance.IdleState;
        currentAnimState.OnStateEnter(this);

        Debug.Assert(!string.IsNullOrEmpty(currentAnimState.AnimationName), "Animation name can not be null or empty.");
        animation.Play(currentAnimState.AnimationName);

        rootBone = transform.Find("Bip01");
        if (rootBone == null)
        {
            rootBone = transform.Find("Root Bone");
        }

        // Set some values
        previousRootPosition = rootBone.position;
        rootOffset           = rootBone.localPosition;
        CalculateMovementSpeed();
    }