备份CatanBuilding瘦身独立工程
This commit is contained in:
38
Assets/Scripts/UI/Tips/tips_base.cs
Normal file
38
Assets/Scripts/UI/Tips/tips_base.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class tips_base : MonoBehaviour
|
||||
{
|
||||
public RectTransform content;
|
||||
public RectTransform bg;
|
||||
public RectTransform arrow;
|
||||
protected float width;
|
||||
#if UNITY_EDITOR
|
||||
private void Reset()
|
||||
{
|
||||
Awake();
|
||||
}
|
||||
#endif
|
||||
protected virtual void Awake()
|
||||
{
|
||||
content = GetComponent<RectTransform>();
|
||||
bg = content.Find("bg").GetComponent<RectTransform>();
|
||||
arrow = bg.Find("arrow").GetComponent<RectTransform>();
|
||||
|
||||
}
|
||||
public void SetContent(Vector3 pos)
|
||||
{
|
||||
bg.transform.position = pos;
|
||||
|
||||
float limit = content.rect.width / 2 - width;
|
||||
//边界检测
|
||||
if (bg.transform.localPosition.x > limit)
|
||||
{
|
||||
bg.transform.localPosition = new Vector3(limit, bg.transform.localPosition.y);
|
||||
}
|
||||
else if (bg.transform.localPosition.x < -limit)
|
||||
{
|
||||
bg.transform.localPosition = new Vector3(-limit, bg.transform.localPosition.y);
|
||||
}
|
||||
arrow.transform.position = new Vector3(pos.x, arrow.transform.position.y);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user