Esempio n. 1
0
    void OnGUI()
    {
        if (!Event.current.type.Equals(EventType.Repaint))
        {
            return;
        }
        Rect      camRect   = _camera.pixelRect;
        Vector2   iconSize  = new Vector2(camRect.height / 14, camRect.height / 14);
        Vector2   iconExt   = iconSize / 2;
        Vector2   arrowSize = new Vector2(iconSize.x / 4, iconSize.y / 2);
        Vector2   arrowExt  = arrowSize / 2;
        Matrix4x4 mt        = new Matrix4x4();

        mt.SetColumn(0, new Vector3(1, 0, 0));
        mt.SetColumn(1, new Vector3(0, 1, 0));
        mt.SetColumn(2, new Vector3(0, 0, 1));
        mt.SetColumn(3, new Vector4(-arrowExt.x, -arrowExt.y, 0, 1));
        float margin = arrowSize.y;

        for (int i = _trackedObjects.Count - 1; i >= 0; i--)
        {
            OffscreenMarker marker = _trackedObjects[i];
            if (marker && marker.gameObject)
            {
                if (!IsVisible(marker.gameObject))
                {
                    Vector3 wp        = FixBehindCamera(marker.transform.position);
                    Vector2 mrkScrPos = _camera.WorldToScreenPoint(wp);
                    mrkScrPos.y = camRect.height - mrkScrPos.y;
                    Vector2 iconPos = new Vector2(
                        Mathf.Clamp(mrkScrPos.x, iconExt.x + margin, camRect.width - iconExt.x - margin),
                        Mathf.Clamp(mrkScrPos.y, iconExt.y + margin, camRect.height - iconExt.y - margin)
                        );
                    Rect ri = new Rect(iconPos.x - iconExt.x, iconPos.y - iconExt.y, iconSize.x, iconSize.y);
                    GUI.DrawTexture(ri, marker.Icon);
                    Vector2 towardMrk = mrkScrPos - iconPos;
                    if (towardMrk.sqrMagnitude > 0.001f)
                    {
                        Vector2   twn      = towardMrk.normalized;
                        Vector2   arrowPos = iconPos + twn * (iconExt.x + arrowExt.y);
                        Matrix4x4 oldm     = GUI.matrix;
                        Matrix4x4 mr       = new Matrix4x4();
                        mr.SetColumn(0, new Vector3(twn.y, -twn.x, 0));
                        mr.SetColumn(1, new Vector3(-twn.x, -twn.y, 0));
                        mr.SetColumn(2, new Vector3(0, 0, 1));
                        mr.SetColumn(3, new Vector4(arrowPos.x, arrowPos.y, 0, 1));
                        GUI.matrix = mr * mt;
                        Rect ra = new Rect(0, 0, arrowSize.x, arrowSize.y);
                        GUI.DrawTexture(ra, marker.Arrow, ScaleMode.StretchToFill, alphaBlend: true, imageAspect: 0,
                                        color: marker.Color, borderWidth: 0, borderRadius: 0);
                        GUI.matrix = oldm;
                    }
                }
            }
            else
            {
                _trackedObjects.RemoveAt(i);
            }
        }
    }
Esempio n. 2
0
            public void Update()
            {
                try
                {
                    lifetime          -= Time.deltaTime;
                    transform.position = pos;

                    if (mark == null)
                    {
                        mark = SingletonManager.Get <Dungeon>(false).DisplayCrystalAndExitOffscreenMarkers(gameObject.transform);
                    }
                    if (lifetime <= 0)
                    {
                        mark.Hide();
                        Destroy(mark);
                        Destroy(gameObject);
                    }
                } catch (Exception e)
                {
                    if (mark != null)
                    {
                        mark.Hide();
                        Destroy(mark);
                    }
                    Destroy(gameObject);
                }
            }
Esempio n. 3
0
 public void Register(OffscreenMarker om)
 {
     if (!_trackedObjects.Contains(om))
     {
         _trackedObjects.Add(om);
     }
     else
     {
         Debug.LogWarning("EntTrackerLib: The tracked objects list already contains " + om, om);
     }
 }