Пример #1
0
 private void OnEnable()
 {
     m_assetHistory     = null;
     m_isLoadingHistory = false;
     m_isAssetValid     = false;
     if (m_asset != null)
     {
         m_isAssetValid = Locker.IsAssetTypeValid(m_asset);
         if (m_isAssetValid)
         {
             Show(m_asset);
         }
     }
 }
Пример #2
0
        private void OnLockedAssetsChanged()
        {
            var newToggled = new List <Object>(8);

            foreach (var asset in Locker.GetAssetsLockedByMe())
            {
                for (var i = 0; i < m_toggledAssets.Count; i++)
                {
                    if (AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(asset.Guid)) == m_toggledAssets[i])
                    {
                        newToggled.Add(m_toggledAssets[i]);
                    }
                }
            }
            m_toggledAssets = newToggled;
            Repaint();
        }
Пример #3
0
        public static void Show(Object asset)
        {
            asset = Locker.FilterAsset(asset);
            var window = GetWindow <HistoryWindow>();

            window.titleContent       = new GUIContent(Title);
            window.m_assetHistory     = null;
            window.m_isLoadingHistory = true;
            window.m_asset            = asset;
            window.Show();
            Locker.FetchAssetHistory(asset, (data) =>
            {
                window.m_assetHistory     = data;
                window.m_isLoadingHistory = false;
                window.m_maxLockerWidth   = EditorStyles.label.CalcSize(new GUIContent(LockerHeader)).x;
                var maxDateWidth          = EditorStyles.label.CalcSize(new GUIContent(DateHeader)).x;
                var iconWidth             = Container.GetLockSettings().LockedByMeIconLarge.width;
                for (var i = 0; i < window.m_assetHistory.Length; i++)
                {
                    var history       = window.m_assetHistory[i];
                    var lockerContent = new GUIContent(history.LockerName);
                    var lockerWidth   = EditorStyles.label.CalcSize(lockerContent).x;
                    var dateContent   = new GUIContent(history.Date.ToString());
                    var dateWidth     = EditorStyles.label.CalcSize(dateContent).x;
                    if (window.m_maxLockerWidth < lockerWidth)
                    {
                        window.m_maxLockerWidth = lockerWidth;
                    }
                    if (maxDateWidth < dateWidth)
                    {
                        maxDateWidth = dateWidth;
                    }
                }
                window.minSize = new Vector2(window.m_maxLockerWidth + maxDateWidth + iconWidth + IconSpacing + IconSpacing + 24, 54);
                window.maxSize = new Vector2(1000000000, 1000000000);
                window.Repaint();
            }, null);
        }
