Repository navigation
Expand file tree
/
Copy pathAgentAnimation.cs
More file actions
98 lines (86 loc) · 2.62 KB
/
Copy pathAgentAnimation.cs
File metadata and controls
98 lines (86 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace FarmGame.Agent
{
[RequireComponent(typeof(Animator))]
public class AgentAnimation : MonoBehaviour
{
private Animator _animator;
[SerializeField]
private string directionX = "DirectionX",
directionY = "DirectionY",
movingBoolFlag = "Movement",
pickup = "Pickup", swing = "Swing",
watering = "Watering",
carry = "Carry";
[SerializeField]
private ToolAnimation toolAnimation;
[HideInInspector]
public UnityEvent OnAnimationEnd, OnAnimationOnce;
public UnityEvent OnFootStep;
public ToolAnimation ToolAnimation { get => toolAnimation;}
private void Awake()
{
_animator = GetComponent<Animator>();
}
public void PlayerActionAnimationEnd()
{
OnAnimationEnd?.Invoke();
OnAnimationEnd.RemoveAllListeners();
}
public void PlayerActionAnimationOnce()
{
OnAnimationOnce?.Invoke();
OnAnimationOnce.RemoveAllListeners();
}
public void PlayFootstep()
=> OnFootStep?.Invoke();
public void PlayMovementAnimation(bool val)
=> _animator.SetBool(movingBoolFlag, val);
public void ChangeDirection(Vector2 direction)
{
if (direction.magnitude < 0.1f)
return;
Vector2Int directionInt = Vector2Int.RoundToInt(direction);
if(directionInt.x != 0)
{
directionInt.y = 0;
}
_animator.SetFloat(directionX, directionInt.x);
_animator.SetFloat(directionY, directionInt.y);
}
public void PlayAnimation(AnimationType animationType)
{
if(animationType == AnimationType.PickUp)
{
_animator.SetTrigger(pickup);
}
else if(animationType == AnimationType.Swing)
{
_animator.SetTrigger(swing);
}
else if (animationType == AnimationType.Watering)
{
_animator.SetTrigger(watering);
}
}
public void SetCarrying(bool val)
{
_animator.SetBool(carry, val);
if (val)
_animator.Play("Idle Carry Blend Tree");
else
_animator.Play("Idle Blend Tree");
}
}
public enum AnimationType
{
None,
PickUp,
Swing,
Watering
}
}