2024-01-19 16:30:05 +01:00
|
|
|
|
//============= Copyright (c) Ludic GmbH, All rights reserved. ==============
|
|
|
|
|
//
|
|
|
|
|
// Purpose: Part of the My Behaviour Tree Controller Code
|
|
|
|
|
//
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using MyBT;
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
[CustomEditor(typeof(NamedCollider))]
|
|
|
|
|
public class NamedColliderInspector : ComponentHandlerInspector {
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class NamedCollider : ComponentHandler {
|
|
|
|
|
public override string TypeLabel () {
|
|
|
|
|
return "Collider";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ContentLabel() {
|
|
|
|
|
UpdateComponent();
|
2024-07-17 17:51:49 +02:00
|
|
|
|
return objName;
|
2024-01-19 16:30:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void UpdateComponent() {
|
|
|
|
|
base.UpdateComponent();
|
|
|
|
|
colliderComponent = GetComponent<Collider>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Collider colliderComponent;
|
2024-07-17 17:51:49 +02:00
|
|
|
|
public string objName = "ColliderXY";
|
|
|
|
|
private bool _collidedWithObj = false;
|
|
|
|
|
private string _otherColliderTag = "";
|
2024-01-19 16:30:05 +01:00
|
|
|
|
|
|
|
|
|
public override string titleText {
|
|
|
|
|
get {
|
|
|
|
|
return "Show/Hide: Enable/Disable Collider";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string[][] helpText {
|
|
|
|
|
get {
|
|
|
|
|
return new string[][] {
|
|
|
|
|
new string[] {"Show", null, $"BTC.Show(\"{roomId}\", \"{gameObject.name}\")"},
|
2024-07-31 17:24:16 +02:00
|
|
|
|
new string[] {"Hide", null, $"BTC.Hide(\"{roomId}\", \"{gameObject.name}\")"},
|
|
|
|
|
new string[] {"Run", "Return Success on Trigger Event", $"BTC.Run(\"{roomId}\", \"{gameObject.name}\")"},
|
2024-01-19 16:30:05 +01:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Show (MyBT.NodeState nodeState) {
|
|
|
|
|
// whan aborting
|
|
|
|
|
if (nodeState == NodeState.Aborting) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// at start
|
|
|
|
|
if (nodeState == NodeState.FirstRun) {
|
|
|
|
|
// reset event trigger
|
|
|
|
|
colliderComponent.enabled = true;
|
|
|
|
|
Task.SetSucceeded();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Hide (MyBT.NodeState nodeState) {
|
|
|
|
|
// whan aborting
|
|
|
|
|
if (nodeState == NodeState.Aborting) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// at start
|
|
|
|
|
if (nodeState == NodeState.FirstRun) {
|
|
|
|
|
// reset event trigger
|
|
|
|
|
colliderComponent.enabled = false;
|
|
|
|
|
Task.SetSucceeded();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-07-17 17:51:49 +02:00
|
|
|
|
|
|
|
|
|
public override void Run(NodeState nodeState)
|
|
|
|
|
{
|
|
|
|
|
switch (nodeState)
|
|
|
|
|
{
|
|
|
|
|
case NodeState.FirstRun:
|
|
|
|
|
_collidedWithObj = false;
|
|
|
|
|
break;
|
|
|
|
|
case NodeState.Running:
|
|
|
|
|
if (_collidedWithObj)
|
|
|
|
|
{
|
|
|
|
|
Task.SetSucceeded();
|
2024-07-19 19:56:36 +02:00
|
|
|
|
_otherColliderTag = "";
|
2024-07-17 17:51:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case NodeState.Aborting:
|
|
|
|
|
_collidedWithObj = false;
|
|
|
|
|
_otherColliderTag = "";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Set(NodeState nodeState, string key, string value)
|
|
|
|
|
{
|
|
|
|
|
if (nodeState == NodeState.FirstRun)
|
|
|
|
|
{
|
2024-07-19 19:56:36 +02:00
|
|
|
|
if (key == "otherTag")
|
2024-07-17 17:51:49 +02:00
|
|
|
|
{
|
|
|
|
|
_otherColliderTag = value;
|
|
|
|
|
Task.SetSucceeded();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Task.SetFailed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
|
{
|
|
|
|
|
if (_otherColliderTag != "")
|
|
|
|
|
{
|
|
|
|
|
if(other.gameObject.CompareTag(_otherColliderTag))
|
|
|
|
|
{
|
|
|
|
|
_collidedWithObj = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_collidedWithObj = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-01-19 16:30:05 +01:00
|
|
|
|
}
|