riversong code showcase
This commit is contained in:
57
Source/Riversong/Game/World/Agents/AgentVisualization.cs
Normal file
57
Source/Riversong/Game/World/Agents/AgentVisualization.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public class AgentVisualization : MonoBehaviour
|
||||
{
|
||||
private static readonly int IsMovingParamID = Animator.StringToHash("IsMoving");
|
||||
|
||||
[Required]
|
||||
[SerializeField]
|
||||
private Animator _animator;
|
||||
|
||||
[SerializeField]
|
||||
private AgentAnimationEventHandler _animationEventHandler;
|
||||
|
||||
[field: SerializeField] public AgentCarriedProductVisualization CarriedProductVisualization { get; private set; }
|
||||
|
||||
private bool _isVisible;
|
||||
|
||||
private List<Renderer> _renderers;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_renderers = new List<Renderer>(1);
|
||||
GetComponentsInChildren(_renderers);
|
||||
|
||||
_isVisible = true;
|
||||
SetVisible(false);
|
||||
}
|
||||
|
||||
public void SetVisible(bool isVisible)
|
||||
{
|
||||
if (_isVisible == isVisible) return;
|
||||
|
||||
foreach (var r in _renderers) r.enabled = isVisible;
|
||||
|
||||
_isVisible = isVisible;
|
||||
}
|
||||
|
||||
public void UpdateAnimationState(bool isMoving)
|
||||
{
|
||||
_animator.SetBool(IsMovingParamID, isMoving);
|
||||
}
|
||||
|
||||
public void SetAnimatorTrigger(int triggerID)
|
||||
{
|
||||
_animator.SetTrigger(triggerID);
|
||||
}
|
||||
|
||||
public bool WaitAnimationCompleted()
|
||||
{
|
||||
return _animationEventHandler.WaitAnimationCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user