You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XFFSM
|
||||
{
|
||||
public class ListenerFile
|
||||
{
|
||||
|
||||
|
||||
[InitializeOnLoadMethod]
|
||||
private static void InitOnLoad() {
|
||||
//Debug.Log("Init");
|
||||
Selection.selectionChanged += OnSelectionChange;
|
||||
|
||||
|
||||
EditorApplication.quitting += OnEditorApplicationQuitting;
|
||||
}
|
||||
|
||||
private static void OnSelectionChange()
|
||||
{
|
||||
RuntimeFSMController controller = Selection.activeObject as RuntimeFSMController;
|
||||
if (controller != null)
|
||||
{
|
||||
// 把InstanceID设置为空
|
||||
Context.Instance.FSMControllerInstanceID = 0;
|
||||
// 设置给Context 保存起来
|
||||
string assetPath = AssetDatabase.GetAssetPath(controller);
|
||||
string guid = AssetDatabase.AssetPathToGUID(assetPath);
|
||||
Context.Instance.RuntimeFSMControllerGUID = guid;
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject gameObj = Selection.activeGameObject;
|
||||
|
||||
if (gameObj == null) return;
|
||||
|
||||
if (gameObj.activeInHierarchy == false)
|
||||
{
|
||||
string path = AssetDatabase.GetAssetPath(gameObj);
|
||||
if(string.IsNullOrEmpty(path)) // 路径不为空说明是预制体
|
||||
return;
|
||||
}
|
||||
// 判断有没有FSMController组件
|
||||
FSMController fsmController = gameObj.GetComponent<FSMController>();
|
||||
if(FSMControllerIsEmpty(fsmController))
|
||||
return;
|
||||
|
||||
for (int i = 0;i<fsmController.RuntimeFSMController.Count;i++)
|
||||
{
|
||||
if (fsmController.RuntimeFSMController[i] != null)
|
||||
{
|
||||
Context.Instance.FSMControllerIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Context.Instance.FSMControllerInstanceID = gameObj.GetInstanceID();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static bool FSMControllerIsEmpty(FSMController fsmController) {
|
||||
if (fsmController == null)
|
||||
return true;
|
||||
|
||||
if (fsmController.RuntimeFSMController == null)
|
||||
return true;
|
||||
|
||||
if (fsmController.RuntimeFSMController.Count == 0)
|
||||
return true;
|
||||
|
||||
for (int i = 0; i < fsmController.RuntimeFSMController.Count; i++) {
|
||||
if (fsmController.RuntimeFSMController[i] != null)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void OnEditorApplicationQuitting() {
|
||||
Context.Instance.FSMControllerIndex = 0;
|
||||
Context.Instance.FSMControllerInstanceID = 0;
|
||||
}
|
||||
|
||||
[UnityEditor.Callbacks.OnOpenAsset(0)]
|
||||
private static bool OnOpenAsset(int insId, int line)
|
||||
{
|
||||
RuntimeFSMController obj = EditorUtility.InstanceIDToObject(insId) as RuntimeFSMController;
|
||||
if (obj != null)
|
||||
{
|
||||
EditorWindow.GetWindow<FSMEditorWindow>().Show();
|
||||
}
|
||||
return obj != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69dd6d65caca2164cb25d77575d54120
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user