2024-12-06 10:46:00 +00:00
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UguiToolkit;
|
|
|
|
|
using UguiToolkit.Editor;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
|
|
|
namespace UguiToolkit.Editor
|
|
|
|
|
{
|
|
|
|
|
public class PrefabEntity : BaseEntity<Transform, LayoutInfo.PrefabInfo>
|
|
|
|
|
{
|
2024-12-10 10:14:38 +00:00
|
|
|
|
protected override void OnApplyTransform(Transform tf)
|
2024-12-06 10:46:00 +00:00
|
|
|
|
{
|
|
|
|
|
var position = ElementInfo.Position;
|
|
|
|
|
tf.position = StageManager.Instance.PrefabContentsRoot.transform.TransformPoint(new Vector3(position.x, position.y, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void InitPreview()
|
|
|
|
|
{
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>
|
2024-12-10 10:14:38 +00:00
|
|
|
|
var asset = GetPrefabAsset(GetCommonDirPath());
|
|
|
|
|
if (asset) {
|
|
|
|
|
var go = PrefabUtility.InstantiatePrefab(asset, transform) as GameObject;
|
2024-12-06 10:46:00 +00:00
|
|
|
|
EntityHelper.UpdateHierarchyAndSceneVisibilityOfEntity(false, go);
|
|
|
|
|
|
|
|
|
|
go.name = asset.name;
|
|
|
|
|
var _tf = go.transform;
|
|
|
|
|
_tf.localPosition = Vector3.zero;
|
|
|
|
|
_tf.localRotation = Quaternion.identity;
|
|
|
|
|
_tf.localScale = Vector3.one;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ApplyTransform(transform);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnApplyData(Transform ui)
|
|
|
|
|
{
|
|
|
|
|
ApplyTransform(ui);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-10 10:14:38 +00:00
|
|
|
|
public GameObject GetPrefabAsset(string commonDirPath)
|
2024-12-06 10:46:00 +00:00
|
|
|
|
{
|
|
|
|
|
var elementInfo = ElementInfo;
|
|
|
|
|
var guids = AssetDatabase.FindAssets(elementInfo.prefabName, new string[] { commonDirPath });
|
|
|
|
|
if (guids.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
return AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath(guids[0]));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError($"[PrefabInfo.GetPrefabPath] ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{elementInfo.prefabName} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> {commonDirPath}");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsPrefab(GameObject asset)
|
|
|
|
|
{
|
|
|
|
|
return PrefabUtility.IsAnyPrefabInstanceRoot(asset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool IsCommonPrefab(GameObject asset)
|
|
|
|
|
{
|
|
|
|
|
var setting = GlobalManager.Instance.setting;
|
|
|
|
|
return PrefabUtility.IsAnyPrefabInstanceRoot(asset) && PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(asset).StartsWith(setting.commonPrefabForUIDirPath);
|
|
|
|
|
}
|
2024-12-10 10:14:38 +00:00
|
|
|
|
|
|
|
|
|
public static string GetCommonDirPath()
|
|
|
|
|
{
|
|
|
|
|
var setting = GlobalManager.Instance.setting;
|
|
|
|
|
return setting.commonPrefabForUIDirPath;
|
|
|
|
|
}
|
2024-12-06 10:46:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|