Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using UnityEngine;
- using UnityEngine.UI;
- namespace Assets.Scripts {
- public class ControllerConfig {
- public List<string> LastConfig = new List<string>();
- public static int Offset {
- get {
- int offset = 0;
- foreach (string item in ControllerPriority()) {
- switch (item) {
- case "mk":
- offset++;
- break;
- case "gp":
- return offset;
- }
- }
- return offset;
- }
- }
- internal static int[] ControllerSensitivity() {
- int[] controllerSensitivity = new int[4] { 7, 7, 7, 7 };
- string path = Path.Combine(Application.persistentDataPath, "cs.cfg");
- if (File.Exists(path)) {
- using (StreamReader reader = new StreamReader(path)) {
- for (int i = 0; i < 4; i++) {
- controllerSensitivity[i] = int.Parse(reader.ReadLine());
- }
- }
- }
- return controllerSensitivity;
- }
- internal static void SaveControllerPriority(InputField[] inputFeilds) {
- string path = Path.Combine(Application.persistentDataPath, "cs.cfg");
- using (StreamWriter writer = new StreamWriter(path)) {
- if (!string.IsNullOrEmpty(inputFeilds[0].text)) {
- foreach (InputField item in inputFeilds) {
- int result = 0;
- int.TryParse(item.text, out result);
- if (result != -1) {
- writer.WriteLine(item.text);
- } else {
- writer.WriteLine(7);
- }
- }
- }
- }
- }
- public static bool HasMouseKeyboardConfigured {
- get {
- int offset = 0;
- foreach (string item in ControllerPriority()) {
- switch (item) {
- case "mk":
- return true;
- }
- }
- return false;
- }
- }
- public static bool NoControllers {
- get {
- return GamePadManager.GamePadCount == 0;
- }
- }
- internal static void SaveControllerPriority(Text[] text) {
- string path = Path.Combine(Application.persistentDataPath, "c.cfg");
- using (StreamWriter writer = new StreamWriter(path)) {
- if (!string.IsNullOrEmpty(text[0].text)) {
- foreach (Text item in text) {
- writer.WriteLine(item.text);
- }
- }
- }
- }
- internal static void SaveControllerPriority(Toggle[] text) {
- string path = Path.Combine(Application.persistentDataPath, "c.cfg");
- using (StreamWriter writer = new StreamWriter(path)) {
- foreach (Toggle item in text) {
- writer.WriteLine(item.isOn ? "gp" : "mk");
- }
- }
- }
- public static string[] ControllerPriority() {
- int connectedControllers = 0;
- string[] controllerPriority = new string[4];
- string path = Path.Combine(Application.persistentDataPath, "c.cfg");
- if (File.Exists(path)) {
- using (StreamReader reader = new StreamReader(path)) {
- for (int i = 0; i < 4; i++) {
- controllerPriority[i] = reader.ReadLine();
- }
- }
- }
- if (string.IsNullOrEmpty(controllerPriority[0]) || NoControllers) {
- controllerPriority[0] = "mk";
- controllerPriority[1] = "gp";
- controllerPriority[2] = "gp";
- controllerPriority[3] = "gp";
- }
- return controllerPriority;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment