实例化所有img
This commit is contained in:
parent
2d22ae3def
commit
7fe83e3342
Binary file not shown.
@ -1,4 +1,5 @@
|
||||
namespace UguiToolkit.Editor
|
||||
#if UNITY_EDITOR
|
||||
namespace UguiToolkit.Editor
|
||||
{
|
||||
public class EditorConst
|
||||
{
|
||||
@ -10,3 +11,4 @@
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UguiToolkit.Editor
|
||||
@ -17,3 +18,4 @@ namespace UguiToolkit.Editor
|
||||
public float[] scale;
|
||||
}
|
||||
}
|
||||
#endif
|
@ -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);
|
||||
}
|
||||
|
||||
// 查找时调用
|
||||
@ -56,3 +58,4 @@ namespace UguiToolkit.Editor
|
||||
protected virtual void OnApplyData(T1 ui, T2 elementInfo) { }
|
||||
}
|
||||
}
|
||||
#endif
|
@ -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<Image, LayoutInfo.ImageInfo>
|
||||
{
|
||||
private Image m_previewImage;
|
||||
|
||||
protected override void OnApplyData(Image ui, LayoutInfo.ImageInfo elementInfo)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void InitPreviewImage() {
|
||||
if (ElementInfo == null) return;
|
||||
|
||||
if (!TryGetComponent<Image>(out m_previewImage))
|
||||
{
|
||||
m_previewImage = gameObject.AddComponent<Image>();
|
||||
}
|
||||
|
||||
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
|
@ -1,3 +1,4 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UguiToolkit.Editor;
|
||||
@ -13,3 +14,4 @@ public class TextEntity : BaseEntity<Text, LayoutInfo.TextInfo>
|
||||
ui.color = elementInfo.color;
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
@ -53,3 +54,4 @@ namespace UguiToolkit.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
namespace UguiToolkit.Editor
|
||||
@ -47,3 +48,4 @@ namespace UguiToolkit.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -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
|
@ -1,4 +1,5 @@
|
||||
using UguiToolkit.Editor.Windows;
|
||||
#if UNITY_EDITOR
|
||||
using UguiToolkit.Editor.Windows;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
@ -33,3 +34,4 @@ namespace UguiToolkit.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -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秒检测
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0bceef231ae47849a692ff9fb726646
|
||||
timeCreated: 1719934421
|
@ -1,10 +1,46 @@
|
||||
//using System;
|
||||
//using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
|
||||
//namespace UguiToolkit
|
||||
//{
|
||||
// public class EntityManager : MonoBehaviour, IManager
|
||||
// {
|
||||
// private PanelCache panelCache;
|
||||
// }
|
||||
//}
|
||||
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<LayoutInfo.ImageInfo>())
|
||||
{
|
||||
go = new GameObject();
|
||||
var entity = go.AddComponent<ImageEntity>();
|
||||
entity.transform.SetParent(entityRoot);
|
||||
entity.transform.SetSiblingIndex(0);
|
||||
|
||||
entity.SetData(elementInfo);
|
||||
entity.InitPreviewImage();
|
||||
}
|
||||
|
||||
// Text
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,4 +1,6 @@
|
||||
using UguiToolkit.Editor;
|
||||
#if UNITY_EDITOR
|
||||
|
||||
using UguiToolkit.Editor;
|
||||
using UnityEditor;
|
||||
|
||||
namespace UguiToolkit
|
||||
@ -29,3 +31,5 @@ namespace UguiToolkit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -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<StageManager>();
|
||||
m_instance.m_scene = scene;
|
||||
m_instance.m_prefabContentsRoot = prefabContentsRoot;
|
||||
@ -65,3 +69,5 @@ namespace UguiToolkit
|
||||
public interface IManager {
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -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<GameObject, PanelCache> panelCaches = new();
|
||||
}
|
||||
|
||||
@ -41,10 +44,12 @@ namespace UguiToolkit.Editor
|
||||
|
||||
|
||||
// 通过cmd计算获得 图片路径(源图) -> 旋转缩放信息(效果图)
|
||||
[SerializeField]
|
||||
public Dictionary<string, List<RotScaleInfoItem>> rotScaleInfos = new();
|
||||
[SerializeField]
|
||||
public LayoutInfo layoutInfo;
|
||||
|
||||
public IEnumerator<T> GetLayoutElementInfos<T>() where T : LayoutInfo.ElementInfo
|
||||
public IEnumerable<T> GetLayoutElementInfos<T>() where T : LayoutInfo.ElementInfo
|
||||
{
|
||||
if (layoutInfo == null) yield break;
|
||||
|
||||
@ -72,8 +77,11 @@ namespace UguiToolkit.Editor
|
||||
[Serializable]
|
||||
public class LayoutInfo: IEnumerable<ElementInfo>
|
||||
{
|
||||
[SerializeField]
|
||||
private List<ElementInfo> 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
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Sirenix.OdinInspector;
|
||||
#if UNITY_EDITOR
|
||||
using Sirenix.OdinInspector;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UguiToolkit.Editor
|
||||
@ -9,3 +10,4 @@ namespace UguiToolkit.Editor
|
||||
public string prefabForUIDirPath;
|
||||
}
|
||||
}
|
||||
#endif
|
@ -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<ActorManager>();
|
||||
var entityManager = stageManager.CreateSubManager<EntityManager>();
|
||||
entityManager.InitAllEntity(panelCache);
|
||||
CloseWindow();
|
||||
}
|
||||
|
||||
@ -59,6 +61,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;
|
||||
}
|
||||
}
|
||||
@ -128,3 +140,4 @@ namespace UguiToolkit.Editor.Windows
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
@ -5,7 +5,9 @@
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
"Editor",
|
||||
"WindowsStandalone32",
|
||||
"WindowsStandalone64"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
Loading…
Reference in New Issue
Block a user