1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System;
- using UnityEngine;
- [ExecuteInEditMode]
- public abstract class UI_ScreenFitBase : MonoBehaviour
- {
- protected static Camera m_NGUICamera
- {
- get
- {
- if (!UI_ScreenFitBase.m_UseNGUICam)
- {
- GameObject gameObject = GameObject.Find("UI Root/Camera");
- if (gameObject)
- {
- UI_ScreenFitBase.m_UseNGUICam = gameObject.GetComponent<Camera>();
- }
- else
- {
- UI_ScreenFitBase.m_UseNGUICam = UICamera.mainCamera;
- }
- }
- return UI_ScreenFitBase.m_UseNGUICam;
- }
- set
- {
- UI_ScreenFitBase.m_UseNGUICam = value;
- }
- }
- protected virtual void Start()
- {
- if (!UI_ScreenFitBase.m_NGUICamera)
- {
- GameObject gameObject = GameObject.Find("UI Root/Camera");
- if (gameObject)
- {
- UI_ScreenFitBase.m_NGUICamera = gameObject.GetComponent<Camera>();
- }
- else
- {
- UI_ScreenFitBase.m_NGUICamera = UICamera.mainCamera;
- }
- }
- if (!UI_ScreenFitBase.m_NGUIRoot)
- {
- GameObject gameObject2 = GameObject.Find("UI Root");
- if (gameObject2)
- {
- UI_ScreenFitBase.m_NGUIRoot = gameObject2.GetComponent<UIRoot>();
- }
- }
- if (Application.isPlaying && (GameMain.Instance.VRMode || this.m_CheckFirstOnly))
- {
- if (this.m_CheckFirstOnly)
- {
- this.FitAction();
- }
- base.enabled = this.m_AlwaysActive;
- }
- }
- protected virtual void Update()
- {
- if (Application.isPlaying && GameMain.Instance.VRMode && !this.m_AlwaysActive)
- {
- return;
- }
- this.FitAction();
- }
- protected abstract void FitAction();
- public static Vector3 PointToScreenPos(Vector3 point)
- {
- Vector3 position = UI_ScreenFitBase.m_NGUICamera.ScreenToWorldPoint(point);
- Vector3 result = UI_ScreenFitBase.m_NGUICamera.transform.parent.InverseTransformPoint(position);
- result.z = 0f;
- return result;
- }
- protected float ScreenRate(float Min = 0f, float Max = 1f, float Rate = 1f)
- {
- return Mathf.Clamp((float)Screen.width / (float)Screen.height * Rate, Min, Max);
- }
- private static Camera m_UseNGUICam;
- protected static UIRoot m_NGUIRoot;
- [SerializeField]
- [Header("解像度に合わせた処理を最初だけ行う")]
- protected bool m_CheckFirstOnly;
- [SerializeField]
- [Header("VR時でも常にアクティブか")]
- protected bool m_AlwaysActive;
- }
|