protected override void Init(AIBehaviors fsm) { navMeshAgent = fsm.GetComponentInChildren <NavMeshAgent>(); sqrDistanceToTargetThreshold = GetSquareDistanceThreshold(); fsm.PlayAudio(); getAsCloseAsPossible &= navMeshAgent != null; previousNoMovementDistance = -1; if (getAsCloseAsPossible) { previousPosition = Vector3.one * Mathf.Infinity; navMeshPath = new NavMeshPath(); } if (seekTarget != null) { targetPosition = GetTargetPosition(); } nextCheckHasMovement = Time.time + checkHasMovementFrequency; if (encircleTarget) { float radians = Random.value * Mathf.PI * 2; encircleOffset = new Vector3(Mathf.Cos(radians), 0.0f, Mathf.Sin(radians)) * distanceToTargetThreshold; } }
protected override void Init(AIBehaviors fsm) { navMeshAgent = fsm.GetComponentInChildren <NavMeshAgent>(); fsm.PlayAudio(); nextCheckHasMovement = Time.time + checkHasMovementFrequency; player = fsm.GetClosestPlayer(objectFinder.GetTransforms()); targetPosition = Vector3.zero; }
protected override void Init(AIBehaviors fsm) { navMeshAgent = fsm.GetComponentInChildren <NavMeshAgent>(); sqrDistanceToTargetThreshold = GetSquareDistanceThreshold(); fsm.PlayAudio(); getAsCloseAsPossible &= navMeshAgent != null; previousNoMovementDistance = -1; if (getAsCloseAsPossible) { previousPosition = Vector3.one * Mathf.Infinity; navMeshPath = new NavMeshPath(); } if (seekTarget != null) { targetPosition = seekTarget.position; } }
protected override void DrawStateInspectorEditor(SerializedObject stateObject, AIBehaviors fsm) { SerializedProperty property; GUILayout.Label("Seek Properties:", EditorStyles.boldLabel); GUILayout.BeginVertical(GUI.skin.box); property = stateObject.FindProperty("specifySeekTarget"); EditorGUILayout.PropertyField(property); if (property.boolValue) { property = stateObject.FindProperty("seekTarget"); EditorGUILayout.PropertyField(property); } EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); { GUILayout.Label("No Seek Target Transition:"); property = stateObject.FindProperty("noSeekTargetFoundState"); property.objectReferenceValue = AIBehaviorsStatePopups.DrawEnabledStatePopup(fsm, property.objectReferenceValue as BaseState); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("No Movement Transition:"); property = stateObject.FindProperty("noMovementState"); property.objectReferenceValue = AIBehaviorsStatePopups.DrawEnabledStatePopup(fsm, property.objectReferenceValue as BaseState); } GUILayout.EndHorizontal(); EditorGUILayout.Separator(); GUILayout.BeginHorizontal(); { GUILayout.Label("Seek Target Reached Transition:"); property = stateObject.FindProperty("seekTargetReachedState"); property.objectReferenceValue = AIBehaviorsStatePopups.DrawEnabledStatePopup(fsm, property.objectReferenceValue as BaseState); } GUILayout.EndHorizontal(); property = stateObject.FindProperty("distanceToTargetThreshold"); float prevValue = property.floatValue; EditorGUILayout.PropertyField(property); if (property.floatValue <= 0.0f) { property.floatValue = prevValue; } property = stateObject.FindProperty("destroyTargetWhenReached"); EditorGUILayout.PropertyField(property); property = stateObject.FindProperty("getAsCloseAsPossible"); EditorGUILayout.PropertyField(property); if (property.boolValue) { if (fsm.GetComponentInChildren <NavMeshAgent>() == null) { EditorGUILayout.HelpBox("This trigger only works with an AI that uses a NavMeshAgent", MessageType.Warning); } } GUILayout.EndVertical(); stateObject.ApplyModifiedProperties(); if (Application.isPlaying) { GUILayout.Label("Debug:", EditorStyles.boldLabel); GUILayout.BeginVertical(GUI.skin.box); if (seekTarget != null) { GUILayout.Label("Distance to target: " + (transform.position - targetPosition).magnitude.ToString(), EditorStyles.boldLabel); } else { GUILayout.Label("No Seek Target Found", EditorStyles.boldLabel); } GUILayout.EndVertical(); } }