嘿,我想创建一个开发人员可以实际看到的编辑器NavMesh Waypoint路径。我想将IntSliders用于我的值,因为它比文本字段更易于使用,但它们却不会像冻结一样移动。
在我添加滑块之前,所有功能均按预期工作,因此我不知道错误在哪里,或者我看不到它。
这是我的代码,我想念什么吗?
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(AIWaypointNetwork))]
public class AIWaypointNetworkEditor : Editor
{
public override void OnInspectorGUI()
{
AIWaypointNetwork network = (AIWaypointNetwork)target;
network.DisplayMode = (PathDisplayMode)EditorGUILayout.EnumPopup("Display Mode", network.DisplayMode);
if (network.DisplayMode == PathDisplayMode.Paths)
{
network.UIStart = EditorGUILayout.IntSlider("Waypoint Start", network.UIStart, 0, network.Waypoints.Count - 1);
network.UIStart = EditorGUILayout.IntSlider("Waypoint End", network.UIEnd, 0, network.Waypoints.Count - 1);
}
DrawDefaultInspector();
}
void OnSceneGUI()
{
AIWaypointNetwork network = (AIWaypointNetwork)target;
for (int i=0; i<network.Waypoints.Count; i++)
{
if (network.Waypoints[i] != null)
Handles.Label (network.Waypoints [i].position, "Waypoint " + i.ToString ());
}
if (network.DisplayMode == PathDisplayMode.Connections)
{
Vector3[] linePoints = new Vector3[network.Waypoints.Count + 1];
for (int i = 0; i <= network.Waypoints.Count; i++)
{
int index = i != network.Waypoints.Count ? i : 0;
if (network.Waypoints [index] != null)
linePoints [i] = network.Waypoints [index].position;
else
linePoints [i] = new Vector3 (Mathf.Infinity, Mathf.Infinity, Mathf.Infinity);
}
Handles.color = Color.cyan;
Handles.DrawPolyLine (linePoints);
}
else
if (network.DisplayMode == PathDisplayMode.Paths)
{
NavMeshPath path = new NavMeshPath();
if(network.Waypoints[network.UIStart]!=null && network.Waypoints[network.UIEnd]!=null)
{
Vector3 from = network.Waypoints[network.UIStart].position;
Vector3 to = network.Waypoints[network.UIEnd].position;
NavMesh.CalculatePath(from, to, NavMesh.AllAreas, path);
Handles.color = Color.yellow;
Handles.DrawPolyLine(path.corners);
}
}
}
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public enum PathDisplayMode { None, Connections, Paths }
public class AIWaypointNetwork : MonoBehaviour
{
[HideInInspector]
public PathDisplayMode DisplayMode = PathDisplayMode.Connections;
[HideInInspector]
public int UIStart = 0;
[HideInInspector]
public int UIEnd = 0;
public List<Transform> Waypoints = new List<Transform> ();
}
答案 0 :(得分:0)
问题是:
network.UIStart = EditorGUILayout.IntSlider("Waypoint Start", network.UIStart, 0, network.Waypoints.Count - 1);
network.UIStart = EditorGUILayout.IntSlider("Waypoint End", network.UIEnd, 0, network.Waypoints.Count - 1);
我忘记将第二个变量更改为UIEnd ...
解决方案是:
network.UIStart = EditorGUILayout.IntSlider("Waypoint Start", network.UIStart, 0, network.Waypoints.Count - 1);
network.UIEnd = EditorGUILayout.IntSlider("Waypoint End", network.UIEnd, 0, network.Waypoints.Count - 1);