SebastianLawe

Untitled

Oct 1st, 2015
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8.  
  9.  
  10. namespace Assets.Scripts {
  11.     public class ControllerConfig {
  12.         public List<string> LastConfig = new List<string>();
  13.         public static int Offset {
  14.             get {
  15.                 int offset = 0;
  16.                 foreach (string item in ControllerPriority()) {
  17.                     switch (item) {
  18.                         case "mk":
  19.                             offset++;
  20.                             break;
  21.                         case "gp":
  22.                             return offset;
  23.  
  24.                     }
  25.                 }
  26.                 return offset;
  27.             }
  28.         }
  29.  
  30.         internal static int[] ControllerSensitivity() {
  31.             int[] controllerSensitivity = new int[4] { 7, 7, 7, 7 };
  32.             string path = Path.Combine(Application.persistentDataPath, "cs.cfg");
  33.             if (File.Exists(path)) {
  34.                 using (StreamReader reader = new StreamReader(path)) {
  35.                     for (int i = 0; i < 4; i++) {
  36.                         controllerSensitivity[i] = int.Parse(reader.ReadLine());
  37.                     }
  38.                 }
  39.             }
  40.             return controllerSensitivity;
  41.         }
  42.         internal static void SaveControllerPriority(InputField[] inputFeilds) {
  43.             string path = Path.Combine(Application.persistentDataPath, "cs.cfg");
  44.             using (StreamWriter writer = new StreamWriter(path)) {
  45.                 if (!string.IsNullOrEmpty(inputFeilds[0].text)) {
  46.                     foreach (InputField item in inputFeilds) {
  47.                         int result = 0;
  48.                         int.TryParse(item.text, out result);
  49.                         if (result != -1) {
  50.                             writer.WriteLine(item.text);
  51.                         } else {
  52.                             writer.WriteLine(7);
  53.                         }
  54.                     }
  55.                 }
  56.             }
  57.         }
  58.         public static bool HasMouseKeyboardConfigured {
  59.             get {
  60.                 int offset = 0;
  61.                 foreach (string item in ControllerPriority()) {
  62.                     switch (item) {
  63.                         case "mk":
  64.                             return true;
  65.  
  66.                     }
  67.                 }
  68.                 return false;
  69.             }
  70.         }
  71.  
  72.         public static bool NoControllers {
  73.             get {
  74.                 return GamePadManager.GamePadCount == 0;
  75.             }
  76.         }
  77.  
  78.         internal static void SaveControllerPriority(Text[] text) {
  79.             string path = Path.Combine(Application.persistentDataPath, "c.cfg");
  80.             using (StreamWriter writer = new StreamWriter(path)) {
  81.                 if (!string.IsNullOrEmpty(text[0].text)) {
  82.                     foreach (Text item in text) {
  83.                         writer.WriteLine(item.text);
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.         internal static void SaveControllerPriority(Toggle[] text) {
  89.             string path = Path.Combine(Application.persistentDataPath, "c.cfg");
  90.             using (StreamWriter writer = new StreamWriter(path)) {
  91.                 foreach (Toggle item in text) {
  92.                     writer.WriteLine(item.isOn ? "gp" : "mk");
  93.                 }
  94.             }
  95.         }
  96.  
  97.         public static string[] ControllerPriority() {
  98.             int connectedControllers = 0;
  99.             string[] controllerPriority = new string[4];
  100.             string path = Path.Combine(Application.persistentDataPath, "c.cfg");
  101.             if (File.Exists(path)) {
  102.                 using (StreamReader reader = new StreamReader(path)) {
  103.                     for (int i = 0; i < 4; i++) {
  104.                         controllerPriority[i] = reader.ReadLine();
  105.                     }
  106.                 }
  107.             }
  108.             if (string.IsNullOrEmpty(controllerPriority[0]) || NoControllers) {
  109.                 controllerPriority[0] = "mk";
  110.                 controllerPriority[1] = "gp";
  111.                 controllerPriority[2] = "gp";
  112.                 controllerPriority[3] = "gp";
  113.             }
  114.             return controllerPriority;
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment