diff --git a/ParrelSync/Editor/AssetModBlock/ParrelSyncAssetModificationProcessor.cs b/ParrelSync/Editor/AssetModBlock/ParrelSyncAssetModificationProcessor.cs index e557862..ac9d19d 100644 --- a/ParrelSync/Editor/AssetModBlock/ParrelSyncAssetModificationProcessor.cs +++ b/ParrelSync/Editor/AssetModBlock/ParrelSyncAssetModificationProcessor.cs @@ -11,7 +11,7 @@ public class ParrelSyncAssetModificationProcessor : UnityEditor.AssetModificatio { public static string[] OnWillSaveAssets(string[] paths) { - if (ClonesManager.IsClone()) + if (ClonesManager.IsClone() && Preferences.AssetModPref.GetValue()) { if (paths != null && paths.Length > 0 && !EditorQuit.IsQuiting) { @@ -20,7 +20,7 @@ public static string[] OnWillSaveAssets(string[] paths) "Asset modifications saving are blocked in the clone instance. \n\n" + "This is a clone of the original project. \n" + "Making changes to asset files via the clone editor is not recommended. \n" + - "Please use the original editor instance if you want to make changes the project files.", + "Please use the original editor window if you want to make changes to the project files.", "ok" ); foreach (var path in paths) diff --git a/ParrelSync/Editor/ClonesManagerWindow.cs b/ParrelSync/Editor/ClonesManagerWindow.cs index cccc1ae..9395e04 100644 --- a/ParrelSync/Editor/ClonesManagerWindow.cs +++ b/ParrelSync/Editor/ClonesManagerWindow.cs @@ -34,7 +34,7 @@ private static void InitWindow() private void OnGUI() { - if(Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.LinuxEditor) + if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.LinuxEditor) { EditorGUILayout.HelpBox( "Sorry, but " + ClonesManager.ProjectName + " doesn't support Mac and Linux currently.\n" + @@ -49,7 +49,7 @@ private void OnGUI() /// If it is a clone project... if (ClonesManager.IsClone()) - { + { //Find out the original project name and show the help box string originalProjectPath = ClonesManager.GetOriginalProjectPath(); if (originalProjectPath == string.Empty) @@ -105,7 +105,7 @@ private void OnGUI() //List all clones clonesScrollPos = - EditorGUILayout.BeginScrollView(clonesScrollPos); + EditorGUILayout.BeginScrollView(clonesScrollPos); var cloneProjectsPath = ClonesManager.GetCloneProjectsPath(); for (int i = 0; i < cloneProjectsPath.Count; i++) { @@ -113,13 +113,19 @@ private void OnGUI() GUILayout.BeginVertical("GroupBox"); string cloneProjectPath = cloneProjectsPath[i]; - //Determine whether it is opened in another instance by checking the UnityLockFile + + //Determine whether it is opened in another instance by checking the UnityLockFile string UnityLockFilePath = Path.Combine(cloneProjectPath, "Temp", "UnityLockfile"); - bool isOpenInAnotherInstance = File.Exists(UnityLockFilePath) && FileUtilities.IsFileLocked(UnityLockFilePath); + bool isOpenInAnotherInstance = false; + if (Preferences.AlsoCheckUnityLockFileStaPref.GetValue()) + isOpenInAnotherInstance = File.Exists(UnityLockFilePath) && FileUtilities.IsFileLocked(UnityLockFilePath); + else + isOpenInAnotherInstance = File.Exists(UnityLockFilePath); + - if (isOpenInAnotherInstance) + if (isOpenInAnotherInstance == true) EditorGUILayout.LabelField("Clone " + i + " (Running)", EditorStyles.boldLabel); else EditorGUILayout.LabelField("Clone " + i); @@ -129,7 +135,7 @@ private void OnGUI() EditorGUILayout.TextField("Clone project path", cloneProjectPath, EditorStyles.textField); if (GUILayout.Button("View Folder", GUILayout.Width(80))) { - ClonesManager.OpenProjectInFileExplorer(cloneProjectPath); + ClonesManager.OpenProjectInFileExplorer(cloneProjectPath); } GUILayout.EndHorizontal(); @@ -165,7 +171,9 @@ private void OnGUI() EditorGUILayout.Space(); EditorGUILayout.Space(); + EditorGUI.BeginDisabledGroup(isOpenInAnotherInstance); + if (GUILayout.Button("Open in New Editor")) { ClonesManager.OpenProject(cloneProjectPath); @@ -184,7 +192,7 @@ private void OnGUI() ClonesManager.DeleteClone(cloneProjectPath); } } - + GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); GUILayout.EndVertical(); diff --git a/ParrelSync/Editor/Preferences.cs b/ParrelSync/Editor/Preferences.cs new file mode 100644 index 0000000..fa6a5cd --- /dev/null +++ b/ParrelSync/Editor/Preferences.cs @@ -0,0 +1,105 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ParrelSync +{ + /// + /// To add value caching for functions + /// + public class BoolPreference + { + public string key { get; private set; } + public bool defaultValue { get; private set; } + public BoolPreference(string key, bool defaultValue) + { + this.key = key; + this.defaultValue = defaultValue; + } + + private bool? valueCache = null; + + public bool GetValue() + { + if (valueCache == null) + valueCache = EditorPrefs.GetBool(key, defaultValue); + + return (bool)valueCache; + } + + public void SetValue(bool value) + { + if (valueCache == value) + return; + + EditorPrefs.SetBool(key, value); + valueCache = value; + Debug.Log("Editor preference updated. key: " + key + ", value: " + value); + } + + public void ClearValue() + { + EditorPrefs.DeleteKey(key); + valueCache = null; + } + } + + public class Preferences : EditorWindow + { + [MenuItem("ParrelSync/Preferences", priority = 1)] + private static void InitWindow() + { + Preferences window = (Preferences)EditorWindow.GetWindow(typeof(Preferences)); + window.titleContent = new GUIContent(ClonesManager.ProjectName + " Preferences"); + window.Show(); + } + + /// + /// Disable asset saving in clone editors? + /// + public static BoolPreference AssetModPref = new BoolPreference("ParrelSync_DisableClonesAssetSaving", true); + + /// + /// In addition of checking the existence of UnityLockFile, + /// also check is the is the UnityLockFile being opened. + /// + public static BoolPreference AlsoCheckUnityLockFileStaPref = new BoolPreference("ParrelSync_CheckUnityLockFileOpenStatus", true); + + private void OnGUI() + { + if (ClonesManager.IsClone()) + { + EditorGUILayout.HelpBox( + "This is a clone project. Please use the original project editor to change preferences.", + MessageType.Info); + return; + } + + GUILayout.BeginVertical("HelpBox"); + GUILayout.Label("Preferences"); + GUILayout.BeginVertical("GroupBox"); + + AssetModPref.SetValue( + EditorGUILayout.ToggleLeft("(recommended) Disable asset saving in clone editors- require re-open clone editors", + AssetModPref.GetValue()) + ); + + + AlsoCheckUnityLockFileStaPref.SetValue( + EditorGUILayout.ToggleLeft("Also check UnityLockFile lock status while checking clone projects running status", + AlsoCheckUnityLockFileStaPref.GetValue()) + ); + + + GUILayout.EndVertical(); + if (GUILayout.Button("Reset to default")) + { + AssetModPref.ClearValue(); + AlsoCheckUnityLockFileStaPref.ClearValue(); + Debug.Log("Editor preferences cleared"); + } + GUILayout.EndVertical(); + } + } +} \ No newline at end of file diff --git a/ParrelSync/Editor/Preferences.cs.meta b/ParrelSync/Editor/Preferences.cs.meta new file mode 100644 index 0000000..0166f9a --- /dev/null +++ b/ParrelSync/Editor/Preferences.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 24641be1c0410a745b529e61b508679f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VERSION.txt b/VERSION.txt index d5e98f7..785cda8 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -1.3.2 \ No newline at end of file +1.3.3 \ No newline at end of file