예제 #1
0
    public Vector3 GetIconScale(NJGMapItem item)
    {
        Vector3 s = item.iconScale * mul;

        s.z = 1;
        return(s);
    }
예제 #2
0
    /// <summary>
    /// Get the map icon entry associated with the specified unit.
    /// </summary>

    protected override UIMapIconBase GetEntry(NJGMapItem item)
    {
        // Try to find an existing entry
        for (int i = 0, imax = mList.Count; i < imax; ++i)
        {
            UIMapIconOnGUI ic = (UIMapIconOnGUI)mList[i];
            if (ic.item == item)
            {
                /*ic.item = item;
                 * ic.sprite = mapOnGUI.GetSprite(item.type);
                 * if (ic.color != item.color) ic.color = item.color;
                 * if (ic.planeRenderer.localScale != GetIconScale(item)) ic.planeRenderer.localScale = GetIconScale(item);*/
                return(ic);
            }
        }

        // See if an unused entry can be reused
        if (mUnused.Count > 0)
        {
            UIMapIconOnGUI ent = (UIMapIconOnGUI)mUnused[mUnused.Count - 1];
            ent.item   = item;
            ent.sprite = mapOnGUI.GetSprite(item.type);
            ent.color  = item.color;
            ent.planeRenderer.localScale = GetIconScale(item);
            mUnused.RemoveAt(mUnused.Count - 1);
            NJGTools.SetActive(ent.gameObject, true);
            mList.Add(ent);
            return(ent);
        }

        // Create this new icon
        GameObject go = NJGTools.AddChild(iconRoot.gameObject);

        go.name = "Icon" + mCount;

        UIMapIconOnGUI mi = go.AddComponent <UIMapIconOnGUI>();

        mi.item   = item;
        mi.sprite = mapOnGUI.GetSprite(item.type);
        mi.color  = item.color;
        mi.planeRenderer.localScale = GetIconScale(item);

        if (mi == null)
        {
            Debug.LogError("Expected to find a Game Map Icon on the prefab to work with", this);
            Destroy(go);
        }
        else
        {
            mCount++;
            mi.item = item;
            mList.Add(mi);
        }
        return(mi);
    }
예제 #3
0
        /// <summary>
        /// Update the icon icon for the specified unit, assuming it's visible.
        /// </summary>

        protected override void UpdateIcon(NJGMapItem item, float x, float y)
        {
            // If the unit is not visible, don't consider it
            bool isVisible = (((x - mapBorderRadius) >= -mapHalfScale.x) &&
                              ((x + mapBorderRadius) <= mapHalfScale.x)) &&
                             (((y - mapBorderRadius) >= -mapHalfScale.y) &&
                              ((y + mapBorderRadius) <= mapHalfScale.y));

            Vector3 newPos = new Vector3(x, y, 0f);

            if (!isVisible)
            {
                return;
            }

            UIMapIconBase icon = GetEntry(item);

            if (icon != null)
            {
                icon.isMapIcon = true;
            }

            if (icon != null && !icon.isValid)
            {
                icon.isValid = true;
                Transform t = icon.cachedTransform;
                if (item.updatePosition)
                {
                    if (t.localPosition != newPos)
                    {
                        t.localPosition = newPos;
                    }
                }

                if (item.rotate)
                {
                    float angle = ((Vector3.Dot(item.cachedTransform.forward, Vector3.Cross(Vector3.up, Vector3.forward)) <= 0f) ? 1f : -1f) * Vector3.Angle(item.cachedTransform.forward, Vector3.forward);
                    t.localEulerAngles = new Vector3(t.localEulerAngles.x, t.localEulerAngles.y, angle);
                }
                else
                {
                    if (t.localEulerAngles != Vector3.zero)
                    {
                        t.localEulerAngles = Vector3.zero;
                    }
                }
            }
        }
예제 #4
0
파일: NJGFOW.cs 프로젝트: andrewang/Unity
    /// <summary>
    /// Reset Fog of War clearing all explored areas.
    /// </summary>

    public void ResetFOW()
    {
        if (map.fow.fowSystem == NJGMapBase.FOW.FOWSystem.BuiltInFOW)
        {
            for (int i = 0; i < NJGMapItem.list.Count; ++i)
            {
                NJGMapItem item = NJGMapItem.list[i];
                if (item.cachedTransform != NJG.UIMiniMapBase.inst.target)
                {
                    item.isRevealed = false;
                }
            }
        }

        Init();
    }
