private static void OnHierarchyWindowItemOnGUI(int instanceId, Rect selectionRect) { if (!Container.GetLockSettings().IsEnabled) { return; } if (!Locker.HasFetched) { return; } var extra = selectionRect.x; selectionRect.width += extra; #if UNITY_2018_3_OR_NEWER selectionRect.width += extra; #endif selectionRect.x = 0; var asset = EditorUtility.InstanceIDToObject(instanceId); if (asset == null) { var scene = (Scene)sm_getSceneMethod.Invoke(null, new object[] { instanceId }); var sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scene.path); LockDrawer.TryDrawLock(selectionRect, sceneAsset, LockDrawer.DrawType.Background); } else { asset = Locker.FilterAsset(asset); LockDrawer.TryDrawLock(selectionRect, asset, LockDrawer.DrawType.Background); } }
private static void OnProjectWindowItemGUI(string guid, Rect selectionRect) { if (!Container.GetLockSettings().IsEnabled) { return; } if (!Locker.HasFetched) { return; } var assetPath = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(assetPath)) { return; } var asset = AssetDatabase.LoadAssetAtPath <Object>(assetPath); LockDrawer.TryDrawLock(selectionRect, asset, LockDrawer.DrawType.SmallIcon); }
private static void OnFinishedHeaderGUI(UnityEditor.Editor editor) { if (editor.GetType() == typeof(MaterialEditor)) { return; } if (!Container.GetLockSettings().IsEnabled) { return; } if (!Locker.HasFetched) { return; } if (!Locker.AreAssetTypesValid(editor.targets)) { return; } var isLockedByMe = Locker.AreAllAssetsLockedByMe(editor.targets); var isLockedBySomeoneElse = Locker.IsAnyAssetLockedBySomeoneElse(editor.targets); var isLockedNowButUnlockedAtLaterCommit = Locker.IsAnyAssetLockedNowButUnlockedAtLaterCommit(editor.targets); using (new GUILayout.HorizontalScope()) { EditorGUILayout.LabelField("Lock", sm_lockLabelStyle, GUILayout.Width(44)); using (new EditorGUI.DisabledGroupScope(isLockedByMe || isLockedBySomeoneElse || isLockedNowButUnlockedAtLaterCommit)) { if (GUILayout.Button(new GUIContent(Constants.LockName), EditorStyles.miniButton)) { Locker.TryLockAssets(editor.targets, null, (errorMessage) => { EditorUtility.DisplayDialog("Asset locking failed", "Asset locking failed\n" + errorMessage, "OK"); }); } } using (new EditorGUI.DisabledGroupScope(!isLockedByMe)) { if (GUILayout.Button(new GUIContent(Constants.RevertName), EditorStyles.miniButton)) { Locker.TryRevertAssetLocks(editor.targets, null, (errorMessage) => { EditorUtility.DisplayDialog("Asset reverting failed", "Asset reverting failed\n" + errorMessage, "OK"); }); } if (GUILayout.Button(new GUIContent(Constants.FinishName), EditorStyles.miniButton)) { Locker.TryFinishLockingAssets(editor.targets, null, (errorMessage) => { EditorUtility.DisplayDialog("Asset finishing failed", "Asset finishing failed\n" + errorMessage, "OK"); }); } } if (GUILayout.Button(new GUIContent(Constants.HistoryName), EditorStyles.miniButton)) { HistoryWindow.Show(editor.target); } } if (isLockedByMe || isLockedBySomeoneElse || isLockedNowButUnlockedAtLaterCommit) { var hasMultipleLockers = false; var locker = Locker.GetAssetLocker(editor.targets[0]); for (var i = 1; i < editor.targets.Length; i++) { if (locker != Locker.GetAssetLocker(editor.targets[1])) { hasMultipleLockers = true; break; } } if (!string.IsNullOrEmpty(locker)) { LockDrawer.TryDrawLock(sm_headerRect, editor.target, LockDrawer.DrawType.LargeIcon); EditorGUILayout.LabelField("Asset" + (editor.targets.Length > 1 ? "s" : "") + " locked by " + (hasMultipleLockers ? "multiple users" : locker), EditorStyles.boldLabel); if (isLockedNowButUnlockedAtLaterCommit) { var hasMultipleUnlockShas = false; var sha = Locker.GetAssetUnlockCommitShaShort(editor.targets[0]); for (var i = 1; i < editor.targets.Length; i++) { if (sha != Locker.GetAssetUnlockCommitShaShort(editor.targets[1])) { hasMultipleUnlockShas = true; break; } } if (!string.IsNullOrEmpty(sha)) { if (hasMultipleUnlockShas) { EditorGUILayout.LabelField("(Unlocked at multiple commits)"); } else { EditorGUILayout.LabelField("(Unlocked at commit " + sha + ")"); } } } } } }