示例#1
0
    // ============================ ANIMATIONS ===================================

    public void AnimateDirection(Vector2 direction, CharacterAnimationState state)
    {
        if (characterAnimator)
        {
            characterAnimator.GetAnimationFromVector2(direction.x, direction.y, state);
        }
    }
示例#2
0
        // During the update function, by switching the animation state, we can switch between the animations
        private void Update()
        {
            // Only spawn more characters if there is a single spawn node
            if (Input.GetKeyDown(KeyCode.T))
            {
                if (SpawnNodeData.Count == 1)
                {
                    SpawnFullCharacters(SpawnNodeData[0].CharacterSpawningData.NumberOfLines);
                }
            }

            // Change the animation between the 2

            if (Animation1 && Animation2)
            {
                if (Input.GetKeyDown(KeyCode.Y))
                {
                    if (AnimationState == CharacterAnimationState.Animation1)
                    {
                        AnimationState = CharacterAnimationState.Animation2;
                    }
                    else
                    {
                        AnimationState = CharacterAnimationState.Animation1;
                    }
                }
            }

            // Quit the application, used in fullscreen mode
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }
        }
示例#3
0
 public void AnimateSpecific(CharacterAnimationState stickFigureAnimation)
 {
     if (characterAnimator)
     {
         characterAnimator.ChangeAnimation(stickFigureAnimation);
     }
 }
示例#4
0
 public void ChangeAnimation(CharacterAnimationState state, CharacterAnimationDirection direction = CharacterAnimationDirection.Down)
 {
     if (currentCharacterAnimation.characterAnimationState != state || currentCharacterAnimation.characterAnimationDirection != direction)
     {
         currentCharacterAnimation = GetCharacterAnimation(state, direction);
         SetUpAnimation();
     }
 }
示例#5
0
    protected virtual void OnEnable()
    {
        characterState          = CharacterBasicState.Idle;
        characterDamagedState   = ChracterDamagedState.None;
        characterAnimationState = CharacterAnimationState.Idle;

        StartCoroutine(FSMMain());
    }
示例#6
0
 void SetUpAnimation(float frameRate, List <Sprite> sprites, CharacterAnimationState animationState)
 {
     StopCoroutine(nameof(playAnimationCo));
     _activeFrameRate  = frameRate;
     _activeSpriteList = sprites;
     _frameIndex       = 0;
     StartCoroutine(nameof(playAnimationCo));
     activeAnimationState = animationState;
 }
 private void setAnimation(CharacterAnimationState charAnimState, CharacterName character)
 {
     Actor actor = actors[character];
     String ch = "Characters/" + character.ToString().ToLower() + "/man/" + charAnimState + ".TVA";
     actor.Actor.ImportAnimations("Characters/" + character.ToString().ToLower() + "/man/" + charAnimState + ".TVA");
     actor.Actor.SetAnimationByName(charAnimState.ToString());
     actor.Actor.PlayAnimation(1);
     actor.CharacterAnimState = charAnimState;
 }
 public void HandleCharacterClickEvent()
 {
     if (animationState == CharacterAnimationState.Idle)
     {
         Array         values = Enum.GetValues(typeof(CharacterAnimationState));
         System.Random random = new System.Random();
         animationState = (CharacterAnimationState)values.GetValue(random.Next(1, values.Length));
         animator.SetBool(animationState.ToString(), true);
     }
 }
示例#9
0
 private CharacterAnimation GetCharacterAnimation(CharacterAnimationState state, CharacterAnimationDirection direction = CharacterAnimationDirection.Down)
 {
     for (int i = 0; i < characterAnimations.Length; i++)
     {
         if (characterAnimations[i].characterAnimationState == state && characterAnimations[i].characterAnimationDirection == direction)
         {
             return(characterAnimations[i]);
         }
     }
     return(characterAnimations[0]);
 }