Пример #4
0
        private static string[] OnWillSaveAssets(string[] paths)
        {
            if (!Container.GetLockSettings().IsEnabled)
            {
                return(paths);
            }
            if (paths.Length == 0)
            {
                return(paths);
            }
            if (!Locker.HasFetched)
            {
                for (var i = 0; i < paths.Length; i++)
                {
                    if (paths[i] == AssetDatabase.GetAssetPath(Container.GetLockSettings()))
                    {
                        return(new[] { paths[i] });
                    }
                }
                EditorUtility.DisplayDialog("Could not save assets", "The UnityLocker plugin has not yet fetched locket assets from the server.\nMake sure the LockSettings asset is configured correctly and that the server is up and running.", "Ok");
                return(new string[0]);
            }

            var pathsLocked   = string.Empty;
            var indexesLocked = new List <int>(8);

            for (var i = 0; i < paths.Length; i++)
            {
                var asset = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(paths[i]);
                var isAssetLockedNowButUnlockedAtLaterCommit = Locker.IsAssetLockedNowButUnlockedAtLaterCommit(asset);
                if (asset != null && (Locker.IsAssetLockedBySomeoneElse(asset) || isAssetLockedNowButUnlockedAtLaterCommit))
                {
                    if (isAssetLockedNowButUnlockedAtLaterCommit)
                    {
                        pathsLocked += paths[i] + " (Locked by " + Locker.GetAssetLocker(asset) + ", unlocks at commit " + Locker.GetAssetUnlockCommitShaShort(asset) + ")\n";
                    }
                    else
                    {
                        pathsLocked += paths[i] + " (Locked by " + Locker.GetAssetLocker(asset) + ")\n";
                    }
                    indexesLocked.Add(i);
                }
            }

            // If all assets can be saved, no need to create a new array.
            if (indexesLocked.Count == 0)
            {
                return(paths);
            }

            if (paths.Length - indexesLocked.Count > 0)
            {
                if (EditorUtility.DisplayDialog("Cannot save some assets", "The following assets are locked:\n" + pathsLocked + "Do you want to save the other assets?", "Yes", "No"))
                {
                    var arr      = new string[paths.Length - indexesLocked.Count];
                    var arrIndex = 0;
                    for (var i = 0; i < paths.Length; i++)
                    {
                        if (!indexesLocked.Contains(i))
                        {
                            arr[arrIndex++] = paths[i];
                        }
                    }

                    return(arr);
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Cannot save assets", "The following assets are locked:\n" + pathsLocked, "Ok");
            }
            return(new string[0]);
        }
Пример #5
0
        private void OnGUI()
        {
            if (m_toggledAssets.Count == 0)
            {
                GUI.enabled = false;
            }
            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Revert Lock"))
                {
                    RevertLock();
                }
                if (GUILayout.Button("Finish Lock"))
                {
                    FinishLock();
                }
            }
            GUI.enabled = true;

            EditorGUILayout.LabelField("Assets locked by you", EditorStyles.boldLabel);

            var lockedAssets = Locker.GetAssetsLockedByMe();

            foreach (var lockedAsset in lockedAssets)
            {
                var rect             = EditorGUILayout.GetControlRect();
                var asset            = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(lockedAsset.Guid));
                var currentlyToggled = m_toggledAssets.Contains(asset);
                var toggleRect       = new Rect(rect.x, rect.y, rect.height, rect.height);
                var toggled          = EditorGUI.Toggle(toggleRect, currentlyToggled);
                if (toggled && !currentlyToggled)
                {
                    m_toggledAssets.Add(asset);
                }
                else if (!toggled && currentlyToggled)
                {
                    m_toggledAssets.Remove(asset);
                }
                rect.x     += toggleRect.width;
                rect.width -= toggleRect.width - 15f;
                GUI.enabled = false;
                EditorGUI.ObjectField(rect, asset, typeof(Object), false);
                GUI.enabled = true;
            }

            var lockedBySomeoneElse = Locker.GetAssetsLockedBySomeoneElse();
            var longestNameWidth    = -1f;

            foreach (var lockedAsset in lockedBySomeoneElse)
            {
                var size = GUIStyle.none.CalcSize(new GUIContent(lockedAsset.LockerName));
                if (size.x > longestNameWidth)
                {
                    longestNameWidth = size.x;
                }
            }
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Assets locked by someone else", EditorStyles.boldLabel);
            if (longestNameWidth >= 0)
            {
                foreach (var lockedAsset in lockedBySomeoneElse)
                {
                    var rect = EditorGUILayout.GetControlRect();
                    rect.width += 16;
                    var texture   = lockedAsset.Locked ? Container.GetLockSettings().LockIcon : Container.GetLockSettings().LockedNowButUnlockedLaterIcon;
                    var originalY = rect.y;
                    rect.y += (rect.height / 2 - texture.height / 2) / 2;
                    GUI.Label(rect, texture);
                    rect.y      = originalY;
                    rect.x     += texture.width;
                    rect.width -= texture.width;
                    var nameRect = new Rect(rect.x, rect.y, longestNameWidth + 5, rect.height);
                    rect.width -= nameRect.width;
                    rect.x     += nameRect.width;
                    var asset = AssetDatabase.LoadAssetAtPath <Object>(AssetDatabase.GUIDToAssetPath(lockedAsset.Guid));
                    GUI.enabled = false;
                    EditorGUI.ObjectField(rect, asset, typeof(Object), false);
                    GUI.enabled = true;
                    var guiContent = lockedAsset.Locked ? new GUIContent(lockedAsset.LockerName) : new GUIContent(lockedAsset.LockerName, "Unlocked at commit " + lockedAsset.UnlockSha);
                    EditorGUI.LabelField(nameRect, guiContent);
                }
            }
        }
Пример #6
0
        private void OnGUI()
        {
            using (var scope = new EditorGUI.ChangeCheckScope())
            {
                m_asset = EditorGUILayout.ObjectField(m_asset, typeof(Object), true);
                if (scope.changed)
                {
                    m_assetHistory = null;
                    m_isAssetValid = Locker.IsAssetTypeValid(m_asset);
                    if (m_isAssetValid)
                    {
                        Show(m_asset);
                    }
                }
            }
            var currentEvent = Event.current;

            if (m_assetHistory == null)
            {
                if (m_isLoadingHistory)
                {
                    EditorGUILayout.LabelField("Loading...");
                }
                else if (m_asset == null)
                {
                    EditorGUILayout.LabelField("Select an asset to view history");
                }
                else if (!m_isAssetValid)
                {
                    EditorGUILayout.LabelField("Asset is not a valid lockable asset");
                }
                return;
            }
            {
                var controlRect = EditorGUILayout.GetControlRect(false, 1);
                EditorGUI.DrawRect(controlRect, Color.gray);
            }
            using (var scroll = new EditorGUILayout.ScrollViewScope(m_scrollPosition))
            {
                var repaint = false;
                DrawSimpleEntry(Container.GetLockSettings().LockIconLarge, DateHeader, LockerHeader, "");
                var controlRect = EditorGUILayout.GetControlRect(false, 1);

                if (m_assetHistory.Length > 0)
                {
                    var height = EditorGUIUtility.singleLineHeight * m_assetHistory.Length + EditorGUIUtility.standardVerticalSpacing * m_assetHistory.Length;
                    GUI.Box(new Rect(controlRect.x, controlRect.y + EditorGUIUtility.standardVerticalSpacing, controlRect.width, height), "", GUI.skin.box);
                    for (var i = 0; i < m_assetHistory.Length; i++)
                    {
                        var rect         = EditorGUILayout.GetControlRect();
                        var history      = m_assetHistory[i];
                        var hasUnlockSha = !string.IsNullOrEmpty(history.UnlockSha);
                        var icon         = history.Locked ? Container.GetLockSettings().LockIconLarge : (hasUnlockSha ? Container.GetLockSettings().LockedNowButUnlockedLaterIconLarge : Container.GetLockSettings().LockedByMeIconLarge);
                        DrawSimpleEntry(rect, icon, history.Date.ToString(), history.LockerName, hasUnlockSha ? "Unlocked at commit " + history.UnlockSha + " (right click to copy)" : "");
                        if (hasUnlockSha && currentEvent.isMouse && currentEvent.button == 1 && currentEvent.type == EventType.MouseDown && rect.Contains(currentEvent.mousePosition))
                        {
                            currentEvent.Use();
                            EditorGUIUtility.systemCopyBuffer = history.UnlockSha;
                        }
                        if (i != m_assetHistory.Length - 1)
                        {
                            EditorGUI.DrawRect(new Rect(rect.x + 1, rect.y + rect.height, rect.width - 2, 1), new Color(0.7f, 0.7f, 0.7f));
                        }
                    }
                }
                m_scrollPosition = scroll.scrollPosition;
                if (repaint)
                {
                    Repaint();
                }
            }
        }
