// Function to replace the PathingAgent's current set of waypoints with onces loaded in from a SCR_WaypointCollection ScriptableObject asset // Calls ResetPathing on a successful load to begin pathing at the beginning of the new collection // Returns whether all waypoints in the collection were successfully loaded public bool LoadWaypointCollection(SCR_WaypointCollection waypointCollection) { List <WaypointObject> loadedWaypoints = new List <WaypointObject>(); if (!TryToLoadWaypointsIntoList(waypointCollection.waypoints, loadedWaypoints)) { return(false); } List <ConnectedWaypointsListContainer> loadedConnectedWaypoints = new List <ConnectedWaypointsListContainer>(); foreach (SCR_WaypointCollection.ConnectedWaypointNamesListContainer waypointGroup in waypointCollection.randWaypointConnections) { ConnectedWaypointsListContainer connectedWaypointsList = new ConnectedWaypointsListContainer(); if (!TryToLoadWaypointsIntoList(waypointGroup.names, connectedWaypointsList.connections)) { return(false); } loadedConnectedWaypoints.Add(connectedWaypointsList); } waypoints = loadedWaypoints; connectedWaypoints = loadedConnectedWaypoints; ResetPathing(); return(true); }
// Function to offer a void-return interface for LoadWaypointCollection for UnityEvents public void LoadWaypoints(SCR_WaypointCollection waypointCollection) { LoadWaypointCollection(waypointCollection); }
public override void OnInspectorGUI() { serializedObject.Update(); GUI.enabled = false; EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script"), true, new GUILayoutOption[0]); EditorGUILayout.PropertyField(serializedObject.FindProperty("currentWaypointTarget")); GUI.enabled = true; EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.PropertyField(serializedObject.FindProperty("tetherObjectTransform")); EditorGUILayout.PropertyField(serializedObject.FindProperty("tetherRadius")); EditorGUILayout.PropertyField(serializedObject.FindProperty("tetherDirectionStartAngle")); EditorGUILayout.PropertyField(serializedObject.FindProperty("tetherDirectionEndAngle")); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.PropertyField(serializedObject.FindProperty("orientParallelToSlopes")); EditorGUILayout.PropertyField(serializedObject.FindProperty("minSlopeReorientAngle")); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.PropertyField(serializedObject.FindProperty("pathingMode")); EditorGUILayout.PropertyField(serializedObject.FindProperty("goRndWaypointChance")); waypointsList.DoLayoutList(); if (GUILayout.Button("Generate Waypoint Collection Asset")) { SCR_WaypointCollection waypointCollection = ScriptableObject.CreateInstance <SCR_WaypointCollection>(); waypointCollection.Initialize(agent.waypoints, agent.connectedWaypoints); if (!AssetDatabase.IsValidFolder("Assets/Mara_Data")) { AssetDatabase.CreateFolder("Assets", "Mara_Data"); } string path = EditorUtility.SaveFilePanel("Save waypoint collection asset", "Assets/Mara_Data", agent.gameObject.name + "_waypointCollection", "asset"); if (path.Length > 0) { int assetsFolderPathIndex = path.IndexOf("Assets"); path = path.Substring(assetsFolderPathIndex); AssetDatabase.CreateAsset(waypointCollection, path); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = waypointCollection; } } if (GUILayout.Button("Load Waypoint Collection Asset")) { if (!AssetDatabase.IsValidFolder("Assets/Mara_Data")) { AssetDatabase.CreateFolder("Assets", "Mara_Data"); } string path = EditorUtility.OpenFilePanelWithFilters("Load waypoint collection asset", "Assets/Mara_Data", new string[] { "Asset", "asset" }); if (path.Length > 0) { int assetsFolderPathIndex = path.IndexOf("Assets"); path = path.Substring(assetsFolderPathIndex); SCR_WaypointCollection waypointCollection = (SCR_WaypointCollection)AssetDatabase.LoadAssetAtPath(path, typeof(SCR_WaypointCollection)); if (waypointCollection) { agent.LoadWaypointCollection(waypointCollection); Selection.activeObject = agent; } } } EditorGUILayout.PropertyField(serializedObject.FindProperty("allWaypointsOnEnter")); EditorGUILayout.PropertyField(serializedObject.FindProperty("allWaypointsOnExit")); EditorGUILayout.PropertyField(serializedObject.FindProperty("nextWaypointIndex")); EditorGUILayout.PropertyField(serializedObject.FindProperty("rotateAtWaypoints")); EditorGUILayout.PropertyField(serializedObject.FindProperty("turnDegreesPerSec")); EditorGUILayout.PropertyField(serializedObject.FindProperty("beginPathingOnStart")); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.PropertyField(serializedObject.FindProperty("navFailureResponse")); showNonNavMeshVariables = EditorGUILayout.Foldout(showNonNavMeshVariables, "Non-NavMesh Settings"); PathingAgent.NavFailureResponse failureResponse = (PathingAgent.NavFailureResponse)serializedObject.FindProperty("navFailureResponse").enumValueIndex; if (showNonNavMeshVariables || failureResponse == PathingAgent.NavFailureResponse.LERP) { EditorGUILayout.PropertyField(serializedObject.FindProperty("inheritSpeedFromNavAgent"));; EditorGUILayout.PropertyField(serializedObject.FindProperty("moveSpeed")); } // Only allow waypoints to be listed as a connectedWaypoint once HashSet <WaypointObject> uniqueConnectedWaypoints = new HashSet <WaypointObject>(); for (int i = 0; i < agent.connectedWaypoints.Count; ++i) { for (int w = 0; w < agent.connectedWaypoints[i].connections.Count; ++w) { if (uniqueConnectedWaypoints.Contains(agent.connectedWaypoints[i].connections[w])) { agent.connectedWaypoints[i].connections[w] = null; } else { uniqueConnectedWaypoints.Add(agent.connectedWaypoints[i].connections[w]); } } uniqueConnectedWaypoints.Clear(); } serializedObject.ApplyModifiedProperties(); }