2024-08-12 14:16:00 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
using MyBT;
|
|
|
|
using UnityEngine.XR.Interaction.Toolkit;
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
using UnityEditor;
|
|
|
|
[CustomEditor(typeof(NamedSocketEvent))]
|
|
|
|
public class NamedSocketEventInspector : ComponentHandlerInspector
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public class NamedSocketEvent : ComponentHandler
|
|
|
|
{
|
|
|
|
public override string TypeLabel()
|
|
|
|
{
|
|
|
|
return "NamedSocketEvent";
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string ContentLabel()
|
|
|
|
{
|
|
|
|
UpdateComponent();
|
|
|
|
return objName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void UpdateComponent()
|
|
|
|
{
|
|
|
|
base.UpdateComponent();
|
|
|
|
|
|
|
|
if (GetComponent<XRSocketInteractor>())
|
|
|
|
{
|
|
|
|
GetComponent<XRSocketInteractor>().selectEntered.AddListener(SelectEnterEventHandler);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogWarning($"NamedSocketEvent '{gameObject.name}' could not attach socket select event (missing XR Socket Interactor?)");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string objName = "SocketObjXY";
|
|
|
|
private bool triggered = false;
|
|
|
|
|
|
|
|
public void SelectEnterEventHandler(SelectEnterEventArgs args)
|
|
|
|
{
|
|
|
|
triggered = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string titleText
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return "Run: Will Succeed on Select Enter Event";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string[][] helpText
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return new string[][] {
|
|
|
|
new string[] {"Run", "Return Success on Select Enter Event", $"BTC.Run(\"{roomId}\", \"{gameObject.name}\")"},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Run(MyBT.NodeState nodeState)
|
|
|
|
{
|
|
|
|
if (nodeState == NodeState.FirstRun)
|
|
|
|
{
|
|
|
|
// reset event trigger at start
|
|
|
|
triggered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nodeState == NodeState.Aborting)
|
|
|
|
{
|
|
|
|
triggered = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (triggered)
|
|
|
|
{
|
2024-09-24 17:33:08 +02:00
|
|
|
Debug.Log($"NamedSocketEvent: Select entered event from {gameObject.name} fired.");
|
2024-08-12 14:16:00 +02:00
|
|
|
Task.SetSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|