示例#10
0
    //개체의 상태가 바뀔때마다 메소드가 실행된다.
    public void SetState(CharacterBasicState _newCharState, CharacterAnimationState _newCharAnimState)
    {
        if (characterState == _newCharState && characterAnimationState == _newCharAnimState)
        {
            return;
        }


        isNewCharacterState = true;

        characterState          = _newCharState;
        characterAnimationState = _newCharAnimState;

        //개체가 가진 Animator 컴포넌트의 state Parameters 에게 상태변화 값을 전달한다.
        animator.SetInteger("State", (int)characterState);
    }
示例#11
0
 public void changeAnimation(CharacterAnimationState charAnimState, CharacterName character)
 {
     int i = 0;
     bool found = false;
     string[] animNames = Enum.GetNames(typeof(CharacterAnimationState));
     while (i < animNames.Length && !found)
     {
         CharacterAnimationState value = (CharacterAnimationState)Enum.Parse(typeof(CharacterAnimationState), animNames[i]);
         if (charAnimState == value && actors[character].CharacterAnimState != value)
         {
             bool animLoop = !(charAnimState == CharacterAnimationState.Die || charAnimState == CharacterAnimationState.Die1 || charAnimState == CharacterAnimationState.Die2);
             setAnimationLoop(animLoop, character);
             setAnimation(value, character);
             found = true;
         }
         i++;
     }
 }
示例#12
0
    public void GetAnimationFromVector2(float x, float y, CharacterAnimationState animationState)
    {
        CharacterAnimationDirection direction = CharacterAnimationDirection.Down;

        if (x == 0 && y != 0)
        {
            if ((y > 0))
            {
                direction = CharacterAnimationDirection.Up;
            }
            else
            {
                direction = CharacterAnimationDirection.Down;
            }
        }
        else
        {
            if (x < 0)
            {
                x        *= -1;
                direction = CharacterAnimationDirection.Left;
            }
            else
            {
                direction = CharacterAnimationDirection.Right;
            }

            if (y > x || (y < 0 && y + x < 0))
            {
                if ((y > 0))
                {
                    direction = CharacterAnimationDirection.Up;
                }
                else
                {
                    direction = CharacterAnimationDirection.Down;
                }
            }
        }
        //else
        //ChangeAnimation(state);
        ChangeAnimation(animationState, direction);
    }
            public override void OnGUI()
            {
                if (instructor == null)
                {
                    instructor = ((GameObject)UnityEngine.Object.Instantiate(AssetBase.GetPrefab(name))).GetComponent <KerbalInstructor>();

                    instructorTexture = new RenderTexture(128, 128, 8);
                    instructor.instructorCamera.targetTexture = instructorTexture;
                    instructor.instructorCamera.ResetAspect();

                    // Remove the lights for Gene/Wernher
                    Light mainlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "mainlight").FirstOrDefault();
                    if (mainlight != null)
                    {
                        UnityEngine.Object.Destroy(mainlight);
                    }
                    Light backlight = instructor.GetComponentsInChildren <Light>(true).Where(l => l.name == "backlight").FirstOrDefault();
                    if (backlight != null)
                    {
                        UnityEngine.Object.Destroy(backlight);
                    }

                    offset += 25f;
                    instructor.gameObject.transform.Translate(offset, 0.0f, 0.0f);

                    // Add a light
                    lightGameObject = new GameObject("Dialog Box Light");
                    Light lightComp = lightGameObject.AddComponent <Light>();
                    lightComp.color = new Color(0.4f, 0.4f, 0.4f);
                    lightGameObject.transform.position = instructor.instructorCamera.transform.position;

                    if (string.IsNullOrEmpty(characterName))
                    {
                        characterName = Localizer.GetStringByTag(instructor.CharacterName);
                    }

                    instructor.SetupAnimations();

                    if (animation != null)
                    {
                        switch (animation.Value)
                        {
                        case Animation.idle:
                            animState = instructor.anim_idle;
                            break;

                        case Animation.idle_lookAround:
                            animState = instructor.anim_idle_lookAround;
                            break;

                        case Animation.idle_sigh:
                            animState = instructor.anim_idle_sigh;
                            break;

                        case Animation.idle_wonder:
                            animState = instructor.anim_idle_wonder;
                            break;

                        case Animation.true_thumbUp:
                            animState = instructor.anim_true_thumbUp;
                            break;

                        case Animation.true_thumbsUp:
                            animState = instructor.anim_true_thumbsUp;
                            break;

                        case Animation.true_nodA:
                            animState = instructor.anim_true_nodA;
                            break;

                        case Animation.true_nodB:
                            animState = instructor.anim_true_nodB;
                            break;

                        case Animation.true_smileA:
                            animState = instructor.anim_true_smileA;
                            break;

                        case Animation.true_smileB:
                            animState = instructor.anim_true_smileB;
                            break;

                        case Animation.false_disappointed:
                            animState = instructor.anim_false_disappointed;
                            break;

                        case Animation.false_disagreeA:
                            animState = instructor.anim_false_disagreeA;
                            break;

                        case Animation.false_disagreeB:
                            animState = instructor.anim_false_disagreeB;
                            break;

                        case Animation.false_disagreeC:
                            animState = instructor.anim_false_disagreeC;
                            break;

                        case Animation.false_sadA:
                            animState = instructor.anim_false_sadA;
                            break;
                        }

                        // Give a short delay before playing the animation
                        nextAnimTime = Time.fixedTime + 0.3f;
                    }
                }

                // Play the animation
                if (nextAnimTime <= Time.fixedTime)
                {
                    instructor.PlayEmote(animState);
                    animState.audioClip = null;
                    nextAnimTime        = Time.fixedTime + animState.clip.length;
                }

                GUILayout.BeginVertical(GUILayout.Width(128));
                GUILayout.Box("", GUILayout.Width(128), GUILayout.Height(128));
                if (Event.current.type == EventType.Repaint)
                {
                    Rect rect = GUILayoutUtility.GetLastRect();
                    rect = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f);
                    Graphics.DrawTexture(rect, instructorTexture, new Rect(0.0f, 0.0f, 1f, 1f), 124, 124, 124, 124, Color.white, PortraitRenderMaterial);
                }

                DisplayName(128);

                GUILayout.EndVertical();
            }
 /// <summary>
 /// Presumably, makes the instructor execute a given animation repeatedly.
 /// </summary>
 /// <param name="st">The animation to exectue.</param>
 /// <param name="repeatInterval">How often to repeat the animation, in seconds?</param>
 public extern void PlayEmoteRepeating(CharacterAnimationState st, float repeatInterval);
 /// <summary>
 /// Presumably, makes the instructor execute a given animation.
 /// </summary>
 /// <param name="st">The animation to execute.</param>
 public extern void PlayEmote(CharacterAnimationState st);
