mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update UIWidget.cs
This commit is contained in:
@@ -132,6 +132,30 @@ namespace TEngine
|
|||||||
return CreateImp(parentUI, widgetRoot, false, visible);
|
return CreateImp(parentUI, widgetRoot, false, visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据资源名创建
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="resPath"></param>
|
||||||
|
/// <param name="parentUI"></param>
|
||||||
|
/// <param name="parentTrans"></param>
|
||||||
|
/// <param name="visible"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool CreateByPath(string resPath, UIBase parentUI, Transform parentTrans = null, bool visible = true)
|
||||||
|
{
|
||||||
|
GameObject goInst = parentUI.AssetReference.LoadAsset<GameObject>(resPath, parentTrans);
|
||||||
|
if (goInst == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!Create(parentUI, goInst, visible))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
goInst.transform.localScale = Vector3.one;
|
||||||
|
goInst.transform.localPosition = Vector3.zero;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据prefab或者模版来创建新的 widget。
|
/// 根据prefab或者模版来创建新的 widget。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -155,7 +179,10 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (AssetReference == null)
|
||||||
|
{
|
||||||
AssetReference = AssetReference.BindAssetReference(widgetRoot,parent:parentUI.AssetReference);
|
AssetReference = AssetReference.BindAssetReference(widgetRoot,parent:parentUI.AssetReference);
|
||||||
|
}
|
||||||
RestChildCanvas(parentUI);
|
RestChildCanvas(parentUI);
|
||||||
parent = parentUI;
|
parent = parentUI;
|
||||||
Parent.ListChild.Add(this);
|
Parent.ListChild.Add(this);
|
||||||
@@ -178,20 +205,23 @@ namespace TEngine
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
gameObject = go;
|
|
||||||
rectTransform = go.GetComponent<RectTransform>();
|
rectTransform = go.GetComponent<RectTransform>();
|
||||||
|
gameObject = go;
|
||||||
Log.Assert(rectTransform != null, $"{go.name} ui base element need to be RectTransform");
|
Log.Assert(rectTransform != null, $"{go.name} ui base element need to be RectTransform");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void RestChildCanvas(UIBase parentUI)
|
protected void RestChildCanvas(UIBase parentUI)
|
||||||
{
|
{
|
||||||
|
if (parentUI == null || parentUI.gameObject == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Canvas parentCanvas = parentUI.gameObject.GetComponentInParent<Canvas>();
|
Canvas parentCanvas = parentUI.gameObject.GetComponentInParent<Canvas>();
|
||||||
if (parentCanvas == null)
|
if (parentCanvas == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameObject != null)
|
if (gameObject != null)
|
||||||
{
|
{
|
||||||
var listCanvas = gameObject.GetComponentsInChildren<Canvas>(true);
|
var listCanvas = gameObject.GetComponentsInChildren<Canvas>(true);
|
||||||
|
Reference in New Issue
Block a user