void OnDestroy() { if (CanSave && EditorUtility.IsDirty(target)) { var preferences = AIPlannerPreferences.GetOrCreatePreferences(); if (preferences.AutoSaveAssets) { ApplyChanges(); } else { var choice = EditorUtility.DisplayDialog("Unapplied changes", $"Would you like to apply the changes made to {AssetDatabase.GetAssetPath(serializedObject.targetObject)}?", "Apply", "Revert"); switch (choice) { case true: ApplyChanges(); break; case false: RevertChanges(); break; } } } }
public override void OnInspectorGUI() { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); var preferences = AIPlannerPreferences.GetOrCreatePreferences(); preferences.AutoSaveAssets = GUILayout.Toggle(preferences.AutoSaveAssets, "Auto-save assets"); if (!preferences.AutoSaveAssets) { GUI.enabled = EditorUtility.IsDirty(target); if (GUILayout.Button("Revert")) { RevertChanges(); GUI.FocusControl(null); } else if (GUILayout.Button("Apply")) { ApplyChanges(); GUI.FocusControl(null); } } EditorGUILayout.EndHorizontal(); }
static void OnPlayModeStateChanged(PlayModeStateChange playMode) { if (AIPlannerPreferences.GetOrCreatePreferences().AutoCompile) { if (playMode == PlayModeStateChange.EnteredPlayMode && EditorApplication.isCompiling) { // If we're still compiling the domain will reload and cause an error, so as a safeguard simply exit play mode EditorApplication.ExitPlaymode(); return; } if (playMode == PlayModeStateChange.ExitingEditMode && !EditorApplication.isCompiling) { if (!PlannerAssetDatabase.HasValidProblemDefinition()) { return; } var assetChangedPath = string.Empty; bool stateRepresentationNeedBuild = !PlannerAssetDatabase.StateRepresentationPackageExists(); if (!stateRepresentationNeedBuild) { DateTime lastStateRepresentationBuildTime = GetAssemblyBuildTime(TypeHelper.StateRepresentationQualifier); stateRepresentationNeedBuild = PlannerAssetDatabase.TryFindNewerAsset(PlannerAssetDatabase.stateRepresentationAssetTypeNames, lastStateRepresentationBuildTime, ref assetChangedPath); if (stateRepresentationNeedBuild) { Debug.Log($"Rebuilding AI Planner State Representation assembly because {assetChangedPath} is newer"); } } else { Debug.Log($"Rebuilding AI Planner assemblies because AI Planner State Representation package cannot be found"); } bool planNeedBuild = !PlannerAssetDatabase.PlansPackageExists(); if (!planNeedBuild) { DateTime lastPlanBuildTime = GetAssemblyBuildTime(TypeHelper.PlansQualifier); planNeedBuild = PlannerAssetDatabase.TryFindNewerAsset(PlannerAssetDatabase.planAssetTypeNames, lastPlanBuildTime, ref assetChangedPath); if (planNeedBuild) { Debug.Log($"Rebuilding AI Plan assembly because {assetChangedPath} is newer"); } } else { Debug.Log($"Rebuilding AI Planner assemblies because AI Plan package cannot be found"); } if (stateRepresentationNeedBuild || planNeedBuild) { EditorApplication.ExitPlaymode(); try { if (Build(stateRepresentationNeedBuild)) { CompilationPipeline.compilationFinished += context => EditorApplication.EnterPlaymode(); } } finally { EditorUtility.ClearProgressBar(); } } } } }