예제 #5
0
 protected override UIMapIconBase GetEntry(NJGMapItem item)
 {
     int i = 0;
     int count = this.mList.Count;
     while (i < count)
     {
         UIMapIcon uIMapIcon = (UIMapIcon)this.mList[i];
         if (uIMapIcon.item.Equals(item))
         {
             return uIMapIcon;
         }
         i++;
     }
     if (this.mUnused.Count > 0)
     {
         UIMapIcon uIMapIcon2 = (UIMapIcon)this.mUnused[this.mUnused.Count - 1];
         uIMapIcon2.item = item;
         uIMapIcon2.sprite.spriteName = NJGMap.instance.GetSprite(item.type).name;
         uIMapIcon2.sprite.depth = 1 + item.depth;
         uIMapIcon2.sprite.color = item.color;
         uIMapIcon2.sprite.gameObject.transform.localEulerAngles = new Vector3(0f, 0f, 180f);
         if (uIMapIcon2.sprite.localSize != (Vector2)item.iconScale)
         {
             if (uIMapIcon2.collider != null)
             {
                 uIMapIcon2.collider.size = item.iconScale;
             }
             uIMapIcon2.sprite.width = (int)item.iconScale.x;
             uIMapIcon2.sprite.height = (int)item.iconScale.y;
         }
         UISpriteData spriteBorder = NJGMap.instance.GetSpriteBorder(item.type);
         if (spriteBorder != null && uIMapIcon2.border != null)
         {
             uIMapIcon2.border.spriteName = spriteBorder.name;
             uIMapIcon2.border.depth = 1 + item.depth;
             uIMapIcon2.border.color = item.color;
             if (uIMapIcon2.border.localSize != (Vector2)item.borderScale)
             {
                 uIMapIcon2.border.width = (int)item.borderScale.x;
                 uIMapIcon2.border.height = (int)item.borderScale.y;
             }
         }
         this.mUnused.RemoveAt(this.mUnused.Count - 1);
         NGUITools.SetActive(uIMapIcon2.gameObject, true);
         this.mList.Add(uIMapIcon2);
         return uIMapIcon2;
     }
     GameObject gameObject = NGUITools.AddChild(base.iconRoot.gameObject);
     gameObject.name = "Icon" + this.mCount;
     UISprite uISprite = NGUITools.AddWidget<UISprite>(gameObject);
     uISprite.name = "Icon";
     uISprite.depth = 1 + item.depth;
     uISprite.atlas = NJGMap.instance.atlas;
     uISprite.spriteName = NJGMap.instance.GetSprite(item.type).name;
     uISprite.color = item.color;
     uISprite.gameObject.transform.localEulerAngles = new Vector3(0f, 0f, 180f);
     uISprite.width = (int)item.iconScale.x;
     uISprite.height = (int)item.iconScale.y;
     UIMapIcon uIMapIcon3 = gameObject.AddComponent<UIMapIcon>();
     uIMapIcon3.item = item;
     uIMapIcon3.sprite = uISprite;
     if (item.interaction)
     {
         if (uIMapIcon3.collider == null)
         {
             NGUITools.AddWidgetCollider(gameObject);
             uIMapIcon3.collider = gameObject.GetComponent<BoxCollider>();
             uIMapIcon3.collider.size = item.iconScale;
         }
         UISpriteData spriteBorder = NJGMap.instance.GetSpriteBorder(item.type);
         if (spriteBorder != null)
         {
             UISprite uISprite2 = NGUITools.AddWidget<UISprite>(gameObject);
             uISprite2.name = "Selection";
             uISprite2.depth = item.depth + 2;
             uISprite2.atlas = NJGMap.instance.atlas;
             uISprite2.spriteName = spriteBorder.name;
             uISprite2.color = item.color;
             uISprite2.width = (int)item.borderScale.x;
             uISprite2.height = (int)item.borderScale.y;
             uIMapIcon3.border = uISprite2;
         }
     }
     if (uIMapIcon3 == null)
     {
         global::Debug.LogError(new object[]
         {
             "Expected to find a Game Map Icon on the prefab to work with",
             this
         });
         UnityEngine.Object.Destroy(gameObject);
     }
     else
     {
         this.mCount++;
         uIMapIcon3.item = item;
         this.mList.Add(uIMapIcon3);
     }
     return uIMapIcon3;
 }
