60 lines
1.9 KiB
C#
60 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
|
|
[RequireComponent(typeof(PlayableDirector))]
|
|
public class EventPartnerStatueDiceView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform dice;
|
|
[SerializeField] private PlayableDirector playableDirector;
|
|
private static readonly Dictionary<EEventPartnerStatueDiceFace, Vector3> diceRotationLookUp = new Dictionary<EEventPartnerStatueDiceFace, Vector3>()
|
|
{
|
|
{EEventPartnerStatueDiceFace.Free, Vector3.zero},
|
|
{EEventPartnerStatueDiceFace.More, new Vector3(180, 0, 0)},
|
|
{EEventPartnerStatueDiceFace.PowerDrill, new Vector3(180, -90, 0)},
|
|
{EEventPartnerStatueDiceFace.Hammer, new Vector3(180, -90, -90)},
|
|
{EEventPartnerStatueDiceFace.HandSaw, new Vector3(180, -90, -180)},
|
|
{EEventPartnerStatueDiceFace.CircularSaw, new Vector3(180, -90, 90)},
|
|
};
|
|
|
|
public void SetDiceFace(EEventPartnerStatueDiceFace face)
|
|
{
|
|
dice.localRotation = Quaternion.Euler(diceRotationLookUp[face]);
|
|
}
|
|
|
|
public async System.Threading.Tasks.Task Play(EEventPartnerStatueDiceFace face)
|
|
{
|
|
gameObject.SetActive(true);
|
|
playableDirector.Play();
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(0.5f));
|
|
SetDiceFace(face);
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(playableDirector.duration - 0.5f));
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
[SerializeField] private EEventPartnerStatueDiceFace testFace;
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.D))
|
|
{
|
|
SetDiceFace(testFace);
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.P))
|
|
{
|
|
_ = Play(testFace);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
private void Reset()
|
|
{
|
|
dice = transform.Find("offset/dice/switch");
|
|
playableDirector = GetComponent<PlayableDirector>();
|
|
}
|
|
}
|