| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | | using Newtonsoft.Json; |
| | 4 | | using Newtonsoft.Json.Converters; |
| | 5 | |
|
| | 6 | | public class AttackBehavior { |
| | 7 | | public string name; |
| | 8 | | public AttackBehaviorType attackBehaviorType; |
| | 9 | |
|
| | 10 | | public Vector3 targetPosition; |
| | 11 | | public Vector3 targetVelocity; |
| | 12 | | public Vector3 targetColliderSize; |
| | 13 | | public FlightPlan flightPlan; |
| | 14 | | // Returns the next waypoint for the threat to navigate to |
| | 15 | | // In addition, return the power setting to use toward the waypoint |
| | 16 | | public virtual (Vector3 waypointPosition, PowerSetting power) |
| 0 | 17 | | GetNextWaypoint(Vector3 currentPosition, Vector3 targetPosition) { |
| 0 | 18 | | return (targetPosition, PowerSetting.IDLE); |
| 0 | 19 | | } |
| | 20 | |
|
| 14 | 21 | | protected static string ResolveBehaviorPath(string json) { |
| | 22 | | // Append "Configs/Behaviors/Attack/" to the json path if it's not already there |
| 28 | 23 | | if (!json.StartsWith("Configs/Behaviors/Attack/")) { |
| 14 | 24 | | json = "Configs/Behaviors/Attack/" + json; |
| 14 | 25 | | } |
| 14 | 26 | | return json; |
| 14 | 27 | | } |
| | 28 | |
|
| 7 | 29 | | public static AttackBehavior FromJson(string json) { |
| 7 | 30 | | string resolvedPath = ResolveBehaviorPath(json); |
| 7 | 31 | | string fileContent = ConfigLoader.LoadFromStreamingAssets(resolvedPath); |
| 7 | 32 | | return JsonConvert.DeserializeObject<AttackBehavior>(fileContent, new JsonSerializerSettings { |
| | 33 | | Converters = { new Newtonsoft.Json.Converters.StringEnumConverter() } |
| | 34 | | }); |
| 7 | 35 | | } |
| | 36 | |
|
| | 37 | | [JsonConverter(typeof(StringEnumConverter))] |
| | 38 | | public enum AttackBehaviorType { DIRECT_ATTACK, PREPLANNED_ATTACK, SLALOM_ATTACK } |
| | 39 | | } |
| | 40 | |
|
| | 41 | | [System.Serializable] |
| | 42 | | public class VectorWaypoint : Waypoint { |
| | 43 | | public Vector3 waypointPosition; |
| | 44 | | public PowerSetting power; |
| | 45 | | } |
| | 46 | |
|
| | 47 | | [System.Serializable] |
| | 48 | | public class Waypoint {} |
| | 49 | | public class FlightPlan { |
| | 50 | | public string type; |
| | 51 | | } |