Пример #7
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            var isEnabledProperty = serializedObject.FindProperty("m_isEnabled");

            EditorGUILayout.PropertyField(isEnabledProperty);
            using (var disabledScope = new EditorGUI.DisabledGroupScope(!isEnabledProperty.boolValue))
            {
                using (var scope = new EditorGUI.ChangeCheckScope())
                {
                    var name = EditorGUILayout.DelayedTextField("Name", EditorPrefs.GetString("LockerName", Environment.UserName));
                    if (scope.changed)
                    {
                        EditorPrefs.SetString("LockerName", name);
                    }
                }
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_lockIcon"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_lockedByMeIcon"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_lockedNowButUnlockedLaterIcon"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_lockIconLarge"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_lockedByMeIconLarge"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_lockedNowButUnlockedLaterIconLarge"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_baseUrl"));

                if (!string.IsNullOrEmpty(serializedObject.FindProperty("m_versionControlName").stringValue))
                {
                    using (var scope = new EditorGUI.ChangeCheckScope())
                    {
                        var parentCountProperty = serializedObject.FindProperty("m_parentFolderCount");
                        EditorGUILayout.DelayedIntField(parentCountProperty);
                        if (scope.changed)
                        {
                            if (parentCountProperty.intValue < 0)
                            {
                                parentCountProperty.intValue = 0;
                            }
                            var baseFolder = string.Empty;
                            for (var i = 0; i < parentCountProperty.intValue; i++)
                            {
                                baseFolder += @"..\";
                            }
                            serializedObject.FindProperty("m_baseFolderAdditionalPath").stringValue = baseFolder;
                        }
                    }
                    EditorGUILayout.LabelField("Repo folder: " + (target as LockSettings).RepoPath, EditorStyles.miniLabel);
                }

                if (sm_versionControllers == null || sm_versionControllers.Count == 0)
                {
                    GUI.enabled = false;
                    EditorGUILayout.Popup("Version Control", 0, new string[0]);
                    GUI.enabled = true;
                }
                else
                {
                    var property     = serializedObject.FindProperty("m_versionControlName");
                    var currentIndex = sm_versionControllers.IndexOf(property.stringValue);
                    using (var changeCheck = new EditorGUI.ChangeCheckScope())
                    {
                        var newIndex = EditorGUILayout.Popup("Version Control", currentIndex, sm_versionControllers.ToArray());
                        if (changeCheck.changed)
                        {
                            property.stringValue = sm_versionControllers[newIndex];
                        }
                    }
                }

                if (sm_assetTypeValidatorNames == null || sm_assetTypeValidatorNames.Count == 0)
                {
                    GUI.enabled = false;
                    EditorGUILayout.Popup("Valid Asset Types", 0, new string[0]);
                    GUI.enabled = true;
                }
                else
                {
                    var property = serializedObject.FindProperty("m_assetTypeValidators");
                    var rect     = EditorGUILayout.GetControlRect();
                    property.intValue = EditorGUI.MaskField(rect, "Valid Asset Types", property.intValue, sm_assetTypeValidatorNames.ToArray());
                }

                if (GUILayout.Button("Unlock all files"))
                {
                    if (EditorUtility.DisplayDialog("Unlock all files", "This removes the lock and history from ALL files, NOT ONLY YOURS. This operation cannot be reverted.\nContinue?", "Ok", "Cancel"))
                    {
                        Locker.TryClearLocks(null, null);
                    }
                }

                if (isEnabledProperty.boolValue && !string.IsNullOrEmpty(Locker.ErrorMessage))
                {
                    EditorGUILayout.LabelField(new GUIContent("Error: " + Locker.ErrorMessage), ErrorStyle);
                }
            }
            serializedObject.ApplyModifiedProperties();
        }