2024-10-23 17:30:59 +00:00
|
|
|
|
#if UNITY_EDITOR
|
2024-10-29 17:51:06 +00:00
|
|
|
|
using Sirenix.OdinInspector;
|
2024-10-28 16:31:38 +00:00
|
|
|
|
using System.Collections.Generic;
|
2024-12-02 17:47:50 +00:00
|
|
|
|
using System.Globalization;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
using System.IO;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
using UnityEditor;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
using UnityEditor.SceneManagement;
|
2024-10-23 17:30:59 +00:00
|
|
|
|
using UnityEngine;
|
2024-12-02 17:47:50 +00:00
|
|
|
|
using UnityEngine.UI;
|
2024-10-23 17:30:59 +00:00
|
|
|
|
|
|
|
|
|
namespace UguiToolkit.Editor
|
|
|
|
|
{
|
2024-10-28 16:31:38 +00:00
|
|
|
|
[ExecuteAlways]
|
2024-10-23 17:30:59 +00:00
|
|
|
|
public class EntityManager : MonoBehaviour, IManager
|
|
|
|
|
{
|
|
|
|
|
private PanelCache m_panelCache;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
private Transform m_entityRoot;
|
2024-12-02 17:47:50 +00:00
|
|
|
|
private Transform m_background;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
private GameObject m_lastSelectionGo;
|
|
|
|
|
private IEntity m_lastSelectionEntity;
|
2024-11-06 17:45:57 +00:00
|
|
|
|
private GameObject m_curSelectionGo;
|
2024-10-23 17:30:59 +00:00
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
private List<ImageEntity> m_imageEntities;
|
2024-12-01 16:33:27 +00:00
|
|
|
|
private List<IEntity> m_textEntities;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
private List<IEntity> m_selectionEntities;
|
2024-10-28 16:31:38 +00:00
|
|
|
|
|
2024-10-29 17:51:06 +00:00
|
|
|
|
[LabelText("脱离选择控制"), ShowInInspector]
|
2024-11-04 18:05:34 +00:00
|
|
|
|
private bool m_noSelection;
|
|
|
|
|
|
|
|
|
|
private StageManager m_stageManager;
|
|
|
|
|
private HashSet<string> m_checkImgPaths;
|
2024-12-02 17:47:50 +00:00
|
|
|
|
private float m_lastCheckTime = 0f;
|
2024-11-28 10:34:17 +00:00
|
|
|
|
private bool m_useTMP;
|
2024-12-02 17:47:50 +00:00
|
|
|
|
private const float m_checkInterval = 3f;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
2024-12-02 17:47:50 +00:00
|
|
|
|
|
2024-10-29 17:51:06 +00:00
|
|
|
|
private void OnEnable()
|
2024-10-28 16:31:38 +00:00
|
|
|
|
{
|
2024-11-28 10:34:17 +00:00
|
|
|
|
var globalMng = GlobalManager.Instance;
|
|
|
|
|
globalMng.showHierarchyOfEntityChanged += OnUpdateHierarchyOfEntityAllEntity;
|
|
|
|
|
m_useTMP = globalMng.setting.useTMP;
|
|
|
|
|
|
2024-10-29 17:51:06 +00:00
|
|
|
|
Selection.selectionChanged += OnSelectionChanged;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
|
|
|
|
|
m_stageManager = StageManager.Instance;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
{
|
|
|
|
|
GlobalManager.Instance.showHierarchyOfEntityChanged -= OnUpdateHierarchyOfEntityAllEntity;
|
|
|
|
|
Selection.selectionChanged -= OnSelectionChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
// 检测是否到达可选实例矩形内部
|
2024-11-06 17:45:57 +00:00
|
|
|
|
if (m_selectionEntities != null && m_curSelectionGo)
|
2024-10-29 17:51:06 +00:00
|
|
|
|
{
|
2024-11-06 17:45:57 +00:00
|
|
|
|
if (m_lastSelectionGo && m_lastSelectionGo == m_curSelectionGo)
|
2024-10-29 17:51:06 +00:00
|
|
|
|
{
|
2024-11-04 18:05:34 +00:00
|
|
|
|
if (m_lastSelectionEntity != null && !m_lastSelectionEntity.IsInside(m_lastSelectionGo.transform))
|
2024-10-29 17:51:06 +00:00
|
|
|
|
{
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_lastSelectionGo = null;
|
|
|
|
|
m_lastSelectionEntity = null;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
foreach (var entity in m_selectionEntities)
|
2024-10-29 17:51:06 +00:00
|
|
|
|
{
|
2024-11-06 17:45:57 +00:00
|
|
|
|
var tf = m_curSelectionGo.transform;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
if (entity.IsInside(tf))
|
|
|
|
|
{
|
|
|
|
|
entity.ApplyTransform(tf);
|
2024-11-06 17:45:57 +00:00
|
|
|
|
if (tf.TryGetComponent<UnityEngine.UI.Image>(out var image))
|
|
|
|
|
{
|
|
|
|
|
entity.ApplyData(image);
|
|
|
|
|
}
|
|
|
|
|
else if (tf.TryGetComponent<UnityEngine.UI.Text>(out var text))
|
|
|
|
|
{
|
|
|
|
|
entity.ApplyData(text);
|
|
|
|
|
}
|
2024-12-02 14:14:39 +00:00
|
|
|
|
else if (tf.TryGetComponent<TMPro.TextMeshProUGUI>(out var temp))
|
|
|
|
|
{
|
|
|
|
|
entity.ApplyData(temp);
|
|
|
|
|
}
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
2024-11-06 17:45:57 +00:00
|
|
|
|
m_lastSelectionGo = m_curSelectionGo;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_lastSelectionEntity = entity;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
|
|
|
|
Selection.activeGameObject = null;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-04 18:05:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检测是否有image变更,及时更新PanelCache
|
2024-12-02 17:47:50 +00:00
|
|
|
|
m_lastCheckTime -= Time.deltaTime;
|
|
|
|
|
CheckPanelCache();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckPanelCache()
|
|
|
|
|
{
|
|
|
|
|
if (m_lastCheckTime <= 0)
|
2024-11-04 18:05:34 +00:00
|
|
|
|
{
|
2024-12-02 17:47:50 +00:00
|
|
|
|
m_lastCheckTime = m_checkInterval;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
|
|
|
|
|
if (m_checkImgPaths != null)
|
|
|
|
|
{
|
|
|
|
|
var images = m_stageManager.PrefabContentsRoot.GetComponentsInChildren<UnityEngine.UI.Image>();
|
|
|
|
|
foreach (var image in images)
|
|
|
|
|
{
|
2024-12-02 17:47:50 +00:00
|
|
|
|
if (image.transform.parent == m_entityRoot || image.transform.parent == m_background || image.sprite == null) continue;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
var srcImgPath = AssetDatabase.GetAssetPath(image.sprite);
|
2024-12-02 17:47:50 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(srcImgPath) && !m_checkImgPaths.Contains(srcImgPath))
|
2024-11-04 18:05:34 +00:00
|
|
|
|
{
|
|
|
|
|
var srcImgDirPath = System.IO.Path.GetDirectoryName(srcImgPath);
|
|
|
|
|
string projectPath = Directory.GetParent(Application.dataPath).FullName;
|
|
|
|
|
foreach (var filePath in System.IO.Directory.GetFiles(srcImgDirPath))
|
|
|
|
|
{
|
|
|
|
|
var _filePath = Path.GetRelativePath(projectPath, filePath).Replace("\\", "/");
|
|
|
|
|
m_checkImgPaths.Add(_filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdatePanelCache(srcImgDirPath, m_panelCache.TargetImgDirPath);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-29 17:51:06 +00:00
|
|
|
|
}
|
2024-10-28 16:31:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-02 17:47:50 +00:00
|
|
|
|
private void InitBackground()
|
|
|
|
|
{
|
|
|
|
|
if (m_background) DestroyImmediate(m_background.gameObject);
|
|
|
|
|
|
|
|
|
|
var go = new GameObject("__background__", typeof(RectTransform));
|
|
|
|
|
UpdateHierarchyOfEntity(false, go);
|
|
|
|
|
m_background = go.transform;
|
|
|
|
|
m_background.SetParent(transform);
|
|
|
|
|
m_background.localPosition = Vector3.zero;
|
|
|
|
|
m_background.localRotation = Quaternion.identity;
|
|
|
|
|
m_background.localScale = Vector3.one;
|
|
|
|
|
|
|
|
|
|
var canvas = m_background.gameObject.AddComponent<Canvas>();
|
|
|
|
|
canvas.pixelPerfect = true;
|
|
|
|
|
canvas.overrideSorting = true;
|
|
|
|
|
canvas.sortingOrder = -100;
|
|
|
|
|
|
|
|
|
|
var imgGo = new GameObject("_", typeof(RectTransform));
|
|
|
|
|
var imgTf = imgGo.transform;
|
|
|
|
|
imgTf.SetParent(m_background);
|
|
|
|
|
imgTf.localPosition = Vector3.zero;
|
|
|
|
|
imgTf.localRotation = Quaternion.identity;
|
|
|
|
|
imgTf.localScale = Vector3.one;
|
|
|
|
|
var img = imgGo.AddComponent<Image>();
|
|
|
|
|
var imgPath = System.IO.Path.Join(m_panelCache.TargetImgDirPath, "__background__.png");
|
|
|
|
|
if (System.IO.File.Exists(imgPath))
|
|
|
|
|
{
|
|
|
|
|
byte[] fileData = System.IO.File.ReadAllBytes(imgPath);
|
|
|
|
|
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));
|
|
|
|
|
img.sprite = sprite;
|
|
|
|
|
img.color = new Color(1, 1, 1, 0.4f);
|
|
|
|
|
img.SetNativeSize();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
private void InitCheckImgPaths()
|
|
|
|
|
{
|
|
|
|
|
if (m_checkImgPaths == null) m_checkImgPaths = new HashSet<string>();
|
|
|
|
|
|
2024-11-28 17:06:27 +00:00
|
|
|
|
//var images = m_stageManager.PrefabContentsRoot.GetComponentsInChildren<UnityEngine.UI.Image>();
|
|
|
|
|
//foreach (var image in images)
|
|
|
|
|
//{
|
|
|
|
|
// if (image.sprite == null) continue;
|
|
|
|
|
// var srcImgPath = AssetDatabase.GetAssetPath(image.sprite);
|
|
|
|
|
// m_checkImgPaths.Add(srcImgPath);
|
|
|
|
|
//}
|
2024-11-04 18:05:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePanelCache(string srcImgDirPath, string targetImgDirPath)
|
|
|
|
|
{
|
2024-11-07 16:16:28 +00:00
|
|
|
|
float distanceDifference = GlobalManager.Instance.setting.distanceDifference;
|
|
|
|
|
CacheScriptObject.CalcRotScaleInfos(srcImgDirPath, targetImgDirPath, distanceDifference,(rotScaleInfoMap) =>
|
2024-11-04 18:05:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (!m_stageManager) return;
|
|
|
|
|
// 拷贝数据
|
|
|
|
|
|
|
|
|
|
if (m_panelCache.rotScaleInfos != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var kv in rotScaleInfoMap)
|
|
|
|
|
{
|
|
|
|
|
if (!m_panelCache.rotScaleInfos.TryGetValue(kv.Key, out var rotScaleInfos))
|
|
|
|
|
{
|
|
|
|
|
m_panelCache.rotScaleInfos[kv.Key] = kv.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
{
|
|
|
|
|
m_panelCache.rotScaleInfos = rotScaleInfoMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存缓存
|
|
|
|
|
GlobalManager.Instance.SaveCache(m_stageManager.PrefabAsset, m_panelCache);
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
|
|
|
|
private void OnSelectionChanged()
|
2024-10-28 16:31:38 +00:00
|
|
|
|
{
|
2024-12-02 14:14:39 +00:00
|
|
|
|
if (m_noSelection) return;
|
|
|
|
|
|
2024-11-06 17:45:57 +00:00
|
|
|
|
m_curSelectionGo = null;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_selectionEntities.Clear();
|
2024-11-06 17:45:57 +00:00
|
|
|
|
m_entityRoot.gameObject.SetActive(false);
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
|
|
|
|
if (Selection.activeGameObject != null && m_panelCache != null)
|
|
|
|
|
{
|
|
|
|
|
var activeGameObject = Selection.activeGameObject;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
if (activeGameObject.transform.parent == m_entityRoot) return;
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
|
|
|
|
if (activeGameObject.TryGetComponent<UnityEngine.UI.Image>(out var image))
|
|
|
|
|
{
|
|
|
|
|
var rotScaleInfos = m_panelCache.rotScaleInfos;
|
|
|
|
|
if (rotScaleInfos == null) return;
|
|
|
|
|
if (image.sprite == null) return;
|
|
|
|
|
var srcImgPath = AssetDatabase.GetAssetPath(image.sprite);
|
|
|
|
|
if (!rotScaleInfos.TryGetValue(srcImgPath, out var rotScaleInfoItems)) return;
|
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_entityRoot.gameObject.SetActive(true);
|
2024-10-29 17:51:06 +00:00
|
|
|
|
bool isFind;
|
2024-11-06 17:45:57 +00:00
|
|
|
|
bool IsInside = false;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
foreach (var imgEntity in m_imageEntities)
|
2024-10-29 17:51:06 +00:00
|
|
|
|
{
|
|
|
|
|
isFind = false;
|
|
|
|
|
foreach (var rotScale in rotScaleInfoItems)
|
|
|
|
|
{
|
|
|
|
|
var imgInfo = imgEntity.ElementInfo;
|
2024-12-01 16:33:27 +00:00
|
|
|
|
if ( (imgInfo.HaveSlice && imgInfo.imgSlicePath == rotScale.imgPath) || imgInfo.imgPath == rotScale.imgPath)
|
2024-10-29 17:51:06 +00:00
|
|
|
|
{
|
2024-11-04 18:05:34 +00:00
|
|
|
|
if (rotScale.similarityCalc)
|
|
|
|
|
{
|
|
|
|
|
imgEntity.SetTransform(0, new Unity.Mathematics.float2(1, 1), true);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
imgEntity.SetTransform(rotScale.rotiation, rotScale.scale, false);
|
|
|
|
|
}
|
2024-12-02 14:14:39 +00:00
|
|
|
|
|
|
|
|
|
imgEntity.ApplyTransform(imgEntity.transform);
|
2024-10-29 17:51:06 +00:00
|
|
|
|
imgEntity.ShowSelectionImg(true);
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_selectionEntities.Add(imgEntity);
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
2024-11-06 17:45:57 +00:00
|
|
|
|
if (!IsInside && imgEntity.IsInside(activeGameObject.transform)) IsInside = true;
|
|
|
|
|
|
2024-10-29 17:51:06 +00:00
|
|
|
|
isFind = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
imgEntity.gameObject.SetActive(isFind);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-06 17:45:57 +00:00
|
|
|
|
if (IsInside)
|
|
|
|
|
{
|
|
|
|
|
if (m_lastSelectionGo && m_lastSelectionGo == activeGameObject)
|
|
|
|
|
{
|
|
|
|
|
m_curSelectionGo = activeGameObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
m_curSelectionGo = activeGameObject;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
foreach (var textEntity in m_textEntities)
|
2024-10-29 17:51:06 +00:00
|
|
|
|
{
|
|
|
|
|
textEntity.gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-02 14:14:39 +00:00
|
|
|
|
else if (activeGameObject.TryGetComponent<UnityEngine.UI.Text>(out var _)
|
|
|
|
|
|| activeGameObject.TryGetComponent<TMPro.TextMeshProUGUI>(out var _))
|
2024-10-29 17:51:06 +00:00
|
|
|
|
{
|
2024-11-06 17:45:57 +00:00
|
|
|
|
bool IsInside = false;
|
|
|
|
|
m_entityRoot.gameObject.SetActive(true);
|
|
|
|
|
foreach (var textEntity in m_textEntities)
|
|
|
|
|
{
|
|
|
|
|
textEntity.ShowSelectionImg(true);
|
|
|
|
|
textEntity.gameObject.SetActive(true);
|
|
|
|
|
|
|
|
|
|
m_selectionEntities.Add(textEntity);
|
|
|
|
|
|
|
|
|
|
if (!IsInside && textEntity.IsInside(activeGameObject.transform)) IsInside = true;
|
|
|
|
|
}
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
2024-11-06 17:45:57 +00:00
|
|
|
|
if (IsInside)
|
|
|
|
|
{
|
|
|
|
|
if (m_lastSelectionGo && m_lastSelectionGo == activeGameObject)
|
|
|
|
|
{
|
|
|
|
|
m_curSelectionGo = activeGameObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_curSelectionGo = activeGameObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var imgEntity in m_imageEntities)
|
|
|
|
|
{
|
|
|
|
|
imgEntity.gameObject.SetActive(false);
|
|
|
|
|
}
|
2024-10-29 17:51:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-28 16:31:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 17:30:59 +00:00
|
|
|
|
public void InitAllEntity(PanelCache panelCache)
|
|
|
|
|
{
|
|
|
|
|
this.m_panelCache = panelCache;
|
|
|
|
|
|
|
|
|
|
// 创建所有实例
|
|
|
|
|
CreateAllEntity();
|
2024-11-04 18:05:34 +00:00
|
|
|
|
InitCheckImgPaths();
|
2024-12-02 17:47:50 +00:00
|
|
|
|
InitBackground();
|
|
|
|
|
|
|
|
|
|
CheckPanelCache();
|
2024-10-23 17:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-29 17:51:06 +00:00
|
|
|
|
private void OnUpdateHierarchyOfEntityAllEntity(bool show)
|
2024-10-28 16:31:38 +00:00
|
|
|
|
{
|
2024-11-04 18:05:34 +00:00
|
|
|
|
UpdateHierarchyOfEntity(show, m_entityRoot.gameObject);
|
2024-12-02 17:47:50 +00:00
|
|
|
|
UpdateHierarchyOfEntity(show, m_background.gameObject);
|
2024-11-04 18:05:34 +00:00
|
|
|
|
foreach (var entity in m_imageEntities) UpdateHierarchyOfEntity(show, entity.gameObject);
|
|
|
|
|
foreach (var entity in m_textEntities) UpdateHierarchyOfEntity(show, entity.gameObject);
|
2024-10-28 16:31:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateHierarchyOfEntity(in bool show, in GameObject entity)
|
|
|
|
|
{
|
2024-10-29 17:51:06 +00:00
|
|
|
|
EntityHelper.UpdateHierarchyAndSceneVisibilityOfEntity(show, entity.gameObject);
|
2024-10-28 16:31:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 17:30:59 +00:00
|
|
|
|
private void CreateAllEntity()
|
|
|
|
|
{
|
|
|
|
|
if (this.m_panelCache == null) return;
|
2024-11-04 18:05:34 +00:00
|
|
|
|
var go = new GameObject("__entityRoot__", typeof(RectTransform));
|
2024-10-28 16:31:38 +00:00
|
|
|
|
UpdateHierarchyOfEntity(false, go);
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_entityRoot = go.transform;
|
|
|
|
|
m_entityRoot.SetParent(transform);
|
|
|
|
|
m_entityRoot.localPosition = Vector3.zero;
|
|
|
|
|
m_entityRoot.localRotation = Quaternion.identity;
|
|
|
|
|
m_entityRoot.localScale = Vector3.one;
|
2024-10-28 16:31:38 +00:00
|
|
|
|
|
2024-12-02 14:14:39 +00:00
|
|
|
|
var canvas = m_entityRoot.gameObject.AddComponent<Canvas>();
|
|
|
|
|
canvas.pixelPerfect = true;
|
|
|
|
|
canvas.overrideSorting = true;
|
|
|
|
|
canvas.sortingOrder = 200;
|
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_imageEntities = new(m_panelCache.layoutInfo.Count);
|
|
|
|
|
m_textEntities = new(m_panelCache.layoutInfo.Count);
|
|
|
|
|
m_selectionEntities = new(m_panelCache.layoutInfo.Count);
|
2024-10-28 16:31:38 +00:00
|
|
|
|
|
|
|
|
|
foreach (var elementInfo in m_panelCache.GetLayoutElementInfos<LayoutInfo.ElementInfo>())
|
2024-10-23 17:30:59 +00:00
|
|
|
|
{
|
2024-10-28 16:31:38 +00:00
|
|
|
|
var imgInfo = elementInfo as LayoutInfo.ImageInfo;
|
|
|
|
|
if (imgInfo != null) // Image
|
|
|
|
|
{
|
2024-11-28 10:34:17 +00:00
|
|
|
|
go = new GameObject(imgInfo.name, typeof(RectTransform));
|
2024-10-28 16:31:38 +00:00
|
|
|
|
var entity = go.AddComponent<ImageEntity>();
|
2024-11-04 18:05:34 +00:00
|
|
|
|
entity.transform.SetParent(m_entityRoot);
|
2024-10-28 16:31:38 +00:00
|
|
|
|
entity.transform.SetSiblingIndex(0);
|
2024-10-23 17:30:59 +00:00
|
|
|
|
|
2024-10-28 16:31:38 +00:00
|
|
|
|
entity.SetData(imgInfo);
|
2024-12-01 16:33:27 +00:00
|
|
|
|
entity.InitPreview();
|
2024-10-28 16:31:38 +00:00
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_imageEntities.Add(entity);
|
2024-10-28 16:31:38 +00:00
|
|
|
|
UpdateHierarchyOfEntity(false, entity.gameObject);
|
2024-12-01 16:33:27 +00:00
|
|
|
|
|
|
|
|
|
// 创建九宫格
|
2024-10-28 16:31:38 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
var textInfo = elementInfo as LayoutInfo.TextInfo;
|
|
|
|
|
if (textInfo != null) // Text
|
|
|
|
|
{
|
2024-11-28 10:34:17 +00:00
|
|
|
|
if (m_useTMP)
|
|
|
|
|
{
|
|
|
|
|
go = new GameObject(textInfo.text, typeof(RectTransform));
|
|
|
|
|
var entity = go.AddComponent<TextMeshProEntity>();
|
|
|
|
|
entity.transform.SetParent(m_entityRoot);
|
|
|
|
|
entity.transform.SetSiblingIndex(0);
|
2024-10-28 16:31:38 +00:00
|
|
|
|
|
2024-11-28 10:34:17 +00:00
|
|
|
|
entity.SetData(textInfo);
|
2024-12-01 16:33:27 +00:00
|
|
|
|
entity.InitPreview();
|
2024-10-23 17:30:59 +00:00
|
|
|
|
|
2024-12-01 16:33:27 +00:00
|
|
|
|
m_textEntities.Add(entity);
|
2024-11-28 10:34:17 +00:00
|
|
|
|
UpdateHierarchyOfEntity(false, entity.gameObject);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
go = new GameObject(textInfo.text, typeof(RectTransform));
|
|
|
|
|
var entity = go.AddComponent<TextEntity>();
|
|
|
|
|
entity.transform.SetParent(m_entityRoot);
|
|
|
|
|
entity.transform.SetSiblingIndex(0);
|
2024-10-28 16:31:38 +00:00
|
|
|
|
|
2024-11-28 10:34:17 +00:00
|
|
|
|
entity.SetData(textInfo);
|
2024-12-01 16:33:27 +00:00
|
|
|
|
entity.InitPreview();
|
2024-11-28 10:34:17 +00:00
|
|
|
|
|
|
|
|
|
m_textEntities.Add(entity);
|
|
|
|
|
UpdateHierarchyOfEntity(false, entity.gameObject);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-28 16:31:38 +00:00
|
|
|
|
}
|
2024-10-29 17:51:06 +00:00
|
|
|
|
|
2024-11-04 18:05:34 +00:00
|
|
|
|
m_entityRoot.gameObject.SetActive(false);
|
2024-10-23 17:30:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|