using UnityEngine; namespace MSCO { /// /// MSCO - My Summer Car Online. Läuft eigenständig (ohne MSCLoader): gestartet über Unity Doorstop, siehe Bootstrap. /// public static class MSCO { /// /// Version der Mod. Kleine Updates: nur die dritte Stelle erhöhen (2.9.1, 2.9.2 ...) - sie bleiben mit /// Servern und Mitspielern derselben ersten zwei Stellen kompatibel. /// public const string ModVersion = "2.10.7"; /// /// Netzwerk-Version (die ersten beiden Stellen). Nur erhöhen, wenn sich das Protokoll inkompatibel ändert - dann /// auch GameServer.ModVersion im Server. /// public const string ProtocolVersion = "2.8"; /// Passt eine andere Version (Server, Host, Mitspieler) zu uns? Verglichen wird die Netzwerk-Version. public static bool Compatible(string other) { return Protocol(other) == ProtocolVersion; } /// "2.8.3" -> "2.8" public static string Protocol(string version) { if (string.IsNullOrEmpty(version)) return ""; string[] parts = version.Trim().Split('.'); return parts.Length >= 2 ? parts[0] + "." + parts[1] : version.Trim(); } /// Beifahrer ein-/aussteigen (Standard P), Konsole (F7), Chat (T) - änderbar mit "bind" in der Konsole. internal static readonly KeyBinding PassengerKey = new KeyBinding("passenger", "Ride along / get out", KeyCode.P); internal static readonly KeyBinding ConsoleKey = new KeyBinding("console", "Open the MSCO console", KeyCode.F7); internal static readonly KeyBinding ChatKey = new KeyBinding("chat", "Open the chat", KeyCode.T); internal static readonly KeyBinding[] Keys = { PassengerKey, ConsoleKey, ChatKey }; } /// Tastenbelegung, gespeichert in den PlayerPrefs (früher in den MSCLoader-Einstellungen). public class KeyBinding { public readonly string Id, Description; public readonly KeyCode Default; bool loaded; KeyCode key; public KeyBinding(string id, string description, KeyCode defaultKey) { Id = id; Description = description; Default = defaultKey; } string Pref { get { return "MSCO_Key_" + Id; } } public KeyCode Key { get { if (!loaded) { // Erst im Spiel lesen (PlayerPrefs gehen nicht in statischen Initialisierern) KeyCode parsed; key = TryParse(PlayerPrefs.GetString(Pref, ""), out parsed) ? parsed : Default; loaded = true; } return key; } set { key = value; loaded = true; PlayerPrefs.SetString(Pref, value.ToString()); PlayerPrefs.Save(); } } public bool GetKeybindDown() { return Key != KeyCode.None && Input.GetKeyDown(Key); } public static bool TryParse(string text, out KeyCode key) { key = KeyCode.None; if (string.IsNullOrEmpty(text)) return false; try { key = (KeyCode)System.Enum.Parse(typeof(KeyCode), text.Trim(), true); return true; } catch { return false; } } } }