using System.Collections; using System.Collections.Generic; using UnityEngine; // Sci-Fi Ship Controller. Copyright (c) 2018-2023 SCSM Pty Ltd. All rights reserved. namespace SciFiShipController { /// /// Executes a simple state machine for determining state information for an "evade" AI. /// [AddComponentMenu("Sci-Fi Ship Controller/Samples/Evade AI")] [HelpURL("http://scsmmedia.com/ssc-documentation")] [RequireComponent(typeof(ShipAIInputModule))] public class SampleEvade : MonoBehaviour { #region Public Variables /// /// The name of the path this AI ship should attempt to follow. /// public string pathName = "Path Name Here"; /// /// The list of ships this AI ship should evade. /// public List shipsToEvade = new List(); #endregion #region Private Variables private ShipAIInputModule shipAIInputModule; private SSCManager sscManager; private PathData flightPath; private List shipsToEvadeAIList; #endregion #region Initialise Methods // Use this for initialization void Awake() { // Get a reference to the ship AI input module attached to this gameobject shipAIInputModule = GetComponent(); // Initialise the ship AI (if it hasn't been initialised already) shipAIInputModule.Initialise(); // Get a reference to the Ship Controller Manager instance sscManager = SSCManager.GetOrCreateManager(); // Find the Path flightPath = sscManager.GetPath(pathName); #if UNITY_EDITOR if (flightPath == null) { Debug.Log("Path not found: " + pathName); } #endif // Initialise the AI in the "move to" state shipAIInputModule.SetState(AIState.moveToStateID); // Set the target path to the flight path shipAIInputModule.AssignTargetPath(flightPath); shipAIInputModule.SetCurrentTargetPathLocationIndex(1, 0f); // Set the list of ships to evade shipsToEvadeAIList = new List(); for (int i = 0; i < shipsToEvade.Count; i++) { if (shipsToEvade[i] != null) { shipsToEvadeAIList.Add(shipsToEvade[i].shipInstance); } } shipAIInputModule.AssignShipsToEvade(shipsToEvadeAIList); } #endregion } }