using UnityEngine; using System.Collections.Generic; public class SoMap : ScriptableObject { public int mapID; public List missionTriggerList = new List(); public List areaTriggerList = new List(); [System.Serializable] public class MissionTrigger { public int id; public int state; public List refreshNPCList = new List(); public List createImpasseList = new List(); } [System.Serializable] public class AreaTrigger { public int id; public Vector3 position; public Vector3 eulerAngle; public Vector3 localScale; public List refreshNPCList = new List(); public List createImpasseList = new List(); } [System.Serializable] public class RefreshNPC : MapEvent { public int NpcID; public E_ClientNpcType npcType; public Vector3 position; public bool randomPostion; public float randomDist; public Vector3 eulerAngles; public int count = 1; public float refreshInterval; public int waveCount = 1; public float waveInterval; public RefreshNPC() { eventType = E_EventType.RefreshNpc; } } [System.Serializable] public class CreateImpasse : MapEvent { public int id; public Vector3 position; public Vector3 eulerAngles; public Vector3 localScale; public int effectID = -1; public CreateImpasse() { eventType = E_EventType.CreateImpasse; } public void Carve() { General(position, eulerAngles, localScale); } public static UnityEngine.AI.NavMeshObstacle General(Vector3 position, Vector3 eulerAngles, Vector3 scale) { GameObject _impasse = new GameObject(); position.y = 0; _impasse.transform.position = position; _impasse.transform.eulerAngles = eulerAngles; _impasse.transform.localScale = scale; UnityEngine.AI.NavMeshObstacle _obstacle = _impasse.AddComponent(); _obstacle.carving = true; return _obstacle; } public static UnityEngine.AI.NavMeshObstacle GeneralCircle(Vector3 position, float radius) { GameObject _impasse = new GameObject(); position.y = 0; _impasse.transform.position = position; _impasse.transform.localScale = new Vector3(1, 5, 1); UnityEngine.AI.NavMeshObstacle _obstacle = _impasse.AddComponent(); _obstacle.shape = UnityEngine.AI.NavMeshObstacleShape.Capsule; _obstacle.carving = true; _obstacle.radius = radius; return _obstacle; } public static UnityEngine.AI.NavMeshObstacle General(Vector3 start, Vector3 end, float angle) { GameObject _impasse = new GameObject(); // 计算长度 float _length = Vector3.Distance(end * .5f, start * .5f); float _width = 1.5f; float _centerX; float _centerZ; if (end.x > start.x) { _centerX = (end.x * .5f - start.x * .5f) * .5f + start.x * .5f; } else { _centerX = (end.x * .5f - start.x * .5f) * .5f + end.x * .5f; } if (end.z > start.z) { _centerZ = (end.z * .5f - start.z * .5f) * .5f + start.z * .5f; } else { _centerZ = (start.z * .5f - end.z * .5f) * .5f + end.z * .5f; } #if UNITY_EDITOR _impasse.name = "Obstacle_" + _length + "_" + _width; #endif _impasse.transform.position = new Vector3(_centerX, 0, _centerZ); _impasse.transform.localScale = new Vector3(_length, 10, _width); UnityEngine.AI.NavMeshObstacle _obstacle = _impasse.AddComponent(); _obstacle.transform.eulerAngles = new Vector3(0, angle, 0); _obstacle.carving = true; return _obstacle; } public static UnityEngine.AI.NavMeshObstacle General(Vector3 start, Vector3 end) { GameObject _impasse = new GameObject(); // 判断是横向还是纵向的阻挡 bool _isHorizontal = start.z == end.z; float _centerX = 0, _centerZ = 0, _width = 0, _height = 0; if (_isHorizontal) { _width = start.x > end.x ? (start.x - end.x) * .5f : (end.x - start.x) * .5f; _height = 2; _centerX = start.x > end.x ? end.x * .5f + _width * .5f : start.x * .5f + _width * .5f; _centerZ = start.z * .5f; } else { _width = 2; _height = start.z > end.z ? (start.z - end.z) * .5f : (end.z - start.z) * .5f; _centerZ = start.z > end.z ? end.z * .5f + _height * .5f : start.z * .5f + _height * .5f; _centerX = start.x * .5f; } #if UNITY_EDITOR _impasse.name = "Obstacle_" + _width + "_" + _height; #endif _impasse.transform.position = new Vector3(_centerX, 0, _centerZ); _impasse.transform.localScale = new Vector3(_width, 10, _height); UnityEngine.AI.NavMeshObstacle _obstacle = _impasse.AddComponent(); _obstacle.carving = true; return _obstacle; } } [System.Serializable] public class MapEvent { public E_EventType eventType; } public enum E_EventType { RefreshNpc, CreateImpasse, ShowDialog, ShowTip, ShowIconTip, ShowGuide, PlayEffect, //后续IL开发添加预设 default1, default2, default3, default4, default5, default6, default7, default8, default9, default10, } public enum E_TriggerType { Mission, Area, //后续IL开发添加预设 default1, default2, default3, default4, default5, default6, default7, default8, default9, default10, } }