예제 #6
0
    //float extraSpace = 0;

    /// <summary>
    /// Draw the Map Marker inspector.
    /// </summary>

    public override void OnInspectorGUI()
    {
#if UNITY_4_3
        EditorGUIUtility.LookLikeControls(120f);
#else
        EditorGUIUtility.labelWidth = 120f;
#endif

        m = target as NJGMapItem;

        NJGEditorTools.DrawEditMap();

        if (UIMiniMapBase.inst != null)
        {
            string info = "Map Position: " + UIMiniMapBase.inst.WorldToMap(m.cachedTransform.position).ToString();

            GUI.color = Color.cyan;
            EditorGUILayout.LabelField(info, EditorStyles.boldLabel);
            GUI.color = Color.white;
        }

        NJGEditorTools.DrawSeparator();

        int type = 0;
        if (NJG.NJGMapBase.instance != null)
        {
            type = NJGEditorTools.DrawList("Marker Type", NJG.NJGMapBase.instance.mapItemTypes, m.type);
        }

        string tooltip = "You can use to display name + anything else you want.\nFor example: Ore [FF0000]+100 Mineral[-]";
        string content = "";

        if (type != 0)
        {
            EditorGUILayout.LabelField(new GUIContent("Tooltip Content", tooltip));
            content = EditorGUILayout.TextArea(m.content);

            GUI.backgroundColor = Color.gray;
            EditorGUILayout.HelpBox(tooltip, MessageType.Info);
            GUI.backgroundColor = Color.white;
        }

        //m.drawDirection = EditorGUILayout.Toggle("Draw Direction Line", m.drawDirection);
        bool revealFOW = EditorGUILayout.Toggle("Reveal FOW", m.revealFOW);
        GUI.enabled = m.revealFOW;
        int revealDistance = (int)EditorGUILayout.Slider("Reveal Distance", m.revealDistance, 0, 100);
        GUI.enabled         = true;
        GUI.backgroundColor = Color.gray;
        EditorGUILayout.HelpBox("Overrides Global Reveal Distance, if value = 0 it will use the global reveal distance.", MessageType.Info);
        GUI.backgroundColor = Color.white;

        /*if (NJG.NJGMapBase.instance != null)
         * {
         *      if (NJG.NJGMapBase.instance.atlas != null)
         *      {
         *              GUILayout.BeginHorizontal();
         *              EditorGUILayout.LabelField("Icon Sprite", GUILayout.Width(100.0f));
         *
         *              // Draw sprite preview.
         *              Material mat = NJG.NJGMapBase.instance.atlas.spriteMaterial;
         *
         *              if (mat != null)
         *              {
         *                      Texture2D tex = mat.mainTexture as Texture2D;
         *
         *                      if (tex != null)
         *                      {
         *                              UIAtlas.Sprite sprite = m.sprite;
         *                              Rect rect = sprite.outer;
         *                              if (NJG.NJGMapBase.instance.atlas.coordinates == UIAtlas.Coordinates.Pixels)
         *                              {
         *                                      rect = NGUIMath.ConvertToTexCoords(rect, tex.width, tex.height);
         *                              }
         *
         *                              GUILayout.Space(4f);
         *                              GUILayout.Label("", GUILayout.Height(NJGMapBase.instance.iconSize));
         *                              GUI.color = m.color;
         *                              DrawSprite(tex, rect, null, false, NJGMapBase.instance.iconSize);
         *                              GUI.color = Color.white;
         *
         *                              extraSpace = NJGMapBase.instance.iconSize * (float)sprite.outer.height / sprite.outer.width;
         *                      }
         *
         *              }
         *              GUILayout.EndHorizontal();
         *
         *              extraSpace = Mathf.Max(0f, extraSpace - 30f);
         *              //GUILayout.Space(extraSpace);
         *      }
         *      EditorGUILayout.Separator();
         * }*/

        EditorGUILayout.Separator();

        if (m.type != type ||
            m.content != content ||
            m.revealFOW != revealFOW ||
            m.revealDistance != revealDistance)
        {
            m.type           = type;
            m.content        = content;
            m.revealFOW      = revealFOW;
            m.revealDistance = revealDistance;
            NJGEditorTools.RegisterUndo("Map Item Properties", m);
        }
    }
