Esempio n. 1
0
        /**
         * <summary>Draws an icon at the Hotspot's centre.</summary>
         * <param name = "inWorldSpace">If True, the icon shall be drawn as a sprite in world space, as opposed to an OnGUI graphic in screen space.</param>
         */
        public void DrawHotspotIcon(bool inWorldSpace = false)
        {
            if (iconAlpha > 0f)
            {
                if (!KickStarter.mainCamera.IsPointInCamera(GetIconScreenPosition()))
                {
                    return;
                }

                if (inWorldSpace)
                {
                    if (iconRenderer == null)
                    {
                        GameObject iconOb = new GameObject(this.name + " - icon");
                        iconRenderer = iconOb.AddComponent <SpriteRenderer>();
                        iconOb.transform.localScale = Vector3.one * (25f * KickStarter.settingsManager.hotspotIconSize);

                        if (GameObject.Find("_Hotspots") && GameObject.Find("_Hotspots").transform.eulerAngles == Vector3.zero)
                        {
                            iconOb.transform.parent = GameObject.Find("_Hotspots").transform;
                        }

                        if (iconSortingLayer != "")
                        {
                            iconRenderer.GetComponent <SpriteRenderer>().sortingLayerName = iconSortingLayer;
                        }
                        iconRenderer.GetComponent <SpriteRenderer>().sortingOrder = iconSortingOrder;
                    }

                    if (KickStarter.settingsManager.hotspotIcon == HotspotIcon.UseIcon)
                    {
                        GetMainIcon();
                        if (mainIcon != null)
                        {
                            iconRenderer.sprite = mainIcon.GetSprite();
                        }
                    }
                    else
                    {
                        if (iconSprite == null && KickStarter.settingsManager.hotspotIconTexture != null)
                        {
                            iconSprite = UnityEngine.Sprite.Create(KickStarter.settingsManager.hotspotIconTexture, new Rect(0f, 0f, KickStarter.settingsManager.hotspotIconTexture.width, KickStarter.settingsManager.hotspotIconTexture.height), new Vector2(0.5f, 0.5f));
                        }
                        if (iconSprite != iconRenderer.sprite)
                        {
                            iconRenderer.sprite = iconSprite;
                        }
                    }
                    iconRenderer.transform.position = GetIconPosition();
                    iconRenderer.transform.LookAt(iconRenderer.transform.position + KickStarter.mainCamera.transform.rotation * Vector3.forward, KickStarter.mainCamera.transform.rotation * Vector3.up);
                }
                else
                {
                    if (iconRenderer != null)
                    {
                        GameObject.Destroy(iconRenderer.gameObject);
                        iconRenderer = null;
                    }

                    Color c         = GUI.color;
                    Color tempColor = c;
                    c.a       = iconAlpha;
                    GUI.color = c;

                    if (KickStarter.settingsManager.hotspotIcon == HotspotIcon.UseIcon)
                    {
                        GetMainIcon();
                        if (mainIcon != null)
                        {
                            mainIcon.Draw(GetIconScreenPosition(), !KickStarter.playerMenus.IsMouseOverInteractionMenu());
                        }
                    }
                    else if (KickStarter.settingsManager.hotspotIconTexture != null)
                    {
                        GUI.DrawTexture(AdvGame.GUIBox(GetIconScreenPosition(), KickStarter.settingsManager.hotspotIconSize), KickStarter.settingsManager.hotspotIconTexture, ScaleMode.ScaleToFit, true, 0f);
                    }

                    GUI.color = tempColor;
                }
            }

            if (inWorldSpace && iconRenderer != null)
            {
                Color tempColor = iconRenderer.color;
                tempColor.a        = iconAlpha;
                iconRenderer.color = tempColor;
            }
        }