public override void OnInspectorGUI() { base.OnInspectorGUI(); linePath = target as LinePath; if (selectedIndex >= 0 && selectedIndex < linePath.PointCount) { DrawSelectedPointInspector(); Tools.hidden = true; } else { Tools.hidden = false; } if (GUILayout.Button("Add Point")) { Undo.RecordObject(linePath, "Add Point"); linePath.AddPoint(); EditorUtility.SetDirty(linePath); } if (linePath.PointCount > 1 && GUILayout.Button("Remove Point")) { Undo.RecordObject(linePath, "Remove Point"); linePath.RemovePoint(); EditorUtility.SetDirty(linePath); } if (GUI.changed) { linePath.OnPathChanged(linePath); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); linePath = target as LinePath; if (selectedIndex >= 0 && selectedIndex < linePath.PointCount) { DrawSelectedPointInspector(); Tools.hidden = true; } else { Tools.hidden = false; } if (GUILayout.Button("Add Point")) { Undo.RecordObject(linePath, "Add Point"); linePath.AddPoint(); EditorUtility.SetDirty(linePath); } if (linePath.PointCount > 2 && GUILayout.Button("Remove Point")) { Undo.RecordObject(linePath, "Remove Point"); linePath.RemovePoint(); EditorUtility.SetDirty(linePath); } if (GUILayout.Button("Reset Normals")) { Undo.RecordObject(linePath, "Remove Point"); if (linePath.PointCount <= 2) { Vector3 pos = linePath.GetPoint(0); Vector3 pos2 = linePath.GetPoint(1); Vector3 toNext = (pos2 - pos).normalized; Vector3 right = Vector3.Cross(Vector3.up, toNext).normalized; Vector3 normal = Vector3.Cross(-right, toNext); if (flipNormal) { normal *= -1f; } for (int i = 0; i < linePath.Normals.Length; i++) { linePath.Normals[i] = normal; } } else { for (int i = 0; i < linePath.Normals.Length; i++) { Vector3 pos = linePath.GetPoint(i); int prevIndex = linePath.SafePointIndex(i - 1); Vector3 prevPos = linePath.GetPoint(prevIndex); int nextIndex = linePath.SafePointIndex(i + 1); Vector3 nextPos = linePath.GetPoint(nextIndex); Vector3 toNext = (nextPos - pos).normalized; Vector3 toPrev = (prevPos - pos).normalized; Vector3 normal = Vector3.Cross(toPrev, toNext).normalized; if (flipNormal) { normal *= -1f; } linePath.Normals[i] = linePath.transform.InverseTransformDirection(normal); } } flipNormal = !flipNormal; ResetHandleSettings(); EditorUtility.SetDirty(linePath); } if (GUI.changed) { linePath.OnPathChanged(linePath); } }