平台设置相关

using UnityEngine;
using System.Collections;

/// <summary>
/// 游戏全局设置管理类
/// </summary>
public class GlobalMngr
{
    /// <summary> 最大尝试量</summary>
    private int max_try_count = 20;
    /// <summary>暂停时间 </summary>
    public float pausedTime;
    /// <summary>时间间隔 </summary>
    private float time_interval;

    public int availableMemSize { get; private set; }

    public string deviceModel { get; private set; }

    public string deviceName { get; private set; }

    public string deviceType { get; private set; }

   public SettingLevelEnum gfxMode { get; private set; }

    public string graphicsDeviceName { get; private set; }

    public bool isMemCritMode { get; set; }

    public string locationInfo { get; private set; }

   public SettingLevelEnum memMode { get; private set; }

    public int memSize { get; private set; }

    public float originalDpi { get; private set; }

    public int originalHeight { get; private set; }

    public int originalWidth { get; private set; }

    public int processorCount { get; private set; }

    public float refDpi { get; private set; }

    public int state { get; set; }


    private static GlobalMngr _this = new GlobalMngr();

    public static GlobalMngr GetInstance()
    {
        return _this;
    }

    public float GetPlayedTime()
    {
        return (Time.realtimeSinceStartup - this.pausedTime);
    }

    public void Pause()
    {
        this.pausedTime = Time.realtimeSinceStartup - this.pausedTime;
    }

    public void PrintGlobalSetting()
    {
        Debug.Log("---global setting---");
        Debug.Log("device model: " + this.deviceModel);
        Debug.Log("graphics device name: " + this.graphicsDeviceName);
        Debug.Log(string.Concat(new object[] { "resolution: " , Screen.width , "x" , Screen.height }));
        Debug.Log("ref dpi: " + this.refDpi);
        Debug.Log("processor count: " + this.processorCount);
        Debug.Log("mem size: " + this.memSize);
        Debug.Log("available mem size: " + this.availableMemSize);
        Debug.Log("gfx mode: " + this.gfxMode);
        Debug.Log("mem mode: " + this.memMode);
        Debug.Log("--------------------");
    }

    public void Resume()
    {
        this.pausedTime = Time.realtimeSinceStartup - this.pausedTime;
    }

    public void SetResolution()
    {
        int num = 400;
        int num2 = (int)((((float)Screen.width) / ((float)Screen.height)) * num);
        if (this.deviceModel == "xiaomihm1sc")
        {
            int height = 600;
            int width = (int)((((float)Screen.width) / ((float)Screen.height)) * height);
            Screen.SetResolution(width , height , true);
        }
        else if (Screen.dpi > this.refDpi)
        {
            float num5 = this.refDpi / Screen.dpi;
            int num6 = (int)((Screen.height * num5) + 0.5f);
            int num7 = (int)((Screen.width * num5) + 0.5f);
            if (num6 < num)
            {
                num7 = num2;
                num6 = num;
            }
            Screen.SetResolution(num7 , num6 , true);
        }
    }