示例#16
0
    private void UpdateMoving()
    {
        // Check This character able to move
        if (fsmPlyer.IsAbleToMove() == false)
        {
            return;
        }


        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");

        if (h == 0.0f && v == 0.0f)
        {
            fsmPlyer.SetState(CharacterBasicState.Idle, CharacterAnimationState.Idle);
            return;
        }


        Vector3 movement = (transform.forward * v) + (transform.right * h);

        CharacterAnimationState animState
            = CharacterAnimationState.Moving_F;

        bool  isFrondSide = (Input.GetKey(KeyCode.W)) ? true : false;
        float moveAngle   = Vector3.Angle(movement, transform.right);

        float moveSpeed = (Input.GetKey(KeyCode.W)) ? moveSpeed_forward : moveSpeed_side;

        //Debug.Log(moveAngle);
        if (180.0f <= moveAngle)
        {
            animState = CharacterAnimationState.Moving_L;
        }
        else if (135.0f <= moveAngle)
        {
            if (isFrondSide)
            {
                animState = CharacterAnimationState.Moving_FL;
            }
            else
            {
                animState = CharacterAnimationState.Moving_BL;
            }
        }
        else if (90.0f <= moveAngle)
        {
            if (isFrondSide)
            {
                animState = CharacterAnimationState.Moving_F;
            }
            else
            {
                animState = CharacterAnimationState.Moving_B;
            }
        }
        else if (45.0f <= moveAngle)
        {
            if (isFrondSide)
            {
                animState = CharacterAnimationState.Moving_FR;
            }
            else
            {
                animState = CharacterAnimationState.Moving_BR;
            }
        }
        else if (0.0f <= moveAngle)
        {
            animState = CharacterAnimationState.Moving_R;
        }


        movement            = movement.normalized * moveSpeed * Time.fixedDeltaTime;
        transform.position += movement;

        fsmPlyer.SetState(CharacterBasicState.Moving, animState);
    }
