public override void OnInspectorGUI() { path = target as EnemyPath; // Resize arrays expandItem and usePolarCoord to match the amount of points if (expandItem.Length != path.pathingPoints.Length) { int oldSize = expandItem.Length; Array.Resize(ref expandItem, path.pathingPoints.Length); Array.Resize(ref usePolarCoord, path.pathingPoints.Length); for (int i = oldSize - 1; i < expandItem.Length; i++) { expandItem[i] = false; usePolarCoord[i] = false; } } // Use for tooltip for point timings in point foldout float ElaspedTravelTime = 0.0f; EditorGUILayout.LabelField("Enemy Path"); for (int i = 0; i < path.pathingPoints.Length; i++) { // The foldout for the currently selected point will be bold if (i == selectedIndex.x) { GUIStyle style = EditorStyles.foldout; FontStyle previousStyle = style.fontStyle; style.fontStyle = FontStyle.Bold; expandItem[i] = EditorGUILayout.Foldout(expandItem[i], "Point " + i + "\tArrival Time: " + ElaspedTravelTime + "\tDepature Time: " + (ElaspedTravelTime + path.pathingPoints[i].GetDelayTime()), style); style.fontStyle = previousStyle; } else { expandItem[i] = EditorGUILayout.Foldout(expandItem[i], "Point " + i + "\tArrival Time: " + ElaspedTravelTime + "\tDepatureTime: " + (ElaspedTravelTime + path.pathingPoints[i].GetDelayTime())); } // Add the total time the point will take for the next points timing tooltip ElaspedTravelTime += path.pathingPoints[i].GetDelayTime() + path.pathingPoints[i].GetTravelTime(); if (expandItem[i]) { EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector2Field("Location", path.GetPointLocation(i)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(path, "Move Point"); path.SetPointLocation(i, point); EditorUtility.SetDirty(path); } // Inspector Control Points EditorGUILayout.LabelField("Control Points", EditorStyles.boldLabel); // Toggle to display control points as Cartesian Coordinates(Default) or Polar Coordinates usePolarCoord[i] = EditorGUILayout.Toggle("As Polar Coordinates", usePolarCoord[i]); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); Vector3 controlPoint0; // If using polar coordinates convert to polar coordinates if (usePolarCoord[i]) { controlPoint0 = EditorGUILayout.Vector2Field("Control Point 0", CartesianToPolar(path.GetControlPoint(i, 0))); } else // Carry on using Cartesian as normal { controlPoint0 = EditorGUILayout.Vector2Field("Control Point 0", path.GetControlPoint(i, 0)); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(path, "Move Point"); // If using Polar Coordinates convert back to Cartesian if (usePolarCoord[i]) { controlPoint0 = PolarToCartesian(controlPoint0); } path.SetControlPoint(i, 0, controlPoint0); EditorUtility.SetDirty(path); } // Second Control Point EditorGUI.BeginChangeCheck(); Vector3 controlPoint1; if (usePolarCoord[i]) { controlPoint1 = EditorGUILayout.Vector2Field("Control Point 1", CartesianToPolar(path.GetControlPoint(i, 1))); } else { controlPoint1 = EditorGUILayout.Vector2Field("Control Point 1", path.GetControlPoint(i, 1)); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(path, "Move Point"); if (usePolarCoord[i]) { controlPoint1 = PolarToCartesian(controlPoint1); } path.SetControlPoint(i, 1, controlPoint1); EditorUtility.SetDirty(path); } EditorGUI.indentLevel--; // Inspector Control Point Mode EditorGUI.BeginChangeCheck(); BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", path.GetPointMode(i)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(path, "Change Point Mode"); path.SetPointMode(i, mode); path.EnforceMode(i, 0); EditorUtility.SetDirty(path); } // Travel Time EditorGUI.BeginChangeCheck(); float travelTime = EditorGUILayout.FloatField("Travel Time", path.GetTravelTime(i)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(path, "Change Travel Time"); path.SetTravelTime(i, travelTime); EditorUtility.SetDirty(path); } // Delay Time EditorGUI.BeginChangeCheck(); float delayTime = EditorGUILayout.FloatField("Delay Time", path.GetDelayTime(i)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(path, "Change Travel Time"); path.SetDelayTime(i, delayTime); EditorUtility.SetDirty(path); } } // Reset indent Level EditorGUI.indentLevel = 0; } if (GUILayout.Button("Add Point")) { Undo.RecordObject(path, "Add Point"); path.AddCurve(); EditorUtility.SetDirty(path); } if (path.pathingPoints.Length > 2) { if (GUILayout.Button("Remove Point")) { Undo.RecordObject(path, "Remove Point"); path.RemoveCurve(); EditorUtility.SetDirty(path); } } }