private static void EnsureSettingsExist() { PapertrailSettings settings = LoadSettings(); if (settings == null) { var folders = System.IO.Directory.GetDirectories(Application.dataPath, "Papertrail"); string createPath = string.Empty; if (folders.Length == 0) { createPath = "Assets/Resources/" + s_settingsPath + ".asset"; } else { createPath = GetRelativeProjectPath(folders[0]); createPath += "Resources/" + s_settingsPath + ".asset"; } string[] split = createPath.Split('/'); string currentDepth = string.Empty; for (int j = 0; j < split.Length - 1; j++) { string parentFolder = currentDepth; if (j > 0) { currentDepth += '/'; } currentDepth += split[j]; if (!UnityEditor.AssetDatabase.IsValidFolder(currentDepth)) { UnityEditor.AssetDatabase.CreateFolder(parentFolder, split[j]); } } settings = CreateInstance <PapertrailSettings>(); UnityEditor.AssetDatabase.CreateAsset(settings, createPath); } if (string.IsNullOrEmpty(settings.systemName)) { settings.systemName = Application.identifier; UnityEditor.EditorUtility.SetDirty(settings); } }
/// <summary> /// Called when the Instance is created. Gathers application information and creates the UDP client /// </summary> private void Awake() { // Ensure this is the only instance if (s_instance != null && s_instance != this) { Destroy(this); return; } // Load settings m_isReady = false; m_settings = PapertrailSettings.LoadSettings(); // Store app information m_processName = Application.identifier.Replace(" ", string.Empty); m_platform = Application.platform.ToString().ToLowerInvariant(); m_localIp = Network.player.ipAddress; if (!string.IsNullOrEmpty(m_settings.hostname) && m_settings.port > 0) { try { // Create the udp client m_udpClient = new UdpClient(m_settings.hostname, m_settings.port); // Hook into Unity's logging system Application.logMessageReceivedThreaded += Application_LogMessageReceived; // Begin looking for a connection StartCoroutine(GetExternalIP()); } catch (Exception ex) { m_udpClient = null; Debug.LogException(ex); } } else { m_udpClient = null; } }