    public GlobalMngr()
    {
        //屏幕 睡眠 设置
        Screen.sleepTimeout = -1;
        //对AssetBundle 的缓存管理,最大字节缓存 
        Caching.maximumAvailableDiskSpace = 0x32000000L;
        //是否能多点触控
        Input.multiTouchEnabled = false;

        //平台 用60帧还是 30帧 值得研究
        //if (PlatformMngr.GetInstance().IsOpenPlatform())
        //{
        //    Application.targetFrameRate = 30;
        //}
        //else
        //{
        //    Application.targetFrameRate = 60;
        //}

        this.state = 0;
        this.isMemCritMode = false;
        this.deviceModel = SystemInfo.deviceModel.Replace(" " , string.Empty).ToLower();
        this.deviceName = SystemInfo.deviceName.Replace(" " , string.Empty).ToLower();
        this.deviceType = SystemInfo.deviceType.ToString().ToLower();
        this.graphicsDeviceName = SystemInfo.graphicsDeviceName.Replace(" " , string.Empty).ToLower();
        this.memSize = (SystemInfo.systemMemorySize <= 0) ? (0x1000 + SystemInfo.systemMemorySize) : SystemInfo.systemMemorySize;
        this.availableMemSize = -1;
        //进程数
        this.processorCount = SystemInfo.processorCount;
        this.originalWidth = Screen.width;
        this.originalHeight = Screen.height;
        this.originalDpi = Screen.dpi;
        //=========== 设置游戏品质 ==========//
        //小米平板 或 英伟达游戏掌机
        if ((this.deviceModel == "xiaomimipad") || (this.deviceModel == "nvidiashield"))
        {
            this.gfxMode = SettingLevelEnum.ULTRA;
        }
        else if(processorCount==1)
        {//游戏渲染品质么???
            gfxMode = SettingLevelEnum.LOW;
        }
        else if(processorCount<4 || memSize<=0x400)
        {
            gfxMode = SettingLevelEnum.MEDIUM;
        }
        {
            this.gfxMode = SettingLevelEnum.HIGH;
        }

        if (this.memSize <= 0x200)
        {
            this.memMode = SettingLevelEnum.LOW;
        }
        else if (this.memSize <= 0x400)
        {
            this.memMode = SettingLevelEnum.MEDIUM;
        }
        else
        {
            this.memMode = SettingLevelEnum.ULTRA;
        }

        //========= GPU ==============//
        if (this.graphicsDeviceName == "mali-450mp")
        {
            this.refDpi = 350f;
        }
        else if (this.graphicsDeviceName == "mali-t628mp")
        {
            this.refDpi = 350f;
        }
        else if (this.graphicsDeviceName == "mali-t720mp")
        {
            this.refDpi = 350f;
        }
        else if (this.graphicsDeviceName == "mali-t760mp")
        {
            this.refDpi = 400f;
        }
        else if (this.graphicsDeviceName == "adreno(tm)320")
        {
            this.refDpi = 350f;
        }
        else if (this.graphicsDeviceName == "adreno(tm)330")
        {
            this.refDpi = 400f;
        }
        else if (this.graphicsDeviceName == "adreno(tm)420")
        {
            this.refDpi = 400f;
        }
        else if (this.graphicsDeviceName == "adreno(tm)430")
        {
            this.refDpi = 400f;
        }
        else if (this.graphicsDeviceName == "powervrg6200")
        {
            this.refDpi = 350f;
        }
        else if (this.graphicsDeviceName == "powervrg6400")
        {
            this.refDpi = 400f;
        }
        else if (this.processorCount >= 4)
        {
            this.refDpi = 250f;
        }
        else
        {
            this.refDpi = 200f;
        }
        if (this.graphicsDeviceName == "bluestacks")
        {
            this.gfxMode = SettingLevelEnum.LOW;
            this.memMode = SettingLevelEnum.LOW;
            this.refDpi = 500f;
        }

        //========= no infor===========//

        //if (RunParam.GetInstance().gfxMode != SettingLevelEnum.AUTO)
        //{
        //    this.gfxMode = RunParam.GetInstance().gfxMode;
        //}
        //if (RunParam.GetInstance().memMode != SettingLevelEnum.AUTO)
        //{
        //    this.memMode = RunParam.GetInstance().memMode;
        //}

    }

    //public void CheckAvailableMemory()
    //{
    //    if (this.availableMemSize == -1)
    //    {
    //        this.availableMemSize = ((int)(RuntimeEnv.GetInstance().GetSystemAvailMemory() >> 20)) + 120;
    //        if (this.memMode == SettingLevelEnum.LOW)
    //        {
    //            if (this.availableMemSize < 300)
    //            {
    //                this.isMemCritMode = true;
    //            }
    //            else
    //            {
    //                this.isMemCritMode = false;
    //            }
    //        }
    //        else if (this.memMode == SettingLevelEnum.MEDIUM)
    //        {
    //            if (this.availableMemSize < 400)
    //            {
    //                this.isMemCritMode = true;
    //            }
    //            else
    //            {
    //                this.isMemCritMode = false;
    //            }
    //        }
    //        else if (this.memMode == SettingLevelEnum.HIGH)
    //        {
    //            if (this.availableMemSize < 500)
    //            {
    //                this.isMemCritMode = true;
    //            }
    //            else
    //            {
    //                this.isMemCritMode = false;
    //            }
    //        }
    //        else if (this.availableMemSize < 600)
    //        {
    //            this.isMemCritMode = true;
    //        }
    //        else
    //        {
    //            this.isMemCritMode = false;
    //        }
    //        PlayerPrefs.SetInt("prevAvailableMemSize" , this.availableMemSize);
    //        PlayerPrefs.SetInt("prevIsMemCritMode" , !this.isMemCritMode ? 0 : 1);
    //        PlayerPrefs.Save();
    //    }
    //}

    //public void ClearSystemMemory()
    //{
    //    RuntimeEnv.GetInstance().ClearMemory(0x40000000L);
    //}

}

 

posted @ 2015-11-28 01:58  bambom  阅读(226)  评论(0编辑  收藏  举报