using IVDataFormat; using UnityEngine; public class IVTraceTarget : MonoBehaviour { protected Camera camMain; protected Camera camUI; protected Transform trfTarget; protected RectTransform trfParent; protected RectTransform trfSelf; protected float fOffsetY; public virtual void SetCameraTarget(Camera cammain, Camera camui, RectTransform trfpr, Transform trftarget, float foffsety) { camMain = cammain; camUI = camui; trfParent = trfpr; trfTarget = trftarget; trfSelf = GetComponent(); fOffsetY = foffsety; } protected void SetPosition() { Vector2 v2pos = trfTarget.position; v2pos.y += fOffsetY; Vector2 canvasPos; Vector2 screenPoint = camMain.WorldToScreenPoint(v2pos); RectTransformUtility.ScreenPointToLocalPointInRectangle(trfParent, screenPoint, camUI, out canvasPos); trfSelf.localPosition = canvasPos; } public void ReSetoffsetY(eMonsterType type) { float foffsety; switch (type) { case eMonsterType.SmalllMonster: foffsety = 2.5f; break; case eMonsterType.MediumMonster: foffsety = 3.5f; break; case eMonsterType.BigMonster: foffsety = 5.5f; break; case eMonsterType.SmallObject: foffsety = 2.5f; break; case eMonsterType.MediumObject: foffsety = 3.5f; break; case eMonsterType.BigObject: foffsety = 5.5f; break; default: foffsety = 2.2f; break; } fOffsetY = foffsety; } protected void LateUpdate() { SetPosition(); } }