using UnityEditor; using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text.RegularExpressions; using System.Linq; using System.IO; using Perforce.P4; using log4net; namespace P4Connect { [Serializable] public class ConfigAsset : ScriptableObject { // These are the config values // We serialize this Class and place it in the P4Connect/Editor Asset Hierarchy public string ServerURI; public string Username; [HideInInspector] public string Password; public string Workspace; public string Hostname; public string Charset; public bool UnityVSSupport; public bool PerforceEnabled; public bool IncludeProjectFiles; public bool IncludeSolutionFiles; public bool ShowPaths; public bool AskBeforeCheckout; public bool DisplayStatusIcons; public string DiffToolPathname; public bool DisplayP4Timings; public bool DisplayP4Commands; public bool CheckStatusForMenus; public int CheckStatusForMenusMaxItems; public int ConnectionTimeOut; public bool WarnOnSpecialCharacters; public string IgnoreName; public bool EnableLog; public Logger.LogLevel ConsoleLogLevel; public string LogPath; public string IgnoreLines; // Copy the contents of this ConfigAsset into the P4Connect Config class. public void CopyAssetToConfig() { Config.ServerURI = ServerURI; Config.Username = Username; Config.Password = Password; Config.Workspace = Workspace; Config.Hostname = Hostname; Config.Charset = Charset; Config.UnityVSSupport = UnityVSSupport; Config.PerforceEnabled = PerforceEnabled; Config.IncludeProjectFiles = IncludeProjectFiles; Config.IncludeSolutionFiles = IncludeSolutionFiles; Config.ShowPaths = ShowPaths; Config.AskBeforeCheckout = AskBeforeCheckout; Config.DisplayStatusIcons = DisplayStatusIcons; Config.DiffToolPathname = DiffToolPathname; Config.DisplayP4Timings = DisplayP4Timings; Config.DisplayP4Commands = DisplayP4Commands; Config.CheckStatusForMenus = CheckStatusForMenus; Config.CheckStatusForMenusMaxItems = CheckStatusForMenusMaxItems; Config.ConnectionTimeOut = ConnectionTimeOut; Config.WarnOnSpecialCharacters = WarnOnSpecialCharacters; Config.IgnoreName = IgnoreName; Config.EnableLog = EnableLog; Config.ConsoleLogLevel = ConsoleLogLevel; Config.LogPath = LogPath; Config.IgnoreLines = IgnoreLines; } // Seed a ConfigAsset with data from the Config Class public void CopyConfigToAsset() { ServerURI = Config.ServerURI; Username = Config.Username; Password = Config.Password; Workspace = Config.Workspace; Hostname = Config.Hostname; Charset = Config.Charset; UnityVSSupport = Config.UnityVSSupport; PerforceEnabled = Config.PerforceEnabled; IncludeProjectFiles = Config.IncludeProjectFiles; IncludeSolutionFiles = Config.IncludeSolutionFiles; ShowPaths = Config.ShowPaths; AskBeforeCheckout = Config.AskBeforeCheckout; DisplayStatusIcons = Config.DisplayStatusIcons; DiffToolPathname = Config.DiffToolPathname; DisplayP4Timings = Config.DisplayP4Timings; DisplayP4Commands = Config.DisplayP4Commands; CheckStatusForMenus = Config.CheckStatusForMenus; CheckStatusForMenusMaxItems = Config.CheckStatusForMenusMaxItems; ConnectionTimeOut = Config.ConnectionTimeOut; WarnOnSpecialCharacters = Config.WarnOnSpecialCharacters; IgnoreName = Config.IgnoreName; EnableLog = Config.EnableLog; ConsoleLogLevel = Config.ConsoleLogLevel; LogPath = Config.LogPath; IgnoreLines = Config.IgnoreLines; } } // This Editor window allows the user to set and store // Perforce connection settings that will be used to // Check out files on Save / Move / Delete / etc... // The connection parameters are saved as Editor Preferences // which means they go the registry. public class Config : EditorWindow { private static readonly ILog log = LogManager.GetLogger(typeof(Config)); static string P4CONFIG_DEFAULT = ".p4config"; // Event triggered when the configuration changes public delegate void OnPrefsChanged(); public static event OnPrefsChanged PrefsChanged; #region Properties // Give access to the Server URI public static string ServerURI { get; set; } // Give access to the User Name public static string Username { get; set; } // Give access to the Password public static string Password { get; set; } // Give access to the Workspace Name public static string Workspace { get; set; } // Give access to whether we integrate with UnityVS public static bool UnityVSSupport { get; set; } // Give access to whether the integration is turned on or not public static bool PerforceEnabled { get; set; } // Give access to whether we check out solution files public static bool IncludeSolutionFiles { get; set; } // Give access to whether we check out project files public static bool IncludeProjectFiles { get; set; } // Give access to whether we print out paths or just filenames public static bool ShowPaths { get; set; } // Give access to whether we automatically check out on edit public static bool AskBeforeCheckout { get; set; } // Give access to whether we want to display Icons in the Project view public static bool DisplayStatusIcons { get; set; } // The host name, if different than the local machine public static string Hostname { get; set; } // The host name, if different than the local machine public static string Charset { get; set; } // The location of the Diff tool public static string DiffToolPathname { get; set; } // Whether or not to display timing info for debugging public static bool DisplayP4Timings { get; set; } // Whether to display the commands sent to P4 public static bool DisplayP4Commands { get; set; } // Whether or not to check the status of files before showing the contextual menu public static bool CheckStatusForMenus { get; set; } // Whether or not to warn when adding files with special characters public static bool WarnOnSpecialCharacters { get; set; } // Whether or not to check the status of files before showing the contextual menu public static int CheckStatusForMenusMaxItems { get; set; } // How many files to submit at once public static int OperationBatchCount { get; set; } // How long to keep connections open public static int ConnectionTimeOut { get; set; } // Provide an Ignore file name public static string IgnoreName { get; set; } // Additional Ignore Lines public static string IgnoreLines { get; set; } // Enable log4net Logging public static bool EnableLog { get; set; } // What log level to display in the console? public static Logger.LogLevel ConsoleLogLevel { get; set; } // Where to save log output public static string LogPath { get; set; } // The following properties are NOT saved between sessions private static string _clientProjectRoot; public static string ClientProjectRoot // Client path associated with project root (has /...) { get { return(_clientProjectRoot); } set { _clientProjectRoot = value; ClientProjectRootMatch = ClientProjectRoot.Substring(0, Math.Max(0, ClientProjectRoot.Length - 4)); ProjectFileSpec = FileSpec.ClientSpecList( new string[1]{ _clientProjectRoot } ); } } public static string ClientProjectRootMatch { get; set; } // Client path without the /... stuff. public static IList ProjectFileSpec { get; set; } // File Spec which describes the scope of the project (with /...) public static string DepotProjectRoot { get; set; } // Depot path associated with project root (has /...) #endregion static bool FoundConfigAsset; // Helper property to indicate that P4 can be used public static bool ValidConfiguration { get { return PerforceEnabled && _CurrentState == ConfigurationState.SettingsValid; } } public const string P4BridgeDLLName = "p4bridge.dll"; public const string P4BridgeDYLIBName = "libp4bridge.dylib"; public const int MaxPendingItems = 200; #region Registry Names // These are the names under which the connection settings are stored in the registry public const string ServerURIPrefName = "ServerURI"; public const string UserNamePrefName = "UserName"; public const string PasswordPrefName = "Password"; public const string WorkspacePrefName = "Workspace"; public const string PerforceEnabledPrefName = "Enabled"; public const string UnityVSSupportPrefName = "UnityVSSupport"; public const string IncludeProjectFilesPrefName = "IncludeProjectFiles"; public const string IncludeSolutionFilesPrefName = "IncludeSolutionFiles"; public const string ShowPathsPrefName = "ShowPaths"; public const string AskBeforeCheckoutPrefName = "AskBeforeCheckout"; public const string DisplayStatusIconsPrefName = "DisplayStatusIcons"; public const string HostnamePrefName = "Hostname"; public const string DiffToolPathnamePrefName = "DiffToolPathname"; public const string DisplayP4TimingsPrefName = "DisplayTimings"; public const string DisplayP4CommandsPrefName = "DisplayCommands"; public const string CheckStatusForMenusPrefName = "CheckStatusForMenus"; public const string CheckStatusForMenusMaxItemsPrefName = "CheckStatusForMenusMaxItems"; public const string OperationBatchCountPrefName = "OperationBatchCount"; public const string ConnectionTimeOutPrefName = "ConnectionTimeOut"; public const string WarnOnSpecialCharactersPrefName = "WarnOnSpecialCharacters"; public const string UseIgnorePrefName = "UseIgnore"; public const string IgnoreNamePrefName = "IgnoreName"; public const string EnableLogPrefName = "EnableLog"; public const string ConsoleLogLevelPrefName = "ConsoleLogLevel"; public const string LogPathPrefName = "LogPath"; public const string IgnoreLinesPrefName = "IgnoreLines"; #endregion // The current state of the configuration, whether it is valid to be used enum ConfigurationState { Unknown = 0, MetaFilesInvalid, MetaFilesValid, ServerInvalid, ServerValid, UsernamePassInvalid, UsernamePassValid, WorkspaceInvalid, WorkspaceValid, ProjectRootInvalid, ProjectRootValid, SettingsValid, } // The current state of the configuration, whether it is valid to be used static ConfigurationState _CurrentState = ConfigurationState.Unknown; enum SaveSettingsMode { EditorPrefs, ConfigAsset, } static SaveSettingsMode _CurrentSaveMode = SaveSettingsMode.EditorPrefs; static SaveSettingsMode saveSelect; bool _Repaint = false; /// /// Set some default configuration values /// static Config() // Config Window Constructor { Initialize(); } static void ResetValues() { // Set some default values ServerURI = "localhost:1666"; Username = Environment.UserName; Password = ""; Workspace = Username + "_" + Main.ProjectName + "_" + Environment.MachineName; UnityVSSupport = false; PerforceEnabled = false; IncludeProjectFiles = false; IncludeSolutionFiles = false; ShowPaths = false; AskBeforeCheckout = false; DisplayStatusIcons = true; Hostname = ""; Charset = ""; DiffToolPathname = ""; DisplayP4Timings = false; DisplayP4Commands = false; CheckStatusForMenus = true; CheckStatusForMenusMaxItems = 10; ConnectionTimeOut = 30; WarnOnSpecialCharacters = true; FoundConfigAsset = false; IgnoreName = ""; IgnoreLines = ""; EnableLog = false; LogPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\p4connect.log"; ConsoleLogLevel = Logger.LogLevel.Info; } static Config window = null; // Add menu item to show the configuration panel [MenuItem("Edit/Perforce Settings", false, 300)] public static void ShowWindow() { // Show existing window instance. If one doesn't exist, make one. window = EditorWindow.GetWindow("P4 Settings"); window.name = "P4 Settings"; window.title = "P4 Settings"; window.minSize = new UnityEngine.Vector2(350.0f, 130.0f); } public static void Refresh() { if (window != null) window.Repaint(); } /// /// Static Constructor, reads connection settings from Prefs at least once /// public static void Initialize() { //Debug.Log("Config.Initialize()"); ResetValues(); FoundConfigAsset = readConfigAsset(); if (FoundConfigAsset) { _CurrentSaveMode = SaveSettingsMode.ConfigAsset; } else { _CurrentSaveMode = SaveSettingsMode.EditorPrefs; ReadPrefs(); } CachedSerializationMode = EditorSettings.serializationMode; Refresh(); if (PerforceEnabled) { if (EnableLog) { Logger.Initialize(); // initialize logging if not done before } CheckSettings(); } } /// /// Checks the that settings are valid /// public static void CheckSettings() { if (ValidConfiguration) return; if (PerforceEnabled) { // We only display a message when something changes ConfigurationState prevState = _CurrentState; _CurrentState = ConfigurationState.Unknown; UpdateConfigState(true); // Run config state machine // If the state is different then when we started if (_CurrentState != prevState) { Icons.UpdateDisplay(); if (_CurrentState != ConfigurationState.SettingsValid) { Debug.LogWarning("P4Connect - Perforce integration is enabled but inactive. Go to Edit->Perforce Settings to update your settings"); } else if (prevState != ConfigurationState.SettingsValid) { Debug.Log("P4Connect - Perforce Integration is Active"); } } //if (_CurrentState == ConfigurationState.SettingsValid) //{ // SetProjectRootDirectory(); //} } } /// /// Updates the current configuration state after checking all the settings /// public static void UpdateConfigState(bool fast) { try { switch (_CurrentState) { case ConfigurationState.Unknown: // The unknown state starts by checking the meta files goto case ConfigurationState.MetaFilesInvalid; case ConfigurationState.MetaFilesInvalid: EditorUtility.DisplayProgressBar("P4Connect - Hold on", "Checking Meta Files", 0.2f); if (P4Connect.VerifySettings.CheckMetaFiles()) { // Meta files are valid, move on _CurrentState = ConfigurationState.MetaFilesValid; goto case ConfigurationState.MetaFilesValid; } else { // Stay in this state _CurrentState = ConfigurationState.MetaFilesInvalid; break; } case ConfigurationState.MetaFilesValid: if (fast) { goto case ConfigurationState.ProjectRootInvalid; // jump ahead for a quick connection } goto case ConfigurationState.ServerInvalid; case ConfigurationState.ServerInvalid: EditorUtility.DisplayProgressBar("P4Connect - Hold on", "Checking Server", 0.4f); if (P4Connect.VerifySettings.CheckServerURI()) { Debug.Log("ServerValid"); // Server is valid, move on _CurrentState = ConfigurationState.ServerValid; goto case ConfigurationState.ServerValid; } else { Debug.Log("ServerInvalid"); // Stay here _CurrentState = ConfigurationState.ServerInvalid; break; } case ConfigurationState.ServerValid: goto case ConfigurationState.UsernamePassInvalid; case ConfigurationState.UsernamePassInvalid: EditorUtility.DisplayProgressBar("P4Connect - Hold on", "Checking Login", 0.6f); if (P4Connect.VerifySettings.CheckUsernamePassword()) { // Username / Password is valid, move on _CurrentState = ConfigurationState.UsernamePassValid; goto case ConfigurationState.UsernamePassValid; } else { // Stay here _CurrentState = ConfigurationState.UsernamePassInvalid; break; } case ConfigurationState.UsernamePassValid: goto case ConfigurationState.WorkspaceInvalid; case ConfigurationState.WorkspaceInvalid: EditorUtility.DisplayProgressBar("P4Connect - Hold on", "Checking Workspace", 0.8f); if (P4Connect.VerifySettings.CheckWorkspace()) { // Workspace is valid _CurrentState = ConfigurationState.WorkspaceValid; goto case ConfigurationState.WorkspaceValid; } else { // Stay here _CurrentState = ConfigurationState.WorkspaceInvalid; break; } case ConfigurationState.WorkspaceValid: goto case ConfigurationState.ProjectRootInvalid; case ConfigurationState.ProjectRootInvalid: if (! fast) EditorUtility.DisplayProgressBar("P4Connect - Hold on", "Checking Project Root", 0.9f); if (P4Connect.VerifySettings.CheckProjectRoot()) { // Root is valid _CurrentState = ConfigurationState.ProjectRootValid; goto case ConfigurationState.ProjectRootValid; } else { // Stay here _CurrentState = ConfigurationState.ProjectRootInvalid; break; } case ConfigurationState.ProjectRootValid: _CurrentState = ConfigurationState.SettingsValid; goto case ConfigurationState.SettingsValid; case ConfigurationState.SettingsValid: break; } EditorUtility.ClearProgressBar(); if (_CurrentState != ConfigurationState.SettingsValid) { EditorUtility.DisplayDialog("p4connect", "Bad Settings, please Fix", "Ok"); } } catch(Exception ex) { log.Debug("Update Config State exception", ex); } } public static void SetProjectRootDirectory() { if (Config.ValidConfiguration) { log.Debug("port: " + Config.ServerURI); log.Debug("_CurrentState: " + Config._CurrentState); Engine.PerformConnectionOperation(con => { // project root in perforce syntax var spec = FileSpec.LocalSpec(System.IO.Path.Combine(Main.RootPath, "...")); var mappings = con.P4Client.GetClientFileMappings(spec); if (mappings != null && mappings.Count > 0) { // string ProjectRoot; ClientProjectRoot = mappings[0].ClientPath.Path; DepotProjectRoot = mappings[0].DepotPath.Path; log.Debug("ClientProjectRoot: " + ClientProjectRoot); log.Debug("DepotProjectRoot: " + DepotProjectRoot); } else { Debug.LogError("Unable to determine Project Root! "); } }); } } static Color save_color; static Color disabled_color = Color.red; static Color connected_color = Color.white; static Color disconnected_color = Color.yellow; private Color StatusColor() { Color c = Color.white; if (PerforceEnabled) { if (ValidConfiguration) c = connected_color; else c = disconnected_color; } else { c = disabled_color; } return c; } // static objects frequently used to create controls static GUILayoutOption _BoxWidth = GUILayout.MaxWidth(200.0f); static GUILayoutOption _EnumWidth = GUILayout.Width(75.0f); static GUILayoutOption _WideEnumWidth = GUILayout.Width(100.0f); static GUILayoutOption _CheckWidth = GUILayout.Width(16.0f); static GUILayoutOption _TextWidth = GUILayout.Width(250.0f); static GUILayoutOption _ButtonWidth = GUILayout.Width(80.0f); static GUILayoutOption _WideButtonWidth = GUILayout.Width(110.0f); static GUILayoutOption _BigButtonWidth = GUILayout.Width(100.0f); static GUILayoutOption _BigButtonHeight = GUILayout.Height(32.0f); static GUILayoutOption _IntWidth = GUILayout.Width(30.0f); static GUILayoutOption _LabelWidth = GUILayout.Width(84.0f); static GUILayoutOption _IndentWidth = GUILayout.Width(10.0f); static GUILayoutOption _BigIconWidth = GUILayout.Width(100.0f); static GUILayoutOption _BigIconHeight = GUILayout.Height(100.0f); static float _VerticalSkip = 8.0f; // ToolTips need GUIContent entries static GUIContent _ContentIcon = new GUIContent("Icon", "View P4Connect documentation on the web"); static GUIContent _ContentConnectPane = new GUIContent("Connection", "Edit P4Connect Connection Settings"); static GUIContent _ContentOptionsPane = new GUIContent("Options", "Edit P4Connect general options"); static GUIContent _ContentDiagnosticsPane = new GUIContent("Diagnostics\n+\nUtilities", "Edit P4Connect Diagnostic options"); static GUIContent _ContentDisable = new GUIContent("Disable", "Disable p4connect for this project"); static GUIContent _ContentEnable = new GUIContent("Enable", "Enable p4connect for this project"); static GUIContent _ContentConnect = new GUIContent("Connect", "Create Connection to Server using current settings"); static GUIContent _ContentDisconnect = new GUIContent("Disconnect", "Break Connection with Server"); static GUIContent _ContentSaveSettings = new GUIContent("Save Settings", "Save the current settings"); static GUIContent _ContentDocLink = new GUIContent("View Web Documentation", "Click to view P4Connect documentation"); static GUIContent _ContentSaveTypeEnum = new GUIContent("Settings storage type:", "Change the current save mode\nEditor Preferences (registry) or \n Config Asset stores config in an asset"); static GUIContent _ContentConsoleLogEnum = new GUIContent("Console Log Reporting Level: ", "Select how much of the P4Connect log gets echoed to the Unity Console"); //int _FrameIndex = 0; //int _MaxFrameCount = 3; // seems to be the right number of repaints needed to display something static Texture2D bigIcon = null; private void OnGUIStatusBar() { save_color = GUI.color; GUI.color = StatusColor(); EditorGUILayout.BeginHorizontal("HelpBox",_BigIconHeight); if (bigIcon == null) { bigIcon = Resources.LoadAssetAtPath("Assets/P4Connect/p4connect_icon.png", typeof(Texture2D)) as Texture2D; _ContentIcon = new GUIContent(bigIcon, "Click to view documentation on the web"); } if (GUILayout.Button(_ContentIcon, _BigIconWidth, _BigIconHeight)) { System.Diagnostics.Process.Start("http://www.perforce.com/perforce/doc.current/manuals/p4connectguide/index.html"); } GUI.color = save_color; EditorGUILayout.BeginVertical(); // Status Pane GUI.color = StatusColor(); if (PerforceEnabled) { if (_CurrentState == ConfigurationState.MetaFilesInvalid) { Debug.LogError("You must set the Editor Version Control to \"Meta Files\" under Edit->Project Settings->Editor"); } if (_CurrentState != ConfigurationState.SettingsValid) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Perforce Integration is INACTIVE. Please Verify your Settings!", MessageType.Warning, true); GUILayout.FlexibleSpace(); GUI.color = save_color; if (GUILayout.Button(_ContentDisable, EditorStyles.miniButton, _BigButtonWidth, _BigButtonHeight)) { PerforceEnabled = false; } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Perforce Integration is ACTIVE.", MessageType.Info, true); GUILayout.FlexibleSpace(); GUI.color = save_color; if (GUILayout.Button(_ContentDisable, EditorStyles.miniButton, _BigButtonWidth, _BigButtonHeight)) { PerforceEnabled = false; } EditorGUILayout.EndHorizontal(); } } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Perforce Integration is DISABLED.", MessageType.Info, true); GUILayout.FlexibleSpace(); GUI.color = save_color; if (GUILayout.Button(_ContentEnable, EditorStyles.miniButton, _BigButtonWidth, _BigButtonHeight)) { PerforceEnabled = true; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginVertical("Box"); GUILayout.Label("Version: " + Version.PerforceReleaseString + "-" + Version.build, "BoldLabel"); GUILayout.Label("Project: " + Main.RootPath.ToStringNullSafe(), EditorStyles.miniLabel); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Save Mode: " + _CurrentSaveMode.ToString(), EditorStyles.miniLabel); GUILayout.FlexibleSpace(); if (GUILayout.Button(_ContentSaveSettings, EditorStyles.miniButton)) { if (_CurrentSaveMode == SaveSettingsMode.EditorPrefs) { Debug.Log("Saving configuration as Editor Preferences"); WritePrefs(); } else { Debug.Log("Saving configuration as Configuration Asset"); writeConfigAsset(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); // Box EditorGUILayout.EndVertical(); // Status Pane EditorGUILayout.EndHorizontal(); // End of Toolbar GUI.color = save_color; } private enum GuiSettingsMode { Connection, Options, Diagnostics } static private GuiSettingsMode _currentMode = GuiSettingsMode.Connection; static private bool bConnection = true; static private bool bOptions = false; static private bool bDiagnostics = false; private void OnGUISettings() { EditorGUILayout.BeginHorizontal("Box"); EditorGUILayout.BeginVertical(); if (bConnection = GUILayout.Toggle(bConnection,_ContentConnectPane, "Button", _BigIconWidth, _BigIconHeight)) { bOptions = bDiagnostics = false; _currentMode = GuiSettingsMode.Connection; } //GUI.backgroundColor = _OptionsColor; if (bOptions = GUILayout.Toggle(bOptions, _ContentOptionsPane, "Button", _BigIconWidth, _BigIconHeight)) { bConnection = bDiagnostics = false; _currentMode = GuiSettingsMode.Options; } //GUI.backgroundColor = _DiagnosticsColor; if (bDiagnostics = GUILayout.Toggle(bDiagnostics, _ContentDiagnosticsPane, "Button",_BigIconWidth, _BigIconHeight)) { bConnection = bOptions = false; _currentMode = GuiSettingsMode.Diagnostics; } EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical("box"); switch(_currentMode) { case GuiSettingsMode.Connection: OnGUIConnectionPanel(); break; case GuiSettingsMode.Options: OnGUIOptionsPanel(); break; case GuiSettingsMode.Diagnostics: OnGUIDiagnosticsPanel(); break; } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } #region ConnectionPanel /// /// Draw the Panel with Connection information /// private void OnGUIConnectionPanel() { GUILayout.BeginVertical(); // Panel // GUILayout.BeginHorizontal(); GUILayout.Label("Connection Settings", EditorStyles.boldLabel); GUILayout.Space(_VerticalSkip); GUILayout.BeginVertical("Box"); // connection box // Disable connection settings if already connected EditorGUI.BeginDisabledGroup(_CurrentState == ConfigurationState.SettingsValid); { EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Server URI:", _LabelWidth); ServerURI = EditorGUILayout.TextField(ServerURI); } EditorGUILayout.EndHorizontal(); if (_CurrentState == ConfigurationState.ServerInvalid) { EditorGUILayout.HelpBox("Invalid Server URI", MessageType.Error); } EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Username:", _LabelWidth); Username = EditorGUILayout.TextField(Username); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Password:", _LabelWidth); Password = EditorGUILayout.PasswordField(Password); } EditorGUILayout.EndHorizontal(); if (_CurrentState == ConfigurationState.UsernamePassInvalid) { EditorGUILayout.HelpBox("Invalid Username / Password", MessageType.Error); } EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Workspace:", _LabelWidth); Workspace = EditorGUILayout.TextField(Workspace); } EditorGUILayout.EndHorizontal(); if (_CurrentState == ConfigurationState.WorkspaceInvalid) { EditorGUILayout.HelpBox("Invalid Workspace", MessageType.Error); } if (_CurrentState == ConfigurationState.ProjectRootInvalid) { // The project isn't under the workspace root string perforcePath = "//" + Workspace + "/..."; string rootPath = P4Connect.Main.RootPath; if (!VerifySettings.ConnectionChecked) { EditorGUILayout.HelpBox("Failed to Connect, check ServerURI and Username", MessageType.Error); } else if (VerifySettings.WorkspaceChecked) { EditorGUILayout.HelpBox("Invalid Workspace. The client path:\n" + "\t" + perforcePath + "\n" + "maps to this folder:\n" + "\t" + VerifySettings.LastWorkspaceMapping + "\n" + "which is not a parent directory of the project's root:\n" + "\t" + rootPath, MessageType.Error); } else { EditorGUILayout.HelpBox("Workspace not found", MessageType.Error); } } EditorGUILayout.BeginHorizontal(); { GUILayout.Label("P4HOST:",_LabelWidth); Hostname = EditorGUILayout.TextField(Hostname); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("P4CHARSET:", _LabelWidth); Charset = EditorGUILayout.TextField(Charset); } EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); // Connection Valid EditorGUILayout.BeginHorizontal(); if (GUILayout.Button((_CurrentState == ConfigurationState.SettingsValid ? _ContentDisconnect : _ContentConnect ), EditorStyles.miniButton, _BoxWidth)) { if (_CurrentState == ConfigurationState.SettingsValid) { _CurrentState = ConfigurationState.Unknown; } else { EditorGUILayout.HelpBox("Please Wait! Checking Perforce Settings. This can take a while ...", MessageType.Info); CheckSettings(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); // Connection Box EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); // New Settings Assistance { GUILayout.Label("Load Settings", EditorStyles.boldLabel); GUILayout.Space(_VerticalSkip); EditorGUILayout.BeginVertical("box"); EditorGUI.BeginDisabledGroup(_CurrentState == ConfigurationState.SettingsValid); { if (GUILayout.Button("Load Defaults", EditorStyles.miniButton, _BoxWidth)) { GUI.FocusControl(""); ResetValues(); _CurrentState = ConfigurationState.Unknown; Repaint(); } if (GUILayout.Button("Load P4 Environment", EditorStyles.miniButton, _BoxWidth)) { GUI.FocusControl(""); if (!ReadEnvironment()) { EditorUtility.DisplayDialog("Read Perforce Environment", "No Perforce Environment variables found!", "OK"); } _CurrentState = ConfigurationState.Unknown; Repaint(); } if (GUILayout.Button("Load P4Config", EditorStyles.miniButton, _BoxWidth)) { GUI.FocusControl(""); string configName = Environment.GetEnvironmentVariable("P4CONFIG"); if (string.IsNullOrEmpty(configName)) { configName = P4CONFIG_DEFAULT; // If not in environment, use the default. } string p4configFile = FindP4ConfigFile(configName); if (string.IsNullOrEmpty(p4configFile)) { Debug.Log("P4Config file " + configName + " Not Found"); } else { LoadP4ConfigFile(p4configFile); Debug.Log("P4Config Found at: " + Path.GetFullPath(p4configFile)); } _CurrentState = ConfigurationState.Unknown; Repaint(); } if (GUILayout.Button("Load Editor Prefs", EditorStyles.miniButton, _BoxWidth)) { GUI.FocusControl(""); ReadPrefs(); _CurrentState = ConfigurationState.Unknown; Repaint(); } if (GUILayout.Button("Load Config Asset", EditorStyles.miniButton, _BoxWidth)) { GUI.FocusControl(""); if (!readConfigAsset()) { EditorUtility.DisplayDialog("Read Configuration Asset", "No Configuration Asset found!", "OK"); } _CurrentState = ConfigurationState.Unknown; Repaint(); } } EditorGUI.EndDisabledGroup(); // Settings Valid EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); } // new settings EditorGUILayout.EndVertical(); GUILayout.EndVertical(); // Panel } #endregion #region OptionsPanel private void OnGUIOptionsPanel() { GUILayout.Label("Options", EditorStyles.boldLabel); GUILayout.Space(_VerticalSkip); EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); { DisplayStatusIcons = EditorGUILayout.Toggle(DisplayStatusIcons, _CheckWidth); GUILayout.Label("Display Status Icons"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { CheckStatusForMenus = EditorGUILayout.Toggle(CheckStatusForMenus, _CheckWidth); GUILayout.Label("Gray out invalid menu options", _TextWidth); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Don't check if more than"); CheckStatusForMenusMaxItems = EditorGUILayout.IntField(CheckStatusForMenusMaxItems, _IntWidth); GUILayout.Label("files selected"); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Diff Tool Executable "); if (GUILayout.Button("Browse...", EditorStyles.miniButton, _ButtonWidth)) { string dir; string path; GUI.FocusControl(""); if (DiffToolPathname.Length > 0) { dir = System.IO.Directory.GetParent(DiffToolPathname).FullName; } else { dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles); } path = EditorUtility.OpenFilePanel("Choose Diff Tool Executable", dir, ""); if (path.Length > 0) { DiffToolPathname = path; } } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label(" ", _IndentWidth); DiffToolPathname = GUILayout.TextField(DiffToolPathname, GUILayout.MinWidth(80.0f), GUILayout.ExpandWidth(true)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { AskBeforeCheckout = EditorGUILayout.Toggle(AskBeforeCheckout, _CheckWidth); GUILayout.Label("Ask before checkout on edit"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { WarnOnSpecialCharacters = EditorGUILayout.Toggle(WarnOnSpecialCharacters, _CheckWidth); GUILayout.Label("Reserved character warning (@#*%)"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); IncludeSolutionFiles = EditorGUILayout.Toggle(IncludeSolutionFiles, _CheckWidth); GUILayout.Label("Include Solution Files"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); IncludeProjectFiles = EditorGUILayout.Toggle(IncludeProjectFiles, _CheckWidth); GUILayout.Label("Include Project Files"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); UnityVSSupport = EditorGUILayout.Toggle(UnityVSSupport, _CheckWidth); GUILayout.Label("Integrate with UnityVS", _TextWidth); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Close Perforce connection after"); ConnectionTimeOut = EditorGUILayout.IntField(ConnectionTimeOut, _IntWidth); GUILayout.Label("seconds"); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("p4ignore: "); if (GUILayout.Button("Browse...", EditorStyles.miniButton, _ButtonWidth)) { string dir; string path; GUI.FocusControl(""); if (IgnoreName.Length > 0) { dir = System.IO.Directory.GetParent(IgnoreName).FullName; } else { dir = Main.RootPath; } path = EditorUtility.OpenFilePanel("Choose P4Ignore File", dir, ""); if (path.Length > 0) { IgnoreName = path; } } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label(" ", _IndentWidth); IgnoreName = GUILayout.TextField(IgnoreName, GUILayout.MinWidth(80.0f), GUILayout.ExpandWidth(true)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Additional Ignore Lines:"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label(" ", _IndentWidth); IgnoreLines = EditorGUILayout.TextArea(IgnoreLines, GUILayout.MinHeight(16.0f), GUILayout.MinWidth(200.0f), GUILayout.ExpandWidth(true)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(_ContentSaveTypeEnum); saveSelect = (SaveSettingsMode)EditorGUILayout.EnumPopup(saveSelect, _WideEnumWidth); _CurrentSaveMode = saveSelect; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); // BOX } #endregion #region DiagnosticsPanel private void OnGUIDiagnosticsPanel() { GUILayout.Label("Diagnostics", EditorStyles.boldLabel); GUILayout.Space(_VerticalSkip); EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); DisplayP4Timings = EditorGUILayout.Toggle(DisplayP4Timings, _CheckWidth); GUILayout.Label("Display P4 Timings"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); ShowPaths = EditorGUILayout.Toggle(ShowPaths, _CheckWidth); GUILayout.Label("Show File Paths in Console"); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup(LogPath.Length == 0); { bool newEnableLog = EditorGUILayout.Toggle(EnableLog, _CheckWidth); if (newEnableLog != EnableLog) { EnableLog = newEnableLog; Logger.Initialize(); } } EditorGUI.EndDisabledGroup(); GUILayout.Label("Enable Logging"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label("Log File: "); if (GUILayout.Button("Browse...", EditorStyles.miniButton, _ButtonWidth)) { string dir; string path; GUI.FocusControl(""); if (LogPath.Length > 0) { dir = System.IO.Directory.GetParent(LogPath).FullName; } else { dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory); } path = EditorUtility.SaveFilePanel("Set P4Connect Log File", dir, "p4connect", "log"); if (path.Length > 0) { LogPath = path; EnableLog = true; } } if (LogPath.Length == 0) { EnableLog = false; } GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Label(" ", _IndentWidth); LogPath = GUILayout.TextField(LogPath, GUILayout.MinWidth(80.0f), GUILayout.ExpandWidth(true)); GUILayout.FlexibleSpace(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(_ContentConsoleLogEnum); ConsoleLogLevel = (Logger.LogLevel)EditorGUILayout.EnumPopup(ConsoleLogLevel, _EnumWidth); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.Label("Utilities", EditorStyles.boldLabel); GUILayout.Space(_VerticalSkip); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Delete Configuration Asset", EditorStyles.miniButton, _BoxWidth)) { if (EditorUtility.DisplayDialog("Delete Configuration Asset", "Are you sure you want to delete this asset?", "OK", "Cancel")) { deleteConfigAsset(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Clear Editor Prefs", EditorStyles.miniButton, _BoxWidth)) { if (EditorUtility.DisplayDialog("Remove All EditorPrefs", "Are you sure you want to remove ALL Unity EditorPreferences?", "OK", "Cancel")) { EditorPrefs.DeleteAll(); } } EditorGUILayout.EndHorizontal(); GUILayout.Space(_VerticalSkip); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(_ContentDocLink, EditorStyles.miniButton, _BoxWidth)) { System.Diagnostics.Process.Start("http://www.perforce.com/perforce/doc.current/manuals/p4connectguide/index.html"); } EditorGUILayout.EndHorizontal(); GUILayout.EndVertical(); } #endregion Vector2 vScroll = Vector2.zero; /// /// Called by Unity when the windows needs to be updated /// void OnGUI() { vScroll = EditorGUILayout.BeginScrollView(vScroll, false, false); // Show the status bar OnGUIStatusBar(); OnGUISettings(); //// Check for a changed value //if (newPerforceEnabled != PerforceEnabled) //{ // PerforceEnabled = newPerforceEnabled; // if (PerforceEnabled) // { // if (_FrameIndex >= _MaxFrameCount) // UI has been running a while // { // CheckSettings(); // } // } //} EditorGUILayout.EndScrollView(); // Scroll View Wrapper for dialog } void OnSelectionChange() { // UnityEngine.Object cursel = Selection.activeObject; } void OnInspectorUpdate() { if (_Repaint) { _Repaint = false; Repaint(); } } // Check for the "well known" Perforce environment variables. public static bool ReadEnvironment() { string value; bool found = false; value = Environment.GetEnvironmentVariable("P4PORT"); if (value != null) { Config.ServerURI = value; found = true; } value = Environment.GetEnvironmentVariable("P4USER"); if (value != null) { Config.Username = value; found = true; } value = Environment.GetEnvironmentVariable("P4PASSWD"); if (value != null) { Config.Password = value; found = true; } value = Environment.GetEnvironmentVariable("P4CLIENT"); if (value != null) { Config.Workspace = value; found = true; } value = Environment.GetEnvironmentVariable("P4HOST"); if (value != null) { Config.Hostname = value; found = true; } value = Environment.GetEnvironmentVariable("P4CHARSET"); if (value != null) { Config.Charset = value; found = true; } value = Environment.GetEnvironmentVariable("P4IGNORE"); if (value != null) { Config.IgnoreName = value; found = true; } Config.Refresh(); return found; } #region EditorPreferences // Utility method to read connection prefs from the registry public static void ReadPrefs() { // Check if the keys exist, and if so, read the values out // Otherwise, leave the existing values if (HasStringPrefNotEmpty(ServerURIPrefName)) ServerURI = GetPrefString(ServerURIPrefName); if (HasStringPrefNotEmpty(UserNamePrefName)) Username = GetPrefString(UserNamePrefName); if (HasStringPrefNotEmpty(PasswordPrefName)) { // Password = Secure.DecryptString(GetPrefString(PasswordPrefName)); Password = GetPrefString(PasswordPrefName); } if (HasStringPrefNotEmpty(WorkspacePrefName)) Workspace = GetPrefString(WorkspacePrefName); if (HasPref(UnityVSSupportPrefName)) UnityVSSupport = GetPrefBool(UnityVSSupportPrefName); if (HasPref(IncludeProjectFilesPrefName)) IncludeProjectFiles = GetPrefBool(IncludeProjectFilesPrefName); if (HasPref(IncludeSolutionFilesPrefName)) IncludeSolutionFiles = GetPrefBool(IncludeSolutionFilesPrefName); if (HasPref(ShowPathsPrefName)) ShowPaths = GetPrefBool(ShowPathsPrefName); if (HasPref(AskBeforeCheckoutPrefName)) AskBeforeCheckout = GetPrefBool(AskBeforeCheckoutPrefName); if (HasPref(DisplayStatusIconsPrefName)) DisplayStatusIcons = GetPrefBool(DisplayStatusIconsPrefName); if (HasStringPrefNotEmpty(HostnamePrefName)) Hostname = GetPrefString(HostnamePrefName); if (HasStringPrefNotEmpty(DiffToolPathnamePrefName)) DiffToolPathname = GetPrefString(DiffToolPathnamePrefName); if (HasPref(DisplayP4TimingsPrefName)) DisplayP4Timings = GetPrefBool(DisplayP4TimingsPrefName); if (HasPref(DisplayP4CommandsPrefName)) DisplayP4Commands = GetPrefBool(DisplayP4CommandsPrefName); if (HasPref(CheckStatusForMenusPrefName)) CheckStatusForMenus = GetPrefBool(CheckStatusForMenusPrefName); if (HasPref(CheckStatusForMenusMaxItemsPrefName)) CheckStatusForMenusMaxItems = GetPrefInt(CheckStatusForMenusMaxItemsPrefName); if (HasPref(OperationBatchCountPrefName)) OperationBatchCount = GetPrefInt(OperationBatchCountPrefName); if (HasPref(ConnectionTimeOutPrefName)) ConnectionTimeOut = GetPrefInt(ConnectionTimeOutPrefName); if (HasPref(WarnOnSpecialCharactersPrefName)) WarnOnSpecialCharacters = GetPrefBool(WarnOnSpecialCharactersPrefName); if (HasStringPrefNotEmpty(IgnoreNamePrefName)) IgnoreName = GetPrefString(IgnoreNamePrefName); if (HasStringPrefNotEmpty(IgnoreLinesPrefName)) IgnoreLines = GetPrefString(IgnoreLinesPrefName); if (HasPref(EnableLogPrefName)) EnableLog = GetPrefBool(EnableLogPrefName); if (HasPref(ConsoleLogLevelPrefName)) ConsoleLogLevel = (Logger.LogLevel)GetPrefInt(ConsoleLogLevelPrefName); if (HasStringPrefNotEmpty(LogPathPrefName)) LogPath = GetPrefString(LogPathPrefName); Config.Refresh(); // Notify users that prefs changed if (PrefsChanged != null) PrefsChanged(); } // Utility method to write our the connection prefs to the registry public static void WritePrefs() { SetPrefString(ServerURIPrefName, ServerURI); SetPrefString(UserNamePrefName, Username); if (!String.IsNullOrEmpty(Password)) { SetPrefString(PasswordPrefName, Password); // SetPrefString(PasswordPrefName, Secure.EncryptString(Password)); // Crashes Unity! } SetPrefString(WorkspacePrefName, Workspace); SetPrefBool(PerforceEnabledPrefName, PerforceEnabled); SetPrefBool(UnityVSSupportPrefName, UnityVSSupport); SetPrefBool(IncludeProjectFilesPrefName, IncludeProjectFiles); SetPrefBool(IncludeSolutionFilesPrefName, IncludeSolutionFiles); SetPrefBool(ShowPathsPrefName, ShowPaths); SetPrefBool(AskBeforeCheckoutPrefName, AskBeforeCheckout); SetPrefBool(DisplayStatusIconsPrefName, DisplayStatusIcons); SetPrefString(HostnamePrefName, Hostname); SetPrefString(DiffToolPathnamePrefName, DiffToolPathname); SetPrefBool(DisplayP4TimingsPrefName, DisplayP4Timings); SetPrefBool(DisplayP4CommandsPrefName, DisplayP4Commands); SetPrefBool(CheckStatusForMenusPrefName, CheckStatusForMenus); SetPrefInt(CheckStatusForMenusMaxItemsPrefName, CheckStatusForMenusMaxItems); SetPrefInt(OperationBatchCountPrefName, OperationBatchCount); SetPrefInt(ConnectionTimeOutPrefName, ConnectionTimeOut); SetPrefBool(WarnOnSpecialCharactersPrefName, WarnOnSpecialCharacters); SetPrefString(IgnoreNamePrefName, IgnoreName); SetPrefString(IgnoreLinesPrefName, IgnoreLines); SetPrefBool(EnableLogPrefName, EnableLog); SetPrefInt(ConsoleLogLevelPrefName, (int)ConsoleLogLevel); SetPrefString(LogPathPrefName, LogPath); } static string GetFullPrefName(string aPrefName) { return "P4Connect_" + Main.ProjectName + "_" + aPrefName; } static bool HasPref(string aPrefName) { return EditorPrefs.HasKey(GetFullPrefName(aPrefName)); } static bool HasStringPrefNotEmpty(string aPrefName) { return (!String.IsNullOrEmpty(EditorPrefs.GetString(GetFullPrefName(aPrefName)))); } static void SetPrefString(string aPrefName, string aPref) { EditorPrefs.SetString(GetFullPrefName(aPrefName), aPref); } static void SetPrefInt(string aPrefName, int aPref) { EditorPrefs.SetInt(GetFullPrefName(aPrefName), aPref); } static void SetPrefBool(string aPrefName, bool aPref) { EditorPrefs.SetBool(GetFullPrefName(aPrefName), aPref); } static string GetPrefString(string aPrefName) { return EditorPrefs.GetString(GetFullPrefName(aPrefName)); } static int GetPrefInt(string aPrefName) { return EditorPrefs.GetInt(GetFullPrefName(aPrefName)); } static bool GetPrefBool(string aPrefName) { return EditorPrefs.GetBool(GetFullPrefName(aPrefName)); } // [MenuItem("Edit/Delete Project EditorPrefs", false, 300)] static void DeleteAllEditorPrefs() { // Delete All keys for this project EditorPrefs.DeleteKey(ServerURIPrefName); EditorPrefs.DeleteKey(UserNamePrefName); EditorPrefs.DeleteKey(PasswordPrefName); EditorPrefs.DeleteKey(WorkspacePrefName); EditorPrefs.DeleteKey(UnityVSSupportPrefName); EditorPrefs.DeleteKey(IncludeProjectFilesPrefName); EditorPrefs.DeleteKey(IncludeSolutionFilesPrefName); EditorPrefs.DeleteKey(ShowPathsPrefName); EditorPrefs.DeleteKey(AskBeforeCheckoutPrefName); EditorPrefs.DeleteKey(DisplayStatusIconsPrefName); EditorPrefs.DeleteKey(HostnamePrefName); EditorPrefs.DeleteKey(DiffToolPathnamePrefName); EditorPrefs.DeleteKey(DisplayP4TimingsPrefName); EditorPrefs.DeleteKey(DisplayP4CommandsPrefName); EditorPrefs.DeleteKey(CheckStatusForMenusPrefName); EditorPrefs.DeleteKey(CheckStatusForMenusMaxItemsPrefName); EditorPrefs.DeleteKey(OperationBatchCountPrefName); EditorPrefs.DeleteKey(ConnectionTimeOutPrefName); EditorPrefs.DeleteKey(WarnOnSpecialCharactersPrefName); EditorPrefs.DeleteKey(IgnoreNamePrefName); EditorPrefs.DeleteKey(IgnoreLinesPrefName); EditorPrefs.DeleteKey(EnableLogPrefName); EditorPrefs.DeleteKey(ConsoleLogLevelPrefName); } #endregion public static SerializationMode CachedSerializationMode { get; private set; } #region P4CONFIG public static string FindP4ConfigFile(string config) { string directoryName; if (!String.IsNullOrEmpty(config)) { string path = Application.dataPath; while (path != null) { directoryName = Path.GetDirectoryName(path); if (!String.IsNullOrEmpty(directoryName)) { string[] files = System.IO.Directory.GetFiles(directoryName, config); if (files.Count() > 0) { return files[0]; } } path = directoryName; } } return null; } public static void LoadP4ConfigFile(string path) { string line; char[] equalsChars = { '=' }; System.IO.StreamReader file = new System.IO.StreamReader(path); while ((line = file.ReadLine()) != null) { string[] segments = line.Split(equalsChars); if (segments.Length >= 2) { string key = segments[0]; string val = segments[1]; switch (segments[0]) { case "P4PORT": { ServerURI = val; } break; case "P4USER": { Username = val; } break; case "P4CLIENT": { Workspace = val; } break; case "P4PASSWD": { Password = val; } break; case "P4HOST": { Hostname = val; } break; case "P4CHARSET": { Charset = val; } break; } } } file.Close(); } #endregion #region ConfigAsset static string configAssetPath = "Assets/P4Connect/Editor/Config.asset"; public static void writeConfigAsset() { ConfigAsset asset = ScriptableObject.CreateInstance(); asset.CopyConfigToAsset(); AssetDatabase.CreateAsset(asset, configAssetPath); AssetDatabase.SaveAssets(); } public static bool readConfigAsset() { ConfigAsset asset = AssetDatabase.LoadAssetAtPath(configAssetPath, (typeof(ConfigAsset))) as ConfigAsset; if (asset != null) { asset.CopyAssetToConfig(); Config.Refresh(); return true; } else { return false; } } public static void deleteConfigAsset() { if (!AssetDatabase.DeleteAsset(configAssetPath)) { System.IO.File.Delete(System.IO.Path.Combine(Main.RootPath, configAssetPath)); } } /* If the inspector is used to view a Config Asset, these properties control the presentation */ [CustomEditor(typeof(ConfigAsset))] public class ConfigAssetPropertiesEditor : Editor { public override void OnInspectorGUI() { GUI.enabled = false; DrawDefaultInspector(); GUI.enabled = true; } } #endregion } //public class XYZZY : EditorWindow //{ // static XYZZY() // { // } // // Add menu named "Styles" to the Window menu // [MenuItem("Window/Styles", false, 1000)] // public static void ShowWindow() // { // // Get existing open window or if none, make a new one: // XYZZY window = EditorWindow.GetWindow(typeof(XYZZY), false, "Styles") as XYZZY; // window.title = "Styles"; // window.name = "Styles"; // } // public static Vector2 _scrollPosition = new Vector2(); // void OnGUI() // { // EditorGUILayout.BeginVertical(); // _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, false, true, GUI.skin.horizontalScrollbar, GUI.skin.verticalScrollbar, GUI.skin.box); // ShowStyles(); // GUILayout.EndScrollView(); // EditorGUILayout.EndVertical(); // } // public static void ShowStyles() // { // foreach (GUIStyle style in GUI.skin.customStyles) // { // GUILayout.Button(style.name, style); // } // } //} }