This commit is contained in:
2025-09-18 18:25:40 +08:00
parent 8ee325cc01
commit ce06ca8571
220 changed files with 165196 additions and 21 deletions

View File

@@ -0,0 +1,292 @@
using System;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;
namespace SkierFramework
{
/* 获取内置图片
* AssetDatabase.GetBuiltinExtraResource
* "UI/Skin/UISprite.psd"
"UI/Skin/Background.psd"
"UI/Skin/InputFieldBackground.psd"
"UI/Skin/Knob.psd"
"UI/Skin/Checkmark.psd"
"UI/Skin/DropdownArrow.psd"
"UI/Skin/UIMask.psd"
*/
public class OverrideUICreate
{
[MenuItem("GameObject/UI/Image", true)]
public static void IgnoreImage()
{
}
[MenuItem("GameObject/UI/Image.")]
public static void CreateImage()
{
var image = Create<Image>();
image.raycastTarget = false;
image.maskable = image.GetComponentInParent<RectMask2D>() != null || image.GetComponentInParent<Mask>() != null;
image.gameObject.SetLayerRecursively(Layer.UI);
}
[MenuItem("GameObject/UI/Raw Image", true)]
public static void IgnoreRawImage()
{
}
[MenuItem("GameObject/UI/RawImage")]
public static void CreateRawImage()
{
var image = Create<RawImage>();
image.raycastTarget = false;
image.maskable = image.GetComponentInParent<RectMask2D>() != null || image.GetComponentInParent<Mask>() != null;
image.gameObject.SetLayerRecursively(Layer.UI);
}
[MenuItem("GameObject/UI/Button")]
public static void CreateButton()
{
var image = Create<Image>("Button");
var button = image.AddComponent<Button>();
image.maskable = image.GetComponentInParent<RectMask2D>() != null || image.GetComponentInParent<Mask>() != null;
image.rectTransform.sizeDelta = new Vector2(160, 30);
image.gameObject.SetLayerRecursively(Layer.UI);
}
[MenuItem("GameObject/UI/Text - TextMeshPro", true)]
public static void IgnoreTextMeshPro()
{
}
[MenuItem("GameObject/UI/Text - TextMeshPro")]
public static void CreateTextMeshPro()
{
var textMeshPro = Create<TextMeshProUGUI>("Text");
textMeshPro.raycastTarget = false;
textMeshPro.color = Color.black;
textMeshPro.maskable = textMeshPro.GetComponentInParent<RectMask2D>() != null || textMeshPro.GetComponentInParent<Mask>() != null;
textMeshPro.gameObject.SetLayerRecursively(Layer.UI);
}
[MenuItem("GameObject/UI/Button - TextMeshPro", true)]
public static void IgnoreButtonTextMeshPro()
{
}
[MenuItem("GameObject/UI/Button - TextMeshPro")]
public static void CreateButtonTextMeshPro()
{
var image = Create<Image>("Button");
var button = image.AddComponent<Button>();
var textMeshPro = Create<TextMeshProUGUI>("Text", button.transform);
textMeshPro.raycastTarget = false;
textMeshPro.maskable = textMeshPro.GetComponentInParent<RectMask2D>() != null || textMeshPro.GetComponentInParent<Mask>() != null;
textMeshPro.text = "Button";
textMeshPro.alignment = TextAlignmentOptions.Center;
textMeshPro.alignment = TextAlignmentOptions.Midline;
textMeshPro.rectTransform.anchorMin = Vector3.zero;
textMeshPro.rectTransform.anchorMax = Vector3.one;
textMeshPro.rectTransform.sizeDelta = Vector2.zero;
textMeshPro.color = Color.black;
textMeshPro.fontSize = 24;
image.maskable = textMeshPro.maskable;
image.rectTransform.sizeDelta = new Vector2(160, 30);
image.gameObject.SetLayerRecursively(Layer.UI);
}
#region ScrollRect
[MenuItem("GameObject/UI/Scroll View", true)]
public static void IgnoreScrollView()
{
}
[MenuItem("GameObject/UI/UIScrollView")]
public static ScrollRect CreateScrollView()
{
var image = Create<Image>("UIScrollView");
image.raycastTarget = true;
image.maskable = false;
image.rectTransform.sizeDelta = new Vector2(200, 200);
var scrollRect = image.AddComponent<ScrollRect>();
var uIScrollView = image.AddComponent<UIScrollView>();
var viewportImage = Create<Image>("Viewport", uIScrollView.transform);
viewportImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UIMask.psd");
viewportImage.type = Image.Type.Sliced;
viewportImage.raycastTarget = true;
viewportImage.maskable = true;
var viewport = viewportImage.transform as RectTransform;
viewport.AddComponent<RectMask2D>();
viewport.anchorMin = Vector2.zero;
viewport.anchorMax = Vector2.one;
viewport.pivot = new Vector2(0, 1);
viewport.sizeDelta = Vector2.zero;
viewport.anchoredPosition = Vector2.zero;
scrollRect.viewport = viewport;
var content = Create<RectTransform>("Content", viewport);
content.anchorMin = new Vector2(0, 1);
content.anchorMax = new Vector2(1, 1);
content.pivot = new Vector2(0, 1);
content.sizeDelta = new Vector2(0, 300);
content.anchoredPosition = Vector2.zero;
scrollRect.content = content;
uIScrollView.m_ScrollRect = scrollRect;
uIScrollView.m_Content = content;
scrollRect.gameObject.SetLayerRecursively(Layer.UI);
return scrollRect;
}
[MenuItem("GameObject/UI/UIScrollView - Horizontal")]
public static void CreateScrollViewHorizontal()
{
var scrollRect = CreateScrollView();
scrollRect.horizontalScrollbar = CreateScrollBar("Scrollbar Horizontal", scrollRect.transform);
scrollRect.horizontalScrollbar.direction = Scrollbar.Direction.LeftToRight;
scrollRect.verticalScrollbarVisibility = scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
scrollRect.verticalScrollbarSpacing = scrollRect.horizontalScrollbarSpacing = -3;
var uiScrollView = scrollRect.GetComponent<UIScrollView>();
uiScrollView.m_AxisType = RectTransform.Axis.Horizontal;
uiScrollView.m_AlignType = AlignType.Left;
scrollRect.gameObject.SetLayerRecursively(Layer.UI);
}
[MenuItem("GameObject/UI/UIScrollView - Vertical")]
public static void CreateScrollViewVertical()
{
var scrollRect = CreateScrollView();
scrollRect.verticalScrollbar = CreateScrollBar("Scrollbar Vertical", scrollRect.transform);
var verticalRect = scrollRect.verticalScrollbar.transform as RectTransform;
verticalRect.anchorMin = new Vector2(1, 0);
verticalRect.anchorMax = new Vector2(1, 1);
verticalRect.pivot = new Vector2(1, 1);
verticalRect.sizeDelta = new Vector2(20, 0);
verticalRect.anchoredPosition = Vector2.zero;
scrollRect.verticalScrollbar.direction = Scrollbar.Direction.BottomToTop;
scrollRect.verticalScrollbarVisibility = scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
scrollRect.verticalScrollbarSpacing = scrollRect.horizontalScrollbarSpacing = -3;
scrollRect.gameObject.SetLayerRecursively(Layer.UI);
}
[MenuItem("GameObject/UI/UIScrollView - All")]
public static void CreateScrollViewAll()
{
var scrollRect = CreateScrollView();
scrollRect.horizontalScrollbar = CreateScrollBar("Scrollbar Horizontal", scrollRect.transform);
scrollRect.horizontalScrollbar.direction = Scrollbar.Direction.LeftToRight;
scrollRect.verticalScrollbar = CreateScrollBar("Scrollbar Vertical", scrollRect.transform);
var verticalRect = scrollRect.verticalScrollbar.transform as RectTransform;
verticalRect.anchorMin = new Vector2(1, 0);
verticalRect.anchorMax = new Vector2(1, 1);
verticalRect.pivot = new Vector2(1, 1);
verticalRect.sizeDelta = new Vector2(20, 0);
verticalRect.anchoredPosition = Vector2.zero;
scrollRect.verticalScrollbar.direction = Scrollbar.Direction.BottomToTop;
scrollRect.verticalScrollbarVisibility = scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
scrollRect.verticalScrollbarSpacing = scrollRect.horizontalScrollbarSpacing = -3;
scrollRect.gameObject.SetLayerRecursively(Layer.UI);
}
public static Scrollbar CreateScrollBar(string name, Transform parent)
{
var verticalScorllImage = Create<Image>(name, parent);
verticalScorllImage.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Background.psd");
verticalScorllImage.type = Image.Type.Sliced;
var verticalScroll = verticalScorllImage.AddComponent<Scrollbar>();
var verticalRect = verticalScroll.transform as RectTransform;
verticalRect.anchorMin = Vector2.zero;
verticalRect.anchorMax = new Vector2(1, 0);
verticalRect.pivot = Vector2.zero;
verticalRect.sizeDelta = new Vector2(0, 20);
verticalRect.anchoredPosition = Vector2.zero;
var handle = Create<Image>("Handle", verticalRect.transform);
handle.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/UISprite.psd");
handle.type = Image.Type.Sliced;
handle.rectTransform.anchorMin = Vector2.zero;
handle.rectTransform.anchorMax = Vector2.one;
handle.rectTransform.sizeDelta = Vector2.zero;
handle.rectTransform.anchoredPosition = Vector2.zero;
verticalScroll.handleRect = handle.rectTransform;
return verticalScroll;
}
#endregion
[MenuItem("GameObject/UI/Slider", true)]
public static void IgnoreSlider()
{
}
[MenuItem("GameObject/UI/Slider.")]
public static void CreateSlider()
{
var image = Create<Image>("Slider");
image.color = Color.grey;
image.rectTransform.sizeDelta = new Vector2(160, 20);
var slider = image.AddComponent<Slider>();
slider.interactable = false;
slider.transition = Selectable.Transition.None;
var fill = Create<Image>("Fill", slider.transform);
fill.rectTransform.anchorMin = Vector2.zero;
fill.rectTransform.anchorMax = new Vector2(0, 1);
fill.rectTransform.sizeDelta = Vector2.zero;
fill.rectTransform.anchoredPosition = Vector2.zero;
slider.fillRect = fill.rectTransform;
var handle = Create<Image>("Handle", slider.transform);
handle.rectTransform.anchorMin = Vector2.zero;
handle.rectTransform.anchorMax = new Vector2(0, 1);
handle.rectTransform.sizeDelta = new Vector2(20, 0);
handle.rectTransform.anchoredPosition = Vector2.zero;
handle.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd");
slider.handleRect = handle.rectTransform;
image.gameObject.SetLayerRecursively(Layer.UI);
}
public static T Create<T>(string name = null, Transform parent = null) where T : Component
{
if (string.IsNullOrEmpty(name))
name = typeof(T).Name;
GameObject go = new GameObject(name);
if (parent == null)
{
go.transform.SetParent(Selection.activeTransform);
Selection.activeGameObject = go;
}
else
{
go.transform.SetParent(parent);
}
go.transform.localScale = Vector3.one;
go.transform.localPosition = Vector3.zero;
go.transform.localRotation = Quaternion.identity;
return go.AddComponent<T>();
}
}
}

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b8cd8920119b49bc95c6755ae94d1b26
timeCreated: 1758179166