예제 #7
0
    /// <summary>
    /// Get the map icon entry associated with the specified unit.
    /// </summary>

    protected override UIMapArrowBase GetArrow(Object o)
    {
        NJGMapItem item = (NJGMapItem)o;

        // Try to find an existing entry
        for (int i = 0, imax = mListArrow.Count; i < imax; ++i)
        {
            if (mListArrow[i].item == item)
            {
                UIMapArrow ic = (UIMapArrow)mListArrow[i];

                /*string spr = NJGMap.instance.GetArrowSprite(item.type).name;
                *  if (ic.sprite.spriteName != spr) ic.sprite.spriteName = spr;*/
                /*if(ic.sprite.depth != item.depth) ic.sprite.depth = item.arrowDepth;
                 * if(!ic.sprite.color.Equals(item.color)) ic.sprite.color = item.color;
                 * if(ic.sprite.cachedTransform.localScale != arrowScale) ic.sprite.cachedTransform.localScale = arrowScale;
                 * Vector3 offset = new Vector3(0, mapScale.y / 2 - item.arrowOffset, 0);
                 * if(ic.sprite.cachedTransform.localPosition != offset) ic.sprite.cachedTransform.localPosition = offset;*/
                return(ic);
            }
        }

        // See if an unused entry can be reused
        if (mUnusedArrow.Count > 0)
        {
            UIMapArrow ent = (UIMapArrow)mUnusedArrow[mUnusedArrow.Count - 1];
            ent.item              = item;
            ent.child             = ent.sprite.cachedTransform;
            ent.sprite.spriteName = NJGMap.instance.GetArrowSprite(item.type).name;
            ent.sprite.depth      = 1 + item.arrowDepth;
            ent.sprite.color      = item.color;
            ent.sprite.width      = (int)arrowScale.x;
            ent.sprite.height     = (int)arrowScale.y;
            ent.sprite.cachedTransform.localPosition = new Vector3(0, mapScale.y / 2 - item.arrowOffset, 0);
            mUnusedArrow.RemoveAt(mUnusedArrow.Count - 1);
            NGUITools.SetActive(ent.gameObject, true);
            mListArrow.Add(ent);
            return(ent);
        }

        // Create this new icon
        GameObject go = NGUITools.AddChild(rendererTransform.parent.gameObject);

        go.name                    = "Arrow" + mArrowCount;
        go.transform.parent        = UIMiniMap.instance.arrowRoot.transform;
        go.transform.localPosition = Vector3.zero;
        go.transform.localScale    = Vector3.one;

        UISprite sprite = NGUITools.AddWidget <UISprite>(go);

        //sprite.type = UISprite.Type.Sliced;
        sprite.depth      = 1 + item.arrowDepth;
        sprite.atlas      = NJGMap.instance.atlas;
        sprite.spriteName = NJGMap.instance.GetArrowSprite(item.type).name;
        sprite.color      = item.color;
        sprite.width      = (int)arrowScale.x;
        sprite.height     = (int)arrowScale.y;
        sprite.cachedTransform.localPosition = new Vector3(0, rendererTransform.localScale.y / 2 - item.arrowOffset, 0);

        UIMapArrow mi = go.AddComponent <UIMapArrow>();

        mi.child = sprite.cachedTransform;
        mi.child.localEulerAngles = new Vector3(0, 180f, 0);
        mi.item   = item;
        mi.sprite = sprite;

        if (mi == null)
        {
            Debug.LogError("Expected to find a UIMapArrow on the prefab to work with");
            Destroy(go);
        }
        else
        {
            mArrowCount++;
            mi.item = item;
            mListArrow.Add(mi);
        }
        return(mi);
    }
