浏览代码

Included pathway component to edit PathwayConfigSO

/main
Yohann Puyhaubert 4 年前
当前提交
22788ea0
共有 8 个文件被更改,包括 88 次插入54 次删除
  1. 14
      UOP1_Project/Assets/Prefabs/Characters/SlimeCritter_Base.prefab
  2. 2
      UOP1_Project/Assets/Scenes/WIP/TestingGround.unity
  3. 14
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset
  4. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset.meta
  5. 18
      UOP1_Project/Assets/Scripts/Characters/Config/PathwayConfigSO.cs
  6. 26
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs
  7. 55
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs
  8. 11
      UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs

14
UOP1_Project/Assets/Prefabs/Characters/SlimeCritter_Base.prefab


_getHitEffectSO: {fileID: 11400000, guid: efe1f84589f6f1f47a7a10a1a215e843, type: 2}
_mainMeshRenderer: {fileID: 7464116941563462636}
_droppableRewardSO: {fileID: 11400000, guid: 6158158d6ef9a3d47827f7851295bcef, type: 2}
--- !u!114 &4729545407786248701
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8687264390989375961}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ac26da34fd58af544a84bf1977bcc424, type: 3}
m_Name:
m_EditorClassIdentifier:
_npcMovementConfig: {fileID: 11400000, guid: ae318779135f76f4d8c1213cf19d2312, type: 2}
_channel: {fileID: 0}
--- !u!1001 &2135821800440209491
PrefabInstance:
m_ObjectHideFlags: 0

2
UOP1_Project/Assets/Scenes/WIP/TestingGround.unity
文件差异内容过多而无法显示
查看文件

14
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset


m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76542500a512494489526e9bcfd3a1b8, type: 3}
m_Name: PathwayConfig
m_Name: NPCPathwayConfig
_waypoints: []
_stopDuration: 0
_speed: 0
_stopDuration: 0.5
_speed: 1
Waypoints:
- {x: 3.4739745, y: 0.033730388, z: 0.6266351}
- {x: 12.061079, y: 0.15954088, z: 9.731606}
- {x: -6.2887483, y: 0.033730388, z: 7.971367}
- {x: -15.76542, y: 0.033730388, z: -0.2936163}
- {x: -11.600259, y: 0.033730388, z: -4.42002}
_pathwayEditorColor: {r: 0, g: 1, b: 1, a: 1}

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Config/NPCPathwayConfig.asset.meta


fileFormatVersion: 2
guid: 3fd89e57021cbbe41a7c94dbf80a103e
guid: ae318779135f76f4d8c1213cf19d2312
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000

18
UOP1_Project/Assets/Scripts/Characters/Config/PathwayConfigSO.cs


[CreateAssetMenu(fileName = "PathwayConfig", menuName = "EntityConfig/Pathway Config")]
public class PathwayConfigSO : NPCMovementConfigSO
{
[Tooltip("Pathway waypoints")]
[SerializeField] private List<Vector3> _waypoints;
[HideInInspector] public List<Vector3> Waypoints;
public List<Vector3> Waypoints => _waypoints;
#if UNITY_EDITOR
[SerializeField]
private Color _pathwayEditorColor = Color.cyan;
private int _textSize = 10;
private Color _textColor = Color.white;
public const string FIELD_LABEL = "Point ";
public const string TITLE_LABEL = "Waypoints";
public Color LineColor { get => _pathwayEditorColor; }
public Color TextColor { get => _textColor; }
public int TextSize { get => _textSize; }
#endif
}

26
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayEditor.cs


using UnityEditorInternal;
[CustomEditor(typeof(Pathway))]
[CustomEditor(typeof(PathwayConfigSO))]
private Pathway _pathway;
private PathwayConfigSO _pathway;
public void OnSceneGUI()
public void OnSceneGUI(SceneView sceneView)
PathwayGizmos.DrawHandlesPath(_pathway);
}
public override void OnInspectorGUI()

_reorderableList.onRemoveCallback += RemoveItem;
_reorderableList.onSelectCallback += SelectItem;
_reorderableList.onChangedCallback += ListModified;
_pathway = (target as Pathway);
_pathway = (target as PathwayConfigSO);
SceneView.duringSceneGui += this.OnSceneGUI;
}
private void OnDisable()

_reorderableList.onRemoveCallback -= RemoveItem;
_reorderableList.onSelectCallback -= SelectItem;
_reorderableList.onChangedCallback -= ListModified;
SceneView.duringSceneGui -= this.OnSceneGUI;
}
private void DrawHeader(Rect rect)

