171 lines
4.0 KiB
C#
171 lines
4.0 KiB
C#
|
using Games.LogicObj;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using Games.ChatHistory;
|
|||
|
|
|||
|
public abstract class Obj_HeadUI : WorldUIItem
|
|||
|
{
|
|||
|
protected ObjParent Target { get; private set; }
|
|||
|
private Transform VirtualModelTarget { get; set; }
|
|||
|
public override WorldUIRoot.WorldUiItemType itemType
|
|||
|
{
|
|||
|
get { return WorldUIRoot.WorldUiItemType.HeadInfo; }
|
|||
|
}
|
|||
|
|
|||
|
// 暂时使用这个变量而不是Prefab参数配置是否受到选项隐藏
|
|||
|
protected abstract bool HideByOption { get; }
|
|||
|
|
|||
|
private GameObject _nameBoardRoot;
|
|||
|
/// <summary>
|
|||
|
/// 是否因为Option而不显示
|
|||
|
/// </summary>
|
|||
|
public bool IsShowByOption { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// 是否因为物体需求而不显示
|
|||
|
/// </summary>
|
|||
|
public bool IsShowByObj { get; private set; }
|
|||
|
/// <summary>
|
|||
|
/// 是否因为物体名称为空
|
|||
|
/// </summary>
|
|||
|
public bool IsShowByName { get; private set; }
|
|||
|
|
|||
|
public Text NameText;
|
|||
|
public Outline OutLine;
|
|||
|
public Text OwerNameText;
|
|||
|
|
|||
|
public override Vector3 worldPosition
|
|||
|
{
|
|||
|
get {
|
|||
|
if(VirtualModelTarget)
|
|||
|
return VirtualModelTarget.position + Target.DeltaHeight * Vector3.up;
|
|||
|
return Target.transform.position + Target.DeltaHeight * Vector3.up;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override float pixelWidth
|
|||
|
{
|
|||
|
// 默认名称面板按中心对齐
|
|||
|
get { return rectTransform.sizeDelta.x; }
|
|||
|
}
|
|||
|
|
|||
|
public virtual void HideChatBubble(bool state)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public virtual void ShowChatBubble(ChatHistoryItem text)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public void OnObjDestroy(ObjParent obj)
|
|||
|
{
|
|||
|
BackToPool();
|
|||
|
gameObject.SetActive(false);
|
|||
|
// 释放尚未完成的加载任务
|
|||
|
WorldUIRoot.Instance.StopLoadHeadUi(obj);
|
|||
|
}
|
|||
|
|
|||
|
public virtual void Init(ObjParent obj)
|
|||
|
{
|
|||
|
Target = obj;
|
|||
|
}
|
|||
|
|
|||
|
public void SetOwnerName(string ownerName)
|
|||
|
{
|
|||
|
OwerNameText.gameObject.SetActive(false);
|
|||
|
if (!string.IsNullOrEmpty(ownerName))
|
|||
|
{
|
|||
|
OwerNameText.gameObject.SetActive(true);
|
|||
|
SetText(OwerNameText, GCGame.Table.StrDictionary.GetClientDictionaryString("#{2670}", ownerName));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public virtual void SetName(string myName)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(myName))
|
|||
|
IsShowByName = false;
|
|||
|
else
|
|||
|
{
|
|||
|
IsShowByName = true;
|
|||
|
SetText(NameText, myName);
|
|||
|
}
|
|||
|
RefreshShow();
|
|||
|
}
|
|||
|
|
|||
|
private void SetText(Text component, string text)
|
|||
|
{
|
|||
|
if (component != null)
|
|||
|
{
|
|||
|
if (string.IsNullOrEmpty(text))
|
|||
|
component.gameObject.SetActive(false);
|
|||
|
else
|
|||
|
{
|
|||
|
component.gameObject.SetActive(true);
|
|||
|
component.text = text;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public virtual void SetNameColor(Color color)
|
|||
|
{
|
|||
|
if (NameText != null)
|
|||
|
NameText.color = color;
|
|||
|
}
|
|||
|
|
|||
|
protected override void Awake()
|
|||
|
{
|
|||
|
base.Awake();
|
|||
|
_nameBoardRoot = transform.GetChild(0).gameObject;
|
|||
|
}
|
|||
|
|
|||
|
private bool _started;
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
_started = true;
|
|||
|
OnEnable();
|
|||
|
}
|
|||
|
|
|||
|
protected virtual void OnEnable()
|
|||
|
{
|
|||
|
if (_started)
|
|||
|
{
|
|||
|
IsShowByObj = true;
|
|||
|
ResetShow();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void BackToPool()
|
|||
|
{
|
|||
|
Target = null;
|
|||
|
base.BackToPool();
|
|||
|
}
|
|||
|
|
|||
|
public void ResetShow()
|
|||
|
{
|
|||
|
IsShowByOption = !HideByOption || WorldUIRoot.ShowHeadUi;
|
|||
|
RefreshShow();
|
|||
|
}
|
|||
|
|
|||
|
public void SetShowByObj(bool isShow)
|
|||
|
{
|
|||
|
IsShowByObj = isShow;
|
|||
|
RefreshShow();
|
|||
|
}
|
|||
|
|
|||
|
private void RefreshShow()
|
|||
|
{
|
|||
|
if(_nameBoardRoot != null)
|
|||
|
_nameBoardRoot.SetActive(IsShowByObj && IsShowByOption && IsShowByName);
|
|||
|
}
|
|||
|
|
|||
|
public override bool CheckPositionValid()
|
|||
|
{
|
|||
|
return Target != null;
|
|||
|
}
|
|||
|
|
|||
|
public void SetVirtualModelTarget(Transform target)
|
|||
|
{
|
|||
|
Debug.LogError("SetHeadUI");
|
|||
|
VirtualModelTarget = target;
|
|||
|
}
|
|||
|
}
|