void AddArrowLabel(ILabel label)
    {
        if (label.GetShow() == EShow.All || label.GetShow() == EShow.MinMap)
        {
            MissionLabel ml = label as MissionLabel;
            if (ml == null)
            {
                return;
            }
            if (ml.m_target == null)
            {
                return;
            }

            GameObject obj = GameObject.Instantiate(mArrowLablePrefab) as GameObject;
            obj.transform.parent        = mSubInfoPanel.transform;
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;
            obj.transform.localRotation = Quaternion.identity;

            UIMapArrow uiArrow = obj.GetComponent <UIMapArrow>();
            if (uiArrow != null)
            {
                uiArrow.SetLabel(label, UIMapArrow.EArrowType.Main);
                mMapArrowList.Add(uiArrow);

                uiArrow.visualWidth  = mMapSize.x - 10;
                uiArrow.visualHeight = mMapSize.y - 10;
            }
        }
    }
    void RemvoArrowLabel(ILabel label)
    {
        UIMapArrow uiLabel = mMapArrowList.Find(itr => (itr.trackLabel.CompareTo(label)));

        if (uiLabel != null)
        {
            GameObject.Destroy(uiLabel.gameObject);
            uiLabel.gameObject.transform.parent = null;
            mMapArrowList.Remove(uiLabel);
        }
    }
Exemple #3
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);
    }