예제 #8
0
    /// <summary>
    /// Get the map icon entry associated with the specified unit.
    /// </summary>

    protected override UIMapIconBase GetEntry(NJGMapItem item)
    {
        UISpriteData s = null;

        // Try to find an existing entry
        for (int i = 0, imax = mList.Count; i < imax; ++i)
        {
            UIMapIcon ic = (UIMapIcon)mList[i];
            if (ic.item.Equals(item))
            {
                string spr = NJGMap.instance.GetSprite(item.type).name;
                if (ic.sprite.spriteName != spr)
                {
                    ic.sprite.spriteName = spr;
                }
                if (ic.sprite.depth != item.depth)
                {
                    ic.sprite.depth = item.depth;
                }

                /*if (!ic.sprite.color.Equals(item.color)) ic.sprite.color = item.color;
                 * if (ic.sprite.cachedTransform.localScale != item.iconScale)
                 * {
                 *  ic.collider.size = item.iconScale;
                 *  ic.sprite.cachedTransform.localScale = item.iconScale;
                 * }
                 *
                 * s = NJGMap.instance.GetSpriteBorder(item.type);
                 * if (s != null)
                 * {
                 *  string brd = s.name;
                 *  if (ic.border != null)
                 *  {
                 *      if (ic.border.spriteName != brd) ic.border.spriteName = brd;
                 *      if (ic.border.depth != (item.depth + 1)) ic.border.depth = item.depth + 1;
                 *      if (!ic.border.color.Equals(item.color)) ic.border.color = item.color;
                 *      if (ic.border.cachedTransform.localScale != item.borderScale)
                 *      {
                 *          ic.border.cachedTransform.localScale = item.borderScale;
                 *      }
                 *  }
                 * }*/
                return(ic);
            }
        }

        // See if an unused entry can be reused
        if (mUnused.Count > 0)
        {
            UIMapIcon ent = (UIMapIcon)mUnused[mUnused.Count - 1];
            ent.item = item;
            ent.sprite.spriteName = NJGMap.instance.GetSprite(item.type).name;
            ent.sprite.depth      = 1 + item.depth;
            ent.sprite.color      = item.color;
            if (ent.sprite.localSize != (Vector2)item.iconScale)
            {
                if (ent.collider != null)
                {
                    if (ent.collider is BoxCollider)
                    {
                        BoxCollider col = ent.collider as BoxCollider;
                        col.size = item.iconScale;
                    }

                    if (ent.collider is BoxCollider2D)
                    {
                        BoxCollider2D col = ent.collider as BoxCollider2D;
                        col.size = item.iconScale;
                    }
                }
                ent.sprite.width  = (int)item.iconScale.x;
                ent.sprite.height = (int)item.iconScale.y;
            }

            s = NJGMap.instance.GetSpriteBorder(item.type);
            if (s != null)
            {
                if (ent.border != null)
                {
                    ent.border.spriteName = s.name;
                    ent.border.depth      = 1 + item.depth;
                    ent.border.color      = item.color;
                    if (ent.border.localSize != (Vector2)item.borderScale)
                    {
                        ent.border.width  = (int)item.borderScale.x;
                        ent.border.height = (int)item.borderScale.y;
                    }
                }
            }
            mUnused.RemoveAt(mUnused.Count - 1);
            //ent.Enable();
            NGUITools.SetActive(ent.gameObject, true);
            mList.Add(ent);
            return(ent);
        }

        // Create this new icon
        GameObject go = NGUITools.AddChild(iconRoot.gameObject);

        go.name = "Icon" + mCount;

        UISprite sprite = NGUITools.AddWidget <UISprite>(go);

        sprite.name       = "Icon";
        sprite.depth      = 1 + item.depth;
        sprite.atlas      = NJGMap.instance.atlas;
        sprite.spriteName = NJGMap.instance.GetSprite(item.type).name;
        sprite.color      = item.color;
        sprite.width      = (int)item.iconScale.x;
        sprite.height     = (int)item.iconScale.y;

        UIMapIcon mi = go.AddComponent <UIMapIcon>();

        mi.item   = item;
        mi.sprite = sprite;
        if (item.interaction)
        {
            if (go.GetComponent <Collider>() == null)
            {
                NGUITools.AddWidgetCollider(go);
                mi.collider = go.GetComponent <Collider>();

                if (mi.collider is BoxCollider)
                {
                    BoxCollider col = mi.collider as BoxCollider;
                    col.size = item.iconScale;
                }

                if (mi.collider is BoxCollider2D)
                {
                    BoxCollider2D col = mi.collider as BoxCollider2D;
                    col.size = item.iconScale;
                }
            }

            s = NJGMap.instance.GetSpriteBorder(item.type);
            if (s != null)
            {
                UISprite border = NGUITools.AddWidget <UISprite>(go);
                border.name       = "Selection";
                border.depth      = item.depth + 2;
                border.atlas      = NJGMap.instance.atlas;
                border.spriteName = s.name;
                border.color      = item.color;
                border.width      = (int)item.borderScale.x;
                border.height     = (int)item.borderScale.y;
                mi.border         = border;
            }
        }

        if (mi == null)
        {
            Debug.LogError("Expected to find a Game Map Icon on the prefab to work with", this);
            Destroy(go);
        }
        else
        {
            mCount++;
            mi.item = item;
            mList.Add(mi);
        }
        return(mi);
    }
