using System.Collections; using System.Collections.Generic; using UnityEngine; using RPGCreationKit; using RPGCreationKit.AI; using UnityEditor; namespace RPGCreationKit.AI { public enum TypeActionPoint { Rest = 0, Eat = 1, Sleep = 2 }; public enum DynamicObjectBone { Rhand = 0, Lhand = 1 }; public class NPCActionPoint : MonoBehaviour { public string actionPointID; public TypeActionPoint actionType; // Editor - Debug // TOCHANGE - SHALL WE USE A CUSTOM INSPECTOR? IT MAY ERASE THE DRAWGIZMOS THING WHICH IS BAD! [SerializeField] private bool showDummies = true; [SerializeField] private GameObject dummyFirstKeyframe; [SerializeField] private GameObject dummyLastKeyframe; // Runtime public bool isOccupied = false; public Transform pivotPoint; public AnimationClip npcAction; public AnimationClip npcActionReturn; public Entity entityUsingThisPoint; public bool spawnDynamicObject; public GameObject dynamicObject; public DynamicObjectBone dynamicObjectBone; [ContextMenu("Regenerate ID")] public void RegenerateGUIDStr() { actionPointID = System.Guid.NewGuid().ToString(); #if UNITY_EDITOR EditorUtility.SetDirty(this); #endif } /// /// This is called when isOccupied is set to true, so when an NPC wants to use this point (it doesn't mean he is currently using it) /// public void OnUserAssigned(Entity _entity = null) { isOccupied = true; entityUsingThisPoint = _entity; } /// /// This is called when the NPC is playing the 'enter' animation to the point. (When the NPC is sitting for example) /// public void OnUserUses(Entity _entity = null) { } /// /// This is called when the npc is playing the 'return' animation of the point. (When the NPC is getting up from the chair) /// public void OnUserIsLeaving(Entity _entity = null) { } /// /// This is called when the NPC that was using this point has completly been released. /// public void OnUserHasLeft(Entity _entity = null) { entityUsingThisPoint = null; isOccupied = false; } /// /// This is called when the NPC that was reaching this point gets reset and it should no more reach it (when it enters in combat) /// public void OnUserForceLeaves() { entityUsingThisPoint = null; isOccupied = false; } #if UNITY_EDITOR private void OnEnable() { if(Application.isPlaying) { if(dummyFirstKeyframe != null) dummyFirstKeyframe.SetActive(false); if(dummyLastKeyframe != null) dummyLastKeyframe.SetActive(false); } } [ContextMenu("Sample")] void SampleDummies() { if (npcAction != null && showDummies) { if(dummyFirstKeyframe) npcAction.SampleAnimation(dummyFirstKeyframe, 0.0f); if(dummyLastKeyframe) npcAction.SampleAnimation(dummyLastKeyframe, npcAction.length); SceneView.RepaintAll(); } } void ShowHideDummies(bool show) { if (dummyFirstKeyframe) dummyFirstKeyframe.SetActive(show); if (dummyLastKeyframe) dummyLastKeyframe.SetActive(show); SceneView.RepaintAll(); } private void OnDrawGizmosSelected() { ShowHideDummies(showDummies); SampleDummies(); } #endif } }