AR Foundation演示项目,使用 AR Foundation 4.1.7 并围绕某些功能演示更高级功能。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

55 行
1.5 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CenterScreenHelper : MonoBehaviour
{
public static CenterScreenHelper Instance;
float m_MidPointWidth;
float m_MidPointHeight;
Vector2 m_CenterScreenVert;
Vector2 m_CenterScreenHor;
ScreenOrientation m_CurrentOrientation;
float m_CurrentWidth;
void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(this);
}
m_CurrentOrientation = Screen.orientation;
m_CurrentWidth = Screen.width;
m_MidPointWidth = Screen.width / 2;
m_MidPointHeight = Screen.height / 2;
if (m_CurrentOrientation == ScreenOrientation.Landscape)
{
m_CenterScreenVert = new Vector2(m_MidPointHeight, m_MidPointWidth);
m_CenterScreenHor = new Vector2(m_MidPointWidth, m_MidPointHeight);
}
else
{
m_CenterScreenVert = new Vector2(m_MidPointWidth, m_MidPointHeight);
m_CenterScreenHor = new Vector2(m_MidPointHeight, m_MidPointWidth);
}
}
public Vector2 GetCenterScreen()
{
if (Screen.width != m_CurrentWidth)
{
m_CurrentWidth = Screen.width;
m_CurrentOrientation = Screen.orientation;
}
return m_CurrentOrientation == ScreenOrientation.Landscape ? m_CenterScreenHor : m_CenterScreenVert;
}
}