示例#17
0
 public void PlayAnimation(CharacterAnimationState state)
 {
     if (state == CharacterAnimationState.None)
     {
         switch (lastState)
         {
             case CharacterAnimationState.Walk_Back:
                 state = CharacterAnimationState.Stand_Back; break;
             case CharacterAnimationState.Walk_Front:
                 state = CharacterAnimationState.Stand_Front; break;
             case CharacterAnimationState.Walk_Left:
                 state = CharacterAnimationState.Stand_Left; break;
             case CharacterAnimationState.Walk_Right:
                 state = CharacterAnimationState.Stand_Right; break;
         }
     }
     string stateName = CharacterAnimationStateManager.instance.getAnimationStateString(state);
     if(hasAnimState(stateName))
     {
         anim.Play(stateName);
         lastState = state;
     }
 }
 public void OnEndAnimation(string animationClip)
 {
     animator.SetBool(animationClip, false);
     animationState = CharacterAnimationState.Idle;
 }
            public override void OnGUI()
            {
                if (instructor == null)
                {
                    instructor = ((GameObject)UnityEngine.Object.Instantiate(AssetBase.GetPrefab(name))).GetComponent<KerbalInstructor>();

                    instructorTexture = new RenderTexture(128, 128, 8);
                    instructor.instructorCamera.targetTexture = instructorTexture;
                    instructor.instructorCamera.ResetAspect();

                    // Remove the lights for Gene/Wernher
                    Light mainlight = instructor.GetComponentsInChildren<Light>(true).Where(l => l.name == "mainlight").FirstOrDefault();
                    if (mainlight != null)
                    {
                        UnityEngine.Object.Destroy(mainlight);
                    }
                    Light backlight = instructor.GetComponentsInChildren<Light>(true).Where(l => l.name == "backlight").FirstOrDefault();
                    if (backlight != null)
                    {
                        UnityEngine.Object.Destroy(backlight);
                    }

                    offset += 25f;
                    instructor.gameObject.transform.Translate(offset, 0.0f, 0.0f);

                    // Add a light
                    lightGameObject = new GameObject("Dialog Box Light");
                    Light lightComp = lightGameObject.AddComponent<Light>();
                    lightComp.color = new Color(0.4f, 0.4f, 0.4f);
                    lightGameObject.transform.position = instructor.instructorCamera.transform.position;

                    if (string.IsNullOrEmpty(characterName))
                    {
                        characterName = instructor.CharacterName;
                    }

                    instructor.SetupAnimations();

                    if (animation != null)
                    {
                        switch (animation.Value)
                        {
                            case Animation.idle:
                                animState = instructor.anim_idle;
                                break;
                            case Animation.idle_lookAround:
                                animState = instructor.anim_idle_lookAround;
                                break;
                            case Animation.idle_sigh:
                                animState = instructor.anim_idle_sigh;
                                break;
                            case Animation.idle_wonder:
                                animState = instructor.anim_idle_wonder;
                                break;
                            case Animation.true_thumbUp:
                                animState = instructor.anim_true_thumbUp;
                                break;
                            case Animation.true_thumbsUp:
                                animState = instructor.anim_true_thumbsUp;
                                break;
                            case Animation.true_nodA:
                                animState = instructor.anim_true_nodA;
                                break;
                            case Animation.true_nodB:
                                animState = instructor.anim_true_nodB;
                                break;
                            case Animation.true_smileA:
                                animState = instructor.anim_true_smileA;
                                break;
                            case Animation.true_smileB:
                                animState = instructor.anim_true_smileB;
                                break;
                            case Animation.false_disappointed:
                                animState = instructor.anim_false_disappointed;
                                break;
                            case Animation.false_disagreeA:
                                animState = instructor.anim_false_disagreeA;
                                break;
                            case Animation.false_disagreeB:
                                animState = instructor.anim_false_disagreeB;
                                break;
                            case Animation.false_disagreeC:
                                animState = instructor.anim_false_disagreeC;
                                break;
                            case Animation.false_sadA:
                                animState = instructor.anim_false_sadA;
                                break;
                        }

                        // Give a short delay before playing the animation
                        nextAnimTime = Time.fixedTime + 0.3f;
                    }
                }

                // Play the animation
                if (nextAnimTime <= Time.fixedTime)
                {
                    instructor.PlayEmote(animState);
                    animState.audioClip = null;
                    nextAnimTime = Time.fixedTime + animState.clip.length;
                }

                GUILayout.BeginVertical(GUILayout.Width(128));
                GUILayout.Box("", GUILayout.Width(128), GUILayout.Height(128));
                if (Event.current.type == EventType.Repaint)
                {
                    Rect rect = GUILayoutUtility.GetLastRect();
                    rect = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f);
                    Graphics.DrawTexture(rect, instructorTexture, new Rect(0.0f, 0.0f, 1f, 1f), 124, 124, 124, 124, Color.white, PortraitRenderMaterial);
                }

                DisplayName(128);

                GUILayout.EndVertical();
            }
