You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.1 KiB
74 lines
2.1 KiB
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<RectTransform>();
|
|
fOffsetY = foffsety;
|
|
}
|
|
|
|
protected void SetPosition()
|
|
{
|
|
Vector2 v2pos = trfTarget.position;
|
|
v2pos.y += fOffsetY;
|
|
|
|
//trfSelf.anchoredPosition = RectTransformUtility.WorldToScreenPoint(camMain, v2pos);
|
|
// Calculate *screen* position (note, not a canvas/recttransform position)
|
|
Vector2 canvasPos;
|
|
Vector2 screenPoint = camMain.WorldToScreenPoint(v2pos);
|
|
// Convert screen position to Canvas / RectTransform space <- leave camera null if Screen Space Overlay
|
|
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();
|
|
}
|
|
}
|