84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using UnityEngine.Splines;
|
|
using System.Linq;
|
|
|
|
[CustomEditor(typeof(MultiSplineFollower))]
|
|
public class MultiSplineFollowerEditor : Editor
|
|
{
|
|
public override void OnInspectorGUI()
|
|
{
|
|
// Vẽ inspector mặc định (hiện các trường routes, routes1, routes2, speed, rotationSpeed, ...)
|
|
base.OnInspectorGUI();
|
|
|
|
MultiSplineFollower follower = (MultiSplineFollower)target;
|
|
|
|
// Hiển thị từng nhóm route
|
|
DrawRouteGroup(follower.routes, "Routes (Nhóm 0)");
|
|
DrawRouteGroup(follower.routes1, "Routes1 (Nhóm 1)");
|
|
DrawRouteGroup(follower.routes2, "Routes2 (Nhóm 2)");
|
|
|
|
if (GUI.changed)
|
|
{
|
|
EditorUtility.SetDirty(follower);
|
|
}
|
|
}
|
|
|
|
private void DrawRouteGroup(SplineRoute[] routeArray, string groupLabel)
|
|
{
|
|
if (routeArray == null) return;
|
|
|
|
EditorGUILayout.Space();
|
|
EditorGUILayout.LabelField(groupLabel, EditorStyles.boldLabel);
|
|
|
|
for (int r = 0; r < routeArray.Length; r++)
|
|
{
|
|
var route = routeArray[r];
|
|
if (route == null) continue;
|
|
|
|
EditorGUILayout.BeginVertical("box");
|
|
EditorGUILayout.LabelField($"Route {r + 1}", EditorStyles.miniBoldLabel);
|
|
|
|
// START
|
|
if (route.splineStart != null)
|
|
{
|
|
int knotCount = route.splineStart.Spline?.Knots.Count() ?? 0;
|
|
if (knotCount > 0)
|
|
{
|
|
string[] options = Enumerable.Range(0, knotCount).Select(i => $"Knot {i}").ToArray();
|
|
route.startKnotIndex = EditorGUILayout.Popup("Start Knot", route.startKnotIndex, options);
|
|
}
|
|
else
|
|
{
|
|
EditorGUILayout.HelpBox("SplineStart không có knot nào.", MessageType.Warning);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EditorGUILayout.HelpBox("Chưa gán splineStart", MessageType.Info);
|
|
}
|
|
|
|
// END
|
|
if (route.splineEnd != null)
|
|
{
|
|
int knotCount = route.splineEnd.Spline?.Knots.Count() ?? 0;
|
|
if (knotCount > 0)
|
|
{
|
|
string[] options = Enumerable.Range(0, knotCount).Select(i => $"Knot {i}").ToArray();
|
|
route.endKnotIndex = EditorGUILayout.Popup("End Knot", route.endKnotIndex, options);
|
|
}
|
|
else
|
|
{
|
|
EditorGUILayout.HelpBox("SplineEnd không có knot nào.", MessageType.Warning);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
EditorGUILayout.HelpBox("Chưa gán splineEnd", MessageType.Info);
|
|
}
|
|
|
|
EditorGUILayout.EndVertical();
|
|
}
|
|
}
|
|
}
|