示例#20
0
 public Character(int initX, int initY, int speed_)
     : base(initX, initY)
 {
     speed = speed_;
     animationState = CharacterAnimationState.FaceFront;
 }
 /// <summary>
 /// Sets animation state of current character.
 /// </summary>
 /// <param name="iState"></param>
 public void SetAnimation(CharacterAnimationState iState)
 {
     _animator.SetInteger(ANIMATION_STATE_REFERENCE, (int)iState);
 }
示例#22
0
    void Awake()
    {
        rb2d = GetComponent<Rigidbody2D>();
        c2d = GetComponent<BoxCollider2D>();

        lastState = CharacterAnimationState.Stand_Front;
    }
 /// <summary>
 /// Presumably, makes the instructor execute a given animation.
 /// </summary>
 /// <param name="st">The animation to execute.</param>
 public extern void PlayEmote(CharacterAnimationState st);
 /// <summary>
 /// Presumably, makes the instructor execute a given animation repeatedly.
 /// </summary>
 /// <param name="st">The animation to exectue.</param>
 /// <param name="repeatInterval">How often to repeat the animation, in seconds?</param>
 public extern void PlayEmoteRepeating(CharacterAnimationState st, float repeatInterval);
示例#25
0
        void WindowFunction(int windowID)
        {
            if (windowStyle == null)
            {
                windowStyle                     = new GUIStyle(HighLogic.Skin.window);
                windowStyle.alignment           = TextAnchor.UpperLeft;
                windowStyle.active.textColor    = Color.white;
                windowStyle.focused.textColor   = Color.white;
                windowStyle.hover.textColor     = Color.white;
                windowStyle.normal.textColor    = Color.white;
                windowStyle.onActive.textColor  = Color.white;
                windowStyle.onFocused.textColor = Color.white;
                windowStyle.onHover.textColor   = Color.white;
                windowStyle.onNormal.textColor  = Color.white;
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Space(8);

            if (instructor == null && !string.IsNullOrEmpty(instructorName))
            {
                instructor = ((GameObject)UnityEngine.Object.Instantiate(AssetBase.GetPrefab(instructorName))).GetComponent <KerbalInstructor>();

                instructorTexture = new RenderTexture(128, 128, 8);
                instructor.instructorCamera.targetTexture = instructorTexture;
                instructor.instructorCamera.ResetAspect();

                offset += 25f;
                instructor.gameObject.transform.Translate(offset, 0.0f, 0.0f);

                // Add a light
                lightGameObject = new GameObject("Dialog Box Light");
                Light lightComp = lightGameObject.AddComponent <Light>();
                lightComp.color = new Color(0.4f, 0.4f, 0.4f);
                lightGameObject.transform.position = instructor.instructorCamera.transform.position;

                if (string.IsNullOrEmpty(characterName))
                {
                    characterName = Localizer.GetStringByTag(instructor.CharacterName);
                }

                instructor.SetupAnimations();

                if (animation != null)
                {
                    switch (animation.Value)
                    {
                    case Animation.idle:
                        animState = instructor.anim_idle;
                        break;

                    case Animation.idle_lookAround:
                        animState = instructor.anim_idle_lookAround;
                        break;

                    case Animation.idle_sigh:
                        animState = instructor.anim_idle_sigh;
                        break;

                    case Animation.idle_wonder:
                        animState = instructor.anim_idle_wonder;
                        break;

                    case Animation.true_thumbUp:
                        animState = instructor.anim_true_thumbUp;
                        break;

                    case Animation.true_thumbsUp:
                        animState = instructor.anim_true_thumbsUp;
                        break;

                    case Animation.true_nodA:
                        animState = instructor.anim_true_nodA;
                        break;

                    case Animation.true_nodB:
                        animState = instructor.anim_true_nodB;
                        break;

                    case Animation.true_smileA:
                        animState = instructor.anim_true_smileA;
                        break;

                    case Animation.true_smileB:
                        animState = instructor.anim_true_smileB;
                        break;

                    case Animation.false_disappointed:
                        animState = instructor.anim_false_disappointed;
                        break;

                    case Animation.false_disagreeA:
                        animState = instructor.anim_false_disagreeA;
                        break;

                    case Animation.false_disagreeB:
                        animState = instructor.anim_false_disagreeB;
                        break;

                    case Animation.false_disagreeC:
                        animState = instructor.anim_false_disagreeC;
                        break;

                    case Animation.false_sadA:
                        animState = instructor.anim_false_sadA;
                        break;
                    }

                    // Give a short delay before playing the animation
                    nextAnimTime = Time.fixedTime + 0.3f;
                }
            }

            if (instructor != null)
            {
                // Play the animation
                if (nextAnimTime <= Time.fixedTime)
                {
                    instructor.PlayEmote(animState);
                    animState.audioClip = null;
                    nextAnimTime        = Time.fixedTime + animState.clip.length;
                }

                GUILayout.BeginVertical(GUILayout.Width(128));
                GUILayout.Box("", GUILayout.Width(128), GUILayout.Height(128));
                if (Event.current.type == EventType.Repaint)
                {
                    Rect rect = GUILayoutUtility.GetLastRect();
                    rect = new Rect(rect.x + 1f, rect.y + 1f, rect.width - 2f, rect.height - 2f);
                    Graphics.DrawTexture(rect, instructorTexture, new Rect(0.0f, 0.0f, 1f, 1f), 124, 124, 124, 124, Color.white, PortraitRenderMaterial);
                }

                DisplayName(128);

                GUILayout.EndVertical();
                GUILayout.Space(8);
            }

            // Display text
            if (text != null)
            {
                if (labelStyle == null)
                {
                    labelStyle                  = new GUIStyle(UnityEngine.GUI.skin.label);
                    labelStyle.alignment        = TextAnchor.UpperLeft;
                    labelStyle.richText         = true;
                    labelStyle.normal.textColor = new Color(0.9f, 0.9f, 0.9f);
                    labelStyle.fontSize         = 16;
                }

                GUILayout.Label(text, labelStyle, GUILayout.ExpandWidth(true));
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("OK", GUILayout.MinWidth(80)))
            {
                visible = false;
                Destroy(this);
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            UnityEngine.GUI.DragWindow();
        }