working on actors
This commit is contained in:
54
Assets/jelycho/Code/ButtonActor.cs
Normal file
54
Assets/jelycho/Code/ButtonActor.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace RebootReality.jelycho {
|
||||
public class ButtonActor : Actor, IInteractable {
|
||||
[SerializeField] Transform m_Graphics;
|
||||
|
||||
public UnityEvent pressed = new UnityEvent();
|
||||
|
||||
protected override IActorData CreateActorData() {
|
||||
return new NoActorData();
|
||||
}
|
||||
|
||||
protected override void OnActorCommandServer(ActorCommand actorCommand) {
|
||||
if (actorCommand.CommandID == (ushort) ButtonActorCommands.Press) {
|
||||
SendActorEvent((ushort) ButtonActorEvents.Pressed);
|
||||
pressed?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnActorEventClient(ActorEvent actorEvent) {
|
||||
if (actorEvent.EventID == (ushort) ButtonActorEvents.Pressed) {
|
||||
PlayPressAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
void PlayPressAnimation() {
|
||||
PressAsync().Forget();
|
||||
}
|
||||
|
||||
async UniTask PressAsync() {
|
||||
m_Graphics.localScale = new Vector3(1, 0.1f, 1);
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(1.0f));
|
||||
m_Graphics.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
public void Interact() {
|
||||
SendActorCommand((ushort) ButtonActorCommands.Press);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ButtonActorCommands : ushort {
|
||||
None = 0x0000,
|
||||
Press = 0x0001,
|
||||
}
|
||||
|
||||
public enum ButtonActorEvents : ushort {
|
||||
None = 0x0000,
|
||||
Pressed = 0x0001,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user