quickoutline
This commit is contained in:
@@ -3,9 +3,13 @@ using Cysharp.Threading.Tasks;
|
||||
using RebootKit.Engine.Simulation;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using Logger = RebootKit.Engine.Foundation.Logger;
|
||||
|
||||
namespace RebootReality.jelycho {
|
||||
public class ButtonActor : Actor, IInteractable {
|
||||
static readonly Logger s_Logger = new Logger(nameof(ButtonActor));
|
||||
|
||||
[SerializeField] Outline m_Outline;
|
||||
[SerializeField] Transform m_Graphics;
|
||||
[SerializeField] float m_CooldownDuration = 0.5f;
|
||||
|
||||
@@ -13,6 +17,17 @@ namespace RebootReality.jelycho {
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -42,10 +57,22 @@ namespace RebootReality.jelycho {
|
||||
|
||||
async UniTask PressAsync() {
|
||||
m_Graphics.localScale = new Vector3(1, 0.1f, 1);
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(1.0f));
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(m_CooldownDuration), cancellationToken: destroyCancellationToken);
|
||||
m_Graphics.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: IInteractable
|
||||
//
|
||||
public void SetHighlight(bool highlight) {
|
||||
if (m_Outline == null) {
|
||||
Debug.LogError("ButtonActor does not have an Outline component.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_Outline.enabled = highlight;
|
||||
}
|
||||
|
||||
public void Interact() {
|
||||
SendActorCommand((ushort) ButtonActorCommands.Press);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace RebootReality.jelycho {
|
||||
public interface IInteractable {
|
||||
void SetHighlight(bool highlight);
|
||||
void Interact();
|
||||
}
|
||||
}
|
||||
@@ -10,21 +10,42 @@ namespace RebootReality.jelycho.Items {
|
||||
class ItemActorData : IActorData {
|
||||
public ItemConfig Config;
|
||||
|
||||
public void Serialize(FastBufferWriter writer) {
|
||||
}
|
||||
public void Deserialize(FastBufferReader reader) {
|
||||
}
|
||||
public void Serialize(FastBufferWriter writer) { }
|
||||
public void Deserialize(FastBufferReader reader) { }
|
||||
}
|
||||
|
||||
|
||||
[field: SerializeField] public ItemConfig Config { get; private set; }
|
||||
|
||||
[SerializeField] Outline m_Outline;
|
||||
|
||||
//
|
||||
// @MARK: Unity callbacks
|
||||
//
|
||||
void Awake() {
|
||||
SetHighlight(false);
|
||||
}
|
||||
|
||||
//
|
||||
// @MARK: Actor
|
||||
//
|
||||
protected override IActorData CreateActorData() {
|
||||
return new ItemActorData {
|
||||
Config = Config
|
||||
};
|
||||
}
|
||||
|
||||
public void Interact() {
|
||||
//
|
||||
// @MARK: IInteractable
|
||||
//
|
||||
public void SetHighlight(bool highlight) {
|
||||
if (m_Outline == null) {
|
||||
s_Logger.Error("ItemActor does not have an Outline component.");
|
||||
return;
|
||||
}
|
||||
|
||||
m_Outline.enabled = highlight;
|
||||
}
|
||||
|
||||
public void Interact() { }
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,8 @@ namespace RebootReality.jelycho.Player {
|
||||
DisposableBag m_OwnerActorDisposableBag = new DisposableBag();
|
||||
IDisposable m_TargetInteractableLabelDisposable;
|
||||
|
||||
IInteractable m_Interactable;
|
||||
|
||||
public override void OnNetworkSpawn() {
|
||||
base.OnNetworkSpawn();
|
||||
|
||||
@@ -64,11 +66,16 @@ namespace RebootReality.jelycho.Player {
|
||||
m_OwnerActorDisposableBag = new DisposableBag();
|
||||
|
||||
m_Actor.TargetInteractable.Subscribe(interactable => {
|
||||
m_Interactable?.SetHighlight(false);
|
||||
|
||||
if (m_TargetInteractableLabelDisposable != null) {
|
||||
m_TargetInteractableLabelDisposable.Dispose();
|
||||
m_TargetInteractableLabelDisposable = null;
|
||||
}
|
||||
|
||||
m_Interactable = interactable;
|
||||
m_Interactable?.SetHighlight(true);
|
||||
|
||||
if (interactable is Actor interactableActor) {
|
||||
m_TargetInteractableLabelDisposable =
|
||||
m_HUD.ObjectsLabels.CreateLabel(interactableActor.transform,
|
||||
|
||||
Reference in New Issue
Block a user