working on humbie still
This commit is contained in:
60
Assets/jelycho/Code/Actors/ActorSpawner.cs
Normal file
60
Assets/jelycho/Code/Actors/ActorSpawner.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using RebootKit.Engine.Main;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using TriInspector;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
namespace RebootReality.jelycho.Actors {
|
||||
public class ActorSpawner : Actor {
|
||||
static readonly Logger s_Logger = new Logger(nameof(ActorSpawner));
|
||||
|
||||
[SerializeField] AssetReferenceGameObject m_ActorPrefabReference;
|
||||
[SerializeField, Range(1, 256)] int m_Count = 1;
|
||||
|
||||
[InfoBox("If empty will use this object transform as spawn point.")]
|
||||
[SerializeField] Transform[] m_SpawnPoints;
|
||||
|
||||
protected override IActorData CreateActorData() {
|
||||
return new NoActorData();
|
||||
}
|
||||
|
||||
protected override void OnActorCommandServer(ulong senderID, ActorCommand actorCommand) {
|
||||
base.OnActorCommandServer(senderID, actorCommand);
|
||||
|
||||
s_Logger.Info("Received actor command: " + actorCommand.CommandID);
|
||||
|
||||
ActorSpawnerCommands spawnerCommand = (ActorSpawnerCommands) actorCommand.CommandID;
|
||||
if (spawnerCommand == ActorSpawnerCommands.SpawnActor) {
|
||||
for (int i = 0; i < m_Count; ++i) {
|
||||
(Vector3 spawnPoint, Quaternion spawnRotation) = GetSpawnPoint();
|
||||
RR.SpawnActor(m_ActorPrefabReference, spawnPoint, spawnRotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Button]
|
||||
public void SpawnActor() {
|
||||
if (m_ActorPrefabReference == null) {
|
||||
s_Logger.Error("ActorPrefabReference is not set. Cannot spawn actor.");
|
||||
return;
|
||||
}
|
||||
|
||||
SendActorCommand((byte) ActorSpawnerCommands.SpawnActor);
|
||||
}
|
||||
|
||||
(Vector3, Quaternion) GetSpawnPoint() {
|
||||
if (m_SpawnPoints.Length == 0) {
|
||||
return (transform.position, transform.rotation);
|
||||
}
|
||||
|
||||
int index = Random.Range(0, m_SpawnPoints.Length);
|
||||
return (m_SpawnPoints[index].position, m_SpawnPoints[index].rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ActorSpawnerCommands : byte {
|
||||
None = 0x00,
|
||||
SpawnActor = 0x01,
|
||||
}
|
||||
}
|
||||
3
Assets/jelycho/Code/Actors/ActorSpawner.cs.meta
Normal file
3
Assets/jelycho/Code/Actors/ActorSpawner.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96676410d3db4402b69bc504218db929
|
||||
timeCreated: 1752274642
|
||||
95
Assets/jelycho/Code/Actors/ButtonActor.cs
Normal file
95
Assets/jelycho/Code/Actors/ButtonActor.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using HighlightPlus;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
namespace RebootReality.jelycho.Actors {
|
||||
public class ButtonActor : Actor, IInteractable {
|
||||
static readonly Logger s_Logger = new Logger(nameof(ButtonActor));
|
||||
|
||||
[SerializeField] Transform m_Graphics;
|
||||
[SerializeField] float m_CooldownDuration = 0.5f;
|
||||
[SerializeField] HighlightEffect m_HighlightEffect;
|
||||
|
||||
DateTime m_LastPressTime;
|
||||
|
||||
public UnityEvent pressed = new UnityEvent();
|
||||
|
||||
//
|
||||
// @MARK: Unity callbacks
|
||||
//
|
||||
void Awake() {
|
||||
SetHighlight(false);
|
||||
m_LastPressTime = DateTime.MinValue;
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: Actor
|
||||
//
|
||||
protected override IActorData CreateActorData() {
|
||||
return new NoActorData();
|
||||
}
|
||||
|
||||
protected override void OnActorCommandServer(ulong senderID, ActorCommand actorCommand) {
|
||||
if (actorCommand.CommandID == (ushort) ButtonActorCommands.Press) {
|
||||
if (DateTime.UtcNow - m_LastPressTime < TimeSpan.FromSeconds(m_CooldownDuration)) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_LastPressTime = DateTime.UtcNow;
|
||||
pressed?.Invoke();
|
||||
|
||||
SendActorEvent((byte) ButtonActorEvents.Pressed);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnActorEventClient(ActorEvent actorEvent) {
|
||||
ButtonActorEvents buttonEvent = (ButtonActorEvents) actorEvent.EventID;
|
||||
|
||||
switch (buttonEvent) {
|
||||
case ButtonActorEvents.Pressed: {
|
||||
PlayPressAnimation();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
s_Logger.Error($"Unknown actor event: {actorEvent.EventID}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayPressAnimation() {
|
||||
PressAsync().Forget();
|
||||
}
|
||||
|
||||
async UniTask PressAsync() {
|
||||
m_Graphics.localScale = new Vector3(1, 0.1f, 1);
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(m_CooldownDuration),
|
||||
cancellationToken: destroyCancellationToken);
|
||||
m_Graphics.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: IInteractable
|
||||
//
|
||||
public void SetHighlight(bool highlight) {
|
||||
m_HighlightEffect.highlighted = highlight;
|
||||
}
|
||||
|
||||
public void Interact() {
|
||||
SendActorCommand((byte) ButtonActorCommands.Press);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ButtonActorCommands : byte {
|
||||
None = 0x00,
|
||||
Press = 0x01,
|
||||
}
|
||||
|
||||
public enum ButtonActorEvents : byte {
|
||||
None = 0x00,
|
||||
Pressed = 0x01,
|
||||
}
|
||||
}
|
||||
3
Assets/jelycho/Code/Actors/ButtonActor.cs.meta
Normal file
3
Assets/jelycho/Code/Actors/ButtonActor.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d10f6d33b0194c67966bb1a1b891ff3e
|
||||
timeCreated: 1751492558
|
||||
8
Assets/jelycho/Code/Actors/IHasHealth.cs
Normal file
8
Assets/jelycho/Code/Actors/IHasHealth.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace RebootReality.jelycho.Actors {
|
||||
public interface IHasHealth {
|
||||
ulong Health { get; }
|
||||
ulong MaxHealth { get; }
|
||||
|
||||
bool IsAlive();
|
||||
}
|
||||
}
|
||||
3
Assets/jelycho/Code/Actors/IHasHealth.cs.meta
Normal file
3
Assets/jelycho/Code/Actors/IHasHealth.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5449b1adab2f474b9d7a25cb59c66e6d
|
||||
timeCreated: 1754955332
|
||||
6
Assets/jelycho/Code/Actors/IInteractable.cs
Normal file
6
Assets/jelycho/Code/Actors/IInteractable.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace RebootReality.jelycho.Actors {
|
||||
public interface IInteractable {
|
||||
void SetHighlight(bool highlight);
|
||||
void Interact();
|
||||
}
|
||||
}
|
||||
3
Assets/jelycho/Code/Actors/IInteractable.cs.meta
Normal file
3
Assets/jelycho/Code/Actors/IInteractable.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2078b76220c046a4b6077ab42e8ccaf3
|
||||
timeCreated: 1751512956
|
||||
Reference in New Issue
Block a user