예제 #9
0
 protected override void UpdateIcon(NJGMapItem item, float x, float y)
 {
     float num = Mathf.Max(this.mapHalfScale.x, this.mapHalfScale.y) - this.mapBorderRadius;
     bool flag = item.gameObject.activeSelf && x * x + y * y <= num * num;
     if (!base.isPanning)
     {
         if (!flag && item.haveArrow)
         {
             if (item.arrow == null)
             {
                 item.arrow = this.GetArrow(item);
             }
             if (item.arrow != null)
             {
                 if (!NJGTools.GetActive(item.arrow.gameObject))
                 {
                     NJGTools.SetActive(item.arrow.gameObject, true);
                 }
                 item.arrow.UpdateRotation(this.target.position);
                 if (this.MinimapFrame != null)
                 {
                     this.MinimapFrame.localEulerAngles = item.arrow.Rotation;
                 }
             }
         }
         else if (flag && item.haveArrow && item.arrow != null && NJGTools.GetActive(item.arrow.gameObject))
         {
             NJGTools.SetActive(item.arrow.gameObject, false);
             if (this.MinimapFrame != null)
             {
                 this.MinimapFrame.localEulerAngles = Vector3.zero;
             }
         }
     }
     if (!flag)
     {
         return;
     }
     UIMapIconBase entry = this.GetEntry(item);
     if (entry != null && !entry.isValid)
     {
         entry.isMapIcon = false;
         entry.isValid = true;
         Transform cachedTransform = entry.cachedTransform;
         Vector3 vector = new Vector3(x, y, 0f);
         if (item.updatePosition && cachedTransform.localPosition != vector)
         {
             cachedTransform.localPosition = vector;
         }
         if (item.rotate)
         {
             float z = ((Vector3.Dot(item.cachedTransform.forward, Vector3.Cross(Vector3.up, Vector3.forward)) > 0f) ? -1f : 1f) * Vector3.Angle(item.cachedTransform.forward, Vector3.forward);
             cachedTransform.localEulerAngles = new Vector3(cachedTransform.localEulerAngles.x, cachedTransform.localEulerAngles.y, z);
         }
         else if (!item.rotate && this.rotateWithPlayer)
         {
             Vector3 vector2 = new Vector3(0f, 0f, -base.iconRoot.localEulerAngles.z);
             if (!cachedTransform.localEulerAngles.Equals(vector2))
             {
                 cachedTransform.localEulerAngles = vector2;
             }
         }
         else if (!cachedTransform.localEulerAngles.Equals(Vector3.zero))
         {
             cachedTransform.localEulerAngles = Vector3.zero;
         }
     }
 }
예제 #10
0
    /// <summary>
    /// Get the map icon entry associated with the specified unit.
    /// </summary>

    protected override UIMapArrowBase GetArrow(Object o)
    {
        NJGMapItem item = (NJGMapItem)o;

        // Try to find an existing entry
        for (int i = 0, imax = mListArrow.Count; i < imax; ++i)
        {
            if (mListArrow[i].item == item)
            {
                UIMapArrowOnGUI ic = (UIMapArrowOnGUI)mListArrow[i];
                //ic.item = item;
                ic.sprite = mapOnGUI.GetArrowSprite(item.type);

                /*ic.color = item.color;
                 * ic.planeRenderer.localScale = iconScale;
                 * ic.child = ent.planeRenderer;*/
                return(ic);
            }
        }

        // See if an unused entry can be reused
        if (mUnusedArrow.Count > 0)
        {
            UIMapArrowOnGUI ent = (UIMapArrowOnGUI)mUnusedArrow[mUnusedArrow.Count - 1];
            ent.item   = item;
            ent.color  = item.color;
            ent.sprite = mapOnGUI.GetArrowSprite(item.type);
            ent.planeRenderer.localScale    = arrowScale;
            ent.planeRenderer.localPosition = new Vector3(0, mapHalfScale.y - item.arrowOffset, -(item.arrowDepth + 1));
            ent.child = ent.planeRenderer;
            mUnusedArrow.RemoveAt(mUnusedArrow.Count - 1);
            NJGTools.SetActive(ent.gameObject, true);
            mListArrow.Add(ent);
            return(ent);
        }

        // Create this new icon
        GameObject go = NJGTools.AddChild(UIMiniMapOnGUI.instance.rendererTransform.parent.gameObject);

        go.name                    = "Arrow" + mArrowCount;
        go.transform.parent        = UIMiniMapOnGUI.instance.arrowRoot.transform;
        go.transform.localPosition = Vector3.zero;
        go.transform.localScale    = Vector3.one;

        UIMapArrowOnGUI mi = go.AddComponent <UIMapArrowOnGUI>();

        mi.item   = item;
        mi.color  = item.color;
        mi.sprite = mapOnGUI.GetArrowSprite(item.type);
        mi.planeRenderer.localScale    = arrowScale;
        mi.planeRenderer.localPosition = new Vector3(0, mapHalfScale.y - item.arrowOffset, -(item.arrowDepth + 1));
        mi.child = mi.planeRenderer;

        if (mi == null)
        {
            Debug.LogError("Expected to find a UIMapArrowOnGUI on the prefab to work with");
            Destroy(go);
        }
        else
        {
            mArrowCount++;
            mi.item = item;
            mListArrow.Add(mi);
        }
        return(mi);
    }
