资源简介

让Unity的主摄像机,根据实际的设计尺寸,缩放到最佳视角。

资源截图

代码片段和文件信息

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
    {
        // 设计区域像素尺寸(由各场景摄像机上的组件参数指定)
        public float contentWidth;
        public float contentHeight;

        //屏幕主摄像机
        private Camera _mainCamera;

        // 屏幕当前分辨率
        private int _resolutionX;
        private int _resolutionY;
        private FullScreenMode? _fullScreenMode = null;

        //屏幕当前宽高比
        private float _aspectRatio;

        // 屏幕当前正交尺寸(正交模式)
        private float _orthographicSize;

        // 屏幕当前透视角度(透视模式)
        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是参数名
                    if (found)
                    {
                        // 如果之前已经找到参数,则跳出循环
                        Output($“参数查找结束“);
                        break;
                    }

                    if (item.IndexOf(“-screen-fullscreen“ StringComparison.Ordinal) == 0)
                    {
                        // 如果找到参数,则开启标志
                        found = true;
                        Output($“找到全屏参数:{item}“);
                    }
                }
                else
                {
                    // item是参数内容
                    if (found)
                    {
                        // 如果是找到参数状态,则保存该数值
                        values.Add(item);
                        Output($“添加参数值:{item}“);
                    }
                }
            }

            if (values.Count > 1)
            {
                Output($“窗口模式参数:({values[1].GetType()}){values[1]}“);
                // 当全屏参数大于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  Camerascript.cs

评论

共有 条评论