203 lines
5.8 KiB
C#
203 lines
5.8 KiB
C#
|
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
public class UiBase :MonoBehaviour
|
|||
|
{
|
|||
|
//public RectTransform targetRect;
|
|||
|
// public CanvasGroup canvasGroup;
|
|||
|
|
|||
|
protected string basePath = "Prefabs/";// ͼƬ<CDBC><C6AC>Resources<65>еĻ<D0B5><C4BB><EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20>ر<EFBFBD>UI<55><49><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public void ClosePanel()
|
|||
|
{
|
|||
|
this.gameObject.SetActive(false);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>UI<55><49><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
protected void OpenPanel()
|
|||
|
{
|
|||
|
this .gameObject.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD>ҹر<D2B9>
|
|||
|
/// </summary>
|
|||
|
/// <param name="parent"></param>
|
|||
|
/// <param name="childName"></param>
|
|||
|
/// <returns></returns>
|
|||
|
protected void CloseFindDeepChildUI(string childName)
|
|||
|
{
|
|||
|
// ʹ<>õݹ<C3B5><DDB9><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD> childName
|
|||
|
Transform item = FindDeepChild(transform, childName);
|
|||
|
if (item != null)
|
|||
|
{
|
|||
|
Debug.Log("<22>ҵ<EFBFBD>ʧ<EFBFBD><CAA7>״̬<D7B4><CCAC> childName");
|
|||
|
GameObject gochildName = item.gameObject;
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4>룺
|
|||
|
gochildName.SetActive(false);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("δ<>ҵ<EFBFBD> childName<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <param name="parent"></param>
|
|||
|
/// <param name="childName"></param>
|
|||
|
/// <returns></returns>
|
|||
|
protected Transform FindDeepChild(Transform parent, string childName)
|
|||
|
{
|
|||
|
// <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
foreach (Transform child in parent)
|
|||
|
{
|
|||
|
if (child.name == childName)
|
|||
|
{
|
|||
|
GameObject item = child.gameObject;
|
|||
|
return child;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
Transform result = FindDeepChild(child, childName);
|
|||
|
if (result != null)
|
|||
|
return result;
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD>Ҵ<EFBFBD><D2B4><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
/// <param name="parent"></param>
|
|||
|
/// <param name="childName"></param>
|
|||
|
/// <returns></returns>
|
|||
|
protected void OPenFindDeepChildUI(string childName)
|
|||
|
{
|
|||
|
// ʹ<>õݹ<C3B5><DDB9><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7><EFBFBD><EFBFBD> childName
|
|||
|
Transform item = FindDeepChild(transform, childName);
|
|||
|
if (item != null)
|
|||
|
{
|
|||
|
|
|||
|
GameObject gochildName = item.gameObject;
|
|||
|
Debug.Log("<22>ҵ<EFBFBD>ʧ<EFBFBD><CAA7>״̬<D7B4><CCAC> childName" + gochildName);
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><E5A3AC><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><C2B4>룺
|
|||
|
gochildName.gameObject.SetActive(true);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
Debug.LogError("δ<>ҵ<EFBFBD> childName<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>Sprite
|
|||
|
/// </summary>
|
|||
|
/// <param name="spritePath"></param>
|
|||
|
/// <returns></returns>
|
|||
|
protected Sprite ResSprit(string spritePath)
|
|||
|
{
|
|||
|
|
|||
|
Sprite go = Resources.Load<Sprite>(spritePath);
|
|||
|
return go;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// ʵ<><CAB5><EFBFBD><EFBFBD>UI
|
|||
|
/// </summary>
|
|||
|
/// <param name="prefabsPath">UI·<49><C2B7></param>
|
|||
|
protected void LoadUI(string prefabsPath)
|
|||
|
{
|
|||
|
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>δ<EFBFBD><CEB4><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD> Resources <20><><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
string fullPath = basePath + prefabsPath;
|
|||
|
GameObject prefab = Resources.Load<GameObject>(fullPath);
|
|||
|
GameObject newUIPanel = Instantiate(prefab);
|
|||
|
// <20><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>Ϊ `UIManager.Instance.goEmptyUI`<60><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> `parentTransform`<60><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>
|
|||
|
newUIPanel.transform.SetParent(GameManager.Instance.goParent.transform);
|
|||
|
|
|||
|
newUIPanel.transform.localScale = Vector3.one;
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>û<EFBFBD>д<EFBFBD><D0B4><EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>Ĭ<EFBFBD><C4AC>λ<EFBFBD><CEBB>
|
|||
|
newUIPanel.transform.localPosition= Vector3.zero;
|
|||
|
}
|
|||
|
///// <summary>
|
|||
|
///// <20><><EFBFBD>Ű<EFBFBD><C5B0><EFBFBD>UI<55>Ķ<EFBFBD><C4B6><EFBFBD>
|
|||
|
///// </summary>
|
|||
|
//public void ActivateHalfUI(float fadeDuration, float scaleDuration, float moveDuration,Vector2 moveStartPosition, Vector2 moveEndPosition)
|
|||
|
//{
|
|||
|
// if (targetRect != null)
|
|||
|
// {
|
|||
|
// // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB> DOTween <20><><EFBFBD><EFBFBD>
|
|||
|
// Sequence sequence = DOTween.Sequence();
|
|||
|
|
|||
|
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ<CABC><CEBB>
|
|||
|
// targetRect.anchoredPosition = moveStartPosition;
|
|||
|
|
|||
|
// // <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼλ<CABC><CEBB><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
|
|||
|
// sequence.Join(targetRect.DOAnchorPos(moveEndPosition, moveDuration).SetEase(Ease.OutCubic));
|
|||
|
|
|||
|
// // <><CDB8><EFBFBD>ȶ<EFBFBD><C8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><> 1
|
|||
|
// if (canvasGroup != null)
|
|||
|
// {
|
|||
|
// canvasGroup.alpha = 0f;
|
|||
|
// sequence.Join(canvasGroup.DOFade(1f, fadeDuration)); // <20><><EFBFBD>䵽<E4B5BD><CDB8><EFBFBD><EFBFBD> 1
|
|||
|
// }
|
|||
|
|
|||
|
// // <20><><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0 <20><> 1
|
|||
|
// sequence.Join(targetRect.DOScale(Vector3.one, scaleDuration).SetEase(Ease.OutBack));
|
|||
|
|
|||
|
// // ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD>
|
|||
|
// sequence.Play();
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// Debug.LogError("Target object does not have a RectTransform or CanvasGroup.");
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
///// <summary>
|
|||
|
///// <20>رհ<D8B1><D5B0><EFBFBD>UI<55><49><EFBFBD><EFBFBD>
|
|||
|
///// </summary>
|
|||
|
//public void DeactivateHalfUI(float fadeDuration, float scaleDuration, float moveDuration, Vector2 moveStartPosition, Vector2 moveEndPosition)
|
|||
|
//{
|
|||
|
// if (targetRect != null)
|
|||
|
// {
|
|||
|
// Sequence sequence = DOTween.Sequence();
|
|||
|
|
|||
|
// //sequence.Append(targetRect.DOScale(Vector3.zero, scaleDuration).SetEase(Ease.OutBack));
|
|||
|
// sequence.Join(targetRect.DOMove(new Vector2(0, -1920), moveDuration).SetEase(Ease.InOutQuart));
|
|||
|
|
|||
|
// sequence.Join(canvasGroup.DOFade(0, fadeDuration).SetEase(Ease.OutBack));
|
|||
|
|
|||
|
|
|||
|
// sequence.OnKill(() => {
|
|||
|
// gameObject.SetActive(false);
|
|||
|
// });
|
|||
|
// }
|
|||
|
// else
|
|||
|
// {
|
|||
|
// Debug.LogError("Target object does not have a RectTransform or CanvasGroup.");
|
|||
|
// }
|
|||
|
//}
|
|||
|
|
|||
|
public void ClearAllChildren(Transform parent)
|
|||
|
{
|
|||
|
foreach (Transform child in parent)
|
|||
|
{
|
|||
|
GameObject.Destroy(child.gameObject);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|