資源簡介
讓Unity的主攝像機(jī),根據(jù)實際的設(shè)計尺寸,縮放到最佳視角。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Linq;
using?script.simplefade;
using?UnityEngine;
using?UnityEngine.SceneManagement;
using?UnityEngine.UI;
namespace?script
{
????public?class?Camerascript?:?MonoBehaviour
????{
????????//?設(shè)計區(qū)域像素尺寸(由各場景攝像機(jī)上的組件參數(shù)指定)
????????public?float?contentWidth;
????????public?float?contentHeight;
????????//屏幕主攝像機(jī)
????????private?Camera?_mainCamera;
????????//?屏幕當(dāng)前分辨率
????????private?int?_resolutionX;
????????private?int?_resolutionY;
????????private?FullScreenMode??_fullScreenMode?=?null;
????????//屏幕當(dāng)前寬高比
????????private?float?_aspectRatio;
????????//?屏幕當(dāng)前正交尺寸(正交模式)
????????private?float?_orthographicSize;
????????//?屏幕當(dāng)前透視角度(透視模式)
????????private?float?_fieldOfView;
????????//?Start?is?called?before?the?first?frame?update
????????private?void?Start()
????????{
????????????_mainCamera?=?GetComponent();
????????????//?InitFullscreenMode();
????????????ResizeCamera();
????????}
????????/**
?????????*?初始化全屏模式
?????????*/
????????private?void?InitFullscreenMode()
????????{
????????????string[]?commandLineArgs?=?Environment.GetCommandLineArgs();
????????????bool?found?=?false;
????????????List?values?=?new?List();
????????????foreach?(var?item?in?commandLineArgs)
????????????{
????????????????if?(item.IndexOf(“-“?StringComparison.Ordinal)?==?0)
????????????????{
????????????????????//?item是參數(shù)名
????????????????????if?(found)
????????????????????{
????????????????????????//?如果之前已經(jīng)找到參數(shù),則跳出循環(huán)
????????????????????????Output($“參數(shù)查找結(jié)束“);
????????????????????????break;
????????????????????}
????????????????????if?(item.IndexOf(“-screen-fullscreen“?StringComparison.Ordinal)?==?0)
????????????????????{
????????????????????????//?如果找到參數(shù),則開啟標(biāo)志
????????????????????????found?=?true;
????????????????????????Output($“找到全屏參數(shù):{item}“);
????????????????????}
????????????????}
????????????????else
????????????????{
????????????????????//?item是參數(shù)內(nèi)容
????????????????????if?(found)
????????????????????{
????????????????????????//?如果是找到參數(shù)狀態(tài),則保存該數(shù)值
????????????????????????values.Add(item);
????????????????????????Output($“添加參數(shù)值:{item}“);
????????????????????}
????????????????}
????????????}
????????????if?(values.Count?>?1)
????????????{
????????????????Output($“窗口模式參數(shù):({values[1].GetType()}){values[1]}“);
????????????????//?當(dāng)全屏參數(shù)大于1個時,取第二個作為全屏模式
????????????????switch?(values[1])
????????????????{
????????????????????case?“1“:
????????????????????????_fullScreenMode?=?FullScreenMode.FullScreenWindow;
????????????????????????break;
????????????????????case?“2“:
????????????????????????_fullScreenMode?=?FullScreenMode.MaximizedWindow;
????????????????????????break;
????????????????????case?“3“:
????????????????????????_fullScreenMode?=?FullScreenMode.ExclusiveFullScreen;
????????????????????????break;
????????????????????default:
????????????????????????_fullScreenMode?=?FullScreenMode.Windowed;
??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????8451??2020-03-09?16:20??Camerasc
- 上一篇:C# 萬能滑塊效果
- 下一篇:別踩白塊wpf 源碼
評論
共有 條評論