mirror of
				https://github.com/DerTyp7/example-top-down-unity.git
				synced 2025-11-04 14:48:58 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			85 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			85 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using UnityEngine;
 | 
						|
using System.Collections;
 | 
						|
 | 
						|
 | 
						|
namespace TMPro.Examples
 | 
						|
{
 | 
						|
    
 | 
						|
    public class TMPro_InstructionOverlay : MonoBehaviour
 | 
						|
    {
 | 
						|
 | 
						|
        public enum FpsCounterAnchorPositions { TopLeft, BottomLeft, TopRight, BottomRight };
 | 
						|
 | 
						|
        public FpsCounterAnchorPositions AnchorPosition = FpsCounterAnchorPositions.BottomLeft;
 | 
						|
 | 
						|
        private const string instructions = "Camera Control - <#ffff00>Shift + RMB\n</color>Zoom - <#ffff00>Mouse wheel.";
 | 
						|
 | 
						|
        private TextMeshPro m_TextMeshPro;
 | 
						|
        private TextContainer m_textContainer;
 | 
						|
        private Transform m_frameCounter_transform;
 | 
						|
        private Camera m_camera;
 | 
						|
 | 
						|
        //private FpsCounterAnchorPositions last_AnchorPosition;
 | 
						|
 | 
						|
        void Awake()
 | 
						|
        {
 | 
						|
            if (!enabled)
 | 
						|
                return;
 | 
						|
 | 
						|
            m_camera = Camera.main;
 | 
						|
 | 
						|
            GameObject frameCounter = new GameObject("Frame Counter");
 | 
						|
            m_frameCounter_transform = frameCounter.transform;
 | 
						|
            m_frameCounter_transform.parent = m_camera.transform;
 | 
						|
            m_frameCounter_transform.localRotation = Quaternion.identity;
 | 
						|
 | 
						|
 | 
						|
            m_TextMeshPro = frameCounter.AddComponent<TextMeshPro>();
 | 
						|
            m_TextMeshPro.font = Resources.Load<TMP_FontAsset>("Fonts & Materials/LiberationSans SDF");
 | 
						|
            m_TextMeshPro.fontSharedMaterial = Resources.Load<Material>("Fonts & Materials/LiberationSans SDF - Overlay");
 | 
						|
 | 
						|
            m_TextMeshPro.fontSize = 30;
 | 
						|
 | 
						|
            m_TextMeshPro.isOverlay = true;
 | 
						|
            m_textContainer = frameCounter.GetComponent<TextContainer>();
 | 
						|
 | 
						|
            Set_FrameCounter_Position(AnchorPosition);
 | 
						|
            //last_AnchorPosition = AnchorPosition;
 | 
						|
 | 
						|
            m_TextMeshPro.text = instructions;
 | 
						|
 | 
						|
        }
 | 
						|
 | 
						|
 | 
						|
 | 
						|
 | 
						|
        void Set_FrameCounter_Position(FpsCounterAnchorPositions anchor_position)
 | 
						|
        {
 | 
						|
 | 
						|
            switch (anchor_position)
 | 
						|
            {
 | 
						|
                case FpsCounterAnchorPositions.TopLeft:
 | 
						|
                    //m_TextMeshPro.anchor = AnchorPositions.TopLeft;
 | 
						|
                    m_textContainer.anchorPosition = TextContainerAnchors.TopLeft;
 | 
						|
                    m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 1, 100.0f));
 | 
						|
                    break;
 | 
						|
                case FpsCounterAnchorPositions.BottomLeft:
 | 
						|
                    //m_TextMeshPro.anchor = AnchorPositions.BottomLeft;
 | 
						|
                    m_textContainer.anchorPosition = TextContainerAnchors.BottomLeft;
 | 
						|
                    m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(0, 0, 100.0f));
 | 
						|
                    break;
 | 
						|
                case FpsCounterAnchorPositions.TopRight:
 | 
						|
                    //m_TextMeshPro.anchor = AnchorPositions.TopRight;
 | 
						|
                    m_textContainer.anchorPosition = TextContainerAnchors.TopRight;
 | 
						|
                    m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 1, 100.0f));
 | 
						|
                    break;
 | 
						|
                case FpsCounterAnchorPositions.BottomRight:
 | 
						|
                    //m_TextMeshPro.anchor = AnchorPositions.BottomRight;
 | 
						|
                    m_textContainer.anchorPosition = TextContainerAnchors.BottomRight;
 | 
						|
                    m_frameCounter_transform.position = m_camera.ViewportToWorldPoint(new Vector3(1, 0, 100.0f));
 | 
						|
                    break;
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |