优化
1.更改了UXController相关的命名空间 2.增加UXController相关的UI生成接口
This commit is contained in:
parent
68566ef5d5
commit
fb9846d10c
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AlicizaX.UI
|
namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
[CustomEditor(typeof(UXBinding))]
|
[CustomEditor(typeof(UXBinding))]
|
||||||
public sealed class UXBindingEditor : UnityEditor.Editor
|
public sealed class UXBindingEditor : UnityEditor.Editor
|
||||||
|
|||||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AlicizaX.UI
|
namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
[CustomEditor(typeof(UXController))]
|
[CustomEditor(typeof(UXController))]
|
||||||
public sealed class UXControllerEditor : UnityEditor.Editor
|
public sealed class UXControllerEditor : UnityEditor.Editor
|
||||||
|
|||||||
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AlicizaX.UI
|
namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
public sealed class UXControllerSceneOverlayWindow : EditorWindow
|
public sealed class UXControllerSceneOverlayWindow : EditorWindow
|
||||||
{
|
{
|
||||||
|
|||||||
66
Editor/UX/Controller/UXControllerUIScriptFileWriter.cs
Normal file
66
Editor/UX/Controller/UXControllerUIScriptFileWriter.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using AlicizaX.UI.Editor;
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI
|
||||||
|
{
|
||||||
|
public sealed class UXControllerUIScriptFileWriter : IUIScriptFileWriter
|
||||||
|
{
|
||||||
|
public void Write(GameObject targetObject, string className, string scriptContent, UIScriptGenerateData scriptGenerateData)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(className)) throw new ArgumentNullException(nameof(className));
|
||||||
|
if (scriptContent == null) throw new ArgumentNullException(nameof(scriptContent));
|
||||||
|
if (scriptGenerateData == null) throw new ArgumentNullException(nameof(scriptGenerateData));
|
||||||
|
|
||||||
|
var scriptFolderPath = scriptGenerateData.GenerateHolderCodePath;
|
||||||
|
var scriptFilePath = Path.Combine(scriptFolderPath, $"{className}.cs");
|
||||||
|
|
||||||
|
Directory.CreateDirectory(scriptFolderPath);
|
||||||
|
scriptContent = scriptContent.Replace("#Controller#", GetControllerContent(targetObject));
|
||||||
|
|
||||||
|
if (File.Exists(scriptFilePath) && IsContentUnchanged(scriptFilePath, scriptContent))
|
||||||
|
{
|
||||||
|
UIScriptGeneratorHelper.BindUIScript();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllText(scriptFilePath, scriptContent, Encoding.UTF8);
|
||||||
|
AssetDatabase.Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsContentUnchanged(string filePath, string newContent)
|
||||||
|
{
|
||||||
|
var oldText = File.ReadAllText(filePath, Encoding.UTF8);
|
||||||
|
return oldText.Equals(newContent, StringComparison.Ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetControllerContent(GameObject targetObject)
|
||||||
|
{
|
||||||
|
UXController controller = targetObject.GetComponent<UXController>();
|
||||||
|
if (controller == null || controller.Controllers.Count == 0) return string.Empty;
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
foreach (var ctl in controller.Controllers)
|
||||||
|
{
|
||||||
|
string varibleName = ctl.Name.Substring(0, 1).ToUpper() + ctl.Name.Substring(1);
|
||||||
|
sb.AppendLine($"\t\tpublic UXController.ControllerDefinition {varibleName} {{ get; private set; }}");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine("\t\tpublic override void Awake()");
|
||||||
|
sb.AppendLine("\t\t{");
|
||||||
|
sb.AppendLine("\t\t\tbase.Awake();");
|
||||||
|
sb.AppendLine("\t\t\tvar ctl = gameObject.GetComponent<UXController>();");
|
||||||
|
|
||||||
|
foreach (var ctl in controller.Controllers)
|
||||||
|
{
|
||||||
|
string varibleName = ctl.Name.Substring(0, 1).ToUpper() + ctl.Name.Substring(1);
|
||||||
|
sb.AppendLine($"\t\t\t{varibleName} = ctl.GetControllerByName(\"{ctl.Name}\");");
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.AppendLine("\t\t}");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ab989ac78a8546a4af89da0f0fe1b8f1
|
||||||
|
timeCreated: 1774247192
|
||||||
@ -2,7 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace AlicizaX.UI
|
namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
public enum UXBindingFallbackMode
|
public enum UXBindingFallbackMode
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace AlicizaX.UI
|
namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
public sealed class UXBindingPropertyMetadata
|
public sealed class UXBindingPropertyMetadata
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,7 +5,7 @@ using UnityEngine;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace AlicizaX.UI
|
namespace UnityEngine.UI
|
||||||
{
|
{
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
[AddComponentMenu("UX/UX Controller")]
|
[AddComponentMenu("UX/UX Controller")]
|
||||||
@ -89,6 +89,7 @@ namespace AlicizaX.UI
|
|||||||
return _controllers;
|
return _controllers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IReadOnlyList<UXBinding> Bindings => _bindings;
|
public IReadOnlyList<UXBinding> Bindings => _bindings;
|
||||||
public int ControllerCount => _controllers.Count;
|
public int ControllerCount => _controllers.Count;
|
||||||
|
|
||||||
@ -128,6 +129,22 @@ namespace AlicizaX.UI
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ControllerDefinition GetControllerByName(string controllerName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(controllerName))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
EnsureInitialized();
|
||||||
|
if (_controllerNameMap.TryGetValue(controllerName, out int index))
|
||||||
|
{
|
||||||
|
return _controllers[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public ControllerDefinition GetControllerAt(int index)
|
public ControllerDefinition GetControllerAt(int index)
|
||||||
{
|
{
|
||||||
EnsureInitialized();
|
EnsureInitialized();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user