This commit is contained in:
2024-10-16 00:03:41 +08:00
commit 897058435c
5033 changed files with 1009728 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using UnityEngine;
namespace XFFSM
{
public class FSMStateCreator : EndNameEditAction
{
static string regex = "^[a-zA-Z][a-zA-Z0-9_]*$";
public override void Action(int instanceId, string pathName, string resourceFile)
{
CreateFSMState(pathName);
}
internal static bool CreateFSMState(string pathName,bool errorTip = true)
{
string fileName = Path.GetFileNameWithoutExtension(pathName);
// 判断文件是否已经存在 如果已经存在则不能创建
string[] guids = AssetDatabase.FindAssets(fileName);
foreach (var item in guids)
{
string asset_path = AssetDatabase.GUIDToAssetPath(item);
MonoScript script = AssetDatabase.LoadAssetAtPath<MonoScript>(asset_path);
if (script == null || script.GetClass() == null) continue;
if (script.GetClass().Name.Equals(fileName))
{
if (errorTip)
{
string message = string.Format("脚本名称:{0}已经存在!", fileName);
//FSMEditorWindow.ShowNotification(string.Format("脚本名称:{0}已经存在!", fileName));
EditorUtility.DisplayDialog("提示", message, "确定");
}
return false;
}
}
if (!Regex.Match(fileName, regex).Success)
{
EditorUtility.DisplayDialog("提示", string.Format("文件名:{0}不可用!", fileName), "确定");
return false;
}
TextAsset template = AssetDatabase.LoadAssetAtPath<TextAsset>("Assets/Editor/Template/FSMStateTemplate.txt");
if (template == null)
{
// Packages/com.xfkj.xffsm/Editor/Texture/logo_web.png
template = AssetDatabase.LoadAssetAtPath<TextAsset>("Packages/com.xfkj.xffsm/Editor/Template/FSMStateTemplate.txt");
}
string content = template.text;
content = content.Replace("{0}", fileName);
FileStream stream = File.Create(pathName);
stream.Write(Encoding.UTF8.GetBytes(content), 0, content.Length);
stream.Close();
//stream.Write()
AssetDatabase.Refresh();
AssetDatabase.SaveAssets();
return true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 921d2044bfcd3fa42a8426b5f080c71c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using UnityEngine;
namespace XFFSM
{
public class RuntimeFSMControllerCreator : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
RuntimeFSMController runtimeFSM = ScriptableObject.CreateInstance<RuntimeFSMController>();
AssetDatabase.CreateAsset(runtimeFSM,pathName);
Selection.activeObject = runtimeFSM;
Rect rect = new Rect(0, 100, FSMConst.StateNodeWith, FSMConst.StateNodeHeight);
FSMStateNodeFactory.CreateStateNode(runtimeFSM, FSMConst.anyState, rect, false,false,null,true,FSMConst.anyState);
rect = new Rect(0, 300, FSMConst.StateNodeWith, FSMConst.StateNodeHeight);
FSMStateNodeFactory.CreateStateNode(runtimeFSM, FSMConst.entryState, rect, false, false,null, true, FSMConst.entryState);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fbb86492958a4b945bf86d27575d1dae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: