diff --git a/.psd2uguiExamples/Sample.psd b/.psd2uguiExamples/Sample.psd index 09e7e6b..0b47cba 100644 Binary files a/.psd2uguiExamples/Sample.psd and b/.psd2uguiExamples/Sample.psd differ diff --git a/Assets/Editor/EditorConst.cs b/Assets/Editor/EditorConst.cs index 4d11fc7..e98200e 100644 --- a/Assets/Editor/EditorConst.cs +++ b/Assets/Editor/EditorConst.cs @@ -1,4 +1,5 @@ -namespace UguiToolkit.Editor +#if UNITY_EDITOR +namespace UguiToolkit.Editor { public class EditorConst { @@ -9,4 +10,5 @@ public const string RotScaleInfoToolFilePath = "Packages/com.soviby.unity.ui.ugui-toolkit/.tools/result_rot_scale/main.exe"; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/EditorDefine.cs b/Assets/Editor/EditorDefine.cs index e00d6de..8a1139c 100644 --- a/Assets/Editor/EditorDefine.cs +++ b/Assets/Editor/EditorDefine.cs @@ -1,4 +1,5 @@ -using System; +#if UNITY_EDITOR +using System; using System.Collections.Generic; namespace UguiToolkit.Editor @@ -16,4 +17,5 @@ namespace UguiToolkit.Editor public float rot; public float[] scale; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Entity/IEntity.cs b/Assets/Editor/Entity/IEntity.cs index 653218d..99c07e5 100644 --- a/Assets/Editor/Entity/IEntity.cs +++ b/Assets/Editor/Entity/IEntity.cs @@ -1,4 +1,4 @@ -using System.Collections; +#if UNITY_EDITOR using Unity.Mathematics; using UnityEngine; @@ -19,6 +19,8 @@ namespace UguiToolkit.Editor private float2 scale; private bool needFillTransform; + protected T2 ElementInfo => m_elementInfo; + public void ApplyTransform(Transform transform) { if (needFillTransform) @@ -27,7 +29,7 @@ namespace UguiToolkit.Editor transform.localScale = new Vector3(scale.x, scale.y, 0); } var position = m_elementInfo.Position; - transform.position = new Vector3(position.x, position.y, 0); + transform.localPosition = new Vector3(position.x, position.y, 0); } // 查找时调用 @@ -55,4 +57,5 @@ namespace UguiToolkit.Editor protected virtual void OnApplyData(T1 ui, T2 elementInfo) { } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Entity/ImageEntity.cs b/Assets/Editor/Entity/ImageEntity.cs index feb60d9..6db922c 100644 --- a/Assets/Editor/Entity/ImageEntity.cs +++ b/Assets/Editor/Entity/ImageEntity.cs @@ -1,13 +1,46 @@ -using System.Collections; -using System.Collections.Generic; +#if UNITY_EDITOR using UguiToolkit.Editor; +using UnityEditor; using UnityEngine; using UnityEngine.UI; public class ImageEntity : BaseEntity { + private Image m_previewImage; + protected override void OnApplyData(Image ui, LayoutInfo.ImageInfo elementInfo) { } + + public void InitPreviewImage() { + if (ElementInfo == null) return; + + if (!TryGetComponent(out m_previewImage)) + { + m_previewImage = gameObject.AddComponent(); + } + + LoadImageFromFile(ElementInfo.imgPath); + ApplyTransform(transform); + } + + void LoadImageFromFile(string path) + { + if (System.IO.File.Exists(path)) + { + byte[] fileData = System.IO.File.ReadAllBytes(path); + Texture2D texture = new Texture2D(2, 2); + texture.LoadImage(fileData); // ͼƬݵTexture2D + + Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); + m_previewImage.sprite = sprite; + m_previewImage.SetNativeSize(); + } + else + { + Debug.LogError("File not found at path: " + path); + } + } } +#endif \ No newline at end of file diff --git a/Assets/Editor/Entity/TextEntity.cs b/Assets/Editor/Entity/TextEntity.cs index db06fee..d4dfd2b 100644 --- a/Assets/Editor/Entity/TextEntity.cs +++ b/Assets/Editor/Entity/TextEntity.cs @@ -1,3 +1,4 @@ +#if UNITY_EDITOR using System.Collections; using System.Collections.Generic; using UguiToolkit.Editor; @@ -12,4 +13,5 @@ public class TextEntity : BaseEntity ui.fontSize = (int)elementInfo.size; ui.color = elementInfo.color; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Helper/CommandHelper.cs b/Assets/Editor/Helper/CommandHelper.cs index 585733a..714085e 100644 --- a/Assets/Editor/Helper/CommandHelper.cs +++ b/Assets/Editor/Helper/CommandHelper.cs @@ -1,4 +1,5 @@  +#if UNITY_EDITOR using System.Collections.Generic; using UnityEngine; using System.IO; @@ -52,4 +53,5 @@ namespace UguiToolkit.Editor Debug.Log("cmd error : " + error); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Helper/InitHelper.cs b/Assets/Editor/Helper/InitHelper.cs index e433c55..cc6cbe5 100644 --- a/Assets/Editor/Helper/InitHelper.cs +++ b/Assets/Editor/Helper/InitHelper.cs @@ -1,4 +1,5 @@ -using UnityEngine; +#if UNITY_EDITOR +using UnityEngine; using UnityEditor; using System.IO; namespace UguiToolkit.Editor @@ -46,4 +47,5 @@ namespace UguiToolkit.Editor G.cache = cacheScriptObject; } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Helper/LayoutParser.cs b/Assets/Editor/Helper/LayoutParser.cs index 81e59b4..bb110d1 100644 --- a/Assets/Editor/Helper/LayoutParser.cs +++ b/Assets/Editor/Helper/LayoutParser.cs @@ -1,4 +1,4 @@ - +#if UNITY_EDITOR using System.Collections.Generic; using System; using Newtonsoft.Json; @@ -113,3 +113,5 @@ namespace UguiToolkit.Editor public string font; } } + +#endif \ No newline at end of file diff --git a/Assets/Editor/Helper/PanelHelper.cs b/Assets/Editor/Helper/PanelHelper.cs index 2180bd6..6682921 100644 --- a/Assets/Editor/Helper/PanelHelper.cs +++ b/Assets/Editor/Helper/PanelHelper.cs @@ -1,4 +1,5 @@ -using UguiToolkit.Editor.Windows; +#if UNITY_EDITOR +using UguiToolkit.Editor.Windows; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; @@ -32,4 +33,5 @@ namespace UguiToolkit.Editor PanelCacheWindow.CloseWindow(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Manager/ActorManager.cs b/Assets/Editor/Manager/ActorManager.cs deleted file mode 100644 index 70d0c60..0000000 --- a/Assets/Editor/Manager/ActorManager.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using UnityEngine; - -namespace UguiToolkit -{ - public class ActorManager : MonoBehaviour, IManager - { - private void Start() - { - // 初始化所有ImageActor - } - - private void Update() - { - // 检测Image是否被选中,并长按2秒,进入选中状态 - - // 选中状态下,每0.3秒检测 - } - } -} \ No newline at end of file diff --git a/Assets/Editor/Manager/ActorManager.cs.meta b/Assets/Editor/Manager/ActorManager.cs.meta deleted file mode 100644 index 902ec4a..0000000 --- a/Assets/Editor/Manager/ActorManager.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: c0bceef231ae47849a692ff9fb726646 -timeCreated: 1719934421 \ No newline at end of file diff --git a/Assets/Editor/Manager/EntityManager.cs b/Assets/Editor/Manager/EntityManager.cs index afeb7de..22f8808 100644 --- a/Assets/Editor/Manager/EntityManager.cs +++ b/Assets/Editor/Manager/EntityManager.cs @@ -1,10 +1,46 @@ -//using System; -//using UnityEngine; +#if UNITY_EDITOR +using UnityEngine; -//namespace UguiToolkit -//{ -// public class EntityManager : MonoBehaviour, IManager -// { -// private PanelCache panelCache; -// } -//} \ No newline at end of file +namespace UguiToolkit.Editor +{ + public class EntityManager : MonoBehaviour, IManager + { + private PanelCache m_panelCache; + private Transform entityRoot; + + public void InitAllEntity(PanelCache panelCache) + { + this.m_panelCache = panelCache; + + // 创建所有实例 + CreateAllEntity(); + } + + private void CreateAllEntity() + { + if (this.m_panelCache == null) return; + var go = new GameObject(); + entityRoot = go.transform; + entityRoot.SetParent(transform); + entityRoot.localPosition = Vector3.zero; + entityRoot.localRotation = Quaternion.identity; + entityRoot.localScale = Vector3.one; + + // Image + foreach (var elementInfo in m_panelCache.GetLayoutElementInfos()) + { + go = new GameObject(); + var entity = go.AddComponent(); + entity.transform.SetParent(entityRoot); + entity.transform.SetSiblingIndex(0); + + entity.SetData(elementInfo); + entity.InitPreviewImage(); + } + + // Text + } + + } +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Manager/GlobalManager.cs b/Assets/Editor/Manager/GlobalManager.cs index ed89508..7fa09f8 100644 --- a/Assets/Editor/Manager/GlobalManager.cs +++ b/Assets/Editor/Manager/GlobalManager.cs @@ -1,4 +1,6 @@ -using UguiToolkit.Editor; +#if UNITY_EDITOR + +using UguiToolkit.Editor; using UnityEditor; namespace UguiToolkit @@ -28,4 +30,6 @@ namespace UguiToolkit AssetDatabase.SaveAssetIfDirty(cache); } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/Assets/Editor/Manager/StageManager.cs b/Assets/Editor/Manager/StageManager.cs index 90af56e..987be43 100644 --- a/Assets/Editor/Manager/StageManager.cs +++ b/Assets/Editor/Manager/StageManager.cs @@ -1,4 +1,5 @@ -using System; +#if UNITY_EDITOR +using System; using UnityEngine; using UnityEditor; using UnityEngine.SceneManagement; @@ -6,7 +7,6 @@ using System.Collections.Generic; namespace UguiToolkit { - [ExecuteAlways] public class StageManager : MonoBehaviour { private Scene m_scene; @@ -35,6 +35,10 @@ namespace UguiToolkit var go = new GameObject(); go.name = "StageManager"; go.transform.parent = prefabContentsRoot.transform; + go.transform.localPosition = Vector3.zero; + go.transform.localRotation= Quaternion.identity; + go.transform.localScale = Vector3.one; + m_instance = go.AddComponent(); m_instance.m_scene = scene; m_instance.m_prefabContentsRoot = prefabContentsRoot; @@ -64,4 +68,6 @@ namespace UguiToolkit public interface IManager { -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/Assets/Editor/ScriptObject/CacheScriptObject.cs b/Assets/Editor/ScriptObject/CacheScriptObject.cs index 1f87bce..64b6adb 100644 --- a/Assets/Editor/ScriptObject/CacheScriptObject.cs +++ b/Assets/Editor/ScriptObject/CacheScriptObject.cs @@ -1,3 +1,4 @@ +#if UNITY_EDITOR using System; using System.Collections; using System.Collections.Generic; @@ -8,8 +9,10 @@ using static UguiToolkit.Editor.LayoutInfo; namespace UguiToolkit.Editor { + [Serializable] public class CacheScriptObject : SerializedScriptableObject { + [SerializeField] public Dictionary panelCaches = new(); } @@ -41,10 +44,12 @@ namespace UguiToolkit.Editor // 通过cmd计算获得 图片路径(源图) -> 旋转缩放信息(效果图) + [SerializeField] public Dictionary> rotScaleInfos = new(); + [SerializeField] public LayoutInfo layoutInfo; - public IEnumerator GetLayoutElementInfos() where T : LayoutInfo.ElementInfo + public IEnumerable GetLayoutElementInfos() where T : LayoutInfo.ElementInfo { if (layoutInfo == null) yield break; @@ -72,8 +77,11 @@ namespace UguiToolkit.Editor [Serializable] public class LayoutInfo: IEnumerable { + [SerializeField] private List m_elementInfos; + [SerializeField] private float m_w; + [SerializeField] private float m_h; public float W => m_w; @@ -160,4 +168,5 @@ namespace UguiToolkit.Editor public float2 scale; } } +#endif diff --git a/Assets/Editor/ScriptObject/SettingScriptObject.cs b/Assets/Editor/ScriptObject/SettingScriptObject.cs index d9e2241..813da36 100644 --- a/Assets/Editor/ScriptObject/SettingScriptObject.cs +++ b/Assets/Editor/ScriptObject/SettingScriptObject.cs @@ -1,4 +1,5 @@ -using Sirenix.OdinInspector; +#if UNITY_EDITOR +using Sirenix.OdinInspector; using UnityEngine; namespace UguiToolkit.Editor @@ -8,4 +9,5 @@ namespace UguiToolkit.Editor [LabelText("ui预制体存放的路径"), FolderPath] public string prefabForUIDirPath; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/Windows/PanelCacheWindow.cs b/Assets/Editor/Windows/PanelCacheWindow.cs index 8fcf7f3..f761463 100644 --- a/Assets/Editor/Windows/PanelCacheWindow.cs +++ b/Assets/Editor/Windows/PanelCacheWindow.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#if UNITY_EDITOR +using System.Collections.Generic; using System.IO; using Sirenix.OdinInspector; using Sirenix.OdinInspector.Editor; @@ -41,7 +42,8 @@ namespace UguiToolkit.Editor.Windows GlobalManager.Instance.SaveCache(); var stageManager = UguiToolkit.StageManager.CreateStageManager(m_prefabStage.scene, m_prefabStage.prefabContentsRoot); - var actorManager = stageManager.CreateSubManager(); + var entityManager = stageManager.CreateSubManager(); + entityManager.InitAllEntity(panelCache); CloseWindow(); } @@ -58,6 +60,16 @@ namespace UguiToolkit.Editor.Windows { var jsonData = reader.ReadToEnd(); var layoutInfo = layoutParser.Parser(jsonData); + + // 对img路径进行修正 + foreach (var elementInfo in layoutInfo) + { + var imgInfo = elementInfo as LayoutInfo.ImageInfo; + if (imgInfo != null) + { + imgInfo.imgPath = System.IO.Path.Join(panelCache.TargetImgDirPath, imgInfo.imgPath) + ".png"; + } + } panelCache.layoutInfo = layoutInfo; } @@ -127,4 +139,5 @@ namespace UguiToolkit.Editor.Windows } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/Assets/Editor/UguiToolkit.Editor.asmdef b/Assets/UguiToolkit.Editor.asmdef similarity index 83% rename from Assets/Editor/UguiToolkit.Editor.asmdef rename to Assets/UguiToolkit.Editor.asmdef index 41cff7b..f5b968f 100644 --- a/Assets/Editor/UguiToolkit.Editor.asmdef +++ b/Assets/UguiToolkit.Editor.asmdef @@ -5,7 +5,9 @@ "GUID:d8b63aba1907145bea998dd612889d6b" ], "includePlatforms": [ - "Editor" + "Editor", + "WindowsStandalone32", + "WindowsStandalone64" ], "excludePlatforms": [], "allowUnsafeCode": false, diff --git a/Assets/Editor/UguiToolkit.Editor.asmdef.meta b/Assets/UguiToolkit.Editor.asmdef.meta similarity index 100% rename from Assets/Editor/UguiToolkit.Editor.asmdef.meta rename to Assets/UguiToolkit.Editor.asmdef.meta