Ejemplo n.º 1
0
        protected override void OnStart()
        {
            base.OnStart();

            if (Application.isPlaying)
            {
                // Create north root and place icon north properly
                northRoot      = NJGTools.AddChild(iconRoot.gameObject);
                northRoot.name = "North";
                northRoot.transform.localPosition = Vector3.zero;

                if (northIcon != null)
                {
                    northIcon.transform.parent        = northRoot.transform;
                    northIcon.transform.localRotation = Quaternion.identity;
                }

                // Calculate the border radius for icon culling.
                if (calculateBorder)
                {
                    mapBorderRadius = (rendererTransform.localScale.x / 2f) / 4f;
                }
            }

            UpdateAlignment();

            // Create a gameObject for the ping marker

            /*GameObject go = NJGTools.AddChild(iconRoot);
             * go.name = "_Ping";
             *
             * // Assign Ping type to this marker, 'Ping' type most be created on the editor
             * pingMarker = go.AddComponent<NJGMapItem>();
             * pingMarker.type = "Ping";*/
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Setup map renderer.
        /// </summary>

        void Awake()
        {
            if (fow.textureSize < 200)
            {
                fow.textureSize = 200;
            }
            if (miniMap == null)
            {
                miniMap = GameObject.FindObjectOfType(typeof(UIMiniMapBase)) as UIMiniMapBase;
            }
            if (worldMap == null)
            {
                worldMap = GameObject.FindObjectOfType(typeof(UIWorldMapBase)) as UIWorldMapBase;
            }
            //Holoville.HOTween.HOTween.Init(false, true, true);
            //Holoville.HOTween.HOTween.EnableOverwriteManager(false);

            if (Application.isPlaying)
            {
                if (mapTexture != null)
                {
                    NJGTools.Destroy(mapTexture);
                }
                if (generateAtStart)
                {
                    GenerateMap();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete the specified entry, adding it to the unused list.
        /// </summary>

        public virtual void DeleteArrow(UIMapArrowBase ent)
        {
            if (ent != null)
            {
                mListArrow.Remove(ent);
                mUnusedArrow.Add(ent);
                NJGTools.SetActive(ent.gameObject, false);
            }
        }
Ejemplo n.º 4
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);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Helper function that returns the selected root object.
    /// </summary>

    static public GameObject SelectedRoot(bool createIfMissing)
    {
        GameObject go = Selection.activeGameObject;

        // Only use active objects
        if (go != null && !NJGTools.GetActive(go))
        {
            go = null;
        }

        return(go);
    }
Ejemplo n.º 6
0
        /// <summary>
        /// Update layer mask for UICamera and Camera inside
        /// </summary>

        protected virtual void Update()
        {
            if (!Application.isPlaying)
            {
                //if (mCam == null) mCam = GetComponentInChildren<Camera>();
                //if (mCam != null) if (mCam.cullingMask != 1 << gameObject.layer) mCam.cullingMask = 1 << gameObject.layer;

                if (mapTexture != null)
                {
                    NJGTools.DestroyImmediate(mapTexture);
                }
            }
        }
Ejemplo n.º 7
0
    void Delete()
    {
        NJGTools.DestroyImmediate(m.gameObject);

        if (NJGMapZone.list.Count > 0)
        {
            Selection.activeGameObject = NJGMapZone.list[NJGMapZone.list.Count - 1].gameObject;
        }
        else
        {
            Selection.activeGameObject = NJGMapBase.instance.gameObject;
        }
    }
Ejemplo n.º 8
0
    void OnDestroy()
    {
        if (Map.miniMap != null)
        {
            Map.miniMap.material.mainTexture = null;
        }
        if (Map.worldMap != null)
        {
            Map.worldMap.material.mainTexture = null;
        }

        if (NJGMap.instance.mapTexture != null)
        {
            NJGTools.Destroy(NJGMap.instance.mapTexture);
        }
        NJGMap.instance.mapTexture = null;
    }
Ejemplo n.º 9
0
    protected override void OnStart()
    {
        mCol = planeRenderer.GetComponent <BoxCollider>();
        if (mCol == null)
        {
            mCol = NJGTools.AddWidgetCollider(planeRenderer.gameObject);
            if (mCol.size != new Vector3(10, 0, 10))
            {
                mCol.size = new Vector3(10, 0, 10);
            }
        }

        if (NJG.NJGMapBase.instance == null)
        {
            return;
        }

        if (planeRenderer != null)
        {
            if (material == null)
            {
                Debug.LogWarning("The UITexture does not have a material assigned", this);
            }
            else
            {
                if (NJG.NJGMapBase.instance.generateMapTexture)
                {
                    material.mainTexture = mapOnGUI.mapTexture;
                }
                //else
                //	material.mainTexture = NJG.NJGMapBase.instance.userMapTexture;

                //if (maskTexture != null) material.SetTexture("_Mask", maskTexture);
            }

            material.color = mapColor;
        }
        base.OnStart();

        if (iconRoot != null)
        {
            iconRoot.localEulerAngles = Vector3.zero;
            iconRoot.localPosition    = new Vector3(rendererTransform.localPosition.x, rendererTransform.localPosition.y, -1);
        }
    }
Ejemplo n.º 10
0
    protected override void OnStart()
    {
        base.OnStart();
        mCol = planeRenderer.GetComponent <BoxCollider>();
        if (mCol == null)
        {
            mCol = NJGTools.AddWidgetCollider(planeRenderer.gameObject);
            if (mCol.size != new Vector3(10, 0, 10))
            {
                mCol.size = new Vector3(10, 0, 10);
            }
        }

        if (iconRoot != null)
        {
            iconRoot.localEulerAngles = Vector3.zero;
        }
    }
Ejemplo n.º 11
0
    /// <summary>
    /// Clean up.
    /// </summary>

    void OnDestroy()
    {
        //if (mapRenderer != null)
        //	if (mapRenderer.gameObject != null)
        //		NJGTools.Destroy(mapRenderer.gameObject);

        if (UIMiniMapOnGUI.instance != null && Application.isPlaying)
        {
            UIMiniMapOnGUI.instance.planeRenderer.material.mainTexture = null;
        }

        if (mapTexture != null)
        {
            NJGTools.Destroy(mapTexture);
        }
        mapTexture = null;

        //base.OnDestroy();
    }
Ejemplo n.º 12
0
    /// <summary>
    /// Automatically find the camera responsible for drawing the widgets under this object.
    /// </summary>

    void Start()
    {
        mNeedsHalfPixelOffset = (Application.platform == RuntimePlatform.WindowsPlayer ||
                                 Application.platform == RuntimePlatform.XBOX360 ||
                                 Application.platform == RuntimePlatform.WindowsWebPlayer ||
                                 Application.platform == RuntimePlatform.WindowsEditor);

        // Only DirectX 9 needs the half-pixel offset
        if (mNeedsHalfPixelOffset)
        {
            mNeedsHalfPixelOffset = (SystemInfo.graphicsShaderLevel < 40);
        }

        if (uiCamera == null)
        {
            uiCamera = NJGTools.FindCameraForLayer(gameObject.layer);
        }
        Update();
    }
Ejemplo n.º 13
0
    void Awake()
    {
        map = NJG.NJGMapBase.instance;
        if (map == null)
        {
            Debug.LogWarning("Can't render map photo. NJGMiniMap instance not found.");
            NJGTools.Destroy(gameObject);
            return;
        }

        if (gameObject.GetComponent <Camera>() == null)
        {
            gameObject.AddComponent <Camera>();
        }

        camera.useOcclusionCulling = false;

        Render();
    }
Ejemplo n.º 14
0
    /// <summary>
    /// Setup map renderer.
    /// </summary>

    void Awake()
    {
        if (NJGMap.instance.fow.textureSize < 200)
        {
            NJGMap.instance.fow.textureSize = 200;
        }
        //Holoville.HOTween.HOTween.Init(false, true, true);
        //Holoville.HOTween.HOTween.EnableOverwriteManager(false);

        if (Application.isPlaying)
        {
            if (NJGMap.instance.mapTexture != null)
            {
                NJGTools.Destroy(NJGMap.instance.mapTexture);
            }
            if (NJGMap.instance.generateAtStart)
            {
                NJGMap.GenerateMap();
            }
        }
    }
Ejemplo n.º 15
0
        protected override void OnStart()
        {
            base.OnStart();
            //if (Application.isPlaying) NJGTools.SetActive(gameObject, false);
            if (mChild == null)
            {
                mChild = cachedTransform.GetChild(0);
            }
            if (mChild == null)
            {
                mChild = transform;
            }
            if (Application.isPlaying)
            {
                NJGTools.SetActive(mChild.gameObject, false);
            }

            if (calculateBorder)
            {
                mapBorderRadius = (rendererTransform.localScale.x / 2f) / 4f;
            }
        }
Ejemplo n.º 16
0
    /// <summary>
    /// Clean up.
    /// </summary>

    void OnDestroy()
    {
        //if (mapRenderer != null)
        //	if (mapRenderer.gameObject != null)
        //		NJGTools.Destroy(mapRenderer.gameObject);

        if (UIMiniMap.instance != null)
        {
            UIMiniMap.instance.material.mainTexture = null;
        }
        if (UIWorldMap.instance != null)
        {
            UIWorldMap.instance.material.mainTexture = null;
        }

        if (mapTexture != null)
        {
            NJGTools.Destroy(mapTexture);
        }
        mapTexture = null;

        //base.OnDestroy();
    }
Ejemplo n.º 17
0
    void Start()
    {
        if (map.boundLayers.value == 0)
        {
            Debug.LogWarning("Can't render map photo. You have not choosen any layer for bounds calculation. Go to the NJGMiniMap inspector.", map);
            NJGTools.DestroyImmediate(gameObject);
            return;
        }

        if (map.renderLayers.value == 0)
        {
            Debug.LogWarning("Can't render map photo. You have not choosen any layer for rendering. Go to the NJGMiniMap inspector.", map);
            NJGTools.DestroyImmediate(gameObject);
            return;
        }

        ConfigCamera();

        //if (map.optimize) StartCoroutine(DelayedDestroy(gameObject, 2));
        if (!Application.isPlaying)
        {
            Render();
        }
    }
Ejemplo n.º 18
0
    /// <summary>
    /// Helper function that figures out the pixel size adjustment for the specified game object.
    /// </summary>

    static public float GetPixelSizeAdjustment(GameObject go)
    {
        GUIRoot root = NJGTools.FindInParents <GUIRoot>(go);

        return((root != null) ? root.pixelSizeAdjustment : 1f);
    }
Ejemplo n.º 19
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);
    }
Ejemplo n.º 20
0
        /// <summary>
        /// Redraw the map's texture.
        /// </summary>

        public void Render()
        {
            if (map == null)
            {
                map = NJGMap.instance;
            }

            if (Time.time >= lastRender)
            {
#if UNITY_EDITOR
                if (Application.isPlaying)
                {
                    cam.targetTexture = null;
                    lastRender        = Time.time + 1f;
                }
#endif
                mReaded    = false;
                mApplied   = false;
                mGenerated = false;
                mWarning   = false;

                if (!map.optimize)
                {
                    canRender = true;
                }

                if (map.mapSize.x == 0 || map.mapSize.y == 0)
                {
                    map.mapSize = new Vector2(Screen.width, Screen.height);
                }

                if (map.generateMapTexture)
                {
                    if (map.userMapTexture != null)
                    {
                        NJGTools.Destroy(map.userMapTexture);
                        map.userMapTexture = null;
                    }

                    /*if (map.mapTexture != null)
                     * {
                     *  NJGTools.DestroyImmediate(map.mapTexture);
                     *  map.mapTexture = null;
                     * }*/

                    if (map.mapTexture == null)
                    {
                        mSize = map.mapSize;
                        if (map.mapResolution == NJGMap.Resolution.Double)
                        {
                            mSize = map.mapSize * 2;
                        }
                        map.mapTexture            = new Texture2D((int)mSize.x, (int)mSize.y, (TextureFormat)map.textureFormat, map.generateMipmaps);
                        map.mapTexture.name       = "_NJGMapTexture";
                        map.mapTexture.filterMode = map.mapFilterMode;
                        map.mapTexture.wrapMode   = map.mapWrapMode;
                        lastSize = mSize;
                    }
                }
                else if (!Application.isPlaying)
                {
                    if (map.mapTexture != null)
                    {
                        NJGTools.DestroyImmediate(map.mapTexture);
                        map.mapTexture = null;
                    }

                    //if (map.userMapTexture != null)
                    //{
                    map.userMapTexture            = new Texture2D((int)map.mapSize.x, (int)map.mapSize.y, (TextureFormat)map.textureFormat, map.generateMipmaps);
                    map.userMapTexture.name       = "_NJGTempTexture";
                    map.userMapTexture.filterMode = map.mapFilterMode;
                    map.userMapTexture.wrapMode   = map.mapWrapMode;
                    //}
                }


                ConfigCamera();
                cam.enabled = true;
                if (!Application.isPlaying)
                {
                    cam.Render();
                }
            }
        }
Ejemplo n.º 21
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;
                }
            }
        }