Skip to content

Commit

Permalink
Merge pull request #5 from VeriorPies/Develop
Browse files Browse the repository at this point in the history
Fix issue with assets modified alert shown when nothing is actually being saved. Add preference options
  • Loading branch information
314pies authored Jul 9, 2020
2 parents b691eee + ca38fa2 commit 149b3a2
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down
24 changes: 16 additions & 8 deletions ParrelSync/Editor/ClonesManagerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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)
Expand Down Expand Up @@ -105,21 +105,27 @@ 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++)
{

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);
Expand All @@ -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();

Expand Down Expand Up @@ -165,7 +171,9 @@ private void OnGUI()
EditorGUILayout.Space();
EditorGUILayout.Space();


EditorGUI.BeginDisabledGroup(isOpenInAnotherInstance);

if (GUILayout.Button("Open in New Editor"))
{
ClonesManager.OpenProject(cloneProjectPath);
Expand All @@ -184,7 +192,7 @@ private void OnGUI()
ClonesManager.DeleteClone(cloneProjectPath);
}
}

GUILayout.EndHorizontal();
EditorGUI.EndDisabledGroup();
GUILayout.EndVertical();
Expand Down
105 changes: 105 additions & 0 deletions ParrelSync/Editor/Preferences.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace ParrelSync
{
/// <summary>
/// To add value caching for <see cref="EditorPrefs"/> functions
/// </summary>
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();
}

/// <summary>
/// Disable asset saving in clone editors?
/// </summary>
public static BoolPreference AssetModPref = new BoolPreference("ParrelSync_DisableClonesAssetSaving", true);

/// <summary>
/// In addition of checking the existence of UnityLockFile,
/// also check is the is the UnityLockFile being opened.
/// </summary>
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();
}
}
}
11 changes: 11 additions & 0 deletions ParrelSync/Editor/Preferences.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.2
1.3.3

0 comments on commit 149b3a2

Please sign in to comment.