Firstborn/Assets/RPG Creation Kit/Scripts/BehaviourTrees/RPGCK_BT.cs
Schaken-Mods 959e80cf72 assets upload
assets upload description.
2023-03-28 12:16:30 -05:00

104 lines
3.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XNode;
using RPGCreationKit.BehaviourTree;
using RPGCreationKit.BehaviourTree.Data;
using RPGCreationKit.AI;
namespace RPGCreationKit.BehaviourTree
{
public enum TreeTickRate
{
EveryFrame = 0,
EveryXFrames = 1,
EveryXSeconds_Realtime = 2,
EveryXSeconds_GameTime = 3
};
[CreateAssetMenu(fileName = "New BehaviourTree", menuName = "RPG Creation Kit/BehaviourTrees/New BehaviourTree", order = 1)]
[System.Serializable]
public class RPGCK_BT : NodeGraph
{
public string ID;
public bool IsCombatBehaviour = false;
public bool isSpecificBehaviourTree = false;
public bool resetVariablesUponStartResume = false;
public GameObject owner;
public RckAI ai;
[SerializeField] public List<BTVariable> graphVariables = new List<BTVariable>();
[Space(10)]
[TextArea(30, 30)]
public string Description;
public RPGCK_BT RPGCK_BTCopy(GameObject _owner, RckAI _ai)
{
ai = _ai;
owner = _owner;
// Instantiate a new nodegraph instance
RPGCK_BT graph = Instantiate(this);
// Instantiate all nodes inside the graph
for (int i = 0; i < nodes.Count; i++)
{
if (nodes[i] == null) continue;
Node.graphHotfix = graph;
Node node = Instantiate(nodes[i]) as Node;
node.graph = graph;
graph.nodes[i] = node;
}
// Redirect all connections
for (int i = 0; i < graph.nodes.Count; i++)
{
if (graph.nodes[i] == null) continue;
foreach (NodePort port in graph.nodes[i].Ports)
{
port.Redirect(nodes, graph.nodes);
}
}
// Copy graphVariables as well
for(int i = 0; i < graphVariables.Count; i++)
{
if (graphVariables[i] == null) continue;
BTVariable variable = Instantiate(graphVariables[i] as BTVariable);
// Ensure that the name of the copied variables are the same as the original one (remove (Clone))
variable.name = graphVariables[i].name;
graph.graphVariables[i] = variable;
}
return graph;
}
[ContextMenu("Reorder")]
public void ReorderTree()
{
for(int i = 0; i < nodes.Count; i++)
{
if(nodes[i] != null && nodes[i] is BTNode)
((BTNode)nodes[i]).ReorderChild();
}
}
public void ResetVariables()
{
for(int i = 0; i < graphVariables.Count; i++)
{
graphVariables[i].SetDefaultValue();
}
}
[ContextMenu("Debug InstanceID")]
public void DebugInstanceID()
{
Debug.Log(this.GetInstanceID());
}
}
}