Do you want to be able to see and edit all the pathfinding links in the editor at the same time? It looks like so:
What I did is add some scripts on the parent PathfindingLinks gameobject. So that when you select it, you will be able to see and edit any of the links inside it at the same time. Le me show you how I did it.
- I moved the logic of moving the position handles in PathfindingLinkEditor to a new public static method (it will be used externally in next steps).
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PathfindingLinkMonoBehaviour))]
public class PathfindingLinkEditor : Editor
{
private void OnSceneGUI()
{
PathfindingLinkMonoBehaviour pathfindingLinkMonoBehaviour = (PathfindingLinkMonoBehaviour) target;
MovePositionHandles(pathfindingLinkMonoBehaviour);
}
public static void MovePositionHandles(PathfindingLinkMonoBehaviour pathfindingLinkMonoBehaviour)
{
EditorGUI.BeginChangeCheck();
Vector3 newLinkPositionA = Handles.PositionHandle(pathfindingLinkMonoBehaviour.linkPositionA, Quaternion.identity);
Vector3 newLinkPositionB = Handles.PositionHandle(pathfindingLinkMonoBehaviour.linkPositionB, Quaternion.identity);
if (!EditorGUI.EndChangeCheck())
return;
Undo.RecordObject(pathfindingLinkMonoBehaviour, "Change Link Positions");
pathfindingLinkMonoBehaviour.linkPositionA = newLinkPositionA;
pathfindingLinkMonoBehaviour.linkPositionB = newLinkPositionB;
}
}
-
Then, I created two new scripts PathfindingLinkMonoBehaviourParent, and PathfindingLinkParentEditor (this one HAS to be on Editor folder, since it is an editor script)
-
PathfindingLinkMonoBehaviourParent should inherit monobehaviour and be empty, its only used to access its already public transform field.
using UnityEngine;
public class PathfindingLinkMonoBehaviourParent : MonoBehaviour
{
// This script is only used to access the transform of the parent object
}
- PathfindingLinkParentEditor adds some logic to cicle through its children, and then show and edit all the handles at once. (This is the script that uses the MovePositionHandles method created before, to avoid code repetition)
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(PathfindingLinkMonoBehaviourParent))]
public class PathfindingLinkParentEditor : Editor
{
private void OnSceneGUI()
{
// Get the target of the editor (parent script)
PathfindingLinkMonoBehaviourParent pathfindingLinkMonoBehaviour = (PathfindingLinkMonoBehaviourParent) target;
// Get the transform of the parent object
Transform parentTransform = pathfindingLinkMonoBehaviour.transform;
// Loop through all the children of the parent object
foreach (Transform transform in parentTransform)
{
// Get the PathfindingLinkMonoBehaviour script of the child object
PathfindingLinkMonoBehaviour pathfindingLinkMonoBehaviourChild = transform.GetComponent<PathfindingLinkMonoBehaviour>();
// Move the position handles
PathfindingLinkEditor.MovePositionHandles(pathfindingLinkMonoBehaviourChild);
}
}
}
-
Add the PathfindingLinkMonoBehaviourParent script to the PathfindingLinks parent gameobject like so:
-
Finished!! Now when you select the parent gameobject you will be able to edit them all at the same time. When you select a children, you will still be able to edit it individually and/or set the coordinates manually.