using UnityEngine;
using System;
using System.Collections;
using System.IO;
/// <summary>
/// Чтение файла настроек и смена разрешения.
/// </summary>
public class ResolutionChanger : MonoBehaviour
{
//Имя файла с настройками.
public string fileName = "";
//Ширина экрана
private int screenWidth;
//Высота экрана
private int screenHeight;
//Полный экран?
private bool screenFull=false;
/// <summary>
/// Выполняется один раз при инициализации объекта.
/// </summary>
void Start()
{
//Создаем поток чтения из файла в отдельной области видимости.
using (StreamReader fileStream = File.OpenText(Path.GetFullPath(fileName)))
{
//Читаем данные
string fileLine = "";
while ((fileLine = fileStream.ReadLine()) != null)
{
string option = fileLine.Substring(0, fileLine.IndexOf("="));
switch (option)
{
case "screen_width":
screenWidth = Convert.ToInt32(fileLine.Substring(fileLine.IndexOf("=") + 1));
break;
case "screen_height":
screenHeight = Convert.ToInt32(fileLine.Substring(fileLine.IndexOf("=") + 1));
break;
case "screen_full":
string fullscreen = fileLine.Substring(fileLine.IndexOf("=") + 1);
if (fullscreen == "true")
screenFull = true;
break;
}
}
//Освобождаем поток.
fileStream.Close();
}
//Устанавливаем разрешение
Screen.SetResolution(screenWidth, screenHeight, screenFull);
}
}
Сейчас этот форум просматривают: Google [Bot], infocratia, Yandex [Bot] и гости: 18