View File

@@ -0,0 +1,41 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenAlpha))]
public class TweenAlphaEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenAlpha tw = target as TweenAlpha;
GUI.changed = false;
var from = EditorGUILayout.Slider("From", tw.from, 0f, 1f);
var to = EditorGUILayout.Slider("To", tw.to, 0f, 1f);
var ds = tw.autoCleanup;
var pn = tw.colorProperty;
if (tw.GetComponent<MeshRenderer>() != null)
{
ds = EditorGUILayout.Toggle("Auto-cleanup", tw.autoCleanup);
pn = EditorGUILayout.TextField("Color Property", tw.colorProperty);
}
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
tw.autoCleanup = ds;
tw.colorProperty = pn;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 6ca1a2b070be6f04f9dc2b6756d084ff
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,30 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenColor))]
public class TweenColorEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenColor tw = target as TweenColor;
GUI.changed = false;
Color from = EditorGUILayout.ColorField("From", tw.from);
Color to = EditorGUILayout.ColorField("To", tw.to);
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 7928b5af346eed04ba391047b8b0ddc8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,30 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenFOV))]
public class TweenFOVEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenFOV tw = target as TweenFOV;
GUI.changed = false;
float from = EditorGUILayout.Slider("From", tw.from, 1f, 180f);
float to = EditorGUILayout.Slider("To", tw.to, 1f, 180f);
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 11db62d6da2a5f34590f41ebb958bd94
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,46 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenHeight))]
public class TweenHeightEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenHeight tw = target as TweenHeight;
GUI.changed = false;
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(tw.fromTarget != null);
var from = EditorGUILayout.FloatField("From", tw.from);
EditorGUI.EndDisabledGroup();
var fc = (RectTransform)EditorGUILayout.ObjectField(tw.fromTarget, typeof(RectTransform), true, GUILayout.Width(110f));
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(tw.toTarget != null);
var to = EditorGUILayout.FloatField("To", tw.to);
EditorGUI.EndDisabledGroup();
var tc = (RectTransform)EditorGUILayout.ObjectField(tw.toTarget, typeof(RectTransform), true, GUILayout.Width(110f));
EditorGUILayout.EndHorizontal();
if (from < 0) from = 0;
if (to < 0) to = 0;
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
tw.fromTarget = fc;
tw.toTarget = tc;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4c135e5506eb921409b47fa6543134ec
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,33 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenOrthoSize))]
public class TweenOrthoSizeEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenOrthoSize tw = target as TweenOrthoSize;
GUI.changed = false;
float from = EditorGUILayout.FloatField("From", tw.from);
float to = EditorGUILayout.FloatField("To", tw.to);
if (from < 0f) from = 0f;
if (to < 0f) to = 0f;
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 37cda4ddb333a6d469473d36a439d20e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,30 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenPosition))]
public class TweenPositionEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenPosition tw = target as TweenPosition;
GUI.changed = false;
Vector3 from = EditorGUILayout.Vector3Field("From", tw.from);
Vector3 to = EditorGUILayout.Vector3Field("To", tw.to);
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5c3ed7d7dc3fe434d8fbe43ba848c7de
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,32 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenRotation))]
public class TweenRotationEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenRotation tw = target as TweenRotation;
GUI.changed = false;
Vector3 from = EditorGUILayout.Vector3Field("From", tw.from);
Vector3 to = EditorGUILayout.Vector3Field("To", tw.to);
var quat = EditorGUILayout.Toggle("Quaternion", tw.quaternionLerp);
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
tw.quaternionLerp = quat;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 37920e4b9f98bd44fa1250a9d995475c
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,30 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenScale))]
public class TweenScaleEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenScale tw = target as TweenScale;
GUI.changed = false;
Vector3 from = EditorGUILayout.Vector3Field("From", tw.from);
Vector3 to = EditorGUILayout.Vector3Field("To", tw.to);
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 50b7b0504ae552a42b20841c085dc185
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,9 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenTransform))]
public class TweenTransformEditor : UITweenerEditor
{
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9ff6713338f44844c82de82685521dd3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,30 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenVolume))]
public class TweenVolumeEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenVolume tw = target as TweenVolume;
GUI.changed = false;
float from = EditorGUILayout.Slider("From", tw.from, 0f, 1f);
float to = EditorGUILayout.Slider("To", tw.to, 0f, 1f);
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 023e6404a70e48148b315cf9737211af
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,46 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(TweenWidth))]
public class TweenWidthEditor : UITweenerEditor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 120f;
TweenWidth tw = target as TweenWidth;
GUI.changed = false;
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(tw.fromTarget != null);
var from = EditorGUILayout.FloatField("From", tw.from);
EditorGUI.EndDisabledGroup();
var fc = (RectTransform)EditorGUILayout.ObjectField(tw.fromTarget, typeof(RectTransform), true, GUILayout.Width(110f));
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(tw.toTarget != null);
var to = EditorGUILayout.FloatField("To", tw.to);
EditorGUI.EndDisabledGroup();
var tc = (RectTransform)EditorGUILayout.ObjectField(tw.toTarget, typeof(RectTransform), true, GUILayout.Width(110f));
EditorGUILayout.EndHorizontal();
if (from < 0) from = 0;
if (to < 0) to = 0;
if (GUI.changed)
{
//NGUIEditorTools.RegisterUndo("Tween Change", tw);
tw.from = from;
tw.to = to;
tw.fromTarget = fc;
tw.toTarget = tc;
//NGUITools.SetDirty(tw);
}
DrawCommonProperties();
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d35cd8e39586acb4a842a0c77019d598
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,118 @@
#if UNITY_EDITOR
//-------------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2020 Tasharen Entertainment Inc
//-------------------------------------------------
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(UITweener), true)]
public class UITweenerEditor : Editor
{
public override void OnInspectorGUI ()
{
GUILayout.Space(6f);
EditorGUIUtility.labelWidth = 110f;
base.OnInspectorGUI();
DrawCommonProperties();
}
static public bool DrawHeader(string text, string key, bool forceOn, bool minimalistic)
{
bool state = EditorPrefs.GetBool(key, true);
if (!minimalistic) GUILayout.Space(3f);
if (!forceOn && !state) GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f);
GUILayout.BeginHorizontal();
GUI.changed = false;
if (minimalistic)
{
if (state) text = "\u25BC" + (char)0x200a + text;
else text = "\u25BA" + (char)0x200a + text;
GUILayout.BeginHorizontal();
GUI.contentColor = EditorGUIUtility.isProSkin ? new Color(1f, 1f, 1f, 0.7f) : new Color(0f, 0f, 0f, 0.7f);
if (!GUILayout.Toggle(true, text, "PreToolbar2", GUILayout.MinWidth(20f))) state = !state;
GUI.contentColor = Color.white;
GUILayout.EndHorizontal();
}
else
{
text = "<b><size=11>" + text + "</size></b>";
if (state) text = "\u25BC " + text;
else text = "\u25BA " + text;
if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) state = !state;
}
if (GUI.changed) EditorPrefs.SetBool(key, state);
if (!minimalistic) GUILayout.Space(2f);
GUILayout.EndHorizontal();
GUI.backgroundColor = Color.white;
if (!forceOn && !state) GUILayout.Space(3f);
return state;
}
static public void BeginContents()
{
EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(10f));
GUILayout.Space(10f);
GUILayout.BeginVertical();
GUILayout.Space(2f);
}
static public void EndContents()
{
GUILayout.Space(3f);
GUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
GUILayout.Space(3f);
}
protected void DrawCommonProperties ()
{
UITweener tw = target as UITweener;
if (DrawHeader("Tweener", "Tweener", false , true))
{
BeginContents();
EditorGUIUtility.labelWidth = 110f;
GUI.changed = false;
UITweener.Style style = (UITweener.Style)EditorGUILayout.EnumPopup("Play Style", tw.style);
AnimationCurve curve = EditorGUILayout.CurveField("Animation Curve", tw.animationCurve, GUILayout.Width(170f), GUILayout.Height(62f));
GUILayout.BeginHorizontal();
float dur = EditorGUILayout.FloatField("Duration", tw.duration, GUILayout.Width(170f));
GUILayout.Label("seconds");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
float del = EditorGUILayout.FloatField("Start Delay", tw.delay, GUILayout.Width(170f));
GUILayout.Label("seconds");
GUILayout.EndHorizontal();
var deff = (UITweener.DelayAffects)EditorGUILayout.EnumPopup("Delay Affects", tw.delayAffects);
int tg = EditorGUILayout.IntField("Tween Group", tw.tweenGroup, GUILayout.Width(170f));
bool ts = EditorGUILayout.Toggle("Ignore TimeScale", tw.ignoreTimeScale);
bool fx = EditorGUILayout.Toggle("Use Fixed Update", tw.useFixedUpdate);
if (GUI.changed)
{
tw.animationCurve = curve;
tw.style = style;
tw.ignoreTimeScale = ts;
tw.tweenGroup = tg;
tw.duration = dur;
tw.delay = del;
tw.delayAffects = deff;
tw.useFixedUpdate = fx;
}
EndContents();
}
}
}
#endif

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 3564c93409a4aaa44a48de1e49be56ba
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 391048bfcbd4480ebaf66c91987b291f
timeCreated: 1758179210