예제 #11
0
        /// <summary>
        /// Update the icon icon for the specified unit, assuming it's visible.
        /// </summary>

        protected override void UpdateIcon(NJGMapItem item, float x, float y)
        {
            // If the unit is not visible, don't consider it
            bool isVisible = false;

            if (map.fow.enabled)
            {
                isVisible = (((x - mapBorderRadius) >= -mapHalfScale.x) &&
                             ((x + mapBorderRadius) <= mapHalfScale.x)) &&
                            (((y - mapBorderRadius) >= -mapHalfScale.y) &&
                             ((y + mapBorderRadius) <= mapHalfScale.y));

                if (!item.isRevealed)
                {
                    isVisible = false;
                }
            }
            else
            {
                isVisible = (((x - mapBorderRadius) >= -mapHalfScale.x) &&
                             ((x + mapBorderRadius) <= mapHalfScale.x)) &&
                            (((y - mapBorderRadius) >= -mapHalfScale.y) &&
                             ((y + mapBorderRadius) <= mapHalfScale.y));
            }

            if (!isPanning)
            {
                if (!isVisible && item.haveArrow)
                {
                    if (item.arrow == null)
                    {
                        item.arrow = (UIMapArrowBase)GetArrow(item);
                    }

                    if (item.arrow != null)
                    {
                        if (!NJGTools.GetActive(item.arrow.gameObject))
                        {
                            NJGTools.SetActive(item.arrow.gameObject, true);
                        }
                        item.arrow.UpdateRotation(target.position);
                    }
                }
                else if (isVisible && item.haveArrow)
                {
                    if (item.arrow != null)
                    {
                        if (NJGTools.GetActive(item.arrow.gameObject))
                        {
                            NJGTools.SetActive(item.arrow.gameObject, false);
                        }
                    }
                }
            }

            if (!isVisible)
            {
                return;
            }

            UIMapIconBase icon = GetEntry(item);

            if (icon != null && !icon.isValid)
            {
                icon.isMapIcon = false;
                icon.isValid   = true;
                Transform t      = icon.cachedTransform;
                Vector3   newPos = new Vector3(x, y, 0f);
                if (item.updatePosition)
                {
                    if (t.localPosition != newPos)
                    {
                        t.localPosition = newPos;
                    }
                }

                if (item.rotate)
                {
                    float angle = ((Vector3.Dot(item.cachedTransform.forward, Vector3.Cross(Vector3.up, Vector3.forward)) <= 0f) ? 1f : -1f) * Vector3.Angle(item.cachedTransform.forward, Vector3.forward);
                    t.localEulerAngles = new Vector3(t.localEulerAngles.x, t.localEulerAngles.y, angle);
                }
                else if (!item.rotate && rotateWithPlayer)
                {
                    Vector3 eu = new Vector3(0, 0, -iconRoot.localEulerAngles.z);
                    if (!t.localEulerAngles.Equals(eu))
                    {
                        t.localEulerAngles = eu;
                    }
                }
                else
                if (!t.localEulerAngles.Equals(Vector3.zero))
                {
                    t.localEulerAngles = Vector3.zero;
                }
            }
        }
예제 #12
0
 protected virtual void UpdateIcon(NJGMapItem item, float x, float y)
 {
 }
예제 #13
0
 protected virtual UIMapIconBase GetEntry(NJGMapItem marker)
 {
     return null;
 }