119 lines
5.0 KiB
C#
119 lines
5.0 KiB
C#
|
//============= Copyright (c) Ludic GmbH, All rights reserved. ==============
|
|||
|
//
|
|||
|
// Purpose: Part of the My Behaviour Tree Code
|
|||
|
//
|
|||
|
//=============================================================================
|
|||
|
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace MyBT {
|
|||
|
using UnityEditor.IMGUI.Controls;
|
|||
|
using UnityEditor;
|
|||
|
using UnityEditor.Callbacks;
|
|||
|
|
|||
|
[InitializeOnLoadAttribute]
|
|||
|
public class DetectBtChanges : AssetPostprocessor {
|
|||
|
public static bool autodetectFilechanges = true;
|
|||
|
|
|||
|
[DidReloadScripts]
|
|||
|
static void MethodsReloaded() {
|
|||
|
Debug.Log("DetectBtChanges.MethodsReloaded");
|
|||
|
if (autodetectFilechanges) {
|
|||
|
foreach (TaskController tc in Object.FindObjectsOfType(typeof(TaskController))) {
|
|||
|
if (tc.InspectorRegenerate!=null) {
|
|||
|
tc.InspectorRegenerate?.Invoke(false);
|
|||
|
}
|
|||
|
tc.RegenerateBehaviourTreeIfRequired(true);
|
|||
|
//tc.ClearBindingsAndScanAndBindMethods();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) {
|
|||
|
if (autodetectFilechanges) {
|
|||
|
List<string> changedFiles = new List<string>();
|
|||
|
foreach (string str in importedAssets) {
|
|||
|
string[] pathSplitStr = str.Split('/');
|
|||
|
string[] fileSplitStr = pathSplitStr[pathSplitStr.Length - 1].Split('.');
|
|||
|
|
|||
|
string fileName = string.Join(".", fileSplitStr, 0, fileSplitStr.Length - 1);
|
|||
|
changedFiles.Add(fileName);
|
|||
|
}
|
|||
|
|
|||
|
//TaskController[] taskControllers = Resources.FindObjectsOfTypeAll<TaskController>();
|
|||
|
foreach (TaskController tc in UnityEngine.Resources.FindObjectsOfTypeAll<TaskController>()) {
|
|||
|
// unmutable objects
|
|||
|
if (tc.hideFlags == HideFlags.NotEditable || tc.hideFlags == HideFlags.HideAndDontSave) {
|
|||
|
Debug.Log("NotEditable || HideAndDontSave");
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
// is a file on disk
|
|||
|
//if (!EditorUtility.IsPersistent(tc.transform.root.gameObject)) {
|
|||
|
// Debug.Log("IsPersistent");
|
|||
|
// continue;
|
|||
|
//}
|
|||
|
|
|||
|
// everything else is a scene TaskController
|
|||
|
foreach (UnityEngine.TextAsset txt in tc.taskScripts) {
|
|||
|
if (txt != null) {
|
|||
|
if (changedFiles.Contains(txt.name)) {
|
|||
|
if (tc.InspectorRegenerate != null) tc.InspectorRegenerate.Invoke(true);
|
|||
|
//tc.BtScriptChangeDetected();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//foreach (string str in deletedAssets) {
|
|||
|
// Debug.Log("Deleted Asset: " + str);
|
|||
|
//}
|
|||
|
|
|||
|
//for (int i = 0; i < movedAssets.Length; i++) {
|
|||
|
// Debug.Log("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]);
|
|||
|
//}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//static DetectBtChanges() {
|
|||
|
// EditorApplication.playModeStateChanged += LogPlayModeState;
|
|||
|
//}
|
|||
|
|
|||
|
//private static void LogPlayModeState(PlayModeStateChange state) {
|
|||
|
// switch (state) {
|
|||
|
// // start playing
|
|||
|
// case PlayModeStateChange.ExitingEditMode:
|
|||
|
// Debug.Log("DetectBtChanges.LogPlayModeState.ExitingEditMode");
|
|||
|
// break;
|
|||
|
// case PlayModeStateChange.EnteredPlayMode:
|
|||
|
// Debug.Log("DetectBtChanges.LogPlayModeState.EnteredPlayMode");
|
|||
|
// break;
|
|||
|
|
|||
|
// // stopping playing
|
|||
|
// case PlayModeStateChange.ExitingPlayMode:
|
|||
|
// Debug.Log("DetectBtChanges.LogPlayModeState.ExitingPlayMode");
|
|||
|
// break;
|
|||
|
// case PlayModeStateChange.EnteredEditMode:
|
|||
|
// Debug.Log("DetectBtChanges.LogPlayModeState.EnteredEditMode");
|
|||
|
// EnterEditMode();
|
|||
|
// break;
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
//private static void EnterEditMode () {
|
|||
|
// TaskController[] taskControllers = Resources.FindObjectsOfTypeAll<TaskController>();
|
|||
|
// Debug.Log($"DetectBtChanges.EnteredEditMode: has {taskControllers.Length} TaskControllers");
|
|||
|
// foreach (TaskController taskController in taskControllers) {
|
|||
|
// // is NOT a file on disk (not in the scene)
|
|||
|
// if (!EditorUtility.IsPersistent(taskController)) {
|
|||
|
// Debug.Log($"Regenerate {taskController.name}");
|
|||
|
// taskController.ResetNodesAndTokens();
|
|||
|
// taskController.GenerateTokensAndNodes();
|
|||
|
// }
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
}
|