View File

@@ -0,0 +1,252 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
namespace SkierFramework
{
public class ControlItemDrawer
{
private UIControlDataEditor _container;
private CtrlItemData _itemData;
private bool _foldout = true;
private int _controlTypeIdx = 0;
public ControlItemDrawer(UIControlDataEditor container, CtrlItemData item)
{
_container = container;
_itemData = item;
}
public bool Draw()
{
EditorGUI.BeginChangeCheck();
Rect rect = EditorGUILayout.BeginVertical();
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("变量名 ", UIControlDataEditor.skin.label, GUILayout.Width(60f));
string newName = EditorGUILayout.TextField(_itemData.name, UIControlDataEditor.skin.textField).Trim();
if (newName != _itemData.name)
{
_itemData.name = newName;
(_container.target as UIControlData).SetDirty();
}
EditorGUILayout.Space();
_foldout = EditorGUILayout.Foldout(_foldout, _foldout ? "收起" : "展开", true);
if (GUILayout.Button("+", EditorStyles.miniButton))
{
_container.AddControlAfter(this);
return false;
}
if (GUILayout.Button("-", EditorStyles.miniButton))
{
_container.RemoveControl(this);
return false;
}
GUILayout.FlexibleSpace();
}
EditorGUILayout.EndHorizontal();
// 控件列表
if (_foldout)
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("变量类型 ", UIControlDataEditor.skin.label, GUILayout.Width(60f));
if (_controlTypeIdx == 0 && !string.IsNullOrEmpty(_itemData.type))
_controlTypeIdx = FindTypeIdx(_itemData.type);
if (EditorGUI.EndChangeCheck())
{
(_container.target as UIControlData).SetDirty();
}
EditorGUI.BeginChangeCheck();
_controlTypeIdx = EditorGUILayout.Popup(_controlTypeIdx, _container.allTypeNames, UIControlDataEditor.popupAlignLeft);
if (EditorGUI.EndChangeCheck())
{
if(_controlTypeIdx != 0)
{
if (!ChangeControlsTypeTo(_controlTypeIdx))
_controlTypeIdx = 0; // 切换失败,重置回自动
}
else // 被主动设置为了自动
_itemData.type = string.Empty;
(_container.target as UIControlData).SetDirty();
return false;
}
EditorGUI.BeginChangeCheck();
GUILayout.FlexibleSpace();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
for (int i = 0, imax = _itemData.targets.Length; i < imax; i++)
{
Object obj = _itemData.targets[i];
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginChangeCheck();
_itemData.targets[i] = EditorGUILayout.ObjectField(obj, typeof(Object), true);
if (EditorGUI.EndChangeCheck())
{
(_container.target as UIControlData).SetDirty();
}
EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space();
if (GUILayout.Button("+", EditorStyles.miniButton))
{
InsertItem(i + 1);
return false;
}
if (GUILayout.Button("-", EditorStyles.miniButton))
{
if(_itemData.targets.Length == 1)
{
Debug.LogError("至少应保留一个控件");
return false;
}
else
{
RemoveItem(i);
return false;
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
}
}
EditorGUILayout.EndVertical();
if (EditorGUIUtility.isProSkin)
GUI.Box(new Rect(rect.x - 10f, rect.y - 5f, rect.width + 20f, rect.height + 15f), "");
else
GUI.Box(new Rect(rect.x - 10f, rect.y - 5f, rect.width + 20f, rect.height + 15f), "", UIControlDataEditor.skin.box);
if (EditorGUI.EndChangeCheck())
{
(_container.target as UIControlData).SetDirty();
}
PostProcess();
return true;
}
private void PostProcess()
{
// 默认将新添加的第一个控件的名字作为变量名
if (_itemData.targets.Length > 0 && _itemData.targets[0] != null && string.IsNullOrEmpty(_itemData.name))
_itemData.name = _itemData.targets[0].name.Trim();
}
private int FindTypeIdx(string typeName)
{
string[] allTypeNames = _container.allTypeNames;
for (int i = 0, imax = allTypeNames.Length; i < imax; i++)
{
if(allTypeNames[i] == typeName)
return i;
}
return 0;
}
private void InsertItem(int idx)
{
Object[] newArr = new Object[_itemData.targets.Length + 1];
for(int i = 0; i < idx; i++)
{
newArr[i] = _itemData.targets[i];
}
newArr[idx] = null;
for(int i = idx + 1; i < newArr.Length; i++)
{
newArr[i] = _itemData.targets[i - 1];
}
_itemData.targets = newArr;
}
private void RemoveItem(int idx)
{
Object[] newArr = new Object[_itemData.targets.Length - 1];
for(int i = 0; i < idx; i++)
{
newArr[i] = _itemData.targets[i];
}
for(int i = idx; i < newArr.Length; i++)
{
newArr[idx] = _itemData.targets[i + 1];
}
_itemData.targets = newArr;
}
/// <summary>
/// 将控件切换到指定类型
/// </summary>
/// <param name="typeIdx"></param>
private bool ChangeControlsTypeTo(int typeIdx)
{
System.Type targetType = _container.allTypes[typeIdx];
string targetTypeName = _container.allTypeNames[typeIdx];
bool isGameObject = targetType == typeof(GameObject);
for(int i = 0, imax = _itemData.targets.Length; i < imax; i++)
{
Object obj = _itemData.targets[i];
if (obj == null)
{
Debug.LogErrorFormat("[{0}.{1}] control[{2}] is null"
, _container.target.name, _itemData.name, i);
return false;
}
if(obj.GetType() != typeof(GameObject))
{
if((obj as Component) == null)
{
Debug.LogErrorFormat("[{0}.{1}] control[{2}] [{3}] must be GameObject or a Component"
, _container.target.name, _itemData.name, i, obj.name);
return false;
}
obj = (obj as Component).gameObject;
}
GameObject go = obj as GameObject;
if (isGameObject)
_itemData.targets[i] = go;
else
{
Component comp = go.GetComponent(targetType);
if(comp == null)
{
Debug.LogErrorFormat("[{0}.{1}] control[{2}] [{3}] isn't a {4}"
, _container.target.name, _itemData.name, i, go.name, targetTypeName);
return false;
}
_itemData.targets[i] = comp;
}
}
_itemData.type = targetTypeName;
return true;
}
}
}
#endif

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 5a19fd525bc43e2439c14dac7ed67295
timeCreated: 1521794417
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace SkierFramework
{
public class SubUIItemDrawer
{
private UIControlDataEditor _container;
private SubUIItemData _itemData;
private bool _foldout = true;
public SubUIItemDrawer(UIControlDataEditor container, SubUIItemData itemData)
{
_container = container;
_itemData = itemData;
}
public bool Draw()
{
Rect rect = EditorGUILayout.BeginVertical();
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("子UI名 ", UIControlDataEditor.skin.label);
_itemData.name = EditorGUILayout.TextField(_itemData.name, UIControlDataEditor.skin.textField).Trim();
EditorGUILayout.Space();
_foldout = EditorGUILayout.Foldout(_foldout, _foldout ? "收起" : "展开", true);
if (GUILayout.Button("+", EditorStyles.miniButton))
{
_container.AddSubUIAfter(this);
return false;
}
if (GUILayout.Button("-", EditorStyles.miniButton))
{
_container.RemoveSubUI(this);
return false;
}
}
EditorGUILayout.EndHorizontal();
if (_foldout)
{
EditorGUILayout.Space();
_itemData.subUIData = EditorGUILayout.ObjectField(_itemData.subUIData as Object, typeof(UIControlData), true) as UIControlData;
}
}
EditorGUILayout.EndVertical();
if (EditorGUIUtility.isProSkin)
GUI.Box(new Rect(rect.x - 10f, rect.y - 5f, rect.width + 20f, rect.height + 15f), "");
else
GUI.Box(new Rect(rect.x - 10f, rect.y - 5f, rect.width + 20f, rect.height + 15f), "", UIControlDataEditor.skin.box);
PostProcess();
return true;
}
private void PostProcess()
{
// 默认将控件的名字作为变量名
if (_itemData.subUIData != null && string.IsNullOrEmpty(_itemData.name))
_itemData.name = _itemData.subUIData.name.Trim();
}
}
}
#endif

