From fcbec4a881b9f87b3b0db9d5b72e6f38b1a75694 Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Mon, 27 Sep 2021 22:57:18 -0700 Subject: [PATCH 01/41] Added NPC script Added a folder specifically for NPC's And created a very rudimentary NPC script. With a dialogue option --- Assets/Scripts/Game/NPCs.meta | 8 +++++ Assets/Scripts/Game/NPCs/BaseNPC.cs | 37 ++++++++++++++++++++++++ Assets/Scripts/Game/NPCs/BaseNPC.cs.meta | 11 +++++++ 3 files changed, 56 insertions(+) create mode 100644 Assets/Scripts/Game/NPCs.meta create mode 100644 Assets/Scripts/Game/NPCs/BaseNPC.cs create mode 100644 Assets/Scripts/Game/NPCs/BaseNPC.cs.meta diff --git a/Assets/Scripts/Game/NPCs.meta b/Assets/Scripts/Game/NPCs.meta new file mode 100644 index 00000000..228fdfa0 --- /dev/null +++ b/Assets/Scripts/Game/NPCs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0c239f08addd9744aad65aa10bc2c82d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Game/NPCs/BaseNPC.cs b/Assets/Scripts/Game/NPCs/BaseNPC.cs new file mode 100644 index 00000000..078c8e89 --- /dev/null +++ b/Assets/Scripts/Game/NPCs/BaseNPC.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using BehaviourTree; +namespace RPG{ + + public class BaseNPC: Actor + { + QuestGiver dialogue; + Agent agent; + + // Start is called before the first frame update + void Start() + { + dialogue=GetComponent(); + agent=GetComponent(); + InitiateDialogue(); + } + + // Update is called once per frame + void Update() + { + + } + + //Force Dialogue with player; + public void InitiateDialogue(){ + Player p=GameObject.FindGameObjectWithTag("player").GetComponent(); + dialogue.Interact(p); + //disable the behaviour script in the meantime + agent.DisableBehaviours(); + + //TODO Detect when dialogue box is closed then switch to regular behaviours + agent.EnableBehaviours(); + } + } +} diff --git a/Assets/Scripts/Game/NPCs/BaseNPC.cs.meta b/Assets/Scripts/Game/NPCs/BaseNPC.cs.meta new file mode 100644 index 00000000..eac1d56b --- /dev/null +++ b/Assets/Scripts/Game/NPCs/BaseNPC.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5dd1dec152424544a6fcae9ff825aa6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 190a26e3ea297b8d8975ba2a2001249d4b7f4cb3 Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Mon, 27 Sep 2021 22:58:34 -0700 Subject: [PATCH 02/41] Update Agent.cs Updated Agent to include a isEnabled field. That prevents Root from running in update if disabled --- Assets/Scripts/Tools/Behaviour Tree/Agent.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs index 14a95ab6..ea841679 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs @@ -13,15 +13,21 @@ public class Agent : MonoBehaviour private Tree.Node root; + private bool isEnabled; + void Awake() { root = behaviourTree.Root; Properties = new Dictionary(); + isEnabled=true; } void Update() { - root.Element.Tick(root, this); + if(isEnabled){ + root.Element.Tick(root, this); + } + } public void SetProperty(string name, object property) @@ -43,5 +49,13 @@ public void RemoveProperty(string name) { Properties.Remove(name); } + + public void DisableBehaviours(){ + isEnabled=false; + } + + public void EnableBehaviours(){ + isEnabled=true; + } } } From 3bf19d1cebb46b9ac4d638d47dd4c0cdae909846 Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Tue, 28 Sep 2021 11:59:15 -0700 Subject: [PATCH 03/41] Make a testNPC Made a test NPC with a rudimentary behaviour tree. --- .../Data/Behaviour Trees/NPCBehaviour.asset | 53 +++++++ .../Behaviour Trees/NPCBehaviour.asset.meta | 8 + Assets/Scenes/Main.unity | 148 ++++++++++++++++++ 3 files changed, 209 insertions(+) create mode 100644 Assets/Data/Behaviour Trees/NPCBehaviour.asset create mode 100644 Assets/Data/Behaviour Trees/NPCBehaviour.asset.meta diff --git a/Assets/Data/Behaviour Trees/NPCBehaviour.asset b/Assets/Data/Behaviour Trees/NPCBehaviour.asset new file mode 100644 index 00000000..f95c7afe --- /dev/null +++ b/Assets/Data/Behaviour Trees/NPCBehaviour.asset @@ -0,0 +1,53 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54fb5e73c80040247a00b01917c6e426, type: 3} + m_Name: NPCBehaviour + m_EditorClassIdentifier: + tree: + serializedNodes: + - childCount: 1 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 1 + - childCount: 0 + element: + propertyInfo: + - name: origin + property: + propertyType: 4 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + - name: max-distance + property: + propertyType: 1 + value: + b: 0 + n: 5 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + - name: move-speed + property: + propertyType: 1 + value: + b: 0 + n: 5 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + nodeTypeName: BehaviourTree.MoveRandomNode + firstChildIndex: 2 diff --git a/Assets/Data/Behaviour Trees/NPCBehaviour.asset.meta b/Assets/Data/Behaviour Trees/NPCBehaviour.asset.meta new file mode 100644 index 00000000..325f178e --- /dev/null +++ b/Assets/Data/Behaviour Trees/NPCBehaviour.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c6852fa420194194f839740aae243d5c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 65cf6b5b..7ed73a54 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -1017,6 +1017,154 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 14 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &462458363 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 462458369} + - component: {fileID: 462458368} + - component: {fileID: 462458367} + - component: {fileID: 462458366} + - component: {fileID: 462458365} + - component: {fileID: 462458364} + m_Layer: 8 + m_Name: TestJimmy + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &462458364 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 462458363} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} + m_Name: + m_EditorClassIdentifier: + behaviourTree: {fileID: 11400000, guid: c6852fa420194194f839740aae243d5c, type: 2} +--- !u!114 &462458365 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 462458363} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c5dd1dec152424544a6fcae9ff825aa6, type: 3} + m_Name: + m_EditorClassIdentifier: + initialMaxHealth: 0 + dialogue: {fileID: 0} + interactionDistance: 2 +--- !u!114 &462458366 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 462458363} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Name: + m_EditorClassIdentifier: + tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, + type: 3} + interactHint: Talk + name: Sneeko + portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} + dialogue: {fileID: 11400000, guid: 8c096da2b4b78d14492866a0ace564a7, type: 2} +--- !u!58 &462458367 +CircleCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 462458363} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + serializedVersion: 2 + m_Radius: 0.5 +--- !u!212 &462458368 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 462458363} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} + m_Color: {r: 0.547801, g: 0.25, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 0.5859375, y: 0.64377683} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &462458369 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 462458363} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.35, y: -4.64, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 15 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &468670149 GameObject: m_ObjectHideFlags: 0 From f8ddbb1ee0fbee9788fd12a4aef43484f3806d9d Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Wed, 29 Sep 2021 00:05:53 -0700 Subject: [PATCH 04/41] Add option to turn NPC to enemy It still requires that behaviour added in the behaviour tree but it will do for now --- .../Data/Behaviour Trees/NPCBehaviour.asset | 17 ++----- Assets/Scripts/Game/NPCs/BaseNPC.cs | 51 ++++++++++++++----- UserSettings/EditorUserSettings.asset | 3 ++ 3 files changed, 46 insertions(+), 25 deletions(-) diff --git a/Assets/Data/Behaviour Trees/NPCBehaviour.asset b/Assets/Data/Behaviour Trees/NPCBehaviour.asset index f95c7afe..8838bc01 100644 --- a/Assets/Data/Behaviour Trees/NPCBehaviour.asset +++ b/Assets/Data/Behaviour Trees/NPCBehaviour.asset @@ -22,21 +22,12 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: - - name: origin - property: - propertyType: 4 - value: - b: 0 - n: 0 - s: - o: {fileID: 0} - v: {x: 0, y: 0} - - name: max-distance + - name: move-range property: propertyType: 1 value: b: 0 - n: 5 + n: 4 s: o: {fileID: 0} v: {x: 0, y: 0} @@ -45,9 +36,9 @@ MonoBehaviour: propertyType: 1 value: b: 0 - n: 5 + n: 4 s: o: {fileID: 0} v: {x: 0, y: 0} - nodeTypeName: BehaviourTree.MoveRandomNode + nodeTypeName: BehaviourTree.MoveNode firstChildIndex: 2 diff --git a/Assets/Scripts/Game/NPCs/BaseNPC.cs b/Assets/Scripts/Game/NPCs/BaseNPC.cs index 078c8e89..65e94fcf 100644 --- a/Assets/Scripts/Game/NPCs/BaseNPC.cs +++ b/Assets/Scripts/Game/NPCs/BaseNPC.cs @@ -6,32 +6,59 @@ namespace RPG{ public class BaseNPC: Actor { - QuestGiver dialogue; - Agent agent; + public QuestGiver dialogue; + private Agent agent; + [SerializeField]private float interactionDistance=5.0f; + + private bool dialogueInitiated=false;//Delete this when we have a means of catching when dialogue is done + + private NPCMovement movement; + + List testNodes=new List(); + private SpriteRenderer spriteRenderer; // Start is called before the first frame update - void Start() - { + private void Awake() { + base.Awake(); dialogue=GetComponent(); agent=GetComponent(); - InitiateDialogue(); + spriteRenderer=GetComponent(); + movement=new NPCMovement(2.0f); } // Update is called once per frame void Update() { - } //Force Dialogue with player; public void InitiateDialogue(){ - Player p=GameObject.FindGameObjectWithTag("player").GetComponent(); - dialogue.Interact(p); - //disable the behaviour script in the meantime - agent.DisableBehaviours(); + GameObject player=GameObject.FindGameObjectWithTag("Player"); + //Detect if player is within range of the player + if(!dialogueInitiated && player!=null && Vector2.Distance(transform.position, player.transform.position)<=interactionDistance){ + Debug.Log("Dialogue initiated"); + dialogue.Interact(player.GetComponent()); + dialogueInitiated=true; + //disable the behaviour script in the meantime + agent.DisableBehaviours(); - //TODO Detect when dialogue box is closed then switch to regular behaviours - agent.EnableBehaviours(); + //TODO Detect when dialogue box is closed then switch to regular behaviours + agent.EnableBehaviours(); + } + } + + public void TurnIntoEnemy(){ + //Change to enemy Layer; + gameObject.layer=LayerMask.NameToLayer("Enemy"); + + //Doesnt if this doesn't have Enemy Script will add it + if(gameObject.GetComponent()==null){ + gameObject.AddComponent(); + } + else{ + gameObject.GetComponent().enabled=true; + } + //TODO add AttackBehaviour in BehaviourTree } } } diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index b58cf319..9d467e20 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -6,6 +6,9 @@ EditorUserSettings: serializedVersion: 4 m_ConfigSettings: RecentlyUsedScenePath-0: + value: 22424703114646680e0b0227036c6b150503361a0f66333e243d04 + flags: 0 + RecentlyUsedScenePath-1: value: 22424703114646680e0b0227036c72111f19563f22213229 flags: 0 vcSharedLogLevel: From 28d214ff8e5d81932265212ea39e7e967bcf9414 Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Wed, 29 Sep 2021 00:09:51 -0700 Subject: [PATCH 05/41] Designate script for NPC movement It is a simple script for now. I'd hope to program the movement scripts into generic behaviour nodes later. Still need to add: -Collision detection and avoidance -A follow path function. --- Assets/Scripts/Game/NPCs/NPCMovement.cs | 40 ++++++++++++++++++++ Assets/Scripts/Game/NPCs/NPCMovement.cs.meta | 11 ++++++ 2 files changed, 51 insertions(+) create mode 100644 Assets/Scripts/Game/NPCs/NPCMovement.cs create mode 100644 Assets/Scripts/Game/NPCs/NPCMovement.cs.meta diff --git a/Assets/Scripts/Game/NPCs/NPCMovement.cs b/Assets/Scripts/Game/NPCs/NPCMovement.cs new file mode 100644 index 00000000..1cc3a45f --- /dev/null +++ b/Assets/Scripts/Game/NPCs/NPCMovement.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using BehaviourTree; +namespace RPG{ + /* + This Class is purely meant to manage until I migrate all of these into separate BehaviourNodes. + I apologize :'( I just didn't have time to tamper with all of the engine yet to implement further changes. + */ + public class NPCMovement + { + private float followDistance; + private bool isRunning; + public NPCMovement(float f=1f){ + followDistance=f; + isRunning=false; + } + + //Follow a player at a distance + public void FollowPlayer(Vector2 position, Agent agent){ + Vector2 playerPos=(Vector2)GameObject.FindGameObjectWithTag("Player").transform.position; + if(playerPos!=null){ + //Get the distance between two vectors + float distance=Vector2.Distance(playerPos,position); + if(distance>=followDistance){ + //Set destination to where followDistance is on the line between the two. + float ratio=followDistance/distance; + agent.SetProperty("destination",Vector2.Lerp(playerPos,position,ratio)); + } + + } + + } + + public void FollowPath(Vector2 position, Agent agent){ + //TODO Follow a path via a list of Vector2s + } + } +} + diff --git a/Assets/Scripts/Game/NPCs/NPCMovement.cs.meta b/Assets/Scripts/Game/NPCs/NPCMovement.cs.meta new file mode 100644 index 00000000..d6499445 --- /dev/null +++ b/Assets/Scripts/Game/NPCs/NPCMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 90f8475ce6de91742904261ce39b646a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 67aa169abdd631b20247324d1ce7c2dba6068086 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Sun, 3 Oct 2021 15:02:46 -0700 Subject: [PATCH 06/41] Add array iterator example nodes --- Assets/Data/Behaviour Trees/ExampleNPC.asset | 108 +++++++++++++++++ .../Behaviour Trees/ExampleNPC.asset.meta | 8 ++ Assets/Scenes/Main.unity | 113 ++++++++++++++++++ .../BehaviourTreeNodeCreator.cs | 8 +- .../Nodes/ArrayIncrementNode.cs | 37 ++++++ .../Nodes/ArrayIncrementNode.cs.meta | 11 ++ .../Nodes/VectorIteratorNode.cs | 51 ++++++++ .../Nodes/VectorIteratorNode.cs.meta | 11 ++ 8 files changed, 346 insertions(+), 1 deletion(-) create mode 100644 Assets/Data/Behaviour Trees/ExampleNPC.asset create mode 100644 Assets/Data/Behaviour Trees/ExampleNPC.asset.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs.meta diff --git a/Assets/Data/Behaviour Trees/ExampleNPC.asset b/Assets/Data/Behaviour Trees/ExampleNPC.asset new file mode 100644 index 00000000..57dc89e9 --- /dev/null +++ b/Assets/Data/Behaviour Trees/ExampleNPC.asset @@ -0,0 +1,108 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54fb5e73c80040247a00b01917c6e426, type: 3} + m_Name: ExampleNPC + m_EditorClassIdentifier: + tree: + serializedNodes: + - childCount: 3 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 1 + - childCount: 0 + element: + propertyInfo: + - name: source-array + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: TODO + o: {fileID: 0} + v: {x: 0, y: 0} + - name: index-source + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: patrol-index + o: {fileID: 0} + v: {x: 0, y: 0} + - name: vector-destination + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: patrol-vector + o: {fileID: 0} + v: {x: 0, y: 0} + nodeTypeName: BehaviourTree.VectorIteratorNode + firstChildIndex: 2 + - childCount: 0 + element: + propertyInfo: + - name: position-source + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: patrol-vector + o: {fileID: 0} + v: {x: 0, y: 0} + - name: min-distance + property: + propertyType: 1 + value: + b: 0 + n: 0.1 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + - name: move-speed + property: + propertyType: 1 + value: + b: 0 + n: 2 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + nodeTypeName: BehaviourTree.SimpleMoveNode + firstChildIndex: 3 + - childCount: 0 + element: + propertyInfo: + - name: index-source + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: patrol-index + o: {fileID: 0} + v: {x: 0, y: 0} + - name: max-index + property: + propertyType: 1 + value: + b: 0 + n: 3 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + nodeTypeName: BehaviourTree.ArrayIncrementNode + firstChildIndex: 4 diff --git a/Assets/Data/Behaviour Trees/ExampleNPC.asset.meta b/Assets/Data/Behaviour Trees/ExampleNPC.asset.meta new file mode 100644 index 00000000..c3eae896 --- /dev/null +++ b/Assets/Data/Behaviour Trees/ExampleNPC.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: de69ac2176667774d94e83467a58ecce +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 9a90da84..1048c3a0 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -508,6 +508,119 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: bc0f3130c06f5e14694bdfacf0eecaa6, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1 &113309044 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 113309049} + - component: {fileID: 113309048} + - component: {fileID: 113309047} + - component: {fileID: 113309050} + m_Layer: 8 + m_Name: TestNPCMover + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!58 &113309047 +CircleCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 113309044} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + serializedVersion: 2 + m_Radius: 0.5 +--- !u!212 &113309048 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 113309044} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 0.5859375, y: 0.64377683} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &113309049 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 113309044} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -3, y: -3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 15 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &113309050 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 113309044} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} + m_Name: + m_EditorClassIdentifier: + behaviourTree: {fileID: 11400000, guid: de69ac2176667774d94e83467a58ecce, type: 2} --- !u!1 &174102886 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index 11f11a41..a2c5d0ce 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -16,7 +16,9 @@ public enum BehaviourTreeNodeType GetRandomPositionNode, SimpleMoveNode, GetDialogueIndexNode, - SetDialogueIndexNode + SetDialogueIndexNode, + VectorIteratorNode, + ArrayIncrementNode } public static class BehaviourTreeNodeCreator @@ -51,6 +53,10 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new GetDialogueIndexNode(); case BehaviourTreeNodeType.SetDialogueIndexNode: return new SetDialogueIndexNode(); + case BehaviourTreeNodeType.VectorIteratorNode: + return new VectorIteratorNode(); + case BehaviourTreeNodeType.ArrayIncrementNode: + return new ArrayIncrementNode(); default: Debug.LogError($"Unimplemented node type: {type}"); return null; diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs new file mode 100644 index 00000000..2ef06ee8 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + // TODO: split into LoopIncrement and PingPongIncrement nodes? + public class ArrayIncrementNode : IBehaviourTreeNode + { + private const string PROP_INDEX_SRC = "index-source"; + private const string PROP_MAX_INDEX = "max-index"; + + public void Init(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_INDEX_SRC, new VariableProperty(VariableProperty.Type.String)); + behaviour.Properties.Add(PROP_MAX_INDEX, new VariableProperty(VariableProperty.Type.Number)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + // 1. Get the current index from the source + string indexSrc = behaviour.GetProperty(PROP_INDEX_SRC).GetString(); + int index = (int)obj.GetProperty(indexSrc); + + // 2. Increment or loop the index and + int maxIndex = (int)behaviour.GetProperty(PROP_MAX_INDEX).GetNumber(); + index = (index + 1) % maxIndex; + + // 3. Save the new index back to the agent + obj.SetProperty(indexSrc, index); + + return NodeStatus.Success; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs.meta new file mode 100644 index 00000000..942c0346 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c2619e5c26b02334bafa2ed7facfe6d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs new file mode 100644 index 00000000..3ab01128 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + public class VectorIteratorNode : IBehaviourTreeNode + { + private const string PROP_ARRAY = "source-array"; + private const string PROP_INDEX_SRC = "index-source"; + private const string PROP_VECTOR_DEST = "vector-destination"; + + public void Init(Behaviour behaviour) + { + // TODO: have an array property to drive these values + behaviour.Properties.Add(PROP_ARRAY, new VariableProperty(VariableProperty.Type.String)); // todo: change type to array (of vectors) + behaviour.Properties.Add(PROP_INDEX_SRC, new VariableProperty(VariableProperty.Type.String)); + behaviour.Properties.Add(PROP_VECTOR_DEST, new VariableProperty(VariableProperty.Type.String)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + Vector2[] tempArr = { + new Vector2(-3, -3), + new Vector2(-5, -5), + new Vector2(-3, -5) + }; + + // we need to output two things: index, and current vector + // these need to be stored in specific properties (defined in the inspector) + + // 1. read the current index from the agent (or set to zero if not exists) + int index = 0; + string indexSrc = behaviour.GetProperty(PROP_INDEX_SRC).GetString(); + if (obj.HasProperty(indexSrc)) + { + index = (int)obj.GetProperty(indexSrc); + } + + // 2. get the vector at the current index + Vector2 vec = tempArr[index]; + + // 3. store the resulting vector on the agent + obj.SetProperty(PROP_VECTOR_DEST, vec); + + return NodeStatus.Success; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs.meta new file mode 100644 index 00000000..783ee938 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35f1ed8904973ff458ee59420ed87bb4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 4b42d5ee703947f9853c2045e6a4ac16732a26f3 Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Tue, 5 Oct 2021 21:00:45 -0700 Subject: [PATCH 07/41] Format NPC to function with rpg branch Reformatted the old scripts to work with the new node system, created a basic follow player behaviour tree, and created a TestNPC companion in scene --- .../Data/Behaviour Trees/NPC FollowTree.asset | 99 ++++++++++ ...r.asset.meta => NPC FollowTree.asset.meta} | 2 +- .../Data/Behaviour Trees/NPCBehaviour.asset | 44 ----- Assets/Scenes/Main.unity | 177 +++--------------- Assets/Scripts/Game/NPCs/BaseNPC.cs | 20 +- Assets/Scripts/Game/NPCs/NPCMovement.cs | 40 ---- Assets/Scripts/Game/NPCs/NPCMovement.cs.meta | 11 -- Assets/Scripts/Tools/Behaviour Tree/Agent.cs | 11 +- 8 files changed, 151 insertions(+), 253 deletions(-) create mode 100644 Assets/Data/Behaviour Trees/NPC FollowTree.asset rename Assets/Data/Behaviour Trees/{NPCBehaviour.asset.meta => NPC FollowTree.asset.meta} (79%) delete mode 100644 Assets/Data/Behaviour Trees/NPCBehaviour.asset delete mode 100644 Assets/Scripts/Game/NPCs/NPCMovement.cs delete mode 100644 Assets/Scripts/Game/NPCs/NPCMovement.cs.meta diff --git a/Assets/Data/Behaviour Trees/NPC FollowTree.asset b/Assets/Data/Behaviour Trees/NPC FollowTree.asset new file mode 100644 index 00000000..04f7cc63 --- /dev/null +++ b/Assets/Data/Behaviour Trees/NPC FollowTree.asset @@ -0,0 +1,99 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54fb5e73c80040247a00b01917c6e426, type: 3} + m_Name: NPC FollowTree + m_EditorClassIdentifier: + tree: + serializedNodes: + - childCount: 3 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 1 + - childCount: 0 + element: + propertyInfo: + - name: tag-name + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: Player + o: {fileID: 0} + v: {x: 0, y: 0} + - name: actor-destination + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: target-object + o: {fileID: 0} + v: {x: 0, y: 0} + nodeTypeName: BehaviourTree.FindActorByTagNode + firstChildIndex: 2 + - childCount: 0 + element: + propertyInfo: + - name: actor-source + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: target-object + o: {fileID: 0} + v: {x: 0, y: 0} + - name: position-destination + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: target-destination + o: {fileID: 0} + v: {x: 0, y: 0} + nodeTypeName: BehaviourTree.GetActorPositionNode + firstChildIndex: 3 + - childCount: 0 + element: + propertyInfo: + - name: position-source + property: + propertyType: 2 + value: + b: 0 + n: 0 + s: target-destination + o: {fileID: 0} + v: {x: 0, y: 0} + - name: min-distance + property: + propertyType: 1 + value: + b: 0 + n: 2 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + - name: move-speed + property: + propertyType: 1 + value: + b: 0 + n: 10 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + nodeTypeName: BehaviourTree.SimpleMoveNode + firstChildIndex: 4 diff --git a/Assets/Data/Behaviour Trees/NPCBehaviour.asset.meta b/Assets/Data/Behaviour Trees/NPC FollowTree.asset.meta similarity index 79% rename from Assets/Data/Behaviour Trees/NPCBehaviour.asset.meta rename to Assets/Data/Behaviour Trees/NPC FollowTree.asset.meta index 325f178e..c65dfd7e 100644 --- a/Assets/Data/Behaviour Trees/NPCBehaviour.asset.meta +++ b/Assets/Data/Behaviour Trees/NPC FollowTree.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c6852fa420194194f839740aae243d5c +guid: 5022140c4fe67e1489a5b6e3f5ff71f2 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Data/Behaviour Trees/NPCBehaviour.asset b/Assets/Data/Behaviour Trees/NPCBehaviour.asset deleted file mode 100644 index 8838bc01..00000000 --- a/Assets/Data/Behaviour Trees/NPCBehaviour.asset +++ /dev/null @@ -1,44 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 54fb5e73c80040247a00b01917c6e426, type: 3} - m_Name: NPCBehaviour - m_EditorClassIdentifier: - tree: - serializedNodes: - - childCount: 1 - element: - propertyInfo: [] - nodeTypeName: BehaviourTree.SequenceNode - firstChildIndex: 1 - - childCount: 0 - element: - propertyInfo: - - name: move-range - property: - propertyType: 1 - value: - b: 0 - n: 4 - s: - o: {fileID: 0} - v: {x: 0, y: 0} - - name: move-speed - property: - propertyType: 1 - value: - b: 0 - n: 4 - s: - o: {fileID: 0} - v: {x: 0, y: 0} - nodeTypeName: BehaviourTree.MoveNode - firstChildIndex: 2 diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 33870adc..c23468ea 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -1017,154 +1017,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 14 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &462458363 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 462458369} - - component: {fileID: 462458368} - - component: {fileID: 462458367} - - component: {fileID: 462458366} - - component: {fileID: 462458365} - - component: {fileID: 462458364} - m_Layer: 8 - m_Name: TestJimmy - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &462458364 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 462458363} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} - m_Name: - m_EditorClassIdentifier: - behaviourTree: {fileID: 11400000, guid: c6852fa420194194f839740aae243d5c, type: 2} ---- !u!114 &462458365 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 462458363} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c5dd1dec152424544a6fcae9ff825aa6, type: 3} - m_Name: - m_EditorClassIdentifier: - initialMaxHealth: 0 - dialogue: {fileID: 0} - interactionDistance: 2 ---- !u!114 &462458366 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 462458363} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} - m_Name: - m_EditorClassIdentifier: - tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, - type: 3} - interactHint: Talk - name: Sneeko - portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} - dialogue: {fileID: 11400000, guid: 8c096da2b4b78d14492866a0ace564a7, type: 2} ---- !u!58 &462458367 -CircleCollider2D: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 462458363} - m_Enabled: 1 - m_Density: 1 - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_UsedByEffector: 0 - m_UsedByComposite: 0 - m_Offset: {x: 0, y: 0} - serializedVersion: 2 - m_Radius: 0.5 ---- !u!212 &462458368 -SpriteRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 462458363} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 0 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_Sprite: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} - m_Color: {r: 0.547801, g: 0.25, b: 1, a: 1} - m_FlipX: 0 - m_FlipY: 0 - m_DrawMode: 0 - m_Size: {x: 0.5859375, y: 0.64377683} - m_AdaptiveModeThreshold: 0.5 - m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 - m_MaskInteraction: 0 - m_SpriteSortPoint: 0 ---- !u!4 &462458369 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 462458363} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.35, y: -4.64, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 15 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &468670149 GameObject: m_ObjectHideFlags: 0 @@ -1529,6 +1381,8 @@ GameObject: - component: {fileID: 539150547} - component: {fileID: 539150546} - component: {fileID: 539150550} + - component: {fileID: 539150552} + - component: {fileID: 539150551} m_Layer: 8 m_Name: TestNPC2 m_TagString: Untagged @@ -1651,6 +1505,33 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: uniqueID: Sneeko +--- !u!114 &539150551 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 539150545} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} + m_Name: + m_EditorClassIdentifier: + behaviourTree: {fileID: 11400000, guid: 5022140c4fe67e1489a5b6e3f5ff71f2, type: 2} +--- !u!114 &539150552 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 539150545} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c5dd1dec152424544a6fcae9ff825aa6, type: 3} + m_Name: + m_EditorClassIdentifier: + initialMaxHealth: 0 + interactionDistance: 5 --- !u!1 &604390397 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Game/NPCs/BaseNPC.cs b/Assets/Scripts/Game/NPCs/BaseNPC.cs index 65e94fcf..79edcc81 100644 --- a/Assets/Scripts/Game/NPCs/BaseNPC.cs +++ b/Assets/Scripts/Game/NPCs/BaseNPC.cs @@ -6,24 +6,23 @@ namespace RPG{ public class BaseNPC: Actor { - public QuestGiver dialogue; + private QuestGiver dialogue; + private CircleCollider2D npcCollider; private Agent agent; + private bool isNPCFollower; + [SerializeField]private float interactionDistance=5.0f; private bool dialogueInitiated=false;//Delete this when we have a means of catching when dialogue is done - - private NPCMovement movement; - List testNodes=new List(); - private SpriteRenderer spriteRenderer; // Start is called before the first frame update - private void Awake() { + protected override void Awake() { base.Awake(); dialogue=GetComponent(); agent=GetComponent(); - spriteRenderer=GetComponent(); - movement=new NPCMovement(2.0f); + npcCollider=GetComponent(); + } // Update is called once per frame @@ -60,5 +59,10 @@ public void TurnIntoEnemy(){ } //TODO add AttackBehaviour in BehaviourTree } + + public void TurnIntoCompanion(){ + //TODO Make Follower movement, interactable + npcCollider.enabled=false; + } } } diff --git a/Assets/Scripts/Game/NPCs/NPCMovement.cs b/Assets/Scripts/Game/NPCs/NPCMovement.cs deleted file mode 100644 index 1cc3a45f..00000000 --- a/Assets/Scripts/Game/NPCs/NPCMovement.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using BehaviourTree; -namespace RPG{ - /* - This Class is purely meant to manage until I migrate all of these into separate BehaviourNodes. - I apologize :'( I just didn't have time to tamper with all of the engine yet to implement further changes. - */ - public class NPCMovement - { - private float followDistance; - private bool isRunning; - public NPCMovement(float f=1f){ - followDistance=f; - isRunning=false; - } - - //Follow a player at a distance - public void FollowPlayer(Vector2 position, Agent agent){ - Vector2 playerPos=(Vector2)GameObject.FindGameObjectWithTag("Player").transform.position; - if(playerPos!=null){ - //Get the distance between two vectors - float distance=Vector2.Distance(playerPos,position); - if(distance>=followDistance){ - //Set destination to where followDistance is on the line between the two. - float ratio=followDistance/distance; - agent.SetProperty("destination",Vector2.Lerp(playerPos,position,ratio)); - } - - } - - } - - public void FollowPath(Vector2 position, Agent agent){ - //TODO Follow a path via a list of Vector2s - } - } -} - diff --git a/Assets/Scripts/Game/NPCs/NPCMovement.cs.meta b/Assets/Scripts/Game/NPCs/NPCMovement.cs.meta deleted file mode 100644 index d6499445..00000000 --- a/Assets/Scripts/Game/NPCs/NPCMovement.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 90f8475ce6de91742904261ce39b646a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs index 2e6a0038..3ba9adf1 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs @@ -8,13 +8,14 @@ namespace BehaviourTree public class Agent : BehaviourObject { [SerializeField] private BehaviourTree behaviourTree; - + private bool isEnabled; private Tree.Node root; protected override void Awake() { base.Awake(); root = behaviourTree.Root; + isEnabled=true; } protected void Update() @@ -24,5 +25,13 @@ protected void Update() } } + + public void DisableBehaviours(){ + isEnabled=false; + } + + public void EnableBehaviours(){ + isEnabled=true; + } } } From 420fe41b2ca13404975c399db35a085201975730 Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Tue, 5 Oct 2021 21:11:48 -0700 Subject: [PATCH 08/41] Update missed Scene Save This is the scene with the added testNPC --- Assets/Scenes/Main.unity | 193 +++++++++++++++++++++++++++++++++------ 1 file changed, 164 insertions(+), 29 deletions(-) diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index c23468ea..29863a45 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -1381,8 +1381,6 @@ GameObject: - component: {fileID: 539150547} - component: {fileID: 539150546} - component: {fileID: 539150550} - - component: {fileID: 539150552} - - component: {fileID: 539150551} m_Layer: 8 m_Name: TestNPC2 m_TagString: Untagged @@ -1505,33 +1503,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: uniqueID: Sneeko ---- !u!114 &539150551 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 539150545} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} - m_Name: - m_EditorClassIdentifier: - behaviourTree: {fileID: 11400000, guid: 5022140c4fe67e1489a5b6e3f5ff71f2, type: 2} ---- !u!114 &539150552 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 539150545} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c5dd1dec152424544a6fcae9ff825aa6, type: 3} - m_Name: - m_EditorClassIdentifier: - initialMaxHealth: 0 - interactionDistance: 5 --- !u!1 &604390397 GameObject: m_ObjectHideFlags: 0 @@ -3131,6 +3102,170 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1134476113 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1134476120} + - component: {fileID: 1134476119} + - component: {fileID: 1134476118} + - component: {fileID: 1134476117} + - component: {fileID: 1134476116} + - component: {fileID: 1134476115} + - component: {fileID: 1134476114} + m_Layer: 8 + m_Name: TestCompanion + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1134476114 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} + m_Name: + m_EditorClassIdentifier: + behaviourTree: {fileID: 11400000, guid: 5022140c4fe67e1489a5b6e3f5ff71f2, type: 2} +--- !u!114 &1134476115 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c5dd1dec152424544a6fcae9ff825aa6, type: 3} + m_Name: + m_EditorClassIdentifier: + initialMaxHealth: 0 + interactionDistance: 5 +--- !u!114 &1134476116 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ebc071df6b26c2c4682605f65e5c191c, type: 3} + m_Name: + m_EditorClassIdentifier: + uniqueID: Jimmy +--- !u!114 &1134476117 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Name: + m_EditorClassIdentifier: + tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, + type: 3} + interactHint: Talk + characterName: Jimmy + portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} + dialogueGraphs: + - {fileID: 11400000, guid: 8c096da2b4b78d14492866a0ace564a7, type: 2} + - {fileID: 11400000, guid: 7852df3d4fd29ae498cfed742fd1b8f7, type: 2} + - {fileID: 11400000, guid: 2e067e40d2dbdc8499f8b6226f5fccf1, type: 2} +--- !u!58 &1134476118 +CircleCollider2D: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_Enabled: 1 + m_Density: 1 + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_UsedByEffector: 0 + m_UsedByComposite: 0 + m_Offset: {x: 0, y: 0} + serializedVersion: 2 + m_Radius: 0.5 +--- !u!212 &1134476119 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_Sprite: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} + m_Color: {r: 1, g: 0.33490568, b: 0.9581065, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 0 + m_Size: {x: 0.5859375, y: 0.64377683} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &1134476120 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -1.83, y: -4.31, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 15 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1157983262 GameObject: m_ObjectHideFlags: 0 From d9c030db59e250808bd68dda531cc97179c90d1a Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Thu, 7 Oct 2021 21:06:12 -0700 Subject: [PATCH 09/41] Add ForceDialogueNode Adds a node that forces the dialogue with the player instead of having that in the NPC behaviour script --- Assets/Scripts/Game/NPCs/BaseNPC.cs | 16 -------- .../BehaviourTreeNodeCreator.cs | 5 ++- .../Behaviour Tree/Nodes/ForceDialogueNode.cs | 40 +++++++++++++++++++ .../Nodes/ForceDialogueNode.cs.meta | 11 +++++ 4 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs.meta diff --git a/Assets/Scripts/Game/NPCs/BaseNPC.cs b/Assets/Scripts/Game/NPCs/BaseNPC.cs index 79edcc81..08474328 100644 --- a/Assets/Scripts/Game/NPCs/BaseNPC.cs +++ b/Assets/Scripts/Game/NPCs/BaseNPC.cs @@ -30,22 +30,6 @@ void Update() { } - //Force Dialogue with player; - public void InitiateDialogue(){ - GameObject player=GameObject.FindGameObjectWithTag("Player"); - //Detect if player is within range of the player - if(!dialogueInitiated && player!=null && Vector2.Distance(transform.position, player.transform.position)<=interactionDistance){ - Debug.Log("Dialogue initiated"); - dialogue.Interact(player.GetComponent()); - dialogueInitiated=true; - //disable the behaviour script in the meantime - agent.DisableBehaviours(); - - //TODO Detect when dialogue box is closed then switch to regular behaviours - agent.EnableBehaviours(); - } - } - public void TurnIntoEnemy(){ //Change to enemy Layer; gameObject.layer=LayerMask.NameToLayer("Enemy"); diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index 11f11a41..d12d6417 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -16,7 +16,8 @@ public enum BehaviourTreeNodeType GetRandomPositionNode, SimpleMoveNode, GetDialogueIndexNode, - SetDialogueIndexNode + SetDialogueIndexNode, + ForceDialogueNode } public static class BehaviourTreeNodeCreator @@ -51,6 +52,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new GetDialogueIndexNode(); case BehaviourTreeNodeType.SetDialogueIndexNode: return new SetDialogueIndexNode(); + case BehaviourTreeNodeType.ForceDialogueNode: + return new ForceDialogueNode(); default: Debug.LogError($"Unimplemented node type: {type}"); return null; diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs new file mode 100644 index 00000000..9e78b89c --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using RPG; + +namespace BehaviourTree{ + public class ForceDialogueNode : IBehaviourTreeNode + { + private const string MAX_INTERACT_DISTANCE="max-interact"; + private const string MIN_INTERACT_DISTANCE="min-interact"; + + public void Serialize(Behaviour behaviour){ + behaviour.Properties.Add(MAX_INTERACT_DISTANCE,new VariableProperty(VariableProperty.Type.Number)); + behaviour.Properties.Add(MIN_INTERACT_DISTANCE,new VariableProperty(VariableProperty.Type.Number)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour=self.Element; + QuestGiver dialogue=obj.GetComponent(); + Player p=GameObject.FindGameObjectWithTag("Player").GetComponent(); + //Checks if the player or the QuestGiver(DialogueScript later) is null + if(dialogue!=null && p!=null){ + Vector2 currentPosition=obj.transform.position, targetPosition=p.transform.position; + float distance=Vector2.Distance(currentPosition,targetPosition); + float minDist=(float)behaviour.Properties[MIN_INTERACT_DISTANCE].GetNumber(); + float maxDist=(float)behaviour.Properties[MAX_INTERACT_DISTANCE].GetNumber(); + //Checks if the distance between the player and the Initiator fit within the min and max parameters + if(distance>=minDist && distance<=maxDist){ + dialogue.Interact(p); + return NodeStatus.Success; + } + + } + return NodeStatus.Failure; + } + + } + +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs.meta new file mode 100644 index 00000000..13092c68 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7fded0b12a0f9ac4a99672c36a0813d0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 6db8bf8960798a0c291bb52681b055468239eb62 Mon Sep 17 00:00:00 2001 From: TheUQGuy <90714695+TheUQGuy@users.noreply.github.com> Date: Thu, 7 Oct 2021 22:01:42 -0700 Subject: [PATCH 10/41] Remove redundant code for ForceDialogue Noticed that checkRangeNode implemented what I wanted already (may need to add both min and max values to checkRange later) but it accomplished what I want for now. --- .../Behaviour Tree/Nodes/ForceDialogueNode.cs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs index 9e78b89c..87e765be 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs @@ -6,13 +6,8 @@ namespace BehaviourTree{ public class ForceDialogueNode : IBehaviourTreeNode { - private const string MAX_INTERACT_DISTANCE="max-interact"; - private const string MIN_INTERACT_DISTANCE="min-interact"; - public void Serialize(Behaviour behaviour){ - behaviour.Properties.Add(MAX_INTERACT_DISTANCE,new VariableProperty(VariableProperty.Type.Number)); - behaviour.Properties.Add(MIN_INTERACT_DISTANCE,new VariableProperty(VariableProperty.Type.Number)); - } + public void Serialize(Behaviour behaviour){} public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { @@ -21,15 +16,8 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) Player p=GameObject.FindGameObjectWithTag("Player").GetComponent(); //Checks if the player or the QuestGiver(DialogueScript later) is null if(dialogue!=null && p!=null){ - Vector2 currentPosition=obj.transform.position, targetPosition=p.transform.position; - float distance=Vector2.Distance(currentPosition,targetPosition); - float minDist=(float)behaviour.Properties[MIN_INTERACT_DISTANCE].GetNumber(); - float maxDist=(float)behaviour.Properties[MAX_INTERACT_DISTANCE].GetNumber(); - //Checks if the distance between the player and the Initiator fit within the min and max parameters - if(distance>=minDist && distance<=maxDist){ - dialogue.Interact(p); - return NodeStatus.Success; - } + dialogue.Interact(p); + return NodeStatus.Success; } return NodeStatus.Failure; From a6566b2906e00767d4409d124f331ce42855a405 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 9 Nov 2021 18:29:24 -0800 Subject: [PATCH 11/41] Fix merge conflicts --- Assets/Scripts/Tools/Behaviour Tree/Agent.cs | 16 +++++++++------- .../Behaviour Tree/Nodes/ArrayIncrementNode.cs | 2 +- .../Behaviour Tree/Nodes/VectorIteratorNode.cs | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs index d774998e..49565e70 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs @@ -24,23 +24,25 @@ protected override void Awake() Animator = GetComponent(); root = behaviourTree.Root; - isEnabled=true; + isEnabled = true; } protected void Update() { - if(isEnabled){ + if (isEnabled) + { root.Element.Tick(root, this); } - } - public void DisableBehaviours(){ - isEnabled=false; + public void DisableBehaviours() + { + isEnabled = false; } - public void EnableBehaviours(){ - isEnabled=true; + public void EnableBehaviours() + { + isEnabled = true; } } } diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs index 2ef06ee8..a656e8a6 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs @@ -10,7 +10,7 @@ public class ArrayIncrementNode : IBehaviourTreeNode private const string PROP_INDEX_SRC = "index-source"; private const string PROP_MAX_INDEX = "max-index"; - public void Init(Behaviour behaviour) + public void Serialize(Behaviour behaviour) { behaviour.Properties.Add(PROP_INDEX_SRC, new VariableProperty(VariableProperty.Type.String)); behaviour.Properties.Add(PROP_MAX_INDEX, new VariableProperty(VariableProperty.Type.Number)); diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs index 3ab01128..fd7afc72 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs @@ -10,7 +10,7 @@ public class VectorIteratorNode : IBehaviourTreeNode private const string PROP_INDEX_SRC = "index-source"; private const string PROP_VECTOR_DEST = "vector-destination"; - public void Init(Behaviour behaviour) + public void Serialize(Behaviour behaviour) { // TODO: have an array property to drive these values behaviour.Properties.Add(PROP_ARRAY, new VariableProperty(VariableProperty.Type.String)); // todo: change type to array (of vectors) From 61c37f55814b756e3cf86126fd790f7ad3d53c2d Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 9 Nov 2021 18:33:46 -0800 Subject: [PATCH 12/41] Update test actors --- Assets/Scenes/Main.unity | 313 ++++++++++++++++++++++++++------------- 1 file changed, 207 insertions(+), 106 deletions(-) diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 98630e5d..a0ca8753 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -487,9 +487,9 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 21 + m_RootOrder: 23 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &141597915 +--- !u!1 &113309044 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -497,52 +497,66 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 141597919} - - component: {fileID: 141597918} - - component: {fileID: 141597917} - - component: {fileID: 141597922} - - component: {fileID: 141597921} - - component: {fileID: 141597920} - - component: {fileID: 141597916} + - component: {fileID: 113309049} + - component: {fileID: 113309048} + - component: {fileID: 113309047} + - component: {fileID: 113309050} + - component: {fileID: 113309046} + - component: {fileID: 113309045} m_Layer: 8 - m_Name: Mum NPC + m_Name: TestNPCMover m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!114 &141597916 -MonoBehaviour: +--- !u!95 &113309045 +Animator: + serializedVersion: 3 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 141597915} + m_GameObject: {fileID: 113309044} m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} - m_Name: - m_EditorClassIdentifier: - tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, - type: 3} - interactHint: Talk - characterName: Mum - portrait: {fileID: 8835284309397123848, guid: 568b897490088f8439d263b261216ec0, - type: 3} - dialogueGraphs: - - {fileID: 11400000, guid: 36bc0c21d35b53f4fa3de317361e9a85, type: 2} - - {fileID: 11400000, guid: 3683391ddc8ff1141a5488ab59cf1199, type: 2} - - {fileID: 11400000, guid: 2589d4ccbf3818b4b998067943801b4d, type: 2} - - {fileID: 11400000, guid: 9c5ab4e0982fac54ab0e05d0dca4093e, type: 2} - - {fileID: 11400000, guid: 2133e95db09dbf34fbd7a3a458719899, type: 2} - - {fileID: 11400000, guid: 12bee71ec794d8b4598dce7ff9fa751f, type: 2} ---- !u!58 &141597917 + m_Avatar: {fileID: 0} + m_Controller: {fileID: 0} + m_CullingMode: 0 + m_UpdateMode: 0 + m_ApplyRootMotion: 0 + m_LinearVelocityBlending: 0 + m_WarningMessage: + m_HasTransformHierarchy: 1 + m_AllowConstantClipSamplingOptimization: 1 + m_KeepAnimatorControllerStateOnDisable: 0 +--- !u!50 &113309046 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 113309044} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 1 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 0 +--- !u!58 &113309047 CircleCollider2D: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 141597915} + m_GameObject: {fileID: 113309044} m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} @@ -551,14 +565,14 @@ CircleCollider2D: m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} serializedVersion: 2 - m_Radius: 0.32188842 ---- !u!212 &141597918 + m_Radius: 0.5 +--- !u!212 &113309048 SpriteRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 141597915} + m_GameObject: {fileID: 113309044} m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 @@ -592,8 +606,7 @@ SpriteRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 - m_Sprite: {fileID: 8835284309397123848, guid: 568b897490088f8439d263b261216ec0, - type: 3} + m_Sprite: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 m_FlipY: 0 @@ -604,66 +617,34 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!4 &141597919 +--- !u!4 &113309049 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 141597915} + m_GameObject: {fileID: 113309044} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -4.97, y: 4.16, z: 0} + m_LocalPosition: {x: 7, y: -1.44, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} m_RootOrder: 15 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &141597920 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 141597915} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ebc071df6b26c2c4682605f65e5c191c, type: 3} - m_Name: - m_EditorClassIdentifier: - uniqueID: Mum ---- !u!114 &141597921 +--- !u!114 &113309050 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 141597915} + m_GameObject: {fileID: 113309044} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3841cfd75fe64b8498769758ea31c7be, type: 3} + m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} m_Name: m_EditorClassIdentifier: - defaultAnimation: {fileID: 7400000, guid: 2dfd4942e6e789b45922a7d97aeec914, type: 2} ---- !u!95 &141597922 -Animator: - serializedVersion: 3 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 141597915} - m_Enabled: 1 - m_Avatar: {fileID: 0} - m_Controller: {fileID: 9100000, guid: d3af1bb34e9ffb044886be104dc98f2f, type: 2} - m_CullingMode: 0 - m_UpdateMode: 0 - m_ApplyRootMotion: 0 - m_LinearVelocityBlending: 0 - m_WarningMessage: - m_HasTransformHierarchy: 1 - m_AllowConstantClipSamplingOptimization: 1 - m_KeepAnimatorControllerStateOnDisable: 0 ---- !u!1 &113309044 + behaviourTree: {fileID: 11400000, guid: de69ac2176667774d94e83467a58ecce, type: 2} +--- !u!1 &141597915 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -671,24 +652,52 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 113309049} - - component: {fileID: 113309048} - - component: {fileID: 113309047} - - component: {fileID: 113309050} + - component: {fileID: 141597919} + - component: {fileID: 141597918} + - component: {fileID: 141597917} + - component: {fileID: 141597922} + - component: {fileID: 141597921} + - component: {fileID: 141597920} + - component: {fileID: 141597916} m_Layer: 8 - m_Name: TestNPCMover + m_Name: Mum NPC m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!58 &113309047 +--- !u!114 &141597916 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 141597915} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Name: + m_EditorClassIdentifier: + tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, + type: 3} + interactHint: Talk + characterName: Mum + portrait: {fileID: 8835284309397123848, guid: 568b897490088f8439d263b261216ec0, + type: 3} + dialogueGraphs: + - {fileID: 11400000, guid: 36bc0c21d35b53f4fa3de317361e9a85, type: 2} + - {fileID: 11400000, guid: 3683391ddc8ff1141a5488ab59cf1199, type: 2} + - {fileID: 11400000, guid: 2589d4ccbf3818b4b998067943801b4d, type: 2} + - {fileID: 11400000, guid: 9c5ab4e0982fac54ab0e05d0dca4093e, type: 2} + - {fileID: 11400000, guid: 2133e95db09dbf34fbd7a3a458719899, type: 2} + - {fileID: 11400000, guid: 12bee71ec794d8b4598dce7ff9fa751f, type: 2} +--- !u!58 &141597917 CircleCollider2D: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 113309044} + m_GameObject: {fileID: 141597915} m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} @@ -697,14 +706,14 @@ CircleCollider2D: m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} serializedVersion: 2 - m_Radius: 0.5 ---- !u!212 &113309048 + m_Radius: 0.32188842 +--- !u!212 &141597918 SpriteRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 113309044} + m_GameObject: {fileID: 141597915} m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 @@ -738,7 +747,8 @@ SpriteRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 - m_Sprite: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} + m_Sprite: {fileID: 8835284309397123848, guid: 568b897490088f8439d263b261216ec0, + type: 3} m_Color: {r: 1, g: 1, b: 1, a: 1} m_FlipX: 0 m_FlipY: 0 @@ -749,33 +759,65 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 ---- !u!4 &113309049 +--- !u!4 &141597919 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 113309044} + m_GameObject: {fileID: 141597915} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -3, y: -3, z: 0} + m_LocalPosition: {x: -4.97, y: 4.16, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 15 + m_RootOrder: 16 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &113309050 +--- !u!114 &141597920 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 113309044} + m_GameObject: {fileID: 141597915} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} + m_Script: {fileID: 11500000, guid: ebc071df6b26c2c4682605f65e5c191c, type: 3} m_Name: m_EditorClassIdentifier: - behaviourTree: {fileID: 11400000, guid: de69ac2176667774d94e83467a58ecce, type: 2} + uniqueID: Mum +--- !u!114 &141597921 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 141597915} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3841cfd75fe64b8498769758ea31c7be, type: 3} + m_Name: + m_EditorClassIdentifier: + defaultAnimation: {fileID: 7400000, guid: 2dfd4942e6e789b45922a7d97aeec914, type: 2} +--- !u!95 &141597922 +Animator: + serializedVersion: 3 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 141597915} + m_Enabled: 1 + m_Avatar: {fileID: 0} + m_Controller: {fileID: 9100000, guid: d3af1bb34e9ffb044886be104dc98f2f, type: 2} + m_CullingMode: 0 + m_UpdateMode: 0 + m_ApplyRootMotion: 0 + m_LinearVelocityBlending: 0 + m_WarningMessage: + m_HasTransformHierarchy: 1 + m_AllowConstantClipSamplingOptimization: 1 + m_KeepAnimatorControllerStateOnDisable: 0 --- !u!1 &174102886 GameObject: m_ObjectHideFlags: 0 @@ -1974,7 +2016,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 19 + m_RootOrder: 21 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &604390397 GameObject: @@ -2135,7 +2177,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 23 + m_RootOrder: 25 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &624982963 GameObject: @@ -3240,7 +3282,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 22 + m_RootOrder: 24 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &940472402 MonoBehaviour: @@ -3730,7 +3772,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 20 + m_RootOrder: 22 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1056019370 GameObject: @@ -3984,7 +4026,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 24 + m_RootOrder: 26 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1085417767 GameObject: @@ -4179,6 +4221,9 @@ GameObject: - component: {fileID: 1134476116} - component: {fileID: 1134476115} - component: {fileID: 1134476114} + - component: {fileID: 1134476123} + - component: {fileID: 1134476122} + - component: {fileID: 1134476121} m_Layer: 8 m_Name: TestCompanion m_TagString: Untagged @@ -4212,6 +4257,9 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: initialMaxHealth: 0 + idleAnimations: {fileID: 11400000, guid: fb206d7e94c25e94b899ed54a07145c6, type: 2} + moveAnimations: {fileID: 11400000, guid: e22d4c8424148f645ae60e803585d737, type: 2} + hurtAnimations: {fileID: 11400000, guid: 1fce7b2292cd9e545984412811fa1820, type: 2} interactionDistance: 5 --- !u!114 &1134476116 MonoBehaviour: @@ -4322,12 +4370,65 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1134476113} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -1.83, y: -4.31, z: 0} + m_LocalPosition: {x: 4.54, y: -0.63, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 15 + m_RootOrder: 17 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1134476121 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3841cfd75fe64b8498769758ea31c7be, type: 3} + m_Name: + m_EditorClassIdentifier: + defaultAnimation: {fileID: 7400000, guid: 511c335ee19612a4e8474882b1c5b7b7, type: 2} +--- !u!95 &1134476122 +Animator: + serializedVersion: 3 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_Enabled: 1 + m_Avatar: {fileID: 0} + m_Controller: {fileID: 9100000, guid: d3af1bb34e9ffb044886be104dc98f2f, type: 2} + m_CullingMode: 0 + m_UpdateMode: 0 + m_ApplyRootMotion: 0 + m_LinearVelocityBlending: 0 + m_WarningMessage: + m_HasTransformHierarchy: 1 + m_AllowConstantClipSamplingOptimization: 1 + m_KeepAnimatorControllerStateOnDisable: 0 +--- !u!50 &1134476123 +Rigidbody2D: + serializedVersion: 4 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1134476113} + m_BodyType: 0 + m_Simulated: 1 + m_UseFullKinematicContacts: 0 + m_UseAutoMass: 0 + m_Mass: 1 + m_LinearDrag: 0 + m_AngularDrag: 0.05 + m_GravityScale: 1 + m_Material: {fileID: 0} + m_Interpolate: 0 + m_SleepingMode: 1 + m_CollisionDetection: 0 + m_Constraints: 4 --- !u!1 &1157983262 GameObject: m_ObjectHideFlags: 0 @@ -5439,7 +5540,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 17 + m_RootOrder: 19 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1410119778 GameObject: @@ -5692,7 +5793,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 18 + m_RootOrder: 20 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1449023113 GameObject: @@ -6466,7 +6567,7 @@ Transform: m_Children: - {fileID: 1368910123} m_Father: {fileID: 0} - m_RootOrder: 16 + m_RootOrder: 18 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!95 &1817463533 Animator: From 78525678b808609f755b0c49f6b6fa4320879e46 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Wed, 10 Nov 2021 16:58:55 -0800 Subject: [PATCH 13/41] Implement patrol behaviour --- Assets/Data/Behaviour Trees/ExampleNPC.asset | 76 +++++++++++++++++-- .../Data/Behaviour Trees/NPC FollowTree.asset | 30 +++++++- Assets/Scenes/Main.unity | 12 +-- .../Nodes/ArrayIncrementNode.cs | 14 ++-- .../Nodes/VectorIteratorNode.cs | 20 ++--- Assets/Scripts/Utils/VariableProperty.cs | 2 +- 6 files changed, 119 insertions(+), 35 deletions(-) diff --git a/Assets/Data/Behaviour Trees/ExampleNPC.asset b/Assets/Data/Behaviour Trees/ExampleNPC.asset index 57dc89e9..dc87de12 100644 --- a/Assets/Data/Behaviour Trees/ExampleNPC.asset +++ b/Assets/Data/Behaviour Trees/ExampleNPC.asset @@ -22,33 +22,73 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: - - name: source-array + - name: vector-array property: - propertyType: 2 + propertyType: 5 + objectType: value: b: 0 n: 0 - s: TODO + s: o: {fileID: 0} v: {x: 0, y: 0} + a: + - propertyType: 4 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: -3, y: -3} + - propertyType: 4 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: -5, y: -5} + - propertyType: 4 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: -3, y: -7} + - propertyType: 4 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: -1, y: -5} + e: 0 + aType: 4 - name: index-source property: propertyType: 2 + objectType: value: b: 0 n: 0 s: patrol-index o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 - name: vector-destination property: propertyType: 2 + objectType: value: b: 0 n: 0 s: patrol-vector o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 nodeTypeName: BehaviourTree.VectorIteratorNode firstChildIndex: 2 - childCount: 0 @@ -57,30 +97,42 @@ MonoBehaviour: - name: position-source property: propertyType: 2 + objectType: value: b: 0 n: 0 s: patrol-vector o: {fileID: 0} v: {x: 0, y: 0} - - name: min-distance + a: [] + e: 0 + aType: 0 + - name: stop-distance property: propertyType: 1 + objectType: value: b: 0 - n: 0.1 + n: 0.2 s: o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 - name: move-speed property: propertyType: 1 + objectType: value: b: 0 - n: 2 + n: 1.5 s: o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 nodeTypeName: BehaviourTree.SimpleMoveNode firstChildIndex: 3 - childCount: 0 @@ -89,20 +141,28 @@ MonoBehaviour: - name: index-source property: propertyType: 2 + objectType: value: b: 0 n: 0 s: patrol-index o: {fileID: 0} v: {x: 0, y: 0} - - name: max-index + a: [] + e: 0 + aType: 0 + - name: array-length property: propertyType: 1 + objectType: value: b: 0 - n: 3 + n: 4 s: o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 nodeTypeName: BehaviourTree.ArrayIncrementNode firstChildIndex: 4 diff --git a/Assets/Data/Behaviour Trees/NPC FollowTree.asset b/Assets/Data/Behaviour Trees/NPC FollowTree.asset index 04f7cc63..f3c9cccc 100644 --- a/Assets/Data/Behaviour Trees/NPC FollowTree.asset +++ b/Assets/Data/Behaviour Trees/NPC FollowTree.asset @@ -25,21 +25,29 @@ MonoBehaviour: - name: tag-name property: propertyType: 2 + objectType: value: b: 0 n: 0 s: Player o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 - name: actor-destination property: propertyType: 2 + objectType: value: b: 0 n: 0 s: target-object o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 nodeTypeName: BehaviourTree.FindActorByTagNode firstChildIndex: 2 - childCount: 0 @@ -48,21 +56,29 @@ MonoBehaviour: - name: actor-source property: propertyType: 2 + objectType: value: b: 0 n: 0 s: target-object o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 - name: position-destination property: propertyType: 2 + objectType: value: b: 0 n: 0 s: target-destination o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 nodeTypeName: BehaviourTree.GetActorPositionNode firstChildIndex: 3 - childCount: 0 @@ -71,29 +87,41 @@ MonoBehaviour: - name: position-source property: propertyType: 2 + objectType: value: b: 0 n: 0 s: target-destination o: {fileID: 0} v: {x: 0, y: 0} - - name: min-distance + a: [] + e: 0 + aType: 0 + - name: stop-distance property: propertyType: 1 + objectType: value: b: 0 n: 2 s: o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 - name: move-speed property: propertyType: 1 + objectType: value: b: 0 n: 10 s: o: {fileID: 0} v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 nodeTypeName: BehaviourTree.SimpleMoveNode firstChildIndex: 4 diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index fb719929..de8dcedb 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -500,9 +500,9 @@ GameObject: - component: {fileID: 113309049} - component: {fileID: 113309048} - component: {fileID: 113309047} - - component: {fileID: 113309050} - component: {fileID: 113309046} - component: {fileID: 113309045} + - component: {fileID: 113309050} m_Layer: 8 m_Name: TestNPCMover m_TagString: Untagged @@ -549,7 +549,7 @@ Rigidbody2D: m_Interpolate: 0 m_SleepingMode: 1 m_CollisionDetection: 0 - m_Constraints: 0 + m_Constraints: 4 --- !u!58 &113309047 CircleCollider2D: m_ObjectHideFlags: 0 @@ -625,7 +625,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 113309044} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 7, y: -1.44, z: 0} + m_LocalPosition: {x: -5.66, y: -1.92, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -1923,7 +1923,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 608919353} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -2.89, y: -4.2, z: 0} + m_LocalPosition: {x: -5.41, y: -0.13, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -2863,7 +2863,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 940472397} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -4.93, y: -4.22, z: 0} + m_LocalPosition: {x: -5.65, y: -3.8, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -3385,7 +3385,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1134476114 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs index a656e8a6..8cef9b4d 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs @@ -8,12 +8,12 @@ namespace BehaviourTree public class ArrayIncrementNode : IBehaviourTreeNode { private const string PROP_INDEX_SRC = "index-source"; - private const string PROP_MAX_INDEX = "max-index"; + private const string PROP_ARR_LEN = "array-length"; public void Serialize(Behaviour behaviour) { behaviour.Properties.Add(PROP_INDEX_SRC, new VariableProperty(VariableProperty.Type.String)); - behaviour.Properties.Add(PROP_MAX_INDEX, new VariableProperty(VariableProperty.Type.Number)); + behaviour.Properties.Add(PROP_ARR_LEN, new VariableProperty(VariableProperty.Type.Number)); } public NodeStatus Tick(Tree.Node self, BehaviourObject obj) @@ -21,12 +21,16 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) Behaviour behaviour = self.Element; // 1. Get the current index from the source + int index = 0; string indexSrc = behaviour.GetProperty(PROP_INDEX_SRC).GetString(); - int index = (int)obj.GetProperty(indexSrc); + if (obj.HasProperty(indexSrc)) + { + index = (int)obj.GetProperty(indexSrc); + } // 2. Increment or loop the index and - int maxIndex = (int)behaviour.GetProperty(PROP_MAX_INDEX).GetNumber(); - index = (index + 1) % maxIndex; + int arrLen = (int)behaviour.GetProperty(PROP_ARR_LEN).GetNumber(); + index = (index + 1) % arrLen; // 3. Save the new index back to the agent obj.SetProperty(indexSrc, index); diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs index fd7afc72..c0bfd686 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs @@ -6,14 +6,13 @@ namespace BehaviourTree { public class VectorIteratorNode : IBehaviourTreeNode { - private const string PROP_ARRAY = "source-array"; + private const string PROP_ARRAY = "vector-array"; private const string PROP_INDEX_SRC = "index-source"; private const string PROP_VECTOR_DEST = "vector-destination"; public void Serialize(Behaviour behaviour) { - // TODO: have an array property to drive these values - behaviour.Properties.Add(PROP_ARRAY, new VariableProperty(VariableProperty.Type.String)); // todo: change type to array (of vectors) + behaviour.Properties.Add(PROP_ARRAY, new VariableProperty(VariableProperty.Type.Array, VariableProperty.Type.Vector)); behaviour.Properties.Add(PROP_INDEX_SRC, new VariableProperty(VariableProperty.Type.String)); behaviour.Properties.Add(PROP_VECTOR_DEST, new VariableProperty(VariableProperty.Type.String)); } @@ -22,15 +21,6 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { Behaviour behaviour = self.Element; - Vector2[] tempArr = { - new Vector2(-3, -3), - new Vector2(-5, -5), - new Vector2(-3, -5) - }; - - // we need to output two things: index, and current vector - // these need to be stored in specific properties (defined in the inspector) - // 1. read the current index from the agent (or set to zero if not exists) int index = 0; string indexSrc = behaviour.GetProperty(PROP_INDEX_SRC).GetString(); @@ -40,10 +30,12 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) } // 2. get the vector at the current index - Vector2 vec = tempArr[index]; + object[] arr = behaviour.GetProperty(PROP_ARRAY).GetArray(); + Vector2 vec = (Vector2)arr[index]; // 3. store the resulting vector on the agent - obj.SetProperty(PROP_VECTOR_DEST, vec); + string vectorDest = behaviour.GetProperty(PROP_VECTOR_DEST).GetString(); + obj.SetProperty(vectorDest, vec); return NodeStatus.Success; } diff --git a/Assets/Scripts/Utils/VariableProperty.cs b/Assets/Scripts/Utils/VariableProperty.cs index e0d97715..2c3ffe92 100644 --- a/Assets/Scripts/Utils/VariableProperty.cs +++ b/Assets/Scripts/Utils/VariableProperty.cs @@ -152,7 +152,7 @@ public object[] GetArray() } return result; } - + public Type GetArrayType() { if (PropertyType != Type.Array) throw new InvalidOperationException("This property is not an array type."); From 42e13a90f0ab4f1adcd50ea5fde46c5d11ad622f Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Wed, 10 Nov 2021 17:10:33 -0800 Subject: [PATCH 14/41] Rename EqualsNode to IntEqualsNode --- ...SetupSneekoTree.asset => SneekoTest.asset} | 4 +-- ...oTree.asset.meta => SneekoTest.asset.meta} | 2 +- .../Dialogue Graphs/SithTestDialogue.asset | 30 +++++++++++++++++++ .../Dialogue Graphs/TestNPC2Dialogue.asset | 2 ++ .../Dialogue Graphs/TestNPCDialogue.asset | 2 +- .../BehaviourTreeNodeCreator.cs | 6 ++-- .../Tools/Behaviour Tree/Nodes/EqualsNode.cs | 2 +- 7 files changed, 40 insertions(+), 8 deletions(-) rename Assets/Data/Behaviour Trees/{SetupSneekoTree.asset => SneekoTest.asset} (97%) rename Assets/Data/Behaviour Trees/{SetupSneekoTree.asset.meta => SneekoTest.asset.meta} (79%) diff --git a/Assets/Data/Behaviour Trees/SetupSneekoTree.asset b/Assets/Data/Behaviour Trees/SneekoTest.asset similarity index 97% rename from Assets/Data/Behaviour Trees/SetupSneekoTree.asset rename to Assets/Data/Behaviour Trees/SneekoTest.asset index 3d162b1c..6e28100d 100644 --- a/Assets/Data/Behaviour Trees/SetupSneekoTree.asset +++ b/Assets/Data/Behaviour Trees/SneekoTest.asset @@ -10,7 +10,7 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 54fb5e73c80040247a00b01917c6e426, type: 3} - m_Name: SetupSneekoTree + m_Name: SneekoTest m_EditorClassIdentifier: tree: serializedNodes: @@ -110,7 +110,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.EqualsNode + nodeTypeName: BehaviourTree.IntEqualsNode firstChildIndex: 4 - childCount: 0 element: diff --git a/Assets/Data/Behaviour Trees/SetupSneekoTree.asset.meta b/Assets/Data/Behaviour Trees/SneekoTest.asset.meta similarity index 79% rename from Assets/Data/Behaviour Trees/SetupSneekoTree.asset.meta rename to Assets/Data/Behaviour Trees/SneekoTest.asset.meta index c23a5777..4ce542bb 100644 --- a/Assets/Data/Behaviour Trees/SetupSneekoTree.asset.meta +++ b/Assets/Data/Behaviour Trees/SneekoTest.asset.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 64a6070144d65fb4a86a0493bb5d72a7 +guid: 3e6bff16d48bace4ca5896521841a0f6 NativeFormatImporter: externalObjects: {} mainObjectFileID: 11400000 diff --git a/Assets/Data/Dialogue Graphs/SithTestDialogue.asset b/Assets/Data/Dialogue Graphs/SithTestDialogue.asset index d4b8a2d2..a5cedc06 100644 --- a/Assets/Data/Dialogue Graphs/SithTestDialogue.asset +++ b/Assets/Data/Dialogue Graphs/SithTestDialogue.asset @@ -16,24 +16,49 @@ MonoBehaviour: - name: Entry body: I have brought peace, freedom, justice, and security to my new empire. position: {x: -660, y: -64} + moralsMod: 0 + leaningsMod: 0 + sexinessMod: 0 questNotes: - {fileID: 0} + dialogueIndexOverrides: [] + customBehaviour: {fileID: 0} - name: Your new empire? body: Don't make me kill you. position: {x: -478, y: -246} + moralsMod: 0 + leaningsMod: 0 + sexinessMod: 0 questNotes: [] + dialogueIndexOverrides: [] + customBehaviour: {fileID: 0} - name: Only a Sith deals in absolutes. I will do what I must. body: You will try. position: {x: 156, y: -210} + moralsMod: 0 + leaningsMod: 0 + sexinessMod: 0 questNotes: [] + dialogueIndexOverrides: [] + customBehaviour: {fileID: 0} - name: Good, good. Let the hate flow through you. body: Dewit! position: {x: -221, y: 118} + moralsMod: 0 + leaningsMod: 0 + sexinessMod: 0 questNotes: [] + dialogueIndexOverrides: [] + customBehaviour: {fileID: 0} - name: Anakin, my allegiance is to the Republic, to Democracy! body: If you are not with me, then you are my enemy. position: {x: -191.5, y: -304} + moralsMod: 0 + leaningsMod: 0 + sexinessMod: 0 questNotes: [] + dialogueIndexOverrides: [] + customBehaviour: {fileID: 0} transitions: - name: Transition from: 0 @@ -57,4 +82,9 @@ MonoBehaviour: name: Exit body: position: {x: -218, y: -175} + moralsMod: 0 + leaningsMod: 0 + sexinessMod: 0 questNotes: [] + dialogueIndexOverrides: [] + customBehaviour: {fileID: 0} diff --git a/Assets/Data/Dialogue Graphs/TestNPC2Dialogue.asset b/Assets/Data/Dialogue Graphs/TestNPC2Dialogue.asset index c14505ed..9d3f9249 100644 --- a/Assets/Data/Dialogue Graphs/TestNPC2Dialogue.asset +++ b/Assets/Data/Dialogue Graphs/TestNPC2Dialogue.asset @@ -24,6 +24,7 @@ MonoBehaviour: dialogueIndexOverrides: - targetUniqueID: indexOverride: 1 + customBehaviour: {fileID: 0} transitions: - name: Transition from: 0 @@ -37,3 +38,4 @@ MonoBehaviour: sexinessMod: 0 questNotes: [] dialogueIndexOverrides: [] + customBehaviour: {fileID: 0} diff --git a/Assets/Data/Dialogue Graphs/TestNPCDialogue.asset b/Assets/Data/Dialogue Graphs/TestNPCDialogue.asset index 341faab6..f7224f6b 100644 --- a/Assets/Data/Dialogue Graphs/TestNPCDialogue.asset +++ b/Assets/Data/Dialogue Graphs/TestNPCDialogue.asset @@ -64,7 +64,7 @@ MonoBehaviour: dialogueIndexOverrides: - targetUniqueID: indexOverride: 1 - customBehaviour: {fileID: 11400000, guid: 64a6070144d65fb4a86a0493bb5d72a7, type: 2} + customBehaviour: {fileID: 11400000, guid: 3e6bff16d48bace4ca5896521841a0f6, type: 2} - name: Errrrr, never mind. See ya later. body: Alright. Later! position: {x: 338, y: -49} diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index 11d0ee28..dcfcfbba 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -9,7 +9,7 @@ public enum BehaviourTreeNodeType ExecuteAllNode, SuccessNode, NotNode, - EqualsNode, + IntEqualsNode, HasPropertyNode, RangeCheckNode, FindActorByTagNode, @@ -44,8 +44,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new SuccessNode(); case BehaviourTreeNodeType.NotNode: return new NotNode(); - case BehaviourTreeNodeType.EqualsNode: - return new EqualsNode(); + case BehaviourTreeNodeType.IntEqualsNode: + return new IntEqualsNode(); case BehaviourTreeNodeType.HasPropertyNode: return new HasPropertyNode(); case BehaviourTreeNodeType.RangeCheckNode: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/EqualsNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/EqualsNode.cs index f22e35b8..f856c65b 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/EqualsNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/EqualsNode.cs @@ -5,7 +5,7 @@ namespace BehaviourTree { - public class EqualsNode : IBehaviourTreeNode + public class IntEqualsNode : IBehaviourTreeNode { private const string PROP_SOURCE = "source-property"; private const string PROP_NUMBER = "comparison-number"; From 3ecced8691162d9cc58f6da7fa9cd2970c9cbba6 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Wed, 10 Nov 2021 22:09:30 -0800 Subject: [PATCH 15/41] Rename IntEqualsNode --- .../Behaviour Tree/Nodes/{EqualsNode.cs => IntEqualsNode.cs} | 0 .../Nodes/{EqualsNode.cs.meta => IntEqualsNode.cs.meta} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Assets/Scripts/Tools/Behaviour Tree/Nodes/{EqualsNode.cs => IntEqualsNode.cs} (100%) rename Assets/Scripts/Tools/Behaviour Tree/Nodes/{EqualsNode.cs.meta => IntEqualsNode.cs.meta} (100%) diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/EqualsNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs similarity index 100% rename from Assets/Scripts/Tools/Behaviour Tree/Nodes/EqualsNode.cs rename to Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/EqualsNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs.meta similarity index 100% rename from Assets/Scripts/Tools/Behaviour Tree/Nodes/EqualsNode.cs.meta rename to Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs.meta From a3574c18edb98a92cb98ac91e737153e731cf05d Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Wed, 10 Nov 2021 22:38:09 -0800 Subject: [PATCH 16/41] Implement NPC idle logic --- Assets/Data/Behaviour Trees/ExampleNPC.asset | 163 ++++++++++++++++-- .../BehaviourTreeNodeCreator.cs | 9 + .../Behaviour Tree/Nodes/BoolEqualsNode.cs | 30 ++++ .../Nodes/BoolEqualsNode.cs.meta | 11 ++ .../Tools/Behaviour Tree/Nodes/IdleNode.cs | 40 +++++ .../Behaviour Tree/Nodes/IdleNode.cs.meta | 11 ++ .../Behaviour Tree/Nodes/IntEqualsNode.cs | 3 +- .../Tools/Behaviour Tree/Nodes/SetBoolNode.cs | 29 ++++ .../Behaviour Tree/Nodes/SetBoolNode.cs.meta | 11 ++ .../Behaviour Tree/Nodes/SimpleMoveNode.cs | 2 +- 10 files changed, 293 insertions(+), 16 deletions(-) create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IdleNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IdleNode.cs.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs.meta diff --git a/Assets/Data/Behaviour Trees/ExampleNPC.asset b/Assets/Data/Behaviour Trees/ExampleNPC.asset index dc87de12..195ec20b 100644 --- a/Assets/Data/Behaviour Trees/ExampleNPC.asset +++ b/Assets/Data/Behaviour Trees/ExampleNPC.asset @@ -14,11 +14,124 @@ MonoBehaviour: m_EditorClassIdentifier: tree: serializedNodes: - - childCount: 3 + - childCount: 1 element: propertyInfo: [] nodeTypeName: BehaviourTree.SequenceNode firstChildIndex: 1 + - childCount: 2 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SelectorNode + firstChildIndex: 2 + - childCount: 4 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 3 + - childCount: 0 + element: + propertyInfo: + - name: property-name + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: idle + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.HasPropertyNode + firstChildIndex: 4 + - childCount: 0 + element: + propertyInfo: + - name: source-property + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: idle + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: comparison-bool + property: + propertyType: 0 + objectType: + value: + b: 1 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.BoolEqualsNode + firstChildIndex: 5 + - childCount: 0 + element: + propertyInfo: + - name: idle-duration + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 3 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.IdleNode + firstChildIndex: 6 + - childCount: 0 + element: + propertyInfo: + - name: target-property + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: idle + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: bool-value + property: + propertyType: 0 + objectType: + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SetBoolNode + firstChildIndex: 7 + - childCount: 4 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 8 - childCount: 0 element: propertyInfo: @@ -53,14 +166,7 @@ MonoBehaviour: n: 0 s: o: {fileID: 0} - v: {x: -3, y: -7} - - propertyType: 4 - value: - b: 0 - n: 0 - s: - o: {fileID: 0} - v: {x: -1, y: -5} + v: {x: -3, y: -5} e: 0 aType: 4 - name: index-source @@ -90,7 +196,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.VectorIteratorNode - firstChildIndex: 2 + firstChildIndex: 9 - childCount: 0 element: propertyInfo: @@ -134,7 +240,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.SimpleMoveNode - firstChildIndex: 3 + firstChildIndex: 10 - childCount: 0 element: propertyInfo: @@ -157,7 +263,7 @@ MonoBehaviour: objectType: value: b: 0 - n: 4 + n: 3 s: o: {fileID: 0} v: {x: 0, y: 0} @@ -165,4 +271,35 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.ArrayIncrementNode - firstChildIndex: 4 + firstChildIndex: 11 + - childCount: 0 + element: + propertyInfo: + - name: target-property + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: idle + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: bool-value + property: + propertyType: 0 + objectType: + value: + b: 1 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SetBoolNode + firstChildIndex: 12 diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index dcfcfbba..e9bf55be 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -10,6 +10,7 @@ public enum BehaviourTreeNodeType SuccessNode, NotNode, IntEqualsNode, + BoolEqualsNode, HasPropertyNode, RangeCheckNode, FindActorByTagNode, @@ -17,6 +18,7 @@ public enum BehaviourTreeNodeType GetActorPositionNode, GetRandomPositionNode, SimpleMoveNode, + IdleNode, SetActionTargetNode, InvokeActionNode, GetDialogueIndexNode, @@ -24,6 +26,7 @@ public enum BehaviourTreeNodeType ForceDialogueNode, VectorIteratorNode, ArrayIncrementNode, + SetBoolNode, GetMoveDirectionNode, GetVectorAxisNode } @@ -46,6 +49,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new NotNode(); case BehaviourTreeNodeType.IntEqualsNode: return new IntEqualsNode(); + case BehaviourTreeNodeType.BoolEqualsNode: + return new BoolEqualsNode(); case BehaviourTreeNodeType.HasPropertyNode: return new HasPropertyNode(); case BehaviourTreeNodeType.RangeCheckNode: @@ -60,6 +65,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new GetRandomPositionNode(); case BehaviourTreeNodeType.SimpleMoveNode: return new SimpleMoveNode(); + case BehaviourTreeNodeType.IdleNode: + return new IdleNode(); case BehaviourTreeNodeType.SetActionTargetNode: return new SetActionTargetNode(); case BehaviourTreeNodeType.InvokeActionNode: @@ -74,6 +81,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new VectorIteratorNode(); case BehaviourTreeNodeType.ArrayIncrementNode: return new ArrayIncrementNode(); + case BehaviourTreeNodeType.SetBoolNode: + return new SetBoolNode(); case BehaviourTreeNodeType.GetMoveDirectionNode: return new GetMoveDirectionNode(); case BehaviourTreeNodeType.GetVectorAxisNode: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs new file mode 100644 index 00000000..59c3e16b --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs @@ -0,0 +1,30 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + public class BoolEqualsNode : IBehaviourTreeNode + { + private const string PROP_SOURCE = "source-property"; + private const string PROP_BOOL = "comparison-bool"; + + public void Serialize(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_SOURCE, new VariableProperty(VariableProperty.Type.String)); + behaviour.Properties.Add(PROP_BOOL, new VariableProperty(VariableProperty.Type.Boolean)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + string source = behaviour.GetProperty(PROP_SOURCE).GetString(); + bool bool1 = (bool)obj.GetProperty(source); + bool bool2 = behaviour.GetProperty(PROP_BOOL).GetBoolean(); + if (bool1 == bool2) return NodeStatus.Success; + + return NodeStatus.Failure; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs.meta new file mode 100644 index 00000000..23c06837 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3d070b572db5c71448046aa2c8ebd8cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IdleNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IdleNode.cs new file mode 100644 index 00000000..26c909a1 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IdleNode.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + public class IdleNode : IBehaviourTreeNode + { + private const string PROP_IDLE_DURATION = "idle-duration"; + + public void Serialize(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_IDLE_DURATION, new VariableProperty(VariableProperty.Type.Number)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + // Get idle time + double idleTime = 0; + if (obj.HasProperty("idle-time")) + { + idleTime = (double)obj.GetProperty("idle-time"); + } + + // Check if we've been idling for long enough + double idleDuration = behaviour.GetProperty(PROP_IDLE_DURATION).GetNumber(); + if (idleTime < idleDuration) + { + obj.SetProperty("idle-time", idleTime + Time.deltaTime); + return NodeStatus.Running; + } + + // Clear idle timer + obj.RemoveProperty("idle-time"); + return NodeStatus.Success; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IdleNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IdleNode.cs.meta new file mode 100644 index 00000000..ef9c2e6b --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IdleNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 620d0b4ae03ab46498c63d5266516ab3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs index f856c65b..eab6b6b4 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs @@ -1,7 +1,6 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using RPG; namespace BehaviourTree { @@ -28,4 +27,4 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) return NodeStatus.Failure; } } -} \ No newline at end of file +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs new file mode 100644 index 00000000..fb6c1448 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + public class SetBoolNode : IBehaviourTreeNode + { + private const string PROP_TARGET = "target-property"; + private const string PROP_VALUE = "bool-value"; + + public void Serialize(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_TARGET, new VariableProperty(VariableProperty.Type.String)); + behaviour.Properties.Add(PROP_VALUE, new VariableProperty(VariableProperty.Type.Boolean)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + string target = behaviour.GetProperty(PROP_TARGET).GetString(); + bool val = behaviour.GetProperty(PROP_VALUE).GetBoolean(); + obj.SetProperty(target, val); + + return NodeStatus.Failure; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs.meta new file mode 100644 index 00000000..67093edc --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: baa536f3743e08942a2ebf3388ae6dd4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SimpleMoveNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SimpleMoveNode.cs index 40971b40..2aae439d 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SimpleMoveNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SimpleMoveNode.cs @@ -43,4 +43,4 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) return NodeStatus.Failure; } } -} \ No newline at end of file +} From dacc5817985b6389250549738172188288171680 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Wed, 10 Nov 2021 22:45:40 -0800 Subject: [PATCH 17/41] Fix array reset inspector bug --- Assets/Scripts/Editor/BehaviourTreeInspector.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Assets/Scripts/Editor/BehaviourTreeInspector.cs b/Assets/Scripts/Editor/BehaviourTreeInspector.cs index 492719b2..335f1f11 100644 --- a/Assets/Scripts/Editor/BehaviourTreeInspector.cs +++ b/Assets/Scripts/Editor/BehaviourTreeInspector.cs @@ -9,6 +9,7 @@ namespace BehaviourTree public class BehaviourTreeInspector : Editor { private BehaviourTree behaviourTree; + private Behaviour selected = null; private bool isArrayExpanded = false; private int arrayLength = 0; @@ -25,6 +26,13 @@ public override void OnInspectorGUI() Behaviour node = behaviourTree.selectedNode; if (node == null) return; + if (selected == null || selected != node) + { + isArrayExpanded = false; + arrayLength = 0; + arr = null; + } + selected = node; ClearArrayData(); From abfecd37c62234a52bd3880f19f8889ea794bf87 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 16 Nov 2021 17:28:02 -0800 Subject: [PATCH 18/41] Remove Animator from Agent --- Assets/Scripts/Tools/Behaviour Tree/Agent.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs index 49565e70..46416c26 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs @@ -5,13 +5,12 @@ namespace BehaviourTree { - [RequireComponent(typeof(Rigidbody2D), typeof(Animator))] + [RequireComponent(typeof(Rigidbody2D))] public class Agent : BehaviourObject { [SerializeField] private BehaviourTree behaviourTree; public Rigidbody2D Rigidbody2D { get; private set; } - public Animator Animator { get; private set; } private Tree.Node root; private bool isEnabled; @@ -21,7 +20,6 @@ protected override void Awake() base.Awake(); Rigidbody2D = GetComponent(); - Animator = GetComponent(); root = behaviourTree.Root; isEnabled = true; From 7c8b1ad25c9167bd2cac9a09dc94720455ca1fa7 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 16 Nov 2021 17:35:59 -0800 Subject: [PATCH 19/41] Update NPC directory structure --- Assets/Scenes/Main.unity | 44 +++++++++------- Assets/Scripts/Game/{NPCs.meta => NPC.meta} | 0 Assets/Scripts/Game/NPC/BaseNPC.cs | 49 +++++++++++++++++ .../Game/{NPCs => NPC}/BaseNPC.cs.meta | 0 .../Game/{Quest/QuestGiver.cs => NPC/NPC.cs} | 2 +- .../QuestGiver.cs.meta => NPC/NPC.cs.meta} | 2 +- Assets/Scripts/Game/NPCs/BaseNPC.cs | 52 ------------------- Assets/Scripts/Game/UI/DialoguePanel.cs | 2 +- Assets/Scripts/Game/UI/DialogueSystem.cs | 8 +-- .../Behaviour Tree/Nodes/ForceDialogueNode.cs | 19 +++---- .../Behaviours/GetDialogueIndexNode.cs | 2 +- .../Behaviours/SetDialogueIndexNode.cs | 2 +- 12 files changed, 92 insertions(+), 90 deletions(-) rename Assets/Scripts/Game/{NPCs.meta => NPC.meta} (100%) create mode 100644 Assets/Scripts/Game/NPC/BaseNPC.cs rename Assets/Scripts/Game/{NPCs => NPC}/BaseNPC.cs.meta (100%) rename Assets/Scripts/Game/{Quest/QuestGiver.cs => NPC/NPC.cs} (93%) rename Assets/Scripts/Game/{Quest/QuestGiver.cs.meta => NPC/NPC.cs.meta} (83%) delete mode 100644 Assets/Scripts/Game/NPCs/BaseNPC.cs diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index de8dcedb..8b601e79 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -404,10 +404,12 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Random4 portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 983069b3f6e25a446b7cc000264e1bb2, type: 2} + k__BackingField: 0 --- !u!58 &109492337 CircleCollider2D: m_ObjectHideFlags: 0 @@ -501,7 +503,6 @@ GameObject: - component: {fileID: 113309048} - component: {fileID: 113309047} - component: {fileID: 113309046} - - component: {fileID: 113309045} - component: {fileID: 113309050} m_Layer: 8 m_Name: TestNPCMover @@ -510,25 +511,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!95 &113309045 -Animator: - serializedVersion: 3 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 113309044} - m_Enabled: 1 - m_Avatar: {fileID: 0} - m_Controller: {fileID: 0} - m_CullingMode: 0 - m_UpdateMode: 0 - m_ApplyRootMotion: 0 - m_LinearVelocityBlending: 0 - m_WarningMessage: - m_HasTransformHierarchy: 1 - m_AllowConstantClipSamplingOptimization: 1 - m_KeepAnimatorControllerStateOnDisable: 0 --- !u!50 &113309046 Rigidbody2D: serializedVersion: 4 @@ -681,6 +663,7 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Mum portrait: {fileID: 8835284309397123848, guid: 568b897490088f8439d263b261216ec0, type: 3} @@ -691,6 +674,7 @@ MonoBehaviour: - {fileID: 11400000, guid: 9c5ab4e0982fac54ab0e05d0dca4093e, type: 2} - {fileID: 11400000, guid: 2133e95db09dbf34fbd7a3a458719899, type: 2} - {fileID: 11400000, guid: 12bee71ec794d8b4598dce7ff9fa751f, type: 2} + k__BackingField: 0 --- !u!58 &141597917 CircleCollider2D: m_ObjectHideFlags: 0 @@ -1532,11 +1516,13 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Goof portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 1038a25bb80e70e4da7c513479466015, type: 2} - {fileID: 11400000, guid: 709ad8f986fdd3442bad33d63bed2752, type: 2} + k__BackingField: 0 --- !u!58 &511373795 CircleCollider2D: m_ObjectHideFlags: 0 @@ -1588,12 +1574,14 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Sneeko portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 8c096da2b4b78d14492866a0ace564a7, type: 2} - {fileID: 11400000, guid: 7852df3d4fd29ae498cfed742fd1b8f7, type: 2} - {fileID: 11400000, guid: 2e067e40d2dbdc8499f8b6226f5fccf1, type: 2} + k__BackingField: 0 --- !u!58 &539150547 CircleCollider2D: m_ObjectHideFlags: 0 @@ -1722,10 +1710,12 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Random2 portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 19e302e7a2839af46ba37481d3432982, type: 2} + k__BackingField: 0 --- !u!58 &561039018 CircleCollider2D: m_ObjectHideFlags: 0 @@ -1841,6 +1831,7 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Jimmy portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: @@ -1848,6 +1839,7 @@ MonoBehaviour: - {fileID: 11400000, guid: ae69f4ad827a0414a91c5ae9bf3b5f7f, type: 2} - {fileID: 11400000, guid: 83b205d62cdb0974393721752ad9e152, type: 2} - {fileID: 11400000, guid: a7387a334354d6349a4477f872978b86, type: 2} + k__BackingField: 0 --- !u!58 &608919355 CircleCollider2D: m_ObjectHideFlags: 0 @@ -2781,12 +2773,14 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Waddlesworth portrait: {fileID: -3713467532807335336, guid: 0bbfe1fef35fa2243a811a7b497fb9e2, type: 3} dialogueGraphs: - {fileID: 11400000, guid: e2d41534d805e214b87b7147251687f5, type: 2} - {fileID: 11400000, guid: 48f86ea51390adb459028fd4ce49c74d, type: 2} + k__BackingField: 0 --- !u!58 &940472399 CircleCollider2D: m_ObjectHideFlags: 0 @@ -3088,10 +3082,12 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Random3 portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: fb7221204d8077242a86860ac28961e6, type: 2} + k__BackingField: 0 --- !u!58 &1047971989 CircleCollider2D: m_ObjectHideFlags: 0 @@ -3219,11 +3215,13 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: QueenBee portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: b841a9376d1e11440948e5662caa909b, type: 2} - {fileID: 11400000, guid: 0f47a4bdeaa57fb4cbb71798ddb17b3c, type: 2} + k__BackingField: 0 --- !u!58 &1060987546 CircleCollider2D: m_ObjectHideFlags: 0 @@ -3444,12 +3442,14 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Jimmy portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 8c096da2b4b78d14492866a0ace564a7, type: 2} - {fileID: 11400000, guid: 7852df3d4fd29ae498cfed742fd1b8f7, type: 2} - {fileID: 11400000, guid: 2e067e40d2dbdc8499f8b6226f5fccf1, type: 2} + k__BackingField: 0 --- !u!58 &1134476118 CircleCollider2D: m_ObjectHideFlags: 0 @@ -4375,10 +4375,12 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Interact + tooltip: {fileID: 0} characterName: Picture portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 9ff2ef79ee780e34397408cbe8755f16, type: 2} + k__BackingField: 0 --- !u!58 &1398485441 CircleCollider2D: m_ObjectHideFlags: 0 @@ -4494,10 +4496,12 @@ MonoBehaviour: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk + tooltip: {fileID: 0} characterName: Random1 portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 3e16ea0b8d9fdc04c8742fec90a182d6, type: 2} + k__BackingField: 0 --- !u!58 &1410663228 CircleCollider2D: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Game/NPCs.meta b/Assets/Scripts/Game/NPC.meta similarity index 100% rename from Assets/Scripts/Game/NPCs.meta rename to Assets/Scripts/Game/NPC.meta diff --git a/Assets/Scripts/Game/NPC/BaseNPC.cs b/Assets/Scripts/Game/NPC/BaseNPC.cs new file mode 100644 index 00000000..524fcba2 --- /dev/null +++ b/Assets/Scripts/Game/NPC/BaseNPC.cs @@ -0,0 +1,49 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using BehaviourTree; + +namespace RPG +{ + public class BaseNPC : Actor + { + private NPC dialogue; + private CircleCollider2D npcCollider; + + private bool isNPCFollower; + + [SerializeField] private float interactionDistance = 5.0f; + + private bool dialogueInitiated = false; //Delete this when we have a means of catching when dialogue is done + + protected override void Awake() + { + base.Awake(); + dialogue = GetComponent(); + npcCollider = GetComponent(); + } + + public void TurnIntoEnemy() + { + //Change to enemy Layer; + gameObject.layer = LayerMask.NameToLayer("Enemy"); + + //Doesnt if this doesn't have Enemy Script will add it + if (gameObject.GetComponent() == null) + { + gameObject.AddComponent(); + } + else + { + gameObject.GetComponent().enabled = true; + } + //TODO add AttackBehaviour in BehaviourTree + } + + public void TurnIntoCompanion() + { + //TODO Make Follower movement, interactable + npcCollider.enabled = false; + } + } +} diff --git a/Assets/Scripts/Game/NPCs/BaseNPC.cs.meta b/Assets/Scripts/Game/NPC/BaseNPC.cs.meta similarity index 100% rename from Assets/Scripts/Game/NPCs/BaseNPC.cs.meta rename to Assets/Scripts/Game/NPC/BaseNPC.cs.meta diff --git a/Assets/Scripts/Game/Quest/QuestGiver.cs b/Assets/Scripts/Game/NPC/NPC.cs similarity index 93% rename from Assets/Scripts/Game/Quest/QuestGiver.cs rename to Assets/Scripts/Game/NPC/NPC.cs index 61e4d561..1385c185 100644 --- a/Assets/Scripts/Game/Quest/QuestGiver.cs +++ b/Assets/Scripts/Game/NPC/NPC.cs @@ -5,7 +5,7 @@ namespace RPG { - public class QuestGiver : Interactable + public class NPC : Interactable { [SerializeField] private string characterName; public string CharacterName { get => characterName; } diff --git a/Assets/Scripts/Game/Quest/QuestGiver.cs.meta b/Assets/Scripts/Game/NPC/NPC.cs.meta similarity index 83% rename from Assets/Scripts/Game/Quest/QuestGiver.cs.meta rename to Assets/Scripts/Game/NPC/NPC.cs.meta index 06f6e841..9e2d1df0 100644 --- a/Assets/Scripts/Game/Quest/QuestGiver.cs.meta +++ b/Assets/Scripts/Game/NPC/NPC.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 7fba3685198575341bfedcdddb0b58fd +guid: 82d10099f0b38ec40b917b3fa80f253e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Game/NPCs/BaseNPC.cs b/Assets/Scripts/Game/NPCs/BaseNPC.cs deleted file mode 100644 index 08474328..00000000 --- a/Assets/Scripts/Game/NPCs/BaseNPC.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using BehaviourTree; -namespace RPG{ - - public class BaseNPC: Actor - { - private QuestGiver dialogue; - private CircleCollider2D npcCollider; - private Agent agent; - - private bool isNPCFollower; - - [SerializeField]private float interactionDistance=5.0f; - - private bool dialogueInitiated=false;//Delete this when we have a means of catching when dialogue is done - - // Start is called before the first frame update - protected override void Awake() { - base.Awake(); - dialogue=GetComponent(); - agent=GetComponent(); - npcCollider=GetComponent(); - - } - - // Update is called once per frame - void Update() - { - } - - public void TurnIntoEnemy(){ - //Change to enemy Layer; - gameObject.layer=LayerMask.NameToLayer("Enemy"); - - //Doesnt if this doesn't have Enemy Script will add it - if(gameObject.GetComponent()==null){ - gameObject.AddComponent(); - } - else{ - gameObject.GetComponent().enabled=true; - } - //TODO add AttackBehaviour in BehaviourTree - } - - public void TurnIntoCompanion(){ - //TODO Make Follower movement, interactable - npcCollider.enabled=false; - } - } -} diff --git a/Assets/Scripts/Game/UI/DialoguePanel.cs b/Assets/Scripts/Game/UI/DialoguePanel.cs index 440fcfad..55697917 100644 --- a/Assets/Scripts/Game/UI/DialoguePanel.cs +++ b/Assets/Scripts/Game/UI/DialoguePanel.cs @@ -31,7 +31,7 @@ public void Hide() gameObject.SetActive(false); } - public void SetTarget(QuestGiver target) + public void SetTarget(NPC target) { dialoguePortrait.sprite = target.Portrait; dialogueName.text = target.CharacterName; diff --git a/Assets/Scripts/Game/UI/DialogueSystem.cs b/Assets/Scripts/Game/UI/DialogueSystem.cs index 9b53943f..6fdeea93 100644 --- a/Assets/Scripts/Game/UI/DialogueSystem.cs +++ b/Assets/Scripts/Game/UI/DialogueSystem.cs @@ -12,11 +12,11 @@ namespace Dialogue public class DialogueSystem : MonoBehaviour { private YieldInstruction letterCooldown = new WaitForSeconds(0.05f); - private QuestGiver currentTarget; + private NPC currentTarget; private DialogueGraph currentGraph; private int currentNode = 0; - public void BeginDialogue(QuestGiver target, DialogueGraph graph) + public void BeginDialogue(NPC target, DialogueGraph graph) { currentTarget = target; currentGraph = graph; @@ -59,10 +59,10 @@ private IEnumerator ShowDialogue(int node) // Apply any dialogue index overrides foreach (DialogueIndexOverride idxOverride in graphNode.dialogueIndexOverrides) { - QuestGiver target = currentTarget; + NPC target = currentTarget; if (idxOverride.targetUniqueID != "") { - target = Entity.Find(idxOverride.targetUniqueID); + target = Entity.Find(idxOverride.targetUniqueID); } target.ActiveIndex = idxOverride.indexOverride; } diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs index 87e765be..daa3005e 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs @@ -3,26 +3,27 @@ using UnityEngine; using RPG; -namespace BehaviourTree{ +namespace BehaviourTree +{ public class ForceDialogueNode : IBehaviourTreeNode - { + { - public void Serialize(Behaviour behaviour){} + public void Serialize(Behaviour behaviour) { } public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { - Behaviour behaviour=self.Element; - QuestGiver dialogue=obj.GetComponent(); - Player p=GameObject.FindGameObjectWithTag("Player").GetComponent(); + Behaviour behaviour = self.Element; + NPC dialogue = obj.GetComponent(); + Player p = GameObject.FindGameObjectWithTag("Player").GetComponent(); //Checks if the player or the QuestGiver(DialogueScript later) is null - if(dialogue!=null && p!=null){ + if (dialogue != null && p != null) + { dialogue.Interact(p); return NodeStatus.Success; - } return NodeStatus.Failure; } - + } } diff --git a/Assets/Scripts/Tools/Dialogue Graph/Behaviours/GetDialogueIndexNode.cs b/Assets/Scripts/Tools/Dialogue Graph/Behaviours/GetDialogueIndexNode.cs index 2fd3b131..4d60a27c 100644 --- a/Assets/Scripts/Tools/Dialogue Graph/Behaviours/GetDialogueIndexNode.cs +++ b/Assets/Scripts/Tools/Dialogue Graph/Behaviours/GetDialogueIndexNode.cs @@ -26,7 +26,7 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) // Get and save the dialogue index in destination prop string indexDest = behaviour.GetProperty(PROP_DEST).GetString(); - obj.SetProperty(indexDest, npc.GetComponent().ActiveIndex); + obj.SetProperty(indexDest, npc.GetComponent().ActiveIndex); return NodeStatus.Success; } diff --git a/Assets/Scripts/Tools/Dialogue Graph/Behaviours/SetDialogueIndexNode.cs b/Assets/Scripts/Tools/Dialogue Graph/Behaviours/SetDialogueIndexNode.cs index 60e459fa..1b522f41 100644 --- a/Assets/Scripts/Tools/Dialogue Graph/Behaviours/SetDialogueIndexNode.cs +++ b/Assets/Scripts/Tools/Dialogue Graph/Behaviours/SetDialogueIndexNode.cs @@ -26,7 +26,7 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) // Set the dialogue index int index = (int)behaviour.GetProperty(PROP_INDEX).GetNumber(); - npc.GetComponent().ActiveIndex = index; + npc.GetComponent().ActiveIndex = index; return NodeStatus.Success; } From 30de1dc1c6269884d53e306519d15fa3f635468c Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 16 Nov 2021 18:41:00 -0800 Subject: [PATCH 20/41] Update NPCs --- Assets/Prefabs/TestEnemy.prefab | 3 +- Assets/Presets/Animator.preset | 59 ++++++++++++++++ Assets/Presets/Animator.preset.meta | 8 +++ Assets/Scenes/Main.unity | 101 ++++++++++++++++++---------- Assets/Scenes/TutorialTown.unity | 9 ++- 5 files changed, 137 insertions(+), 43 deletions(-) create mode 100644 Assets/Presets/Animator.preset create mode 100644 Assets/Presets/Animator.preset.meta diff --git a/Assets/Prefabs/TestEnemy.prefab b/Assets/Prefabs/TestEnemy.prefab index 16cf7d2a..a0926ada 100644 --- a/Assets/Prefabs/TestEnemy.prefab +++ b/Assets/Prefabs/TestEnemy.prefab @@ -169,13 +169,12 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7157c15a42769b0458c85c94a11a8d26, type: 3} m_Name: m_EditorClassIdentifier: - initialMaxHealth: 15 + initialMaxHealth: 10 idleAnimations: {fileID: 11400000, guid: fb206d7e94c25e94b899ed54a07145c6, type: 2} moveAnimations: {fileID: 11400000, guid: e22d4c8424148f645ae60e803585d737, type: 2} hurtAnimations: {fileID: 11400000, guid: 1fce7b2292cd9e545984412811fa1820, type: 2} actions: - {fileID: 11400000, guid: cd54c1a41bfdb6745b6a33c7b765967e, type: 2} - flashDuration: 0.2 --- !u!114 &4011296362009397300 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Presets/Animator.preset b/Assets/Presets/Animator.preset new file mode 100644 index 00000000..6a7f5b1c --- /dev/null +++ b/Assets/Presets/Animator.preset @@ -0,0 +1,59 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!181963792 &2655988077585873504 +Preset: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Animator + m_TargetType: + m_NativeTypeID: 95 + m_ManagedTypePPtr: {fileID: 0} + m_ManagedTypeFallback: + m_Properties: + - target: {fileID: 0} + propertyPath: m_Enabled + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_Avatar + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_Controller + value: + objectReference: {fileID: 9100000, guid: d3af1bb34e9ffb044886be104dc98f2f, type: 2} + - target: {fileID: 0} + propertyPath: m_CullingMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_UpdateMode + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_ApplyRootMotion + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_LinearVelocityBlending + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_WarningMessage + value: + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_HasTransformHierarchy + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_AllowConstantClipSamplingOptimization + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 0} + propertyPath: m_KeepAnimatorControllerStateOnDisable + value: 0 + objectReference: {fileID: 0} + m_ExcludedProperties: [] diff --git a/Assets/Presets/Animator.preset.meta b/Assets/Presets/Animator.preset.meta new file mode 100644 index 00000000..687610ae --- /dev/null +++ b/Assets/Presets/Animator.preset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ff96623c6707a72418a0b766fe2b0e8c +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2655988077585873504 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 8b601e79..fd3feb01 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -398,18 +398,16 @@ MonoBehaviour: m_GameObject: {fileID: 109492335} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Random4 portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 983069b3f6e25a446b7cc000264e1bb2, type: 2} - k__BackingField: 0 --- !u!58 &109492337 CircleCollider2D: m_ObjectHideFlags: 0 @@ -503,6 +501,9 @@ GameObject: - component: {fileID: 113309048} - component: {fileID: 113309047} - component: {fileID: 113309046} + - component: {fileID: 113309052} + - component: {fileID: 113309051} + - component: {fileID: 113309045} - component: {fileID: 113309050} m_Layer: 8 m_Name: TestNPCMover @@ -511,6 +512,24 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 +--- !u!114 &113309045 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 113309044} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7157c15a42769b0458c85c94a11a8d26, type: 3} + m_Name: + m_EditorClassIdentifier: + initialMaxHealth: 6 + idleAnimations: {fileID: 11400000, guid: fb206d7e94c25e94b899ed54a07145c6, type: 2} + moveAnimations: {fileID: 11400000, guid: e22d4c8424148f645ae60e803585d737, type: 2} + hurtAnimations: {fileID: 11400000, guid: 1fce7b2292cd9e545984412811fa1820, type: 2} + actions: + - {fileID: 11400000, guid: cd54c1a41bfdb6745b6a33c7b765967e, type: 2} --- !u!50 &113309046 Rigidbody2D: serializedVersion: 4 @@ -626,6 +645,38 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: behaviourTree: {fileID: 11400000, guid: de69ac2176667774d94e83467a58ecce, type: 2} +--- !u!114 &113309051 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 113309044} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3841cfd75fe64b8498769758ea31c7be, type: 3} + m_Name: + m_EditorClassIdentifier: + defaultAnimation: {fileID: 7400000, guid: 511c335ee19612a4e8474882b1c5b7b7, type: 2} +--- !u!95 &113309052 +Animator: + serializedVersion: 3 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 113309044} + m_Enabled: 1 + m_Avatar: {fileID: 0} + m_Controller: {fileID: 9100000, guid: d3af1bb34e9ffb044886be104dc98f2f, type: 2} + m_CullingMode: 0 + m_UpdateMode: 0 + m_ApplyRootMotion: 0 + m_LinearVelocityBlending: 0 + m_WarningMessage: + m_HasTransformHierarchy: 1 + m_AllowConstantClipSamplingOptimization: 1 + m_KeepAnimatorControllerStateOnDisable: 0 --- !u!1 &141597915 GameObject: m_ObjectHideFlags: 0 @@ -657,13 +708,12 @@ MonoBehaviour: m_GameObject: {fileID: 141597915} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Mum portrait: {fileID: 8835284309397123848, guid: 568b897490088f8439d263b261216ec0, type: 3} @@ -674,7 +724,6 @@ MonoBehaviour: - {fileID: 11400000, guid: 9c5ab4e0982fac54ab0e05d0dca4093e, type: 2} - {fileID: 11400000, guid: 2133e95db09dbf34fbd7a3a458719899, type: 2} - {fileID: 11400000, guid: 12bee71ec794d8b4598dce7ff9fa751f, type: 2} - k__BackingField: 0 --- !u!58 &141597917 CircleCollider2D: m_ObjectHideFlags: 0 @@ -1510,19 +1559,17 @@ MonoBehaviour: m_GameObject: {fileID: 511373791} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Goof portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 1038a25bb80e70e4da7c513479466015, type: 2} - {fileID: 11400000, guid: 709ad8f986fdd3442bad33d63bed2752, type: 2} - k__BackingField: 0 --- !u!58 &511373795 CircleCollider2D: m_ObjectHideFlags: 0 @@ -1568,20 +1615,18 @@ MonoBehaviour: m_GameObject: {fileID: 539150545} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Sneeko portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 8c096da2b4b78d14492866a0ace564a7, type: 2} - {fileID: 11400000, guid: 7852df3d4fd29ae498cfed742fd1b8f7, type: 2} - {fileID: 11400000, guid: 2e067e40d2dbdc8499f8b6226f5fccf1, type: 2} - k__BackingField: 0 --- !u!58 &539150547 CircleCollider2D: m_ObjectHideFlags: 0 @@ -1704,18 +1749,16 @@ MonoBehaviour: m_GameObject: {fileID: 561039016} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Random2 portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 19e302e7a2839af46ba37481d3432982, type: 2} - k__BackingField: 0 --- !u!58 &561039018 CircleCollider2D: m_ObjectHideFlags: 0 @@ -1825,13 +1868,12 @@ MonoBehaviour: m_GameObject: {fileID: 608919353} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Jimmy portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: @@ -1839,7 +1881,6 @@ MonoBehaviour: - {fileID: 11400000, guid: ae69f4ad827a0414a91c5ae9bf3b5f7f, type: 2} - {fileID: 11400000, guid: 83b205d62cdb0974393721752ad9e152, type: 2} - {fileID: 11400000, guid: a7387a334354d6349a4477f872978b86, type: 2} - k__BackingField: 0 --- !u!58 &608919355 CircleCollider2D: m_ObjectHideFlags: 0 @@ -2767,20 +2808,18 @@ MonoBehaviour: m_GameObject: {fileID: 940472397} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Waddlesworth portrait: {fileID: -3713467532807335336, guid: 0bbfe1fef35fa2243a811a7b497fb9e2, type: 3} dialogueGraphs: - {fileID: 11400000, guid: e2d41534d805e214b87b7147251687f5, type: 2} - {fileID: 11400000, guid: 48f86ea51390adb459028fd4ce49c74d, type: 2} - k__BackingField: 0 --- !u!58 &940472399 CircleCollider2D: m_ObjectHideFlags: 0 @@ -3076,18 +3115,16 @@ MonoBehaviour: m_GameObject: {fileID: 1047971987} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Random3 portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: fb7221204d8077242a86860ac28961e6, type: 2} - k__BackingField: 0 --- !u!58 &1047971989 CircleCollider2D: m_ObjectHideFlags: 0 @@ -3209,19 +3246,17 @@ MonoBehaviour: m_GameObject: {fileID: 1060987544} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: QueenBee portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: b841a9376d1e11440948e5662caa909b, type: 2} - {fileID: 11400000, guid: 0f47a4bdeaa57fb4cbb71798ddb17b3c, type: 2} - k__BackingField: 0 --- !u!58 &1060987546 CircleCollider2D: m_ObjectHideFlags: 0 @@ -3436,20 +3471,18 @@ MonoBehaviour: m_GameObject: {fileID: 1134476113} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Jimmy portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 8c096da2b4b78d14492866a0ace564a7, type: 2} - {fileID: 11400000, guid: 7852df3d4fd29ae498cfed742fd1b8f7, type: 2} - {fileID: 11400000, guid: 2e067e40d2dbdc8499f8b6226f5fccf1, type: 2} - k__BackingField: 0 --- !u!58 &1134476118 CircleCollider2D: m_ObjectHideFlags: 0 @@ -4369,18 +4402,16 @@ MonoBehaviour: m_GameObject: {fileID: 1398485439} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Interact - tooltip: {fileID: 0} characterName: Picture portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 9ff2ef79ee780e34397408cbe8755f16, type: 2} - k__BackingField: 0 --- !u!58 &1398485441 CircleCollider2D: m_ObjectHideFlags: 0 @@ -4490,18 +4521,16 @@ MonoBehaviour: m_GameObject: {fileID: 1410663226} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk - tooltip: {fileID: 0} characterName: Random1 portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 3e16ea0b8d9fdc04c8742fec90a182d6, type: 2} - k__BackingField: 0 --- !u!58 &1410663228 CircleCollider2D: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/TutorialTown.unity b/Assets/Scenes/TutorialTown.unity index 02eca651..53715377 100644 --- a/Assets/Scenes/TutorialTown.unity +++ b/Assets/Scenes/TutorialTown.unity @@ -908,7 +908,7 @@ MonoBehaviour: m_GameObject: {fileID: 541681862} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, @@ -1317,7 +1317,7 @@ MonoBehaviour: m_GameObject: {fileID: 727577739} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, @@ -1594,15 +1594,14 @@ MonoBehaviour: m_GameObject: {fileID: 996557711} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 7fba3685198575341bfedcdddb0b58fd, type: 3} + m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} m_Name: m_EditorClassIdentifier: tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, type: 3} interactHint: Talk characterName: Jimmy - portrait: {fileID: 9076241471376651639, guid: 93cb617996c05b6489970fc681f440ef, - type: 3} + portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} dialogueGraphs: - {fileID: 11400000, guid: 5b4e3c749eebe4248b38084f7c56a999, type: 2} - {fileID: 11400000, guid: ae69f4ad827a0414a91c5ae9bf3b5f7f, type: 2} From da700e7e7ff0a263aa7379149b4e7b592a9c6746 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 16 Nov 2021 18:53:12 -0800 Subject: [PATCH 21/41] Fix dialogue option timing --- Assets/Scripts/Game/UI/DialoguePanel.cs | 8 ++++--- Assets/Scripts/Game/UI/DialogueSystem.cs | 29 ++++++++++++++---------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Assets/Scripts/Game/UI/DialoguePanel.cs b/Assets/Scripts/Game/UI/DialoguePanel.cs index 55697917..5c354da3 100644 --- a/Assets/Scripts/Game/UI/DialoguePanel.cs +++ b/Assets/Scripts/Game/UI/DialoguePanel.cs @@ -37,12 +37,12 @@ public void SetTarget(NPC target) dialogueName.text = target.CharacterName; } - public void PlayDialogue(string dialogue) + public void PlayDialogue(string dialogue, UnityAction onFinished) { - StartCoroutine(AnimateDialogue(dialogue)); + StartCoroutine(AnimateDialogue(dialogue, onFinished)); } - private IEnumerator AnimateDialogue(string dialogue) + private IEnumerator AnimateDialogue(string dialogue, UnityAction onFinished) { foreach (GameObject go in buttonPool) { @@ -56,6 +56,8 @@ private IEnumerator AnimateDialogue(string dialogue) dialogueText.text = dialogue.Substring(0, index++); yield return letterCooldown; } + + onFinished(); } public void CreateOption(string name, UnityAction listener) diff --git a/Assets/Scripts/Game/UI/DialogueSystem.cs b/Assets/Scripts/Game/UI/DialogueSystem.cs index 6fdeea93..3c822293 100644 --- a/Assets/Scripts/Game/UI/DialogueSystem.cs +++ b/Assets/Scripts/Game/UI/DialogueSystem.cs @@ -14,7 +14,7 @@ public class DialogueSystem : MonoBehaviour private YieldInstruction letterCooldown = new WaitForSeconds(0.05f); private NPC currentTarget; private DialogueGraph currentGraph; - private int currentNode = 0; + private int currentNodeIdx = 0; public void BeginDialogue(NPC target, DialogueGraph graph) { @@ -24,15 +24,15 @@ public void BeginDialogue(NPC target, DialogueGraph graph) HUD.DialoguePanel.Show(); HUD.DialoguePanel.SetTarget(target); - StartCoroutine(ShowDialogue(0)); + ShowDialogue(0); } - private DialogueGraphTransition[] GetTransitionsFor(DialogueGraph graph, int node) + private DialogueGraphTransition[] GetTransitionsFor(DialogueGraph graph, int nodeIdx) { LinkedList transitionsList = new LinkedList(); foreach (DialogueGraphTransition t in graph.transitions) { - if (t.from == node) + if (t.from == nodeIdx) { transitionsList.AddLast(t); } @@ -43,12 +43,16 @@ private DialogueGraphTransition[] GetTransitionsFor(DialogueGraph graph, int nod return transitions; } - private IEnumerator ShowDialogue(int node) + private void ShowDialogue(int nodeIdx) { - currentNode = node; - DialogueGraphNode graphNode = currentGraph.nodes[node]; + currentNodeIdx = nodeIdx; + HUD.DialoguePanel.PlayDialogue(currentGraph.nodes[nodeIdx].body, () => OnDialogueNodeFinished(nodeIdx)); + } + + private void OnDialogueNodeFinished(int nodeIdx) + { + DialogueGraphNode graphNode = currentGraph.nodes[nodeIdx]; string dialogue = graphNode.body; - HUD.DialoguePanel.PlayDialogue(dialogue); // Apply quest notes for this dialogue node after it finishes reading foreach (QuestNote note in graphNode.questNotes) @@ -74,18 +78,18 @@ private IEnumerator ShowDialogue(int node) root.Element.Tick(root, HUD.DialoguePanel.GetComponent()); } - DialogueGraphTransition[] transitions = GetTransitionsFor(currentGraph, node); + // Display transitionss + DialogueGraphTransition[] transitions = GetTransitionsFor(currentGraph, nodeIdx); foreach (DialogueGraphTransition t in transitions) { DialogueGraphNode to = t.to < 0 ? currentGraph.exitNode : currentGraph.nodes[t.to]; HUD.DialoguePanel.CreateOption(to.name, (idx) => OnDialogueOptionClicked(idx)); - yield return letterCooldown; } } private void OnDialogueOptionClicked(int index) { - DialogueGraphTransition[] transitions = GetTransitionsFor(currentGraph, currentNode); + DialogueGraphTransition[] transitions = GetTransitionsFor(currentGraph, currentNodeIdx); DialogueGraphTransition transition = transitions[index]; if (transition.to < 0) { @@ -100,7 +104,8 @@ private void OnDialogueOptionClicked(int index) GameManager.AlignmentSystem.UpdateMorals(graphNode.moralsMod); GameManager.AlignmentSystem.UpdateSexiness(graphNode.sexinessMod); - StartCoroutine(ShowDialogue(transition.to)); + // Show the next dialogue node + ShowDialogue(transition.to); } } } From fa4b30ecf2068bb2c65f5ddfd2f0095ca7c1653b Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 16 Nov 2021 21:45:06 -0800 Subject: [PATCH 22/41] Implement player enable/disable system and forced dialogue node --- Assets/Scripts/Game/Player/Player.cs | 49 ++++++++++++++----- Assets/Scripts/Game/UI/DialogueSystem.cs | 3 ++ .../Behaviour Tree/Nodes/ForceDialogueNode.cs | 18 +++---- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/Assets/Scripts/Game/Player/Player.cs b/Assets/Scripts/Game/Player/Player.cs index f31e2f78..e21e0de8 100644 --- a/Assets/Scripts/Game/Player/Player.cs +++ b/Assets/Scripts/Game/Player/Player.cs @@ -28,6 +28,8 @@ public class Player : Actor public ClassBaseStats ClassBaseStats { get; private set; } + public bool Enabled { get; private set; } + private List availableAbilities; private AbilitySlot[] abilitySlots; private Dictionary equipment; @@ -67,8 +69,9 @@ protected override void Awake() } Equip(ItemSlot.Mainhand, defaultPrimaryWeapon); Equip(ItemSlot.Offhand, defaultSecondaryWeapon); - actionData = new ActionData(LayerMask.GetMask("Enemy")); + + Enabled = true; } void OnGUI() @@ -130,6 +133,9 @@ void OnGUI() protected override void Update() { + // Enabled check: skip updates while not enabled + if (!Enabled) return; + // Handle movement inputs float inputH = Input.GetAxisRaw("Horizontal"); float inputV = Input.GetAxisRaw("Vertical"); @@ -166,6 +172,17 @@ protected override void Update() } } + public void Enable() + { + Enabled = true; + } + + public void Disable() + { + Enabled = false; + ClearInteractions(); + } + public void ApplyClassBaseStats(ClassBaseStats classBaseStats) { ClassBaseStats = classBaseStats; @@ -277,18 +294,8 @@ private IEnumerator AnimationLock() private void UpdateInteractions() { - Interactable interactable; - - // Clear current interactions - for (int i = 0; i < numInteractTargets; i++) - { - Collider2D target = interactTargets[i]; - if (target != null && target.TryGetComponent(out interactable)) - { - interactable.SetTooltipActive(false); - } - } - targetInteractable = null; + // Clear interactions + ClearInteractions(); // Check for nearby interactables numInteractTargets = Physics2D.OverlapCircleNonAlloc(transform.position, interactRadius, interactTargets, interactLayer); @@ -305,11 +312,27 @@ private void UpdateInteractions() } // Set the nearest interactable active + Interactable interactable; if (closestIdx >= 0 && interactTargets[closestIdx].TryGetComponent(out interactable)) { targetInteractable = interactable; interactable.SetTooltipActive(true); } } + + private void ClearInteractions() + { + // Clear current interactions + Interactable interactable; + for (int i = 0; i < numInteractTargets; i++) + { + Collider2D target = interactTargets[i]; + if (target != null && target.TryGetComponent(out interactable)) + { + interactable.SetTooltipActive(false); + } + } + targetInteractable = null; + } } } diff --git a/Assets/Scripts/Game/UI/DialogueSystem.cs b/Assets/Scripts/Game/UI/DialogueSystem.cs index 3c822293..eb49f0ff 100644 --- a/Assets/Scripts/Game/UI/DialogueSystem.cs +++ b/Assets/Scripts/Game/UI/DialogueSystem.cs @@ -18,6 +18,8 @@ public class DialogueSystem : MonoBehaviour public void BeginDialogue(NPC target, DialogueGraph graph) { + GameManager.Player.Disable(); + currentTarget = target; currentGraph = graph; @@ -95,6 +97,7 @@ private void OnDialogueOptionClicked(int index) { // We've reached the end of the tree HUD.DialoguePanel.Hide(); + GameManager.Player.Enable(); } else { diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs index daa3005e..604c4b8a 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs @@ -7,23 +7,19 @@ namespace BehaviourTree { public class ForceDialogueNode : IBehaviourTreeNode { - public void Serialize(Behaviour behaviour) { } public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { - Behaviour behaviour = self.Element; - NPC dialogue = obj.GetComponent(); - Player p = GameObject.FindGameObjectWithTag("Player").GetComponent(); - //Checks if the player or the QuestGiver(DialogueScript later) is null - if (dialogue != null && p != null) + if (obj.TryGetComponent(out NPC npc)) + { + npc.Interact(GameManager.Player); + } + else { - dialogue.Interact(p); - return NodeStatus.Success; + throw new MissingComponentException("Current agent does not have the required NPC component!"); } - return NodeStatus.Failure; + return NodeStatus.Success; } - } - } From df1ebf669094824dba05d61f5c4a787383985cfa Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Sun, 21 Nov 2021 13:59:47 -0800 Subject: [PATCH 23/41] Implement basic enemy/npc conversion and jimmy behaviour tree --- .../Data/Behaviour Trees/JimmyBehaviour.asset | 527 ++++++++++++++++++ .../Behaviour Trees/JimmyBehaviour.asset.meta | 8 + Assets/Scenes/TutorialTown.unity | 12 +- Assets/Scripts/Game/NPC/NPC.cs | 12 + .../BehaviourTreeNodeCreator.cs | 5 +- .../Tools/Behaviour Tree/Nodes/IsEnemyNode.cs | 18 + .../Behaviour Tree/Nodes/IsEnemyNode.cs.meta | 11 + 7 files changed, 587 insertions(+), 6 deletions(-) create mode 100644 Assets/Data/Behaviour Trees/JimmyBehaviour.asset create mode 100644 Assets/Data/Behaviour Trees/JimmyBehaviour.asset.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs.meta diff --git a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset new file mode 100644 index 00000000..e2a5ebc6 --- /dev/null +++ b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset @@ -0,0 +1,527 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54fb5e73c80040247a00b01917c6e426, type: 3} + m_Name: JimmyBehaviour + m_EditorClassIdentifier: + tree: + serializedNodes: + - childCount: 1 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 1 + - childCount: 3 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SelectorNode + firstChildIndex: 2 + - childCount: 4 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 3 + - childCount: 0 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.IsEnemyNode + firstChildIndex: 4 + - childCount: 0 + element: + propertyInfo: + - name: tag-name + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: Player + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: actor-destination + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: player + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.FindActorByTagNode + firstChildIndex: 5 + - childCount: 0 + element: + propertyInfo: + - name: actor-source + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: player + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: position-destination + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: player-pos + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.GetActorPositionNode + firstChildIndex: 6 + - childCount: 2 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SelectorNode + firstChildIndex: 7 + - childCount: 3 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 8 + - childCount: 0 + element: + propertyInfo: + - name: range + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 1.2 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: position-source + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: player-pos + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.RangeCheckNode + firstChildIndex: 9 + - childCount: 0 + element: + propertyInfo: + - name: target-source + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: player-pos + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SetActionTargetNode + firstChildIndex: 10 + - childCount: 0 + element: + propertyInfo: + - name: action-index + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.InvokeActionNode + firstChildIndex: 11 + - childCount: 2 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 12 + - childCount: 0 + element: + propertyInfo: + - name: range + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 4 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: position-source + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: player-pos + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.RangeCheckNode + firstChildIndex: 13 + - childCount: 0 + element: + propertyInfo: + - name: position-source + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: player-pos + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: stop-distance + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 1.2 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: move-speed + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 1.5 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SimpleMoveNode + firstChildIndex: 14 + - childCount: 4 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 15 + - childCount: 0 + element: + propertyInfo: + - name: property-name + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: idle + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.HasPropertyNode + firstChildIndex: 16 + - childCount: 0 + element: + propertyInfo: + - name: source-property + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: idle + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: comparison-bool + property: + propertyType: 0 + objectType: + value: + b: 1 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.BoolEqualsNode + firstChildIndex: 17 + - childCount: 0 + element: + propertyInfo: + - name: idle-duration + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 2 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.IdleNode + firstChildIndex: 18 + - childCount: 0 + element: + propertyInfo: + - name: target-property + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: idle + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: bool-value + property: + propertyType: 0 + objectType: + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SetBoolNode + firstChildIndex: 19 + - childCount: 4 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 20 + - childCount: 0 + element: + propertyInfo: + - name: vector-array + property: + propertyType: 5 + objectType: + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: + - propertyType: 4 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: -8, y: -0.3} + - propertyType: 4 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: -3, y: -0.3} + e: 0 + aType: 4 + - name: index-source + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: patrol-idx + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: vector-destination + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: patrol-pos + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.VectorIteratorNode + firstChildIndex: 21 + - childCount: 0 + element: + propertyInfo: + - name: position-source + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: patrol-pos + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: stop-distance + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 0.1 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: move-speed + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 1 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SimpleMoveNode + firstChildIndex: 22 + - childCount: 0 + element: + propertyInfo: + - name: index-source + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: patrol-idx + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: array-length + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 2 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.ArrayIncrementNode + firstChildIndex: 23 + - childCount: 0 + element: + propertyInfo: + - name: target-property + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: idle + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: bool-value + property: + propertyType: 0 + objectType: + value: + b: 1 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SetBoolNode + firstChildIndex: 24 diff --git a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset.meta b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset.meta new file mode 100644 index 00000000..1a228fad --- /dev/null +++ b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8bd8b783c74999f44b82c57c7c59c5f6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/TutorialTown.unity b/Assets/Scenes/TutorialTown.unity index 53715377..9d5ca659 100644 --- a/Assets/Scenes/TutorialTown.unity +++ b/Assets/Scenes/TutorialTown.unity @@ -1576,8 +1576,8 @@ GameObject: - component: {fileID: 996557717} - component: {fileID: 996557716} - component: {fileID: 996557712} - - component: {fileID: 996557718} - component: {fileID: 996557720} + - component: {fileID: 996557718} m_Layer: 8 m_Name: Jimmy NPC m_TagString: Untagged @@ -1683,7 +1683,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 996557711} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -4.71, y: -0.72, z: 0} + m_LocalPosition: {x: -8, y: -0.3, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -1701,7 +1701,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3841cfd75fe64b8498769758ea31c7be, type: 3} m_Name: m_EditorClassIdentifier: - defaultAnimation: {fileID: 7400000, guid: 9e341e0589474734e85c03acab0bef7d, type: 2} + defaultAnimation: {fileID: 7400000, guid: f3d8518500d6a1f4db92b67fe4d88910, type: 2} --- !u!95 &996557717 Animator: serializedVersion: 3 @@ -1730,13 +1730,15 @@ MonoBehaviour: m_GameObject: {fileID: 996557711} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ff501692e9724c7439955e72bfce135c, type: 3} + m_Script: {fileID: 11500000, guid: 7157c15a42769b0458c85c94a11a8d26, type: 3} m_Name: m_EditorClassIdentifier: initialMaxHealth: 10 idleAnimations: {fileID: 11400000, guid: 5efbdb18b6bca104e927472b7dd579d8, type: 2} moveAnimations: {fileID: 11400000, guid: 23f348e6b58f0704fb0c3669a6b7c8f6, type: 2} hurtAnimations: {fileID: 11400000, guid: 23f348e6b58f0704fb0c3669a6b7c8f6, type: 2} + actions: + - {fileID: 11400000, guid: cd54c1a41bfdb6745b6a33c7b765967e, type: 2} --- !u!50 &996557719 Rigidbody2D: serializedVersion: 4 @@ -1770,7 +1772,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} m_Name: m_EditorClassIdentifier: - behaviourTree: {fileID: 11400000, guid: 75e6ba3057cc6b04e9727d170650b9fe, type: 2} + behaviourTree: {fileID: 11400000, guid: 8bd8b783c74999f44b82c57c7c59c5f6, type: 2} --- !u!1 &1169265892 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Game/NPC/NPC.cs b/Assets/Scripts/Game/NPC/NPC.cs index 1385c185..7bcab25e 100644 --- a/Assets/Scripts/Game/NPC/NPC.cs +++ b/Assets/Scripts/Game/NPC/NPC.cs @@ -22,5 +22,17 @@ public override void Interact(Player player) DialogueGraph graph = dialogueGraphs[ActiveIndex]; GameManager.DialogueSystem.BeginDialogue(this, graph); } + + // TODO: make enemy stuff based on factions! + + public void SetEnemy(bool isEnemy) + { + gameObject.layer = isEnemy ? LayerMask.NameToLayer("Enemy") : LayerMask.NameToLayer("Interactable"); + } + + public bool IsEnemy() + { + return gameObject.layer == LayerMask.NameToLayer("Enemy"); + } } } diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index e9bf55be..b7006b2c 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -28,7 +28,8 @@ public enum BehaviourTreeNodeType ArrayIncrementNode, SetBoolNode, GetMoveDirectionNode, - GetVectorAxisNode + GetVectorAxisNode, + IsEnemyNode, } public static class BehaviourTreeNodeCreator @@ -87,6 +88,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new GetMoveDirectionNode(); case BehaviourTreeNodeType.GetVectorAxisNode: return new GetVectorAxisNode(); + case BehaviourTreeNodeType.IsEnemyNode: + return new IsEnemyNode(); default: Debug.LogError($"Unimplemented node type: {type}"); return null; diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs new file mode 100644 index 00000000..f4d4af0a --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using RPG; + +namespace BehaviourTree +{ + // TODO: turn this into HasFactionNode later! + public class IsEnemyNode : IBehaviourTreeNode + { + public void Serialize(Behaviour behaviour) { } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + return obj.GetComponent().IsEnemy() ? NodeStatus.Success : NodeStatus.Failure; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs.meta new file mode 100644 index 00000000..ed02a736 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b6ab174a2f4541649942f990e0ad1ad2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From ac441d3c210ed2ea753cd38cfbb1926dbb7ea3a4 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 23 Nov 2021 14:29:37 -0800 Subject: [PATCH 24/41] Update UniqueId API --- Assets/Scripts/Game/Core/Entity.cs | 24 ------------------------ Assets/Scripts/Game/Core/UniqueID.cs | 17 +++++++++++++++-- Assets/Scripts/Game/UI/DialogueSystem.cs | 2 +- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/Assets/Scripts/Game/Core/Entity.cs b/Assets/Scripts/Game/Core/Entity.cs index 55b99450..7d1b0715 100644 --- a/Assets/Scripts/Game/Core/Entity.cs +++ b/Assets/Scripts/Game/Core/Entity.cs @@ -12,30 +12,6 @@ public abstract class Entity : MonoBehaviour private Dictionary propertyChangedEvents = new Dictionary(); - ///Returns the Entity matching the given unique id. The desired Entity must have a corresponding UniqueID component. - public static Entity Find(string id) - { - GameObject obj = UniqueID.Get(id); - if (obj == null) - { - Debug.LogWarning($"Entity.Find() failed to find Entity with ID \"{id}\"; returning null."); - return null; - } - return obj.GetComponent(); - } - - ///Returns the Entity matching the given unique id. The desired Entity must have a corresponding UniqueID component. - public static T Find(string id) where T : Entity - { - GameObject obj = UniqueID.Get(id); - if (obj == null) - { - Debug.LogWarning($"Entity.Find() failed to find Entity with ID \"{id}\"; returning null."); - return null; - } - return obj.GetComponent(); - } - public bool HasProperty(PropertyName name) { return properties.HasProperty(name); diff --git a/Assets/Scripts/Game/Core/UniqueID.cs b/Assets/Scripts/Game/Core/UniqueID.cs index 3a72dd4d..884d4810 100644 --- a/Assets/Scripts/Game/Core/UniqueID.cs +++ b/Assets/Scripts/Game/Core/UniqueID.cs @@ -18,10 +18,23 @@ protected void Awake() uniqueObjects.Add(uniqueID, gameObject); } - ///Low-level interface for getting objects by unique ID. You almost always want the Entity.Find() wrapper instead! + ///Low-level interface for getting objects by unique ID. public static GameObject Get(string id) { - return uniqueObjects.ContainsKey(id) ? uniqueObjects[id] : null; + GameObject obj = uniqueObjects.ContainsKey(id) ? uniqueObjects[id] : null; + if (obj == null) + { + Debug.LogWarning($"UniqueID.Get() failed to find Object with ID \"{id}\"; returning null."); + return null; + } + return obj; + } + + ///Low-level generic interface for getting objects by unique ID. + public static T Get(string id) where T : Object + { + GameObject obj = Get(id); + return obj != null ? obj.GetComponent() : null; } private bool ValidateNotEmpty(string uniqueID) diff --git a/Assets/Scripts/Game/UI/DialogueSystem.cs b/Assets/Scripts/Game/UI/DialogueSystem.cs index eb49f0ff..02cb185a 100644 --- a/Assets/Scripts/Game/UI/DialogueSystem.cs +++ b/Assets/Scripts/Game/UI/DialogueSystem.cs @@ -68,7 +68,7 @@ private void OnDialogueNodeFinished(int nodeIdx) NPC target = currentTarget; if (idxOverride.targetUniqueID != "") { - target = Entity.Find(idxOverride.targetUniqueID); + target = UniqueID.Get(idxOverride.targetUniqueID); } target.ActiveIndex = idxOverride.indexOverride; } From b5ad21185b40974d72763065d777b92bd16b5fb1 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 23 Nov 2021 14:29:58 -0800 Subject: [PATCH 25/41] Remove Entity parent from Interactable --- Assets/Scripts/Game/Items/Interactable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Game/Items/Interactable.cs b/Assets/Scripts/Game/Items/Interactable.cs index 8000f3d4..5b2e3516 100644 --- a/Assets/Scripts/Game/Items/Interactable.cs +++ b/Assets/Scripts/Game/Items/Interactable.cs @@ -4,7 +4,7 @@ namespace RPG { - public abstract class Interactable : Entity + public abstract class Interactable : MonoBehaviour { [SerializeField] private Tooltip tooltipPrefab; [SerializeField] [TextArea] private string interactHint; From a68a44e8cfa72d43280e74510500034e62dd788c Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 23 Nov 2021 14:30:40 -0800 Subject: [PATCH 26/41] Change dialogue behaviours to run on current NPC --- Assets/Prefabs/UI/Canvas.prefab | 13 ------------- Assets/Scripts/Game/UI/DialogueSystem.cs | 9 ++++++++- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Assets/Prefabs/UI/Canvas.prefab b/Assets/Prefabs/UI/Canvas.prefab index 81f1ff26..5a1c5a96 100644 --- a/Assets/Prefabs/UI/Canvas.prefab +++ b/Assets/Prefabs/UI/Canvas.prefab @@ -454,7 +454,6 @@ GameObject: - component: {fileID: 1594993686604947230} - component: {fileID: 1594993686604947228} - component: {fileID: 1594993686604947229} - - component: {fileID: 1594993686604947203} - component: {fileID: 216887218} m_Layer: 5 m_Name: DialogueUI @@ -524,18 +523,6 @@ MonoBehaviour: m_FillOrigin: 0 m_UseSpriteMesh: 0 m_PixelsPerUnitMultiplier: 1 ---- !u!114 &1594993686604947203 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1594993686604947231} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 6314624073fd19344a66e0b14acc8eef, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!114 &216887218 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Game/UI/DialogueSystem.cs b/Assets/Scripts/Game/UI/DialogueSystem.cs index 02cb185a..b6e3b969 100644 --- a/Assets/Scripts/Game/UI/DialogueSystem.cs +++ b/Assets/Scripts/Game/UI/DialogueSystem.cs @@ -77,7 +77,14 @@ private void OnDialogueNodeFinished(int nodeIdx) if (graphNode.customBehaviour != null) { Tree.Node root = graphNode.customBehaviour.Root; - root.Element.Tick(root, HUD.DialoguePanel.GetComponent()); + if (currentTarget.TryGetComponent(out BehaviourObject obj)) + { + root.Element.Tick(root, obj); + } + else + { + Debug.LogError("Failed to run custom dialogue behaviour due to target NPC not having a BehaviourObject component!"); + } } // Display transitionss From 14ff5ef180f4bd828fa73f226e00a553e7bde964 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 23 Nov 2021 14:35:26 -0800 Subject: [PATCH 27/41] Implement behaviours for enemy management and update jimmy --- .../Data/Behaviour Trees/JimmyBehaviour.asset | 197 +++++++++++++++--- .../Behaviour Trees/JimmyFightTrigger.asset | 70 +++++++ .../JimmyFightTrigger.asset.meta | 8 + .../In the Street 2/Tutorial-Jimmy.asset | 2 +- Assets/Scenes/TutorialTown.unity | 2 +- .../BehaviourTreeNodeCreator.cs | 12 ++ .../Behaviour Tree/Nodes/ForceDialogueNode.cs | 2 + .../Nodes/GetEntityPropertyNode.cs | 77 +++++++ .../Nodes/GetEntityPropertyNode.cs.meta | 11 + .../Tools/Behaviour Tree/Nodes/GetSelfNode.cs | 25 +++ .../Behaviour Tree/Nodes/GetSelfNode.cs.meta | 11 + .../Behaviour Tree/Nodes/IntLessThanNode.cs | 34 +++ .../Nodes/IntLessThanNode.cs.meta | 11 + .../Tools/Behaviour Tree/Nodes/IsEnemyNode.cs | 12 +- .../Behaviour Tree/Nodes/SetEnemyNode.cs | 37 ++++ .../Behaviour Tree/Nodes/SetEnemyNode.cs.meta | 11 + 16 files changed, 494 insertions(+), 28 deletions(-) create mode 100644 Assets/Data/Behaviour Trees/JimmyFightTrigger.asset create mode 100644 Assets/Data/Behaviour Trees/JimmyFightTrigger.asset.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs.meta create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs.meta diff --git a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset index e2a5ebc6..ba28ebaa 100644 --- a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset +++ b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset @@ -24,16 +24,47 @@ MonoBehaviour: propertyInfo: [] nodeTypeName: BehaviourTree.SelectorNode firstChildIndex: 2 - - childCount: 4 + - childCount: 5 element: propertyInfo: [] nodeTypeName: BehaviourTree.SequenceNode firstChildIndex: 3 - childCount: 0 element: - propertyInfo: [] - nodeTypeName: BehaviourTree.IsEnemyNode + propertyInfo: + - name: object-destination + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: self + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.GetSelfNode firstChildIndex: 4 + - childCount: 0 + element: + propertyInfo: + - name: source-npc + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: self + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.IsEnemyNode + firstChildIndex: 5 - childCount: 0 element: propertyInfo: @@ -64,7 +95,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.FindActorByTagNode - firstChildIndex: 5 + firstChildIndex: 6 - childCount: 0 element: propertyInfo: @@ -95,17 +126,135 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.GetActorPositionNode - firstChildIndex: 6 - - childCount: 2 + firstChildIndex: 7 + - childCount: 3 element: propertyInfo: [] nodeTypeName: BehaviourTree.SelectorNode - firstChildIndex: 7 + firstChildIndex: 8 + - childCount: 4 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 9 + - childCount: 0 + element: + propertyInfo: + - name: property-name + property: + propertyType: 6 + objectType: RPG.PropertyName, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 1 + aType: 0 + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.EntityPropertyReadType, Assembly-CSharp, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: property-destination + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: health + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.GetEntityPropertyNode + firstChildIndex: 10 + - childCount: 0 + element: + propertyInfo: + - name: source-property + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: health + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: comparison-number + property: + propertyType: 1 + objectType: + value: + b: 0 + n: 4 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.IntLessThanNode + firstChildIndex: 11 + - childCount: 0 + element: + propertyInfo: + - name: source-npc + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: self + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: is-enemy + property: + propertyType: 0 + objectType: + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SetEnemyNode + firstChildIndex: 12 + - childCount: 0 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.ForceDialogueNode + firstChildIndex: 13 - childCount: 3 element: propertyInfo: [] nodeTypeName: BehaviourTree.SequenceNode - firstChildIndex: 8 + firstChildIndex: 14 - childCount: 0 element: propertyInfo: @@ -136,7 +285,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.RangeCheckNode - firstChildIndex: 9 + firstChildIndex: 15 - childCount: 0 element: propertyInfo: @@ -154,7 +303,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.SetActionTargetNode - firstChildIndex: 10 + firstChildIndex: 16 - childCount: 0 element: propertyInfo: @@ -172,12 +321,12 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.InvokeActionNode - firstChildIndex: 11 + firstChildIndex: 17 - childCount: 2 element: propertyInfo: [] nodeTypeName: BehaviourTree.SequenceNode - firstChildIndex: 12 + firstChildIndex: 18 - childCount: 0 element: propertyInfo: @@ -208,7 +357,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.RangeCheckNode - firstChildIndex: 13 + firstChildIndex: 19 - childCount: 0 element: propertyInfo: @@ -252,12 +401,12 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.SimpleMoveNode - firstChildIndex: 14 + firstChildIndex: 20 - childCount: 4 element: propertyInfo: [] nodeTypeName: BehaviourTree.SequenceNode - firstChildIndex: 15 + firstChildIndex: 21 - childCount: 0 element: propertyInfo: @@ -275,7 +424,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.HasPropertyNode - firstChildIndex: 16 + firstChildIndex: 22 - childCount: 0 element: propertyInfo: @@ -306,7 +455,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.BoolEqualsNode - firstChildIndex: 17 + firstChildIndex: 23 - childCount: 0 element: propertyInfo: @@ -324,7 +473,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.IdleNode - firstChildIndex: 18 + firstChildIndex: 24 - childCount: 0 element: propertyInfo: @@ -355,12 +504,12 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.SetBoolNode - firstChildIndex: 19 + firstChildIndex: 25 - childCount: 4 element: propertyInfo: [] nodeTypeName: BehaviourTree.SequenceNode - firstChildIndex: 20 + firstChildIndex: 26 - childCount: 0 element: propertyInfo: @@ -418,7 +567,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.VectorIteratorNode - firstChildIndex: 21 + firstChildIndex: 27 - childCount: 0 element: propertyInfo: @@ -462,7 +611,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.SimpleMoveNode - firstChildIndex: 22 + firstChildIndex: 28 - childCount: 0 element: propertyInfo: @@ -493,7 +642,7 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.ArrayIncrementNode - firstChildIndex: 23 + firstChildIndex: 29 - childCount: 0 element: propertyInfo: @@ -524,4 +673,4 @@ MonoBehaviour: e: 0 aType: 0 nodeTypeName: BehaviourTree.SetBoolNode - firstChildIndex: 24 + firstChildIndex: 30 diff --git a/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset b/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset new file mode 100644 index 00000000..6a816f19 --- /dev/null +++ b/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset @@ -0,0 +1,70 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 54fb5e73c80040247a00b01917c6e426, type: 3} + m_Name: JimmyFightTrigger + m_EditorClassIdentifier: + tree: + serializedNodes: + - childCount: 2 + element: + propertyInfo: [] + nodeTypeName: BehaviourTree.SequenceNode + firstChildIndex: 1 + - childCount: 0 + element: + propertyInfo: + - name: object-destination + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: self + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.GetSelfNode + firstChildIndex: 2 + - childCount: 0 + element: + propertyInfo: + - name: source-npc + property: + propertyType: 2 + objectType: + value: + b: 0 + n: 0 + s: self + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: is-enemy + property: + propertyType: 0 + objectType: + value: + b: 1 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + nodeTypeName: BehaviourTree.SetEnemyNode + firstChildIndex: 3 diff --git a/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset.meta b/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset.meta new file mode 100644 index 00000000..80d81d4b --- /dev/null +++ b/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d69f03b258b57d142aedb2501fb2a531 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Data/Dialogue Graphs/Tutorial Dialogue/In the Street 2/Tutorial-Jimmy.asset b/Assets/Data/Dialogue Graphs/Tutorial Dialogue/In the Street 2/Tutorial-Jimmy.asset index 9147338f..7f3fbd8e 100644 --- a/Assets/Data/Dialogue Graphs/Tutorial Dialogue/In the Street 2/Tutorial-Jimmy.asset +++ b/Assets/Data/Dialogue Graphs/Tutorial Dialogue/In the Street 2/Tutorial-Jimmy.asset @@ -60,7 +60,7 @@ MonoBehaviour: dialogueIndexOverrides: - targetUniqueID: indexOverride: 1 - customBehaviour: {fileID: 0} + customBehaviour: {fileID: 11400000, guid: d69f03b258b57d142aedb2501fb2a531, type: 2} transitions: - name: Transition from: 0 diff --git a/Assets/Scenes/TutorialTown.unity b/Assets/Scenes/TutorialTown.unity index 9d5ca659..378b97a8 100644 --- a/Assets/Scenes/TutorialTown.unity +++ b/Assets/Scenes/TutorialTown.unity @@ -1733,7 +1733,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7157c15a42769b0458c85c94a11a8d26, type: 3} m_Name: m_EditorClassIdentifier: - initialMaxHealth: 10 + initialMaxHealth: 8 idleAnimations: {fileID: 11400000, guid: 5efbdb18b6bca104e927472b7dd579d8, type: 2} moveAnimations: {fileID: 11400000, guid: 23f348e6b58f0704fb0c3669a6b7c8f6, type: 2} hurtAnimations: {fileID: 11400000, guid: 23f348e6b58f0704fb0c3669a6b7c8f6, type: 2} diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index b7006b2c..bb6eda78 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -9,10 +9,12 @@ public enum BehaviourTreeNodeType ExecuteAllNode, SuccessNode, NotNode, + IntLessThanNode, IntEqualsNode, BoolEqualsNode, HasPropertyNode, RangeCheckNode, + GetSelfNode, FindActorByTagNode, FindObjectByIdNode, GetActorPositionNode, @@ -29,7 +31,9 @@ public enum BehaviourTreeNodeType SetBoolNode, GetMoveDirectionNode, GetVectorAxisNode, + SetEnemyNode, IsEnemyNode, + GetEntityPropertyNode, } public static class BehaviourTreeNodeCreator @@ -48,6 +52,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new SuccessNode(); case BehaviourTreeNodeType.NotNode: return new NotNode(); + case BehaviourTreeNodeType.IntLessThanNode: + return new IntLessThanNode(); case BehaviourTreeNodeType.IntEqualsNode: return new IntEqualsNode(); case BehaviourTreeNodeType.BoolEqualsNode: @@ -56,6 +62,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new HasPropertyNode(); case BehaviourTreeNodeType.RangeCheckNode: return new RangeCheckNode(); + case BehaviourTreeNodeType.GetSelfNode: + return new GetSelfNode(); case BehaviourTreeNodeType.FindActorByTagNode: return new FindActorByTagNode(); case BehaviourTreeNodeType.FindObjectByIdNode: @@ -88,8 +96,12 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new GetMoveDirectionNode(); case BehaviourTreeNodeType.GetVectorAxisNode: return new GetVectorAxisNode(); + case BehaviourTreeNodeType.SetEnemyNode: + return new SetEnemyNode(); case BehaviourTreeNodeType.IsEnemyNode: return new IsEnemyNode(); + case BehaviourTreeNodeType.GetEntityPropertyNode: + return new GetEntityPropertyNode(); default: Debug.LogError($"Unimplemented node type: {type}"); return null; diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs index 604c4b8a..8bafda20 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs @@ -11,8 +11,10 @@ public void Serialize(Behaviour behaviour) { } public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { + Debug.Log("FORCING DIALOGUE"); if (obj.TryGetComponent(out NPC npc)) { + Debug.Log("FORCED"); npc.Interact(GameManager.Player); } else diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs new file mode 100644 index 00000000..3167e9cb --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs @@ -0,0 +1,77 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using RPG; + +namespace BehaviourTree +{ + public enum EntityPropertyReadType { Int, Float, Bool, String } // TODO: replace with RPG.PropertyType (git gud) + + public class GetEntityPropertyNode : IBehaviourTreeNode + { + private const string PROP_NAME = "property-name"; + private const string PROP_TYPE = "property-type"; + private const string PROP_DEST = "property-destination"; + + public void Serialize(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_NAME, new VariableProperty(VariableProperty.Type.Enum, typeof(RPG.PropertyName))); + behaviour.Properties.Add(PROP_TYPE, new VariableProperty(VariableProperty.Type.Enum, typeof(EntityPropertyReadType))); + behaviour.Properties.Add(PROP_DEST, new VariableProperty(VariableProperty.Type.String)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + Debug.Log("CHECKING HEALTHHHHH"); + + Entity entity = null; + if (!obj.TryGetComponent(out entity)) + { + Debug.LogError("Attempted to use GetEntityPropertyNode with no Entity component!"); + return NodeStatus.Failure; + } + + RPG.PropertyName propName = behaviour.GetProperty(PROP_NAME).GetEnum(); + Debug.Log(propName); + foreach (var p in entity.Properties) + { + Debug.Log(p.Key); + Debug.Log(p.Value); + } + if (!entity.HasProperty(propName)) + { + Debug.Log("PROP NOT FOUND!!"); + return NodeStatus.Failure; + } + + EntityPropertyReadType readType = behaviour.GetProperty(PROP_TYPE).GetEnum(); + string propDest = behaviour.GetProperty(PROP_DEST).GetString(); + switch (readType) + { + case EntityPropertyReadType.Int: + int iVal = entity.GetProperty(propName); + obj.SetProperty(propDest, iVal); + Debug.Log("READING INT VALUE: " + iVal); + break; + case EntityPropertyReadType.Float: + float fVal = entity.GetProperty(propName); + obj.SetProperty(propDest, fVal); + break; + case EntityPropertyReadType.Bool: + bool bVal = entity.GetProperty(propName); + obj.SetProperty(propDest, bVal); + break; + case EntityPropertyReadType.String: + string sVal = entity.GetProperty(propName); + obj.SetProperty(propDest, sVal); + break; + } + + Debug.Log("READ THAT SHIII: " + obj.GetProperty(propDest).ToString()); + + return NodeStatus.Success; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs.meta new file mode 100644 index 00000000..c074145f --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 193d41c42c68dfe40ad39bb6318ab988 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs new file mode 100644 index 00000000..3eebd8e9 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using RPG; + +namespace BehaviourTree +{ + public class GetSelfNode : IBehaviourTreeNode + { + private const string PROP_OBJECT_DEST = "object-destination"; + + public void Serialize(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_OBJECT_DEST, new VariableProperty(VariableProperty.Type.String)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + string dest = behaviour.GetProperty(PROP_OBJECT_DEST).GetString(); + obj.SetProperty(dest, obj.gameObject); + return NodeStatus.Success; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs.meta new file mode 100644 index 00000000..7c750a98 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 22ab99dc6cd71b64e9d6556fe2abe378 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs new file mode 100644 index 00000000..7bc667c7 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + public class IntLessThanNode : IBehaviourTreeNode + { + private const string PROP_SOURCE = "source-property"; + private const string PROP_NUMBER = "comparison-number"; + + public void Serialize(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_SOURCE, new VariableProperty(VariableProperty.Type.String)); + behaviour.Properties.Add(PROP_NUMBER, new VariableProperty(VariableProperty.Type.Number)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + Debug.Log("CHECKING LESS THAN"); + + string source = behaviour.GetProperty(PROP_SOURCE).GetString(); + int num1 = (int)obj.GetProperty(source); + int num2 = (int)behaviour.GetProperty(PROP_NUMBER).GetNumber(); + if (num1 < num2) return NodeStatus.Success; + + Debug.Log("NOT LESS THAN"); + + return NodeStatus.Failure; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs.meta new file mode 100644 index 00000000..69029129 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dd8b2df639481a949867fa9374c4f146 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs index f4d4af0a..25266e36 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IsEnemyNode.cs @@ -8,11 +8,19 @@ namespace BehaviourTree // TODO: turn this into HasFactionNode later! public class IsEnemyNode : IBehaviourTreeNode { - public void Serialize(Behaviour behaviour) { } + private const string PROP_NPC_SRC = "source-npc"; + + public void Serialize(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_NPC_SRC, new VariableProperty(VariableProperty.Type.String)); + } public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { - return obj.GetComponent().IsEnemy() ? NodeStatus.Success : NodeStatus.Failure; + Behaviour behaviour = self.Element; + string npcSrc = behaviour.GetProperty(PROP_NPC_SRC).GetString(); + GameObject npc = obj.GetProperty(npcSrc) as GameObject; + return npc.GetComponent().IsEnemy() ? NodeStatus.Success : NodeStatus.Failure; } } } diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs new file mode 100644 index 00000000..6c2e99ed --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using RPG; + +namespace BehaviourTree +{ + // TODO: turn this into SetFactionNode later! + public class SetEnemyNode : IBehaviourTreeNode + { + private const string PROP_NPC_SRC = "source-npc"; + private const string PROP_IS_ENEMY = "is-enemy"; + + public void Serialize(Behaviour behaviour) + { + behaviour.Properties.Add(PROP_NPC_SRC, new VariableProperty(VariableProperty.Type.String)); + behaviour.Properties.Add(PROP_IS_ENEMY, new VariableProperty(VariableProperty.Type.Boolean)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + Debug.Log("SETTING ENEMY!"); + + // Get NPC + string npcSrc = behaviour.GetProperty(PROP_NPC_SRC).GetString(); + GameObject npc = obj.GetProperty(npcSrc) as GameObject; + + // Set enemy status + bool isEnemy = behaviour.GetProperty(PROP_IS_ENEMY).GetBoolean(); + npc.GetComponent().SetEnemy(isEnemy); + + return NodeStatus.Success; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs.meta new file mode 100644 index 00000000..7255a3d2 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 07541633d309568428db2bd9093e7a87 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 4887777b085eddde0144a88d83c1db0ae18f8e6b Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 23 Nov 2021 17:04:06 -0800 Subject: [PATCH 28/41] Implement DILF system --- .../Data/Behaviour Trees/AnimatedEnemy.asset | 7 ++ Assets/Data/Behaviour Trees/ExampleNPC.asset | 50 ++++++++- .../Data/Behaviour Trees/JimmyBehaviour.asset | 106 +++++++++++++++++- .../Behaviour Trees/JimmyFightTrigger.asset | 3 + .../Data/Behaviour Trees/NPC FollowTree.asset | 7 ++ Assets/Data/Behaviour Trees/SneekoTest.asset | 42 ++++++- Assets/Data/Behaviour Trees/Test Tree.asset | 25 +++++ Assets/Scenes/Main.unity | 13 +++ .../Scripts/Editor/BehaviourTreeInspector.cs | 66 +++++++++-- .../BehaviourTreeNodeCreator.cs | 3 + .../Tools/Behaviour Tree/Nodes/CompareNode.cs | 100 +++++++++++++++++ .../Behaviour Tree/Nodes/CompareNode.cs.meta | 11 ++ Assets/Scripts/Utils/VariableProperty.cs | 21 +++- 13 files changed, 430 insertions(+), 24 deletions(-) create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/CompareNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/CompareNode.cs.meta diff --git a/Assets/Data/Behaviour Trees/AnimatedEnemy.asset b/Assets/Data/Behaviour Trees/AnimatedEnemy.asset index d2210b31..ab3b2065 100644 --- a/Assets/Data/Behaviour Trees/AnimatedEnemy.asset +++ b/Assets/Data/Behaviour Trees/AnimatedEnemy.asset @@ -41,6 +41,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -59,6 +60,7 @@ MonoBehaviour: property: propertyType: 4 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -72,6 +74,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0.1 @@ -85,6 +88,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -103,6 +107,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -116,6 +121,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0.1 @@ -129,6 +135,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0.8 diff --git a/Assets/Data/Behaviour Trees/ExampleNPC.asset b/Assets/Data/Behaviour Trees/ExampleNPC.asset index 195ec20b..91c3e20c 100644 --- a/Assets/Data/Behaviour Trees/ExampleNPC.asset +++ b/Assets/Data/Behaviour Trees/ExampleNPC.asset @@ -36,6 +36,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -50,10 +51,41 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.CompareNode+CompareType, Assembly-CSharp, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 2 + aType: 0 + - name: operator + property: + propertyType: 6 + objectType: BehaviourTree.CompareNode+OperatorType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 0 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 - name: source-property property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -63,10 +95,11 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: comparison-bool + - name: comparator property: propertyType: 0 objectType: + forceReserialization: 0 value: b: 1 n: 0 @@ -76,7 +109,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.BoolEqualsNode + nodeTypeName: BehaviourTree.CompareNode firstChildIndex: 5 - childCount: 0 element: @@ -85,6 +118,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 3 @@ -103,6 +137,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -116,6 +151,7 @@ MonoBehaviour: property: propertyType: 0 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -139,6 +175,7 @@ MonoBehaviour: property: propertyType: 5 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -173,6 +210,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -186,6 +224,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -204,6 +243,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -217,6 +257,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0.2 @@ -230,6 +271,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 1.5 @@ -248,6 +290,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -261,6 +304,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 3 @@ -279,6 +323,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -292,6 +337,7 @@ MonoBehaviour: property: propertyType: 0 objectType: + forceReserialization: 0 value: b: 1 n: 0 diff --git a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset index ba28ebaa..d79cbe9a 100644 --- a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset +++ b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset @@ -36,6 +36,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -54,6 +55,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -72,6 +74,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -85,6 +88,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -103,6 +107,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -116,6 +121,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -145,6 +151,7 @@ MonoBehaviour: propertyType: 6 objectType: RPG.PropertyName, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 0 value: b: 0 n: 0 @@ -159,6 +166,7 @@ MonoBehaviour: propertyType: 6 objectType: BehaviourTree.EntityPropertyReadType, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 0 value: b: 0 n: 0 @@ -172,6 +180,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -186,10 +195,41 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.CompareNode+CompareType, Assembly-CSharp, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: operator + property: + propertyType: 6 + objectType: BehaviourTree.CompareNode+OperatorType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 0 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 1 + aType: 0 - name: source-property property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -199,10 +239,11 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: comparison-number + - name: comparator property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 4 @@ -212,7 +253,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.IntLessThanNode + nodeTypeName: BehaviourTree.CompareNode firstChildIndex: 11 - childCount: 0 element: @@ -221,6 +262,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -234,6 +276,7 @@ MonoBehaviour: property: propertyType: 0 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -262,6 +305,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 1.2 @@ -275,6 +319,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -293,6 +338,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -311,6 +357,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -334,6 +381,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 4 @@ -347,6 +395,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -365,6 +414,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -378,6 +428,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 1.2 @@ -391,6 +442,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 1.5 @@ -414,6 +466,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -428,10 +481,41 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.CompareNode+CompareType, Assembly-CSharp, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 2 + aType: 0 + - name: operator + property: + propertyType: 6 + objectType: BehaviourTree.CompareNode+OperatorType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 0 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 - name: source-property property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -441,10 +525,11 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: comparison-bool + - name: comparator property: propertyType: 0 objectType: + forceReserialization: 0 value: b: 1 n: 0 @@ -454,7 +539,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.BoolEqualsNode + nodeTypeName: BehaviourTree.CompareNode firstChildIndex: 23 - childCount: 0 element: @@ -463,6 +548,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 2 @@ -481,6 +567,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -494,6 +581,7 @@ MonoBehaviour: property: propertyType: 0 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -517,6 +605,7 @@ MonoBehaviour: property: propertyType: 5 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -544,6 +633,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -557,6 +647,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -575,6 +666,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -588,6 +680,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0.1 @@ -601,6 +694,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 1 @@ -619,6 +713,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -632,6 +727,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 2 @@ -650,6 +746,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -663,6 +760,7 @@ MonoBehaviour: property: propertyType: 0 objectType: + forceReserialization: 0 value: b: 1 n: 0 diff --git a/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset b/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset index 6a816f19..6ad70a6a 100644 --- a/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset +++ b/Assets/Data/Behaviour Trees/JimmyFightTrigger.asset @@ -26,6 +26,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -44,6 +45,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -57,6 +59,7 @@ MonoBehaviour: property: propertyType: 0 objectType: + forceReserialization: 0 value: b: 1 n: 0 diff --git a/Assets/Data/Behaviour Trees/NPC FollowTree.asset b/Assets/Data/Behaviour Trees/NPC FollowTree.asset index f3c9cccc..1608a89c 100644 --- a/Assets/Data/Behaviour Trees/NPC FollowTree.asset +++ b/Assets/Data/Behaviour Trees/NPC FollowTree.asset @@ -26,6 +26,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -39,6 +40,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -57,6 +59,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -70,6 +73,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -88,6 +92,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -101,6 +106,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 2 @@ -114,6 +120,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 10 diff --git a/Assets/Data/Behaviour Trees/SneekoTest.asset b/Assets/Data/Behaviour Trees/SneekoTest.asset index 6e28100d..521796c9 100644 --- a/Assets/Data/Behaviour Trees/SneekoTest.asset +++ b/Assets/Data/Behaviour Trees/SneekoTest.asset @@ -26,6 +26,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -39,6 +40,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -57,6 +59,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -70,6 +73,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -84,10 +88,41 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.CompareNode+CompareType, Assembly-CSharp, Version=0.0.0.0, + Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 + - name: operator + property: + propertyType: 6 + objectType: BehaviourTree.CompareNode+OperatorType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 0 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 0 + aType: 0 - name: source-property property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -97,10 +132,11 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: comparison-number + - name: comparator property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -110,7 +146,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.IntEqualsNode + nodeTypeName: BehaviourTree.CompareNode firstChildIndex: 4 - childCount: 0 element: @@ -119,6 +155,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -132,6 +169,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 2 diff --git a/Assets/Data/Behaviour Trees/Test Tree.asset b/Assets/Data/Behaviour Trees/Test Tree.asset index 867d8b46..87a28418 100644 --- a/Assets/Data/Behaviour Trees/Test Tree.asset +++ b/Assets/Data/Behaviour Trees/Test Tree.asset @@ -26,6 +26,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -39,6 +40,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -57,6 +59,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -70,6 +73,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -98,6 +102,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 1.1 @@ -111,6 +116,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -129,6 +135,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -147,6 +154,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -170,6 +178,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 3 @@ -183,6 +192,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -201,6 +211,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -214,6 +225,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 1 @@ -227,6 +239,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 2 @@ -265,6 +278,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -283,6 +297,7 @@ MonoBehaviour: property: propertyType: 4 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -296,6 +311,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 3 @@ -309,6 +325,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -332,6 +349,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0.2 @@ -345,6 +363,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -363,6 +382,7 @@ MonoBehaviour: property: propertyType: 4 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -376,6 +396,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 3 @@ -389,6 +410,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -412,6 +434,7 @@ MonoBehaviour: property: propertyType: 2 objectType: + forceReserialization: 0 value: b: 0 n: 0 @@ -425,6 +448,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0.1 @@ -438,6 +462,7 @@ MonoBehaviour: property: propertyType: 1 objectType: + forceReserialization: 0 value: b: 0 n: 0.8 diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index fd3feb01..1b6b8320 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -1478,6 +1478,7 @@ GameObject: - component: {fileID: 511373792} - component: {fileID: 511373795} - component: {fileID: 511373794} + - component: {fileID: 511373796} m_Layer: 8 m_Name: TestNPC m_TagString: Untagged @@ -1586,6 +1587,18 @@ CircleCollider2D: m_Offset: {x: 0, y: 0} serializedVersion: 2 m_Radius: 0.32188842 +--- !u!114 &511373796 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 511373791} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 6314624073fd19344a66e0b14acc8eef, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &539150545 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Editor/BehaviourTreeInspector.cs b/Assets/Scripts/Editor/BehaviourTreeInspector.cs index 335f1f11..b22bff89 100644 --- a/Assets/Scripts/Editor/BehaviourTreeInspector.cs +++ b/Assets/Scripts/Editor/BehaviourTreeInspector.cs @@ -40,7 +40,8 @@ public override void OnInspectorGUI() GUILayout.Label(name); foreach (string propertyName in node.Properties.Keys) { - DisplayProperty(propertyName, node.Properties[propertyName]); + bool reserializing = DisplayProperty(propertyName, node.Properties[propertyName]); + if (reserializing) break; } serializedObject.ApplyModifiedProperties(); @@ -48,12 +49,12 @@ public override void OnInspectorGUI() Repaint(); } - private void DisplayProperty(string name, VariableProperty property) + private bool DisplayProperty(string name, VariableProperty property) { if (property.PropertyType == VariableProperty.Type.Array) { DisplayArray(name, property); - return; + return false; } GUILayout.BeginHorizontal(); @@ -62,29 +63,72 @@ private void DisplayProperty(string name, VariableProperty property) switch (property.PropertyType) { case VariableProperty.Type.Boolean: - property.Set(GUILayout.Toggle(property.GetBoolean(), GUIContent.none)); + bool bPrev = property.GetBoolean(); + bool bNew = GUILayout.Toggle(bPrev, GUIContent.none); + property.Set(bNew); + if (property.ForceReserialization && bPrev != bNew) + { + selected.Node.Serialize(selected); + return true; + } break; case VariableProperty.Type.Number: - property.Set(EditorGUILayout.DoubleField(property.GetNumber())); + double nPrev = property.GetNumber(); + double nNew = EditorGUILayout.DoubleField(nPrev); + property.Set(nNew); + if (property.ForceReserialization && nPrev != nNew) + { + selected.Node.Serialize(selected); + return true; + } break; case VariableProperty.Type.String: - property.Set(GUILayout.TextField(property.GetString())); + string sPrev = property.GetString(); + string sNew = GUILayout.TextField(sPrev); + property.Set(sNew); + if (property.ForceReserialization && sPrev != sNew) + { + selected.Node.Serialize(selected); + return true; + } break; case VariableProperty.Type.Object: - property.Set(EditorGUILayout.ObjectField(property.GetObject(), property.ObjectType, true)); + Object oPrev = property.GetObject(); + Object oNew = EditorGUILayout.ObjectField(oPrev, property.ObjectType, true); + property.Set(oNew); + if (property.ForceReserialization && oPrev != oNew) + { + selected.Node.Serialize(selected); + return true; + } break; case VariableProperty.Type.Vector: - property.Set(EditorGUILayout.Vector2Field("", property.GetVector())); + Vector2 vPrev = property.GetVector(); + Vector2 vNew = EditorGUILayout.Vector2Field("", vPrev); + property.Set(vNew); + if (property.ForceReserialization && vPrev != vNew) + { + selected.Node.Serialize(selected); + return true; + } break; case VariableProperty.Type.Enum: - System.Enum eVal = (System.Enum)System.Enum.ToObject(property.ObjectType, property.GetEnum()); + int ePrev = property.GetEnum(); + System.Enum eVal = (System.Enum)System.Enum.ToObject(property.ObjectType, ePrev); string sResult = EditorGUILayout.EnumPopup(eVal).ToString(); - int iResult = (int)System.Enum.Parse(property.ObjectType, sResult); - property.Set(iResult); + int eNew = (int)System.Enum.Parse(property.ObjectType, sResult); + property.Set(eNew); + if (property.ForceReserialization && ePrev != eNew) + { + selected.Node.Serialize(selected); + return true; + } break; } GUILayout.EndHorizontal(); + + return false; } private void DisplayArray(string name, VariableProperty property) diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index bb6eda78..70ff0a4f 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -9,6 +9,7 @@ public enum BehaviourTreeNodeType ExecuteAllNode, SuccessNode, NotNode, + CompareNode, IntLessThanNode, IntEqualsNode, BoolEqualsNode, @@ -52,6 +53,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new SuccessNode(); case BehaviourTreeNodeType.NotNode: return new NotNode(); + case BehaviourTreeNodeType.CompareNode: + return new CompareNode(); case BehaviourTreeNodeType.IntLessThanNode: return new IntLessThanNode(); case BehaviourTreeNodeType.IntEqualsNode: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/CompareNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/CompareNode.cs new file mode 100644 index 00000000..40fa24ee --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/CompareNode.cs @@ -0,0 +1,100 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + public class CompareNode : IBehaviourTreeNode + { + private enum CompareType { Int, Double, Bool, String, Vector } + private enum OperatorType { Equals, LessThan, GreaterThan } + + private const string PROP_TYPE = "property-type"; + private const string PROP_OPERATOR = "operator"; + private const string PROP_SOURCE = "source-property"; + private const string PROP_COMPARATOR = "comparator"; + + public void Serialize(Behaviour behaviour) + { + if (!behaviour.Properties.ContainsKey(PROP_TYPE)) + { + behaviour.SetProperty(PROP_TYPE, new VariableProperty(VariableProperty.Type.Enum, typeof(CompareType), true)); + } + CompareType comparatorType = behaviour.GetProperty(PROP_TYPE).GetEnum(); + behaviour.SetProperty(PROP_OPERATOR, new VariableProperty(VariableProperty.Type.Enum, typeof(OperatorType))); + behaviour.SetProperty(PROP_SOURCE, new VariableProperty(VariableProperty.Type.String)); + behaviour.SetProperty(PROP_COMPARATOR, new VariableProperty(ToPropertyType(comparatorType))); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + string source = behaviour.GetProperty(PROP_SOURCE).GetString(); + CompareType compareType = behaviour.GetProperty(PROP_TYPE).GetEnum(); + OperatorType operatorType = behaviour.GetProperty(PROP_OPERATOR).GetEnum(); + + bool success = false; + switch (compareType) + { + case CompareType.Int: + int i1 = (int)obj.GetProperty(source); + int i2 = (int)behaviour.GetProperty(PROP_COMPARATOR).GetNumber(); + success = Compare(i1, i2, operatorType); + break; + case CompareType.Double: + double d1 = (double)obj.GetProperty(source); + double d2 = behaviour.GetProperty(PROP_COMPARATOR).GetNumber(); + success = Compare(d1, d2, operatorType); + break; + case CompareType.Bool: + bool b1 = (bool)obj.GetProperty(source); + bool b2 = behaviour.GetProperty(PROP_COMPARATOR).GetBoolean(); + success = Compare(b1, b2, operatorType); + break; + case CompareType.String: + string s1 = (string)obj.GetProperty(source); + string s2 = behaviour.GetProperty(PROP_COMPARATOR).GetString(); + success = Compare(s1, s2, operatorType); + break; + case CompareType.Vector: + Vector2 v1 = (Vector2)obj.GetProperty(source); + Vector2 v2 = behaviour.GetProperty(PROP_COMPARATOR).GetVector(); + success = Compare(v1.sqrMagnitude, v2.sqrMagnitude, operatorType); + break; + } + return success ? NodeStatus.Success : NodeStatus.Failure; + } + + private VariableProperty.Type ToPropertyType(CompareType compareType) + { + switch (compareType) + { + case CompareType.Int: + case CompareType.Double: + return VariableProperty.Type.Number; + case CompareType.Bool: + return VariableProperty.Type.Boolean; + case CompareType.String: + return VariableProperty.Type.String; + case CompareType.Vector: + return VariableProperty.Type.Vector; + } + return VariableProperty.Type.Number; + } + + private bool Compare(T a, T b, OperatorType operation) where T : System.IComparable + { + switch (operation) + { + case OperatorType.Equals: + return a.CompareTo(b) == 0; + case OperatorType.LessThan: + return a.CompareTo(b) < 0; + case OperatorType.GreaterThan: + return a.CompareTo(b) > 0; + } + return false; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/CompareNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/CompareNode.cs.meta new file mode 100644 index 00000000..e2f1e8c1 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/CompareNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 62d9153d9a1afc042acbeb72d5b4aff7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Utils/VariableProperty.cs b/Assets/Scripts/Utils/VariableProperty.cs index 2c3ffe92..bc6eb02f 100644 --- a/Assets/Scripts/Utils/VariableProperty.cs +++ b/Assets/Scripts/Utils/VariableProperty.cs @@ -21,27 +21,36 @@ public System.Type ObjectType private set => objectType = value.AssemblyQualifiedName; } + [SerializeField] private bool forceReserialization; + public bool ForceReserialization + { + get => forceReserialization; + private set => forceReserialization = value; + } + [SerializeField] private Value value; [SerializeField] private Type aType; - public VariableProperty(Type type) + public VariableProperty(Type type, bool forceReserialization = false) { if (type == Type.Object) Debug.LogError("ERROR: Attempting to use Object-based VariableProperty constructor with no Object type! You must specify the Object type!"); if (type == Type.Array) Debug.LogError("ERROR: Attempting to use Array-based VariableProperty constructor with no Array type! You must specify the Array type!"); PropertyType = type; value = new Value(); + ForceReserialization = forceReserialization; } - public VariableProperty(Type type, System.Type objectType) + public VariableProperty(Type type, System.Type objectType, bool forceReserialization = false) { if (type != Type.Object && type != Type.Enum) Debug.LogError("ERROR: Attempting to use Object/Enum-based VariableProperty constructor with non-Object/Enum type!"); PropertyType = type; ObjectType = objectType; value = new Value(); if (type == Type.Enum) Set(0); + ForceReserialization = forceReserialization; } - public VariableProperty(Type type, Type arrayType) + public VariableProperty(Type type, Type arrayType, bool forceReserialization = false) { if (type != Type.Array) Debug.LogError("ERROR: Attempting to use Array-based VariableProperty constructor with non-Array type!"); if (arrayType == Type.Object) Debug.LogError("ERROR: Attempting to use Array-of-Objects-based VariableProperty constructor with no Object type! You must specify the Object type!"); @@ -49,9 +58,10 @@ public VariableProperty(Type type, Type arrayType) PropertyType = Type.Array; aType = arrayType; value = new Value(); + ForceReserialization = forceReserialization; } - public VariableProperty(Type type, Type arrayType, System.Type objectType) + public VariableProperty(Type type, Type arrayType, System.Type objectType, bool forceReserialization = false) { if (type != Type.Array) Debug.LogError("ERROR: Attempting to use Array-based VariableProperty constructor with non-Array type!"); if (arrayType == Type.Array) Debug.LogError("ERROR: VariableProperty Array type cannot have nested Arrays!"); @@ -59,6 +69,7 @@ public VariableProperty(Type type, Type arrayType, System.Type objectType) aType = arrayType; ObjectType = objectType; value = new Value(); + ForceReserialization = forceReserialization; } public bool GetBoolean() @@ -152,7 +163,7 @@ public object[] GetArray() } return result; } - + public Type GetArrayType() { if (PropertyType != Type.Array) throw new InvalidOperationException("This property is not an array type."); From 40ab692cb19278444f724c6b7981bbe88ce12dab Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Wed, 24 Nov 2021 15:10:40 -0800 Subject: [PATCH 29/41] Remove now-unused comparison nodes --- .../Behaviour Tree/Nodes/BoolEqualsNode.cs | 30 ---------------- .../Nodes/BoolEqualsNode.cs.meta | 11 ------ .../Behaviour Tree/Nodes/IntEqualsNode.cs | 30 ---------------- .../Nodes/IntEqualsNode.cs.meta | 11 ------ .../Behaviour Tree/Nodes/IntLessThanNode.cs | 34 ------------------- .../Nodes/IntLessThanNode.cs.meta | 11 ------ 6 files changed, 127 deletions(-) delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs.meta delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs.meta delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs.meta diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs deleted file mode 100644 index 59c3e16b..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace BehaviourTree -{ - public class BoolEqualsNode : IBehaviourTreeNode - { - private const string PROP_SOURCE = "source-property"; - private const string PROP_BOOL = "comparison-bool"; - - public void Serialize(Behaviour behaviour) - { - behaviour.Properties.Add(PROP_SOURCE, new VariableProperty(VariableProperty.Type.String)); - behaviour.Properties.Add(PROP_BOOL, new VariableProperty(VariableProperty.Type.Boolean)); - } - - public NodeStatus Tick(Tree.Node self, BehaviourObject obj) - { - Behaviour behaviour = self.Element; - - string source = behaviour.GetProperty(PROP_SOURCE).GetString(); - bool bool1 = (bool)obj.GetProperty(source); - bool bool2 = behaviour.GetProperty(PROP_BOOL).GetBoolean(); - if (bool1 == bool2) return NodeStatus.Success; - - return NodeStatus.Failure; - } - } -} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs.meta deleted file mode 100644 index 23c06837..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/BoolEqualsNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3d070b572db5c71448046aa2c8ebd8cb -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs deleted file mode 100644 index eab6b6b4..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace BehaviourTree -{ - public class IntEqualsNode : IBehaviourTreeNode - { - private const string PROP_SOURCE = "source-property"; - private const string PROP_NUMBER = "comparison-number"; - - public void Serialize(Behaviour behaviour) - { - behaviour.Properties.Add(PROP_SOURCE, new VariableProperty(VariableProperty.Type.String)); - behaviour.Properties.Add(PROP_NUMBER, new VariableProperty(VariableProperty.Type.Number)); - } - - public NodeStatus Tick(Tree.Node self, BehaviourObject obj) - { - Behaviour behaviour = self.Element; - - string source = behaviour.GetProperty(PROP_SOURCE).GetString(); - int num1 = (int)obj.GetProperty(source); - int num2 = (int)behaviour.GetProperty(PROP_NUMBER).GetNumber(); - if (num1 == num2) return NodeStatus.Success; - - return NodeStatus.Failure; - } - } -} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs.meta deleted file mode 100644 index d1120b86..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntEqualsNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 2f3c96ed6d2244642ab00c01103c4876 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs deleted file mode 100644 index 7bc667c7..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace BehaviourTree -{ - public class IntLessThanNode : IBehaviourTreeNode - { - private const string PROP_SOURCE = "source-property"; - private const string PROP_NUMBER = "comparison-number"; - - public void Serialize(Behaviour behaviour) - { - behaviour.Properties.Add(PROP_SOURCE, new VariableProperty(VariableProperty.Type.String)); - behaviour.Properties.Add(PROP_NUMBER, new VariableProperty(VariableProperty.Type.Number)); - } - - public NodeStatus Tick(Tree.Node self, BehaviourObject obj) - { - Behaviour behaviour = self.Element; - - Debug.Log("CHECKING LESS THAN"); - - string source = behaviour.GetProperty(PROP_SOURCE).GetString(); - int num1 = (int)obj.GetProperty(source); - int num2 = (int)behaviour.GetProperty(PROP_NUMBER).GetNumber(); - if (num1 < num2) return NodeStatus.Success; - - Debug.Log("NOT LESS THAN"); - - return NodeStatus.Failure; - } - } -} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs.meta deleted file mode 100644 index 69029129..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/IntLessThanNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: dd8b2df639481a949867fa9374c4f146 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From 31360ddd6024c306973f1aae59590ddb41073e87 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Wed, 24 Nov 2021 15:22:15 -0800 Subject: [PATCH 30/41] Update BehaviourTreeNodeCreator.cs --- .../Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index 70ff0a4f..ec4591be 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -10,9 +10,6 @@ public enum BehaviourTreeNodeType SuccessNode, NotNode, CompareNode, - IntLessThanNode, - IntEqualsNode, - BoolEqualsNode, HasPropertyNode, RangeCheckNode, GetSelfNode, @@ -55,12 +52,6 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new NotNode(); case BehaviourTreeNodeType.CompareNode: return new CompareNode(); - case BehaviourTreeNodeType.IntLessThanNode: - return new IntLessThanNode(); - case BehaviourTreeNodeType.IntEqualsNode: - return new IntEqualsNode(); - case BehaviourTreeNodeType.BoolEqualsNode: - return new BoolEqualsNode(); case BehaviourTreeNodeType.HasPropertyNode: return new HasPropertyNode(); case BehaviourTreeNodeType.RangeCheckNode: From 50b9962e52f3f21a13bf50cebb7f8d33365b15ab Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 25 Nov 2021 15:45:43 -0800 Subject: [PATCH 31/41] Implement DILF-based set property node --- Assets/Data/Behaviour Trees/ExampleNPC.asset | 38 +++++++++- .../Data/Behaviour Trees/JimmyBehaviour.asset | 38 +++++++++- .../BehaviourTreeNodeCreator.cs | 6 +- .../Tools/Behaviour Tree/Nodes/SetBoolNode.cs | 29 ------- .../Behaviour Tree/Nodes/SetPropertyNode.cs | 76 +++++++++++++++++++ ...olNode.cs.meta => SetPropertyNode.cs.meta} | 2 +- 6 files changed, 148 insertions(+), 41 deletions(-) delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/SetPropertyNode.cs rename Assets/Scripts/Tools/Behaviour Tree/Nodes/{SetBoolNode.cs.meta => SetPropertyNode.cs.meta} (83%) diff --git a/Assets/Data/Behaviour Trees/ExampleNPC.asset b/Assets/Data/Behaviour Trees/ExampleNPC.asset index 91c3e20c..14b3438e 100644 --- a/Assets/Data/Behaviour Trees/ExampleNPC.asset +++ b/Assets/Data/Behaviour Trees/ExampleNPC.asset @@ -133,6 +133,21 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.SetPropertyNode+ValueType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 2 + aType: 0 - name: target-property property: propertyType: 2 @@ -147,7 +162,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: bool-value + - name: property-value property: propertyType: 0 objectType: @@ -161,7 +176,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.SetBoolNode + nodeTypeName: BehaviourTree.SetPropertyNode firstChildIndex: 7 - childCount: 4 element: @@ -319,6 +334,21 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.SetPropertyNode+ValueType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 2 + aType: 0 - name: target-property property: propertyType: 2 @@ -333,7 +363,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: bool-value + - name: property-value property: propertyType: 0 objectType: @@ -347,5 +377,5 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.SetBoolNode + nodeTypeName: BehaviourTree.SetPropertyNode firstChildIndex: 12 diff --git a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset index d79cbe9a..1c89e2e3 100644 --- a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset +++ b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset @@ -563,6 +563,21 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.SetPropertyNode+ValueType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 2 + aType: 0 - name: target-property property: propertyType: 2 @@ -577,7 +592,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: bool-value + - name: property-value property: propertyType: 0 objectType: @@ -591,7 +606,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.SetBoolNode + nodeTypeName: BehaviourTree.SetPropertyNode firstChildIndex: 25 - childCount: 4 element: @@ -742,6 +757,21 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.SetPropertyNode+ValueType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 2 + aType: 0 - name: target-property property: propertyType: 2 @@ -756,7 +786,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: bool-value + - name: property-value property: propertyType: 0 objectType: @@ -770,5 +800,5 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.SetBoolNode + nodeTypeName: BehaviourTree.SetPropertyNode firstChildIndex: 30 diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index ec4591be..574b9882 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -11,6 +11,7 @@ public enum BehaviourTreeNodeType NotNode, CompareNode, HasPropertyNode, + SetPropertyNode, RangeCheckNode, GetSelfNode, FindActorByTagNode, @@ -26,7 +27,6 @@ public enum BehaviourTreeNodeType ForceDialogueNode, VectorIteratorNode, ArrayIncrementNode, - SetBoolNode, GetMoveDirectionNode, GetVectorAxisNode, SetEnemyNode, @@ -54,6 +54,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new CompareNode(); case BehaviourTreeNodeType.HasPropertyNode: return new HasPropertyNode(); + case BehaviourTreeNodeType.SetPropertyNode: + return new SetPropertyNode(); case BehaviourTreeNodeType.RangeCheckNode: return new RangeCheckNode(); case BehaviourTreeNodeType.GetSelfNode: @@ -84,8 +86,6 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new VectorIteratorNode(); case BehaviourTreeNodeType.ArrayIncrementNode: return new ArrayIncrementNode(); - case BehaviourTreeNodeType.SetBoolNode: - return new SetBoolNode(); case BehaviourTreeNodeType.GetMoveDirectionNode: return new GetMoveDirectionNode(); case BehaviourTreeNodeType.GetVectorAxisNode: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs deleted file mode 100644 index fb6c1448..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace BehaviourTree -{ - public class SetBoolNode : IBehaviourTreeNode - { - private const string PROP_TARGET = "target-property"; - private const string PROP_VALUE = "bool-value"; - - public void Serialize(Behaviour behaviour) - { - behaviour.Properties.Add(PROP_TARGET, new VariableProperty(VariableProperty.Type.String)); - behaviour.Properties.Add(PROP_VALUE, new VariableProperty(VariableProperty.Type.Boolean)); - } - - public NodeStatus Tick(Tree.Node self, BehaviourObject obj) - { - Behaviour behaviour = self.Element; - - string target = behaviour.GetProperty(PROP_TARGET).GetString(); - bool val = behaviour.GetProperty(PROP_VALUE).GetBoolean(); - obj.SetProperty(target, val); - - return NodeStatus.Failure; - } - } -} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetPropertyNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetPropertyNode.cs new file mode 100644 index 00000000..d4abb618 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetPropertyNode.cs @@ -0,0 +1,76 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + public class SetPropertyNode : IBehaviourTreeNode + { + private enum ValueType { Int, Double, Bool, String, Vector } + + private const string PROP_TYPE = "property-type"; + private const string PROP_TARGET = "target-property"; + private const string PROP_VALUE = "property-value"; + + public void Serialize(Behaviour behaviour) + { + if (!behaviour.Properties.ContainsKey(PROP_TYPE)) + { + behaviour.SetProperty(PROP_TYPE, new VariableProperty(VariableProperty.Type.Enum, typeof(ValueType), true)); + } + ValueType valueType = behaviour.GetProperty(PROP_TYPE).GetEnum(); + behaviour.SetProperty(PROP_TARGET, new VariableProperty(VariableProperty.Type.String)); + behaviour.SetProperty(PROP_VALUE, new VariableProperty(ToPropertyType(valueType))); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + string target = behaviour.GetProperty(PROP_TARGET).GetString(); + ValueType valueType = behaviour.GetProperty(PROP_TYPE).GetEnum(); + switch (valueType) + { + case ValueType.Int: + int iVal = (int)behaviour.GetProperty(PROP_VALUE).GetNumber(); + obj.SetProperty(target, iVal); + break; + case ValueType.Double: + double dVal = behaviour.GetProperty(PROP_VALUE).GetNumber(); + obj.SetProperty(target, dVal); + break; + case ValueType.Bool: + bool bVal = behaviour.GetProperty(PROP_VALUE).GetBoolean(); + obj.SetProperty(target, bVal); + break; + case ValueType.String: + string sVal = behaviour.GetProperty(PROP_VALUE).GetString(); + obj.SetProperty(target, sVal); + break; + case ValueType.Vector: + Vector2 vVal = behaviour.GetProperty(PROP_VALUE).GetVector(); + obj.SetProperty(target, vVal); + break; + } + + return NodeStatus.Success; + } + + private VariableProperty.Type ToPropertyType(ValueType valueType) + { + switch (valueType) + { + case ValueType.Int: + case ValueType.Double: + return VariableProperty.Type.Number; + case ValueType.Bool: + return VariableProperty.Type.Boolean; + case ValueType.String: + return VariableProperty.Type.String; + case ValueType.Vector: + return VariableProperty.Type.Vector; + } + return VariableProperty.Type.Number; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetPropertyNode.cs.meta similarity index 83% rename from Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs.meta rename to Assets/Scripts/Tools/Behaviour Tree/Nodes/SetPropertyNode.cs.meta index 67093edc..2b9c7b35 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetBoolNode.cs.meta +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetPropertyNode.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: baa536f3743e08942a2ebf3388ae6dd4 +guid: 8e86ff3a5538cf64f8d4242a9eb5c794 MonoImporter: externalObjects: {} serializedVersion: 2 From b4d5df307713461fda1dc1c91282cc3688e387e3 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 25 Nov 2021 15:53:53 -0800 Subject: [PATCH 32/41] Remove behaviour debug logging --- .../Data/Behaviour Trees/JimmyBehaviour.asset | 4 +-- .../Behaviour Tree/Nodes/ForceDialogueNode.cs | 2 -- .../Nodes/GetEntityPropertyNode.cs | 28 +++++-------------- .../Behaviour Tree/Nodes/SetEnemyNode.cs | 2 -- 4 files changed, 9 insertions(+), 27 deletions(-) diff --git a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset index 1c89e2e3..f8bc7566 100644 --- a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset +++ b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset @@ -164,8 +164,8 @@ MonoBehaviour: - name: property-type property: propertyType: 6 - objectType: BehaviourTree.EntityPropertyReadType, Assembly-CSharp, Version=0.0.0.0, - Culture=neutral, PublicKeyToken=null + objectType: RPG.PropertyType, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null forceReserialization: 0 value: b: 0 diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs index 8bafda20..604c4b8a 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ForceDialogueNode.cs @@ -11,10 +11,8 @@ public void Serialize(Behaviour behaviour) { } public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { - Debug.Log("FORCING DIALOGUE"); if (obj.TryGetComponent(out NPC npc)) { - Debug.Log("FORCED"); npc.Interact(GameManager.Player); } else diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs index 3167e9cb..dfa84b0d 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetEntityPropertyNode.cs @@ -5,8 +5,6 @@ namespace BehaviourTree { - public enum EntityPropertyReadType { Int, Float, Bool, String } // TODO: replace with RPG.PropertyType (git gud) - public class GetEntityPropertyNode : IBehaviourTreeNode { private const string PROP_NAME = "property-name"; @@ -16,7 +14,7 @@ public class GetEntityPropertyNode : IBehaviourTreeNode public void Serialize(Behaviour behaviour) { behaviour.Properties.Add(PROP_NAME, new VariableProperty(VariableProperty.Type.Enum, typeof(RPG.PropertyName))); - behaviour.Properties.Add(PROP_TYPE, new VariableProperty(VariableProperty.Type.Enum, typeof(EntityPropertyReadType))); + behaviour.Properties.Add(PROP_TYPE, new VariableProperty(VariableProperty.Type.Enum, typeof(PropertyType))); behaviour.Properties.Add(PROP_DEST, new VariableProperty(VariableProperty.Type.String)); } @@ -24,53 +22,41 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { Behaviour behaviour = self.Element; - Debug.Log("CHECKING HEALTHHHHH"); - Entity entity = null; if (!obj.TryGetComponent(out entity)) { - Debug.LogError("Attempted to use GetEntityPropertyNode with no Entity component!"); return NodeStatus.Failure; } RPG.PropertyName propName = behaviour.GetProperty(PROP_NAME).GetEnum(); - Debug.Log(propName); - foreach (var p in entity.Properties) - { - Debug.Log(p.Key); - Debug.Log(p.Value); - } if (!entity.HasProperty(propName)) { - Debug.Log("PROP NOT FOUND!!"); + Debug.LogWarning("Warning: target entity " + entity.name + " does not have property " + propName); return NodeStatus.Failure; } - EntityPropertyReadType readType = behaviour.GetProperty(PROP_TYPE).GetEnum(); + PropertyType readType = behaviour.GetProperty(PROP_TYPE).GetEnum(); string propDest = behaviour.GetProperty(PROP_DEST).GetString(); switch (readType) { - case EntityPropertyReadType.Int: + case PropertyType.Int: int iVal = entity.GetProperty(propName); obj.SetProperty(propDest, iVal); - Debug.Log("READING INT VALUE: " + iVal); break; - case EntityPropertyReadType.Float: + case PropertyType.Float: float fVal = entity.GetProperty(propName); obj.SetProperty(propDest, fVal); break; - case EntityPropertyReadType.Bool: + case PropertyType.Bool: bool bVal = entity.GetProperty(propName); obj.SetProperty(propDest, bVal); break; - case EntityPropertyReadType.String: + case PropertyType.String: string sVal = entity.GetProperty(propName); obj.SetProperty(propDest, sVal); break; } - Debug.Log("READ THAT SHIII: " + obj.GetProperty(propDest).ToString()); - return NodeStatus.Success; } } diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs index 6c2e99ed..3d26d993 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/SetEnemyNode.cs @@ -21,8 +21,6 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) { Behaviour behaviour = self.Element; - Debug.Log("SETTING ENEMY!"); - // Get NPC string npcSrc = behaviour.GetProperty(PROP_NPC_SRC).GetString(); GameObject npc = obj.GetProperty(npcSrc) as GameObject; From 4b4c0c7141e38e1b4aa5aa9ac4c1e8cf72194e20 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 25 Nov 2021 16:30:08 -0800 Subject: [PATCH 33/41] Implement DILF-based array nodes --- Assets/Data/Behaviour Trees/ExampleNPC.asset | 29 +++++-- .../Data/Behaviour Trees/JimmyBehaviour.asset | 21 ++++- .../BehaviourTreeNodeCreator.cs | 3 + .../Behaviour Tree/Nodes/ArrayIteratorNode.cs | 87 +++++++++++++++++++ .../Nodes/ArrayIteratorNode.cs.meta | 11 +++ 5 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIteratorNode.cs create mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIteratorNode.cs.meta diff --git a/Assets/Data/Behaviour Trees/ExampleNPC.asset b/Assets/Data/Behaviour Trees/ExampleNPC.asset index 14b3438e..2f458b2d 100644 --- a/Assets/Data/Behaviour Trees/ExampleNPC.asset +++ b/Assets/Data/Behaviour Trees/ExampleNPC.asset @@ -186,7 +186,22 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: - - name: vector-array + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.ArrayIteratorNode+ValueType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 4 + aType: 0 + - name: value-array property: propertyType: 5 objectType: @@ -229,13 +244,13 @@ MonoBehaviour: value: b: 0 n: 0 - s: patrol-index + s: patrol-idx o: {fileID: 0} v: {x: 0, y: 0} a: [] e: 0 aType: 0 - - name: vector-destination + - name: value-destination property: propertyType: 2 objectType: @@ -243,13 +258,13 @@ MonoBehaviour: value: b: 0 n: 0 - s: patrol-vector + s: patrol-pos o: {fileID: 0} v: {x: 0, y: 0} a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.VectorIteratorNode + nodeTypeName: BehaviourTree.ArrayIteratorNode firstChildIndex: 9 - childCount: 0 element: @@ -262,7 +277,7 @@ MonoBehaviour: value: b: 0 n: 0 - s: patrol-vector + s: patrol-pos o: {fileID: 0} v: {x: 0, y: 0} a: [] @@ -309,7 +324,7 @@ MonoBehaviour: value: b: 0 n: 0 - s: patrol-index + s: patrol-idx o: {fileID: 0} v: {x: 0, y: 0} a: [] diff --git a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset index f8bc7566..cd7882ce 100644 --- a/Assets/Data/Behaviour Trees/JimmyBehaviour.asset +++ b/Assets/Data/Behaviour Trees/JimmyBehaviour.asset @@ -616,7 +616,22 @@ MonoBehaviour: - childCount: 0 element: propertyInfo: - - name: vector-array + - name: property-type + property: + propertyType: 6 + objectType: BehaviourTree.ArrayIteratorNode+ValueType, Assembly-CSharp, + Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + forceReserialization: 1 + value: + b: 0 + n: 0 + s: + o: {fileID: 0} + v: {x: 0, y: 0} + a: [] + e: 4 + aType: 0 + - name: value-array property: propertyType: 5 objectType: @@ -658,7 +673,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - - name: vector-destination + - name: value-destination property: propertyType: 2 objectType: @@ -672,7 +687,7 @@ MonoBehaviour: a: [] e: 0 aType: 0 - nodeTypeName: BehaviourTree.VectorIteratorNode + nodeTypeName: BehaviourTree.ArrayIteratorNode firstChildIndex: 27 - childCount: 0 element: diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index 574b9882..72463882 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -26,6 +26,7 @@ public enum BehaviourTreeNodeType SetDialogueIndexNode, ForceDialogueNode, VectorIteratorNode, + ArrayIteratorNode, ArrayIncrementNode, GetMoveDirectionNode, GetVectorAxisNode, @@ -84,6 +85,8 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new ForceDialogueNode(); case BehaviourTreeNodeType.VectorIteratorNode: return new VectorIteratorNode(); + case BehaviourTreeNodeType.ArrayIteratorNode: + return new ArrayIteratorNode(); case BehaviourTreeNodeType.ArrayIncrementNode: return new ArrayIncrementNode(); case BehaviourTreeNodeType.GetMoveDirectionNode: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIteratorNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIteratorNode.cs new file mode 100644 index 00000000..84093854 --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIteratorNode.cs @@ -0,0 +1,87 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace BehaviourTree +{ + public class ArrayIteratorNode : IBehaviourTreeNode + { + private enum ValueType { Int, Double, Bool, String, Vector } + + private const string PROP_TYPE = "property-type"; + private const string PROP_ARRAY = "value-array"; + private const string PROP_INDEX_SRC = "index-source"; + private const string PROP_VALUE_DEST = "value-destination"; + + public void Serialize(Behaviour behaviour) + { + if (!behaviour.Properties.ContainsKey(PROP_TYPE)) + { + behaviour.SetProperty(PROP_TYPE, new VariableProperty(VariableProperty.Type.Enum, typeof(ValueType), true)); + } + ValueType valueType = behaviour.GetProperty(PROP_TYPE).GetEnum(); + behaviour.SetProperty(PROP_ARRAY, new VariableProperty(VariableProperty.Type.Array, ToPropertyType(valueType))); + behaviour.SetProperty(PROP_INDEX_SRC, new VariableProperty(VariableProperty.Type.String)); + behaviour.SetProperty(PROP_VALUE_DEST, new VariableProperty(VariableProperty.Type.String)); + } + + public NodeStatus Tick(Tree.Node self, BehaviourObject obj) + { + Behaviour behaviour = self.Element; + + // read the current index from the agent (or set to zero if not exists) + int index = 0; + string indexSrc = behaviour.GetProperty(PROP_INDEX_SRC).GetString(); + if (obj.HasProperty(indexSrc)) + { + index = (int)obj.GetProperty(indexSrc); + } + + // get the value at the current index + object[] arr = behaviour.GetProperty(PROP_ARRAY).GetArray(); + object val = null; + ValueType valueType = behaviour.GetProperty(PROP_TYPE).GetEnum(); + switch (valueType) + { + case ValueType.Int: + val = (int)arr[index]; + break; + case ValueType.Double: + val = (double)arr[index]; + break; + case ValueType.Bool: + val = (bool)arr[index]; + break; + case ValueType.String: + val = (string)arr[index]; + break; + case ValueType.Vector: + val = (Vector2)arr[index]; + break; + } + + // store the resulting value on the agent + string valueDest = behaviour.GetProperty(PROP_VALUE_DEST).GetString(); + obj.SetProperty(valueDest, val); + + return NodeStatus.Success; + } + + private VariableProperty.Type ToPropertyType(ValueType valueType) + { + switch (valueType) + { + case ValueType.Int: + case ValueType.Double: + return VariableProperty.Type.Number; + case ValueType.Bool: + return VariableProperty.Type.Boolean; + case ValueType.String: + return VariableProperty.Type.String; + case ValueType.Vector: + return VariableProperty.Type.Vector; + } + return VariableProperty.Type.Number; + } + } +} diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIteratorNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIteratorNode.cs.meta new file mode 100644 index 00000000..2b25149c --- /dev/null +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIteratorNode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2b55e72d0d3822546b3d3178a5a43c8a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From aa3cb14b648439178f79b3dbe04c1b11498c4fff Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 25 Nov 2021 19:00:47 -0800 Subject: [PATCH 34/41] Force disable NPC movement during dialogue --- Assets/Scenes/TutorialTown.unity | 2 +- Assets/Scripts/Game/Core/Actor.cs | 9 +++++++++ Assets/Scripts/Game/Player/Player.cs | 20 +------------------- Assets/Scripts/Game/UI/DialogueSystem.cs | 13 +++++++++++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Assets/Scenes/TutorialTown.unity b/Assets/Scenes/TutorialTown.unity index 378b97a8..06740cdf 100644 --- a/Assets/Scenes/TutorialTown.unity +++ b/Assets/Scenes/TutorialTown.unity @@ -1752,7 +1752,7 @@ Rigidbody2D: m_UseFullKinematicContacts: 0 m_UseAutoMass: 0 m_Mass: 1 - m_LinearDrag: 0 + m_LinearDrag: 10 m_AngularDrag: 0.05 m_GravityScale: 1 m_Material: {fileID: 0} diff --git a/Assets/Scripts/Game/Core/Actor.cs b/Assets/Scripts/Game/Core/Actor.cs index da4bffec..6d61526c 100644 --- a/Assets/Scripts/Game/Core/Actor.cs +++ b/Assets/Scripts/Game/Core/Actor.cs @@ -38,10 +38,14 @@ public int Health private UnityEvent onDeath = new UnityEvent(); public UnityEvent OnDeath { get => onDeath; } + private UnityEvent onPositionChanged = new UnityEvent(); + public UnityEvent OnPositionChanged { get => onPositionChanged; } + protected ActionData actionData; protected Vector2Int facingDirection; protected new Rigidbody2D rigidbody2D; protected Animator2D animator2D; + private Vector3 prevFramePosition; protected virtual void Awake() { @@ -59,6 +63,9 @@ protected virtual void Awake() protected virtual void Update() { + // Update position info + if (transform.position != prevFramePosition) onPositionChanged.Invoke(transform.position); + // Animate movement if (GetMoveDirection() != Vector2Int.zero) { @@ -68,6 +75,8 @@ protected virtual void Update() { AnimateIdle(); } + + prevFramePosition = transform.position; } public virtual void TakeDamage(int damage) diff --git a/Assets/Scripts/Game/Player/Player.cs b/Assets/Scripts/Game/Player/Player.cs index e21e0de8..4607d64a 100644 --- a/Assets/Scripts/Game/Player/Player.cs +++ b/Assets/Scripts/Game/Player/Player.cs @@ -28,8 +28,6 @@ public class Player : Actor public ClassBaseStats ClassBaseStats { get; private set; } - public bool Enabled { get; private set; } - private List availableAbilities; private AbilitySlot[] abilitySlots; private Dictionary equipment; @@ -39,7 +37,6 @@ public class Player : Actor private bool isGCDActive; private bool isAnimLocked; - private Vector3 prevFramePosition; private Collider2D[] interactTargets = new Collider2D[MAX_INTERACT_TARGETS]; private int numInteractTargets = 0; private Interactable targetInteractable; @@ -47,8 +44,6 @@ public class Player : Actor private YieldInstruction animLockInstruction; private YieldInstruction globalCooldownInstruction; - private UnityEvent onPositionChanged = new UnityEvent(); - protected override void Awake() { base.Awake(); @@ -70,8 +65,6 @@ protected override void Awake() Equip(ItemSlot.Mainhand, defaultPrimaryWeapon); Equip(ItemSlot.Offhand, defaultSecondaryWeapon); actionData = new ActionData(LayerMask.GetMask("Enemy")); - - Enabled = true; } void OnGUI() @@ -133,18 +126,13 @@ void OnGUI() protected override void Update() { - // Enabled check: skip updates while not enabled - if (!Enabled) return; - // Handle movement inputs float inputH = Input.GetAxisRaw("Horizontal"); float inputV = Input.GetAxisRaw("Vertical"); Vector2 inputDir = new Vector2(inputH, inputV).normalized; // Update position - prevFramePosition = transform.position; rigidbody2D.velocity = inputDir * moveSpeed; - if (transform.position != prevFramePosition) onPositionChanged.Invoke(transform.position); // Run base Actor update base.Update(); @@ -172,14 +160,8 @@ protected override void Update() } } - public void Enable() - { - Enabled = true; - } - - public void Disable() + protected void OnDisable() { - Enabled = false; ClearInteractions(); } diff --git a/Assets/Scripts/Game/UI/DialogueSystem.cs b/Assets/Scripts/Game/UI/DialogueSystem.cs index b6e3b969..e6cad8e2 100644 --- a/Assets/Scripts/Game/UI/DialogueSystem.cs +++ b/Assets/Scripts/Game/UI/DialogueSystem.cs @@ -18,7 +18,12 @@ public class DialogueSystem : MonoBehaviour public void BeginDialogue(NPC target, DialogueGraph graph) { - GameManager.Player.Disable(); + // Disable actions of interacting entities + GameManager.Player.enabled = false; + if (target.TryGetComponent(out BehaviourObject obj)) + { + obj.enabled = false; + } currentTarget = target; currentGraph = graph; @@ -104,7 +109,11 @@ private void OnDialogueOptionClicked(int index) { // We've reached the end of the tree HUD.DialoguePanel.Hide(); - GameManager.Player.Enable(); + GameManager.Player.enabled = true; + if (currentTarget.TryGetComponent(out BehaviourObject obj)) + { + obj.enabled = true; + } } else { From 213e784d8b20fc9cbb24ffa15df23bd5e3770bc0 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 2 Dec 2021 22:43:55 -0800 Subject: [PATCH 35/41] Remove BaseNPC class --- Assets/Scenes/Main.unity | 241 +----------------------- Assets/Scripts/Game/NPC/BaseNPC.cs | 49 ----- Assets/Scripts/Game/NPC/BaseNPC.cs.meta | 11 -- 3 files changed, 9 insertions(+), 292 deletions(-) delete mode 100644 Assets/Scripts/Game/NPC/BaseNPC.cs delete mode 100644 Assets/Scripts/Game/NPC/BaseNPC.cs.meta diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 1b6b8320..f42d9643 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -487,7 +487,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 23 + m_RootOrder: 22 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &113309044 GameObject: @@ -1851,7 +1851,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 21 + m_RootOrder: 20 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &608919353 GameObject: @@ -1973,7 +1973,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 25 + m_RootOrder: 24 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &624982963 GameObject: @@ -2913,7 +2913,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 24 + m_RootOrder: 23 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &940472402 MonoBehaviour: @@ -3217,7 +3217,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 22 + m_RootOrder: 21 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1056019372 stripped MonoBehaviour: @@ -3349,7 +3349,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 26 + m_RootOrder: 25 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1085417769 stripped MonoBehaviour: @@ -3407,229 +3407,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &1134476113 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1134476120} - - component: {fileID: 1134476119} - - component: {fileID: 1134476118} - - component: {fileID: 1134476117} - - component: {fileID: 1134476116} - - component: {fileID: 1134476115} - - component: {fileID: 1134476114} - - component: {fileID: 1134476123} - - component: {fileID: 1134476122} - - component: {fileID: 1134476121} - m_Layer: 8 - m_Name: TestCompanion - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 0 ---- !u!114 &1134476114 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 255646b43a4b22b4586a6b091e9ce397, type: 3} - m_Name: - m_EditorClassIdentifier: - behaviourTree: {fileID: 11400000, guid: 5022140c4fe67e1489a5b6e3f5ff71f2, type: 2} ---- !u!114 &1134476115 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c5dd1dec152424544a6fcae9ff825aa6, type: 3} - m_Name: - m_EditorClassIdentifier: - initialMaxHealth: 0 - idleAnimations: {fileID: 11400000, guid: fb206d7e94c25e94b899ed54a07145c6, type: 2} - moveAnimations: {fileID: 11400000, guid: e22d4c8424148f645ae60e803585d737, type: 2} - hurtAnimations: {fileID: 11400000, guid: 1fce7b2292cd9e545984412811fa1820, type: 2} - interactionDistance: 5 ---- !u!114 &1134476116 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ebc071df6b26c2c4682605f65e5c191c, type: 3} - m_Name: - m_EditorClassIdentifier: - uniqueID: Jimmy ---- !u!114 &1134476117 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 82d10099f0b38ec40b917b3fa80f253e, type: 3} - m_Name: - m_EditorClassIdentifier: - tooltipPrefab: {fileID: 7921253115471860706, guid: 1ff60417f84c75a4b929b73aa77269b9, - type: 3} - interactHint: Talk - characterName: Jimmy - portrait: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} - dialogueGraphs: - - {fileID: 11400000, guid: 8c096da2b4b78d14492866a0ace564a7, type: 2} - - {fileID: 11400000, guid: 7852df3d4fd29ae498cfed742fd1b8f7, type: 2} - - {fileID: 11400000, guid: 2e067e40d2dbdc8499f8b6226f5fccf1, type: 2} ---- !u!58 &1134476118 -CircleCollider2D: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_Enabled: 1 - m_Density: 1 - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_UsedByEffector: 0 - m_UsedByComposite: 0 - m_Offset: {x: 0, y: 0} - serializedVersion: 2 - m_Radius: 0.5 ---- !u!212 &1134476119 -SpriteRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_Enabled: 1 - m_CastShadows: 0 - m_ReceiveShadows: 0 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 0 - m_RayTraceProcedural: 0 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 1 - m_SelectedEditorRenderState: 0 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_Sprite: {fileID: 21300000, guid: d58d73c2ff94bc84e88ee2cf8e12bc09, type: 3} - m_Color: {r: 1, g: 0.33490568, b: 0.9581065, a: 1} - m_FlipX: 0 - m_FlipY: 0 - m_DrawMode: 0 - m_Size: {x: 0.5859375, y: 0.64377683} - m_AdaptiveModeThreshold: 0.5 - m_SpriteTileMode: 0 - m_WasSpriteAssigned: 1 - m_MaskInteraction: 0 - m_SpriteSortPoint: 0 ---- !u!4 &1134476120 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 4.54, y: -0.63, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 17 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1134476121 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 3841cfd75fe64b8498769758ea31c7be, type: 3} - m_Name: - m_EditorClassIdentifier: - defaultAnimation: {fileID: 7400000, guid: 511c335ee19612a4e8474882b1c5b7b7, type: 2} ---- !u!95 &1134476122 -Animator: - serializedVersion: 3 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_Enabled: 1 - m_Avatar: {fileID: 0} - m_Controller: {fileID: 9100000, guid: d3af1bb34e9ffb044886be104dc98f2f, type: 2} - m_CullingMode: 0 - m_UpdateMode: 0 - m_ApplyRootMotion: 0 - m_LinearVelocityBlending: 0 - m_WarningMessage: - m_HasTransformHierarchy: 1 - m_AllowConstantClipSamplingOptimization: 1 - m_KeepAnimatorControllerStateOnDisable: 0 ---- !u!50 &1134476123 -Rigidbody2D: - serializedVersion: 4 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1134476113} - m_BodyType: 0 - m_Simulated: 1 - m_UseFullKinematicContacts: 0 - m_UseAutoMass: 0 - m_Mass: 1 - m_LinearDrag: 0 - m_AngularDrag: 0.05 - m_GravityScale: 1 - m_Material: {fileID: 0} - m_Interpolate: 0 - m_SleepingMode: 1 - m_CollisionDetection: 0 - m_Constraints: 4 --- !u!224 &1157983263 stripped RectTransform: m_CorrespondingSourceObject: {fileID: 1594993687448914316, guid: d935c8bab1c94f34e87afb5182e447d3, @@ -4504,7 +4281,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 19 + m_RootOrder: 18 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1410663226 GameObject: @@ -4623,7 +4400,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 20 + m_RootOrder: 19 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1774711815 stripped MonoBehaviour: @@ -4788,7 +4565,7 @@ Transform: m_Children: - {fileID: 1368910123} m_Father: {fileID: 0} - m_RootOrder: 18 + m_RootOrder: 17 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!95 &1817463533 Animator: diff --git a/Assets/Scripts/Game/NPC/BaseNPC.cs b/Assets/Scripts/Game/NPC/BaseNPC.cs deleted file mode 100644 index 524fcba2..00000000 --- a/Assets/Scripts/Game/NPC/BaseNPC.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using BehaviourTree; - -namespace RPG -{ - public class BaseNPC : Actor - { - private NPC dialogue; - private CircleCollider2D npcCollider; - - private bool isNPCFollower; - - [SerializeField] private float interactionDistance = 5.0f; - - private bool dialogueInitiated = false; //Delete this when we have a means of catching when dialogue is done - - protected override void Awake() - { - base.Awake(); - dialogue = GetComponent(); - npcCollider = GetComponent(); - } - - public void TurnIntoEnemy() - { - //Change to enemy Layer; - gameObject.layer = LayerMask.NameToLayer("Enemy"); - - //Doesnt if this doesn't have Enemy Script will add it - if (gameObject.GetComponent() == null) - { - gameObject.AddComponent(); - } - else - { - gameObject.GetComponent().enabled = true; - } - //TODO add AttackBehaviour in BehaviourTree - } - - public void TurnIntoCompanion() - { - //TODO Make Follower movement, interactable - npcCollider.enabled = false; - } - } -} diff --git a/Assets/Scripts/Game/NPC/BaseNPC.cs.meta b/Assets/Scripts/Game/NPC/BaseNPC.cs.meta deleted file mode 100644 index eac1d56b..00000000 --- a/Assets/Scripts/Game/NPC/BaseNPC.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c5dd1dec152424544a6fcae9ff825aa6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From e7fed8b621eb71ccb45d0286a3f1b1d8c6ec0360 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 2 Dec 2021 22:46:32 -0800 Subject: [PATCH 36/41] Fix comment typo --- Assets/Scripts/Game/UI/DialogueSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Game/UI/DialogueSystem.cs b/Assets/Scripts/Game/UI/DialogueSystem.cs index e6cad8e2..efcd4af9 100644 --- a/Assets/Scripts/Game/UI/DialogueSystem.cs +++ b/Assets/Scripts/Game/UI/DialogueSystem.cs @@ -92,7 +92,7 @@ private void OnDialogueNodeFinished(int nodeIdx) } } - // Display transitionss + // Display transitions DialogueGraphTransition[] transitions = GetTransitionsFor(currentGraph, nodeIdx); foreach (DialogueGraphTransition t in transitions) { From 21708121f290964d4d2d7c3d9575683d99738e8d Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 2 Dec 2021 22:49:49 -0800 Subject: [PATCH 37/41] Refactor agent enable logic --- Assets/Scripts/Tools/Behaviour Tree/Agent.cs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs index 46416c26..634b4df3 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Agent.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Agent.cs @@ -13,34 +13,17 @@ public class Agent : BehaviourObject public Rigidbody2D Rigidbody2D { get; private set; } private Tree.Node root; - private bool isEnabled; protected override void Awake() { base.Awake(); - Rigidbody2D = GetComponent(); - root = behaviourTree.Root; - isEnabled = true; } protected void Update() { - if (isEnabled) - { - root.Element.Tick(root, this); - } - } - - public void DisableBehaviours() - { - isEnabled = false; - } - - public void EnableBehaviours() - { - isEnabled = true; + root.Element.Tick(root, this); } } } From 24f9d77eb73fbc426eb4e8554866332e5fb7ac4e Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 2 Dec 2021 22:51:38 -0800 Subject: [PATCH 38/41] Update array increment comment --- Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs index 8cef9b4d..b3e77352 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/ArrayIncrementNode.cs @@ -4,9 +4,9 @@ namespace BehaviourTree { - // TODO: split into LoopIncrement and PingPongIncrement nodes? public class ArrayIncrementNode : IBehaviourTreeNode { + // TODO: implement Loop, PingPong, etc. increment wrap types? private const string PROP_INDEX_SRC = "index-source"; private const string PROP_ARR_LEN = "array-length"; From d91a5a2f4c110ad1aa4aced83c5ea73180aa91f1 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 2 Dec 2021 22:54:11 -0800 Subject: [PATCH 39/41] Add newline at end of file --- Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs index 3eebd8e9..6610d777 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/Nodes/GetSelfNode.cs @@ -22,4 +22,4 @@ public NodeStatus Tick(Tree.Node self, BehaviourObject obj) return NodeStatus.Success; } } -} \ No newline at end of file +} From f3dd7df562ffb3329e08e91454bea9a9b5e47d05 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Thu, 2 Dec 2021 22:55:17 -0800 Subject: [PATCH 40/41] Remove VectorIteratorNode --- .../BehaviourTreeNodeCreator.cs | 3 -- .../Nodes/VectorIteratorNode.cs | 43 ------------------- .../Nodes/VectorIteratorNode.cs.meta | 11 ----- 3 files changed, 57 deletions(-) delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs delete mode 100644 Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs.meta diff --git a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs index d469ee8e..30f30531 100644 --- a/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs +++ b/Assets/Scripts/Tools/Behaviour Tree/BehaviourTreeNodeCreator.cs @@ -25,7 +25,6 @@ public enum BehaviourTreeNodeType GetDialogueIndexNode, SetDialogueIndexNode, ForceDialogueNode, - VectorIteratorNode, ArrayIteratorNode, ArrayIncrementNode, GetMoveDirectionNode, @@ -84,8 +83,6 @@ public static IBehaviourTreeNode Create(BehaviourTreeNodeType type) return new SetDialogueIndexNode(); case BehaviourTreeNodeType.ForceDialogueNode: return new ForceDialogueNode(); - case BehaviourTreeNodeType.VectorIteratorNode: - return new VectorIteratorNode(); case BehaviourTreeNodeType.ArrayIteratorNode: return new ArrayIteratorNode(); case BehaviourTreeNodeType.ArrayIncrementNode: diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs deleted file mode 100644 index c0bfd686..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace BehaviourTree -{ - public class VectorIteratorNode : IBehaviourTreeNode - { - private const string PROP_ARRAY = "vector-array"; - private const string PROP_INDEX_SRC = "index-source"; - private const string PROP_VECTOR_DEST = "vector-destination"; - - public void Serialize(Behaviour behaviour) - { - behaviour.Properties.Add(PROP_ARRAY, new VariableProperty(VariableProperty.Type.Array, VariableProperty.Type.Vector)); - behaviour.Properties.Add(PROP_INDEX_SRC, new VariableProperty(VariableProperty.Type.String)); - behaviour.Properties.Add(PROP_VECTOR_DEST, new VariableProperty(VariableProperty.Type.String)); - } - - public NodeStatus Tick(Tree.Node self, BehaviourObject obj) - { - Behaviour behaviour = self.Element; - - // 1. read the current index from the agent (or set to zero if not exists) - int index = 0; - string indexSrc = behaviour.GetProperty(PROP_INDEX_SRC).GetString(); - if (obj.HasProperty(indexSrc)) - { - index = (int)obj.GetProperty(indexSrc); - } - - // 2. get the vector at the current index - object[] arr = behaviour.GetProperty(PROP_ARRAY).GetArray(); - Vector2 vec = (Vector2)arr[index]; - - // 3. store the resulting vector on the agent - string vectorDest = behaviour.GetProperty(PROP_VECTOR_DEST).GetString(); - obj.SetProperty(vectorDest, vec); - - return NodeStatus.Success; - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs.meta b/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs.meta deleted file mode 100644 index 783ee938..00000000 --- a/Assets/Scripts/Tools/Behaviour Tree/Nodes/VectorIteratorNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 35f1ed8904973ff458ee59420ed87bb4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From ae0b4b92922425a289acb7d4d57b6dc5bdcb4491 Mon Sep 17 00:00:00 2001 From: Jaden Balogh Date: Tue, 7 Dec 2021 23:16:06 -0800 Subject: [PATCH 41/41] Make Animator preset the default --- ProjectSettings/PresetManager.asset | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ProjectSettings/PresetManager.asset b/ProjectSettings/PresetManager.asset index aff43146..a95946a5 100644 --- a/ProjectSettings/PresetManager.asset +++ b/ProjectSettings/PresetManager.asset @@ -14,3 +14,12 @@ PresetManager: type: 2} m_Filter: m_Disabled: 0 + - first: + m_NativeTypeID: 95 + m_ManagedTypePPtr: {fileID: 0} + m_ManagedTypeFallback: + second: + - m_Preset: {fileID: 2655988077585873504, guid: ff96623c6707a72418a0b766fe2b0e8c, + type: 2} + m_Filter: + m_Disabled: 0