2025-12-01 16:46:28 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
2025-12-09 20:31:44 +08:00
|
|
|
namespace AlicizaX.UXTool
|
2025-12-01 16:46:28 +08:00
|
|
|
{
|
|
|
|
|
public class FindContainerLogic
|
|
|
|
|
{
|
|
|
|
|
public static bool ObjectFit(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj == null) return false;
|
|
|
|
|
//Graphic[] components = obj.GetComponents<Graphic>();
|
|
|
|
|
//if (components == null || components.Length == 0) return false;
|
|
|
|
|
return obj.activeInHierarchy && obj.GetComponent<RectTransform>() != null && obj.GetComponent<StageEngine>() == null && obj != PrefabStageUtils.StageRoot.gameObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 只选中一个非 Root的节点时,拖动出来的节点应该和该节点同层级
|
|
|
|
|
/// 未选中或者选中 根Canvas 节点,拖动出来的节点都在 根Canvas 子节点层级
|
|
|
|
|
/// 选中多个时 拖动出来的节点在 根Canvas 子节点层级
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Transform GetObjectParent(GameObject[] selection)
|
|
|
|
|
{
|
|
|
|
|
var prefabStage = PrefabStageUtils.GetCurrentPrefabStage();
|
|
|
|
|
if (prefabStage != null)
|
|
|
|
|
{
|
|
|
|
|
//Prefab编辑模式下,需要额外区分是否是Canvas (Environment)
|
|
|
|
|
if (selection.Length == 1
|
|
|
|
|
&& !selection[0].name.Equals("Canvas (Environment)")
|
|
|
|
|
&& selection[0].transform != prefabStage.prefabContentsRoot.transform)
|
|
|
|
|
{
|
|
|
|
|
return selection[0].transform.parent.transform;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return prefabStage.prefabContentsRoot.transform;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (selection.Length == 1)
|
|
|
|
|
{
|
|
|
|
|
if (selection[0].transform == selection[0].transform.root)
|
|
|
|
|
{
|
|
|
|
|
return selection[0].transform.root;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return selection[0].transform.parent.transform;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Object.FindObjectsOfType<Canvas>().Length == 0)
|
|
|
|
|
{
|
|
|
|
|
new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Object.FindObjectsOfType<Canvas>()[0].transform;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|