View File

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

View File

@@ -0,0 +1,234 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
namespace SkierFramework
{
[CustomEditor(typeof(UIControlData))]
public class UIControlDataEditor : Editor
{
public static GUISkin skin;
public static GUIStyle popupAlignLeft; // TODO 挪出去一个 SkinManager
public string[] allTypeNames;
public Type[] allTypes;
private List<CtrlItemData> _ctrlItemDatas;
private List<SubUIItemData> _subUIItemDatas;
private List<ControlItemDrawer> _ctrlItemDrawers;
private List<SubUIItemDrawer> _subUIItemDrawers;
void Awake()
{
if(skin == null)
{
if (EditorGUIUtility.isProSkin)
skin = Resources.Load("Editor/UIControlDataSkinPro") as GUISkin;
else
skin = Resources.Load("Editor/UIControlDataSkinPersonal") as GUISkin;
}
if(popupAlignLeft == null)
{
popupAlignLeft = new GUIStyle("Popup");
popupAlignLeft.alignment = TextAnchor.MiddleLeft;
}
allTypeNames = UIControlData.GetAllTypeNames();
allTypes = UIControlData.GetAllTypes();
UIControlData uIControlData = target as UIControlData;
if (uIControlData != null)
{
uIControlData.CorrectComponents();
uIControlData.CheckSubUIs();
}
}
public override void OnInspectorGUI()
{
if (skin == null || skin.customStyles == null || skin.customStyles.Length == 0)
{
base.OnInspectorGUI();
return;
}
UIControlData data = target as UIControlData;
if(data.ctrlItemDatas == null)
data.ctrlItemDatas = new List<CtrlItemData>();
if(data.subUIItemDatas == null)
data.subUIItemDatas = new List<SubUIItemData>();
_ctrlItemDatas = data.ctrlItemDatas;
_subUIItemDatas = data.subUIItemDatas;
CheckDrawers();
EditorGUILayout.BeginVertical();
EditorGUILayout.Space();
// 绘制控件绑定
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("控件绑定", skin.customStyles[0]);
if(_ctrlItemDrawers.Count == 0)
{
if(GUILayout.Button("+", EditorStyles.miniButton))
{
AddControlAfter(-1);
Repaint();
return;
}
}
EditorGUILayout.EndHorizontal();
foreach (var drawer in _ctrlItemDrawers)
{
GUILayout.Space(10f);
if (!drawer.Draw())
{
Repaint();
return;
}
GUILayout.Space(10f);
}
GUILayout.Space(10f);
// 绘制子UI
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("子UI绑定", skin.customStyles[0]);
if(_subUIItemDrawers.Count == 0)
{
if (GUILayout.Button("+", EditorStyles.miniButton))
{
AddSubUIAfter(-1);
Repaint();
return;
}
}
EditorGUILayout.EndHorizontal();
foreach(var drawer in _subUIItemDrawers)
{
GUILayout.Space(10f);
if (!drawer.Draw())
{
Repaint();
return;
}
GUILayout.Space(10f);
}
EditorGUILayout.Space(); EditorGUILayout.Space();
EditorGUILayout.EndVertical();
this.Repaint();
}
public void AddControlAfter(ControlItemDrawer drawer)
{
int idx = _ctrlItemDrawers.IndexOf(drawer);
Debug.Assert(idx != -1);
AddControlAfter(idx);
}
public void AddSubUIAfter(SubUIItemDrawer drawer)
{
int idx = _subUIItemDrawers.IndexOf(drawer);
Debug.Assert(idx != -1);
AddSubUIAfter(idx);
}
public void RemoveControl(ControlItemDrawer drawer)
{
int idx = _ctrlItemDrawers.IndexOf(drawer);
Debug.Assert(idx != -1);
RemoveControl(idx);
}
public void RemoveSubUI(SubUIItemDrawer drawer)
{
int idx = _subUIItemDrawers.IndexOf(drawer);
Debug.Assert(idx != -1);
RemoveSubUI(idx);
}
#region Private
private void CheckDrawers()
{
if (_ctrlItemDrawers == null)
{
_ctrlItemDrawers = new List<ControlItemDrawer>(100);
foreach(var item in _ctrlItemDatas)
{
ControlItemDrawer drawer = new ControlItemDrawer(this, item);
_ctrlItemDrawers.Add(drawer);
}
}
if(_subUIItemDrawers == null)
{
_subUIItemDrawers = new List<SubUIItemDrawer>(100);
foreach(var item in _subUIItemDatas)
{
SubUIItemDrawer drawer = new SubUIItemDrawer(this, item);
_subUIItemDrawers.Add(drawer);
}
}
}
private void AddControlAfter(int idx)
{
CtrlItemData itemData = new CtrlItemData();
_ctrlItemDatas.Insert(idx + 1, itemData);
ControlItemDrawer drawer = new ControlItemDrawer(this, itemData);
_ctrlItemDrawers.Insert(idx + 1, drawer);
SetPrefabDirty();
}
private void AddSubUIAfter(int idx)
{
SubUIItemData itemData = new SubUIItemData();
_subUIItemDatas.Insert(idx + 1, itemData);
SubUIItemDrawer drawer = new SubUIItemDrawer(this, itemData);
_subUIItemDrawers.Insert(idx + 1, drawer);
SetPrefabDirty();
}
private void RemoveControl(int idx)
{
_ctrlItemDatas.RemoveAt(idx);
_ctrlItemDrawers.RemoveAt(idx);
SetPrefabDirty();
}
private void RemoveSubUI(int idx)
{
_subUIItemDatas.RemoveAt(idx);
_subUIItemDrawers.RemoveAt(idx);
SetPrefabDirty();
}
private void SetPrefabDirty()
{
UIControlData uIControlData = target as UIControlData;
uIControlData.SetDirty();
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 27c41d595322d554a9afea0d2b516863
timeCreated: 1521786373
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,564 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Text.RegularExpressions;
using System.IO;
using SkierFramework;
using System;
using System.Linq;
using Newtonsoft.Json;
using YooAsset.Editor;
public class UICreateWindow : EditorWindow
{
#region MenuItem
[MenuItem("Assets/Create/CreateUI")]
private static void CopyUI()
{
if (Selection.activeObject == null || !(Selection.activeObject is GameObject))
{
Debug.LogError("请选择UI预制体!");
return;
}
UICreateWindow.OpenWindow().uiPrefab = Selection.activeObject as GameObject;
}
[MenuItem("Tools/UI管理")]
public static UICreateWindow OpenWindow()
{
var window = GetWindow<UICreateWindow>("UI管理");
if (window == null)
{
window = CreateWindow<UICreateWindow>("UI管理");
}
window.name = "UI管理";
window.Focus();
return window;
}
#endregion
private string _packageName;
private string _mInput;
private Vector2 _scroll;
private Vector2 _scroll2;
private Vector2 _scroll3;
private string _uiViewTemplate = "UIViewTemplate";
private string _uiConfig = "UIConfig";
private string _uiType = "UIType";
private string _saveUIPath = "SaveUIPath";
private string _uiName;
public GameObject uiPrefab;
private Dictionary<string, string> _uiNames = new Dictionary<string, string>();
private Dictionary<string, UIConfigJson> _uiJsonDatas = new Dictionary<string, UIConfigJson>();
private bool _isWindow = true;
private UILayer _layer = UILayer.NormalLayer;
private IEnumerable<Type> uiViews;
private void OnEnable()
{
TryGetPath(ref _uiViewTemplate, _uiViewTemplate, ".txt");
TryGetPath(ref _uiType, _uiType, ".cs");
TryGetPath(ref _uiConfig, _uiConfig, ".json");
_saveUIPath = PlayerPrefs.GetString(_saveUIPath, "Assets/Scripts");
_uiJsonDatas.Clear();
_uiNames.Clear();
// string[] strs = Enum.GetNames(typeof(UIType));
uiViews = ReflectionHelper.GetAllUIViewTypes();
foreach (var uiView in uiViews)
{
string str = uiView.Name;
if (str.Equals("Max")) continue;
var jsonData = GetUIJson(str);
if (jsonData == null || string.IsNullOrEmpty(jsonData.path)) continue;
var scriptPath = GetUIScript(str, true);
_uiNames.AddOrUpdate(str, scriptPath);
}
}
private void OnGUI()
{
EditorGUILayout.LabelField("通过[Tools/UI管理]可以打开");
_scroll = EditorGUILayout.BeginScrollView(_scroll);
{
EditorGUILayout.HelpBox("UI基础文件", MessageType.Info);
{
_packageName = StringInputFild("PackageName", "UIPackageName");
PathField("UI模板文件.txt", ref _uiViewTemplate, nameof(_uiViewTemplate), ".txt");
PathField("UI配置文件.json", ref _uiConfig, nameof(_uiConfig), ".json");
PathField("UIType.cs", ref _uiType, nameof(_uiType), ".cs");
}
EditorGUILayout.Space(10);
EditorGUILayout.BeginHorizontal();
{
_scroll2 = EditorGUILayout.BeginScrollView(_scroll2, "box", GUILayout.Width(position.width * 0.4f - 6));
{
EditorGUILayout.HelpBox("已创建的UI", MessageType.Info);
_mInput = EditorGUILayout.TextField(_mInput, EditorStyles.toolbarSearchField, GUILayout.Height(20));
//string[] strs = Enum.GetNames(typeof(UIType));
foreach (var uiView in uiViews)
{
string str = uiView.Name;
if (str.Equals("Max")) continue;
if (!string.IsNullOrEmpty(_mInput) && !str.Contains(_mInput)) continue;
var jsonData = GetUIJson(str);
var scriptPath = GetUIScript(str);
if (jsonData == null || string.IsNullOrEmpty(jsonData.path) ||
string.IsNullOrEmpty(scriptPath)) continue;
var defaultColor = GUI.color;
if (str.Equals(_uiName))
{
GUI.color = Color.yellow;
}
EditorGUILayout.BeginHorizontal("box");
if (GUILayout.Button("选中"))
{
uiPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(jsonData.path);
}
EditorGUILayout.ObjectField(AssetDatabase.LoadAssetAtPath<GameObject>(jsonData.path),
typeof(GameObject), true);
EditorGUILayout.ObjectField(AssetDatabase.LoadAssetAtPath<TextAsset>(scriptPath),
typeof(TextAsset), true);
EditorGUILayout.EndHorizontal();
GUI.color = defaultColor;
}
if (GUILayout.Button("标记资源"))
{
Mask();
}
}
EditorGUILayout.EndScrollView();
_scroll3 = EditorGUILayout.BeginScrollView(_scroll3, "box", GUILayout.Width(position.width * 0.6f - 6));
{
EditorGUILayout.HelpBox("UI操作", MessageType.Info);
uiPrefab = EditorGUILayout.ObjectField("UI预制体", uiPrefab, typeof(GameObject), true) as GameObject;
if (uiPrefab != null)
{
_uiName = uiPrefab.name;
var uiScriptPath = GetUIScript(_uiName);
if (string.IsNullOrEmpty(uiScriptPath))
{
if (GUILayout.Button($"选择创建路径:{_saveUIPath}"))
{
var newPath = EditorUtility.OpenFolderPanel("UI生成路径", _saveUIPath, "");
_saveUIPath = newPath.Replace(Application.dataPath, "Assets");
PlayerPrefs.SetString(nameof(_saveUIPath), _saveUIPath);
}
if (uiPrefab != null)
{
EditorGUILayout.TextField("UI生成路径", $"{_saveUIPath}/{_uiName}.cs");
}
_isWindow = EditorGUILayout.Toggle("是否为窗口", _isWindow);
_layer = (UILayer)EditorGUILayout.EnumPopup("UILayer设置", _layer);
var defaultColor = GUI.color;
GUI.color = Color.green;
if (GUILayout.Button("创建UI"))
{
// 生成代码
string str = Regex.Replace(File.ReadAllText(_uiViewTemplate), "UIXXXView", _uiName);
UIControlData uiControlData = uiPrefab.GetComponent<UIControlData>();
if (uiControlData != null)
{
uiControlData.CopyCodeToClipBoardPrivate();
}
str = Regex.Replace(str, "//UIControlData",
uiControlData != null ? UnityEngine.GUIUtility.systemCopyBuffer : "");
string newPath = $"{_saveUIPath}/{_uiName}.cs";
File.WriteAllText(newPath, str);
var jsonData = new UIConfigJson
{
uiType = _uiName,
path = AssetDatabase.GetAssetPath(uiPrefab),
isWindow = _isWindow,
uiLayer = _layer.ToString(),
};
_uiJsonDatas.Add(_uiName, jsonData);
_uiNames.Add(_uiName, newPath);
SaveJson();
// 生成UIType
var newStr = Regex.Replace(File.ReadAllText(_uiType), "Max,", $"{_uiName},\n\t\tMax,");
File.Delete(_uiType);
File.WriteAllText(_uiType, newStr);
Debug.Log("生成成功:" + newPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
GUI.color = defaultColor;
}
else
{
var jsonData = GetUIJson(_uiName);
if (UnityEditor.PrefabUtility.IsPartOfPrefabAsset(uiPrefab))
{
// 预制体资源就是自身
jsonData.path = UnityEditor.AssetDatabase.GetAssetPath(uiPrefab);
}
EditorGUILayout.ObjectField("已创建脚本",
AssetDatabase.LoadAssetAtPath(uiScriptPath, typeof(TextAsset)), typeof(TextAsset),
true);
jsonData.isWindow = EditorGUILayout.Toggle("是否为窗口", jsonData.isWindow);
Enum.TryParse(jsonData.uiLayer, out UILayer layer);
jsonData.uiLayer = EditorGUILayout.EnumPopup("UILayer设置", layer).ToString();
var defaultColor = GUI.color;
GUI.color = Color.green;
if (GUILayout.Button("保存设置"))
{
SaveJson();
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
GUI.color = defaultColor;
GUI.color = Color.red;
if (GUILayout.Button("删除UI脚本"))
{
if (EditorUtility.DisplayDialog("是否确认删除",
$"请确认是否删除:\n{uiScriptPath}\n同时会清除JsonUIType中相关数据", "确定", "取消"))
{
// 清除UIType中指定类型
var uiTypeStr = File.ReadAllText(_uiType);
int index = uiTypeStr.IndexOf(_uiName);
int leftIndex = uiTypeStr.Substring(0, index).LastIndexOf(',') + 1;
int rightIndex = uiTypeStr.Substring(index, uiTypeStr.Length - index).IndexOf(',') +
index + 1;
var newStr = uiTypeStr.Substring(0, leftIndex) +
uiTypeStr.Substring(rightIndex, uiTypeStr.Length - rightIndex);
File.Delete(_uiType);
File.WriteAllText(_uiType, newStr);
// 清除UIConfig中的指定类型
_uiJsonDatas.Remove(_uiName);
_uiNames.Remove(_uiName);
SaveJson();
// 删除文件
File.Delete(uiScriptPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
_uiNames.Remove(_uiName);
}
}
GUI.color = defaultColor;
}
}
else
{
_uiName = "";
}
}
EditorGUILayout.EndScrollView();
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
}
private void SaveJson()
{
List<UIConfigJson> list = new List<UIConfigJson>();
foreach (var name in _uiNames.Keys)
{
if (_uiJsonDatas.TryGetValue(name, out var data))
{
list.Add(data);
}
}
File.Delete(_uiConfig);
File.WriteAllText(_uiConfig, JsonConvert.SerializeObject(list, Formatting.Indented));
}
private void TryGetPath(ref string path, string pathName, string endsWith)
{
path = PlayerPrefs.GetString(pathName);
if (!File.Exists(path))
{
string[] ids = AssetDatabase.FindAssets(pathName);
if (ids != null)
{
foreach (var id in ids)
{
var str = AssetDatabase.GUIDToAssetPath(id);
if (str.EndsWith(endsWith))
{
path = str;
}
}
}
}
}
private string GetUIScript(string name, bool tryFind = false)
{
if (_uiNames.TryGetValue(name, out string path))
{
return path;
}
if (!tryFind)
{
return string.Empty;
}
if (GetUIJson(name) == null) return string.Empty;
string[] ids = AssetDatabase.FindAssets(name);
if (ids != null)
{
foreach (var id in ids)
{
var str = AssetDatabase.GUIDToAssetPath(id);
if (str.EndsWith(".cs"))
{
return str;
}
}
}
return string.Empty;
}
private UIConfigJson GetUIJson(string name)
{
if (_uiJsonDatas.Count == 0)
{
try
{
var json = File.ReadAllText(_uiConfig);
var list = JsonConvert.DeserializeObject<List<UIConfigJson>>(json);
foreach (var item in list)
{
_uiJsonDatas.AddOrUpdate(item.uiType, item);
}
}
catch (Exception e)
{
Debug.LogError(e);
}
}
if (_uiJsonDatas.TryGetValue(name, out var jsonData))
{
return jsonData;
}
return null;
}
private string StringInputFild(string name, string endsWith)
{
string value = PlayerPrefs.GetString(name);
if (string.IsNullOrEmpty(value))
{
if (!string.IsNullOrEmpty(endsWith))
{
PlayerPrefs.SetString(name, endsWith);
}
}
else
{
endsWith = value;
}
return EditorGUILayout.TextField(name, endsWith);
}
private void PathField(string name, ref string path, string pathName, string endsWith)
{
var obj = EditorGUILayout.ObjectField(name, AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset)),
typeof(TextAsset), true);
if (obj != null)
{
var newPath = AssetDatabase.GetAssetPath(obj);
if (newPath.EndsWith(endsWith) && !newPath.Equals(path))
{
path = newPath;
PlayerPrefs.SetString(pathName, path);
}
}
}
#region Mask
public void Mask()
{
// //清空主包旧数据
AssetBundleCollectorPackage assetBundleCollectorPackage = null;
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
{
if (package.PackageName == _packageName)
{
assetBundleCollectorPackage = package;
}
}
if (assetBundleCollectorPackage == null)
{
var setting = YooAsset.Editor.AssetBundleCollectorSettingData.Setting;
setting.ShowPackageView = true;
setting.UniqueBundleName = true;
//创建Package文件
assetBundleCollectorPackage = YooAsset.Editor.AssetBundleCollectorSettingData.CreatePackage(_packageName);
}
//检测Packages是否存在TestPackage
assetBundleCollectorPackage.PackageName = _packageName;
assetBundleCollectorPackage.EnableAddressable = false;
assetBundleCollectorPackage.IncludeAssetGUID = true;
assetBundleCollectorPackage.AutoCollectShaders = true;
assetBundleCollectorPackage.IgnoreRuleName = "NormalIgnoreRule";
//标记json配置文件
if (!string.IsNullOrEmpty(_uiConfig))
{
var collectorGroup = ReflectionHelper.RemoveGroup(assetBundleCollectorPackage, "Config");
var guid = ReflectionHelper.GetGUIDByRelativePath(_uiConfig);
AssetBundleCollector collector = new AssetBundleCollector()
{
CollectPath = _uiConfig,
CollectorGUID = guid,
CollectorType = ECollectorType.MainAssetCollector,
AddressRuleName = nameof(AddressByFolderAndFileName),
};
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(collectorGroup, collector);
}
//标记预制体
foreach (var data in _uiJsonDatas)
{
var collectorGroup = ReflectionHelper.RemoveGroup(assetBundleCollectorPackage, "Prefab");
var guid = ReflectionHelper.GetGUIDByRelativePath(data.Value.path);
AssetBundleCollector collector = new AssetBundleCollector()
{
CollectPath = data.Value.path,
CollectorGUID = guid,
CollectorType = ECollectorType.MainAssetCollector,
AddressRuleName = nameof(AddressByFolderAndFileName),
AssetTags = data.Value.uiLayer.ToString(),
};
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(collectorGroup, collector);
}
YooAsset.Editor.AssetBundleCollectorSettingData.SaveFile();
Debug.Log("MarkAsset Successful");
}
#endregion
}
#endif
static class ReflectionHelper
{
public static IEnumerable<T> CreateAllInstancesOf<T>()
{
return typeof(ReflectionHelper).Assembly.GetTypes() //获取当前类库下所有类型
.Where(t => typeof(T).IsAssignableFrom(t)) //获取间接或直接继承t的所有类型
.Where(t => !t.IsAbstract && t.IsClass) //获取非抽象类 排除接口继承
.Select(t => (T)Activator.CreateInstance(t)); //创造实例,并返回结果(项目需求,可删除)
}
// 新增方法专门用于查找UIView类型的所有实现类
public static IEnumerable<Type> GetAllUIViewTypes()
{
// 查找所有程序集中的UIView类型实现
var uiviewType = typeof(UIView);
List<Type> result = new List<Type>();
// 遍历所有已加载的程序集
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
try
{
result.AddRange(assembly.GetTypes()
.Where(t => uiviewType.IsAssignableFrom(t))
.Where(t => !t.IsAbstract && t.IsClass));
}
catch (Exception)
{
// 忽略无法访问的程序集
}
}
return result;
}
/// <summary>
/// 根据相对路径获取资源的GUID
/// </summary>
/// <param name="relativePath">相对于Assets目录的路径例如"Assets/UI/Prefabs/LoginPanel.prefab"</param>
/// <returns>资源的GUID字符串如果路径无效则返回空字符串</returns>
public static string GetGUIDByRelativePath(string relativePath)
{
// 检查路径是否为空
if (string.IsNullOrEmpty(relativePath))
{
Debug.LogError("相对路径不能为空");
return string.Empty;
}
// 检查路径是否存在
if (!AssetDatabase.IsValidFolder(Path.GetDirectoryName(relativePath)) &&
!System.IO.File.Exists(Path.Combine(Application.dataPath, relativePath.Replace("Assets/", ""))))
{
Debug.LogError(string.Format("路径不存在: {0}", relativePath));
return string.Empty;
}
// 获取GUID
string guid = AssetDatabase.AssetPathToGUID(relativePath);
if (string.IsNullOrEmpty(guid))
{
Debug.LogWarning(string.Format("无法获取路径的GUID: {0}", relativePath));
}
return guid;
}
public static AssetBundleCollectorGroup RemoveGroup(AssetBundleCollectorPackage package, string groupName)
{
//删除的Group
var groupToDelete = package.Groups.FirstOrDefault(g => g.GroupName == groupName);
if (groupToDelete == null)
{
UnityEngine.Debug.LogError($"在Package中未找到Group '{groupName}'");
}
// 3. 从Package的Groups集合中删除该Group
package.Groups.Remove(groupToDelete);
return YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(package, groupName);
}
}

View File

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

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using TMPro;
namespace SkierFramework
{
public class UIXXXView : UIView
{
//UIControlData
public override void OnInit(UIControlData uIControlData, UIViewController controller)
{
base.OnInit(uIControlData, controller);
}
public override void OnOpen(object userData)
{
base.OnOpen(userData);
}
public override void OnAddListener()
{
base.OnAddListener();
}
public override void OnRemoveListener()
{
base.OnRemoveListener();
}
public override void OnClose()
{
base.OnClose();
}
}
}

View File

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