{
int index = list.index;
if (index > -1 && list.serializedProperty.arraySize >= 1)
if (index < 0)
index = list.serializedProperty.arraySize - 1;
}
if (list.serializedProperty.arraySize >= 1)
{
Vector3 previous = (list.serializedProperty.GetArrayElementAtIndex(index).vector3Value + list.serializedProperty.GetArrayElementAtIndex((index + 1) % list.serializedProperty.arraySize).vector3Value) / 2;
Vector3 previous = list.serializedProperty.GetArrayElementAtIndex(index).vector3Value;
list.serializedProperty.GetArrayElementAtIndex(index + 1).vector3Value = new Vector3(previous.x + 2, previous.y, previous.z + 2);
list.serializedProperty.GetArrayElementAtIndex(index + 1).vector3Value = new Vector3(previous.x, previous.y, previous.z);
Vector3 previous = Vector3.zero;
Vector3 previous = _pathway.transform.position;
list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1).vector3Value = new Vector3(previous.x + 2, previous.y, previous.z + 2);
list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1).vector3Value = new Vector3(previous.x, previous.y, previous.z);
}
list.index++;

55
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayGizmos.cs


using UnityEngine;
using UnityEditor;
using UnityEngine.AI;
[DrawGizmo(GizmoType.Selected)]
private static void DrawGizmosSelected(Pathway pathway, GizmoType gizmoType)
{
DrawHandlesPath(pathway);
}
private static void DrawElements(Pathway pathway, List<Vector3> path, int index)
{
GUIStyle style = new GUIStyle();
Vector3 textHeight = Vector3.up;
style.normal.textColor = pathway.TextColor;
style.fontSize = pathway.TextSize;
Handles.Label(path[index] + textHeight, index.ToString(), style);
}
private static void DrawHandlesPath(Pathway pathway)
public static void DrawHandlesPath(PathwayConfigSO pathway)
for (int i = 0; i < pathway.Waypoints.Count; i++)
if (pathway.Waypoints.Count > 1)
if (i != 0 && pathway.Waypoints.Count > 1)
for (int index = 0; index < pathway.Waypoints.Count && pathway.Waypoints.Count > 1; index++)
DrawElements(pathway, pathway.Waypoints, i);
int nextIndex = (index + 1) % pathway.Waypoints.Count;
DrawElements(pathway, pathway.Waypoints, index);
List<Vector3> navMeshPath = new List<Vector3>();
NavMeshPath navPath = new NavMeshPath();
NavMesh.CalculatePath(pathway.Waypoints[index], pathway.Waypoints[nextIndex], NavMesh.AllAreas, navPath);
Handles.DrawDottedLine(pathway.Waypoints[i - 1], pathway.Waypoints[i], 2);
for (int j = 0; j < navPath.corners.Length - 1; j++)
{
Handles.DrawDottedLine(navPath.corners[j], navPath.corners[j + 1], 2);
}
}
if (pathway.Waypoints.Count > 2)
{
using (new Handles.DrawingScope(pathway.LineColor))
{
Handles.DrawDottedLine(pathway.Waypoints[0], pathway.Waypoints[pathway.Waypoints.Count - 1], 2);
}
}
private static void DrawElements(PathwayConfigSO pathway, List<Vector3> path, int index)
{
GUIStyle style = new GUIStyle();
Vector3 textHeight = Vector3.up;
style.normal.textColor = pathway.TextColor;
style.fontSize = pathway.TextSize;
Handles.Label(path[index] + textHeight, index.ToString(), style);
}

11
UOP1_Project/Assets/Scripts/Editor/Pathway/PathwayHandles.cs


using UnityEngine;
using UnityEditor;
using UnityEngine.AI;
private Pathway _pathway;
private PathwayConfigSO _pathway;
public PathwayHandles(Pathway pathway)
public PathwayHandles(PathwayConfigSO pathway)
{
_pathway = pathway;
}

for (int i = 0; i < _pathway.Waypoints.Count; i++)
{
_pathway.Waypoints[i] = Handles.PositionHandle(_pathway.Waypoints[i], Quaternion.identity);
}
for (int i = 0; i < _pathway.Waypoints.Count; i++)
{
NavMesh.SamplePosition(_pathway.Waypoints[i], out NavMeshHit hit, 99.0f, NavMesh.AllAreas);
_pathway.Waypoints[i] = hit.position;
}
}
正在加载...
取消
保存