public static void CreateVCContextMenu(ref GenericMenu menu, string assetPath, Object instance = null) { if (VCUtility.ValidAssetPath(assetPath)) { bool ready = VCCommands.Instance.Ready; if (ready) { if (instance && ObjectUtilities.ChangesStoredInScene(instance)) { assetPath = SceneManagerUtilities.GetCurrentScenePath(); } var validActions = GetValidActions(assetPath, instance); if (validActions.showDiff) { menu.AddItem(new GUIContent(Terminology.diff), false, () => VCUtility.DiffWithBase(assetPath)); } if (validActions.showAdd) { menu.AddItem(new GUIContent(Terminology.add), false, () => VCCommands.Instance.Add(new[] { assetPath })); } if (validActions.showOpen) { menu.AddItem(new GUIContent(Terminology.getlock), false, () => GetLock(assetPath, instance)); } if (validActions.showOpenLocal) { menu.AddItem(new GUIContent(Terminology.allowLocalEdit), false, () => AllowLocalEdit(assetPath, instance)); } if (validActions.showForceOpen) { menu.AddItem(new GUIContent("Force " + Terminology.getlock), false, () => GetLock(assetPath, instance, OperationMode.Force)); } if (validActions.showCommit) { menu.AddItem(new GUIContent(Terminology.commit), false, () => Commit(assetPath, instance)); } if (validActions.showUnlock) { menu.AddItem(new GUIContent(Terminology.unlock), false, () => VCCommands.Instance.ReleaseLock(new[] { assetPath })); } if (validActions.showDisconnect) { menu.AddItem(new GUIContent("Disconnect"), false, () => PrefabHelper.DisconnectPrefab(instance as GameObject)); } if (validActions.showDelete) { menu.AddItem(new GUIContent(Terminology.delete), false, () => VCCommands.Instance.Delete(new[] { assetPath })); } if (validActions.showRevert) { menu.AddItem(new GUIContent(Terminology.revert), false, () => Revert(assetPath, instance)); } } else { menu.AddDisabledItem(new GUIContent("..Busy..")); } } }
private static void HierarchyWindowListElementOnGUI(int instanceID, Rect selectionRect) { var obj = EditorUtility.InstanceIDToObject(instanceID); if (obj == null) { string sceneAssetPath = SceneManagerUtilities.GetSceneAssetPathFromHandle(instanceID); if (!string.IsNullOrEmpty(sceneAssetPath)) { MultiSceneHierarchyElement(sceneAssetPath, selectionRect); } return; } if (EditorApplication.isPlayingOrWillChangePlaymode || !VCSettings.HierarchyIcons || !VCCommands.Active) { return; } var objectIndirection = ObjectUtilities.GetObjectIndirection(obj); string assetPath = obj.GetAssetPath(); bool changesStoredInPrefab = ObjectUtilities.ChangesStoredInPrefab(obj); bool guiLockForPrefabs = VCSettings.PrefabGUI; if (assetPath != SceneManagerUtilities.GetCurrentScenePath() && (!changesStoredInPrefab || guiLockForPrefabs)) { VCUtility.RequestStatus(assetPath, VCSettings.HierarchyReflectionMode); DrawIcon(selectionRect, GetHierarchyIcon(obj), assetPath, objectIndirection); } }
static void SceneViewUpdate(SceneView sceneView) { if (!shouldDraw) { return; } string assetPath = SceneManagerUtilities.GetCurrentScenePath(); VCUtility.RequestStatus(assetPath, VCSettings.HierarchyReflectionMode); var vcSceneStatus = VCCommands.Instance.GetAssetStatus(assetPath); buttonStyle = new GUIStyle(EditorStyles.miniButton) { margin = new RectOffset(0, 0, 0, 0), fixedWidth = 80 }; backgroundGuiStyle = VCGUIControls.GetVCBox(vcSceneStatus); backgroundGuiStyle.padding = new RectOffset(4, 8, 1, 1); backgroundGuiStyle.margin = new RectOffset(1, 1, 1, 1); backgroundGuiStyle.border = new RectOffset(1, 1, 1, 1); backgroundGuiStyle.alignment = TextAnchor.MiddleCenter; var rect = new Rect(5, 5, 200, 100); Handles.BeginGUI(); GUILayout.BeginArea(new Rect(0, 0, rect.width, rect.height)); GUILayout.TextField(AssetStatusUtils.GetLockStatusMessage(vcSceneStatus), backgroundGuiStyle); int numberOfButtons = 0; const int maxButtons = 4; var validActions = VCGUIControls.GetValidActions(assetPath); using (GUILayoutHelper.Vertical()) { using (new PushState <bool>(GUI.enabled, VCCommands.Instance.Ready, v => GUI.enabled = v)) { if (validActions.showAdd) { numberOfButtons++; if (GUILayout.Button(Terminology.add, buttonStyle)) { SceneManagerUtilities.SaveActiveScene(); OnNextUpdate.Do(() => VCCommands.Instance.CommitDialog(new[] { SceneManagerUtilities.GetCurrentScenePath() })); } } if (validActions.showOpen) { numberOfButtons++; if (GUILayout.Button(Terminology.getlock, buttonStyle)) { VCCommands.Instance.GetLockTask(new[] { SceneManagerUtilities.GetCurrentScenePath() }); } } if (validActions.showCommit) { numberOfButtons++; if (GUILayout.Button(Terminology.commit, buttonStyle)) { OnNextUpdate.Do(() => VCCommands.Instance.CommitDialog(new[] { SceneManagerUtilities.GetCurrentScenePath() })); } } if (validActions.showRevert) { numberOfButtons++; if (GUILayout.Button(new GUIContent(Terminology.revert, "Shift-click to " + Terminology.revert + " without confirmation"), buttonStyle)) { var sceneAssetPath = new[] { SceneManagerUtilities.GetCurrentScenePath() }; if (Event.current.shift || VCUtility.VCDialog(Terminology.revert, sceneAssetPath)) { SceneManagerUtilities.SaveActiveScene(); VCCommands.Instance.Revert(sceneAssetPath); OnNextUpdate.Do(AssetDatabase.Refresh); } } } if (validActions.showOpenLocal) { numberOfButtons++; if (GUILayout.Button(Terminology.allowLocalEdit, buttonStyle)) { VCCommands.Instance.AllowLocalEdit(new[] { SceneManagerUtilities.GetCurrentScenePath() }); } } if (validActions.showUnlock) { numberOfButtons++; if (GUILayout.Button(Terminology.unlock, buttonStyle)) { OnNextUpdate.Do(() => VCCommands.Instance.ReleaseLock(new[] { SceneManagerUtilities.GetCurrentScenePath() })); } } if (validActions.showForceOpen) { numberOfButtons++; if (GUILayout.Button("Force Open", buttonStyle)) { OnNextUpdate.Do(() => VCUtility.GetLock(SceneManagerUtilities.GetCurrentScenePath(), OperationMode.Force)); } } // bug: Workaround for a bug in Unity to avoid Tools getting stuck when number of GUI elements change while right mouse is down. using (GUILayoutHelper.Enabled(false)) { for (int i = numberOfButtons; i <= maxButtons; ++i) { GUI.Button(new Rect(0, 0, 0, 0), "", EditorStyles.label); } } } } GUILayout.EndArea(); Handles.EndGUI(); }
static void EditorUpdate() { shouldDraw = VCSettings.SceneviewGUI && VCCommands.Active && VCUtility.ValidAssetPath(SceneManagerUtilities.GetCurrentScenePath()); }
static void Refresh() { VCUtility.RequestStatus(SceneManagerUtilities.GetCurrentScenePath(), VCSettings.HierarchyReflectionMode); SceneView.RepaintAll(); }
public static void CreateVCContextMenu(ref GenericMenu menu, string assetPath, Object instance = null) { if (VCUtility.ValidAssetPath(assetPath)) { bool ready = VCCommands.Instance.Ready; if (ready) { if (instance && ObjectUtilities.ChangesStoredInScene(instance)) { assetPath = SceneManagerUtilities.GetCurrentScenePath(); } var validActions = GetValidActions(assetPath, instance); if ((validActions & ValidActions.Diff) != 0) { menu.AddItem(new GUIContent(Terminology.diff), false, () => MergeHandler.DiffWithBase(assetPath)); } if ((validActions & ValidActions.Add) != 0) { menu.AddItem(new GUIContent(Terminology.add), false, () => VCCommands.Instance.Add(new[] { assetPath })); } if ((validActions & ValidActions.Open) != 0) { menu.AddItem(new GUIContent(Terminology.getlock), false, () => GetLock(assetPath, instance)); } if ((validActions & ValidActions.OpenLocal) != 0) { menu.AddItem(new GUIContent(Terminology.allowLocalEdit), false, () => AllowLocalEdit(assetPath, instance)); } if ((validActions & ValidActions.Commit) != 0) { menu.AddItem(new GUIContent(Terminology.commit), false, () => Commit(assetPath, instance)); } if ((validActions & ValidActions.Unlock) != 0) { menu.AddItem(new GUIContent(Terminology.unlock), false, () => VCCommands.Instance.ReleaseLock(new[] { assetPath })); } if ((validActions & ValidActions.Delete) != 0) { menu.AddItem(new GUIContent(Terminology.delete), false, () => VCCommands.Instance.Delete(new[] { assetPath })); } if ((validActions & ValidActions.Revert) != 0) { menu.AddItem(new GUIContent(Terminology.revert), false, () => Revert(assetPath, instance)); } if ((validActions & ValidActions.UseTheirs) != 0) { menu.AddItem(new GUIContent("Use Theirs"), false, () => VCCommands.Instance.Resolve(new [] { assetPath }, ConflictResolution.Theirs)); } if ((validActions & ValidActions.UseMine) != 0) { menu.AddItem(new GUIContent("Use Mine"), false, () => VCCommands.Instance.Resolve(new [] { assetPath }, ConflictResolution.Mine)); } if ((validActions & ValidActions.Merge) != 0) { menu.AddItem(new GUIContent("Merge"), false, () => MergeHandler.ResolveConflict(assetPath)); } if ((validActions & ValidActions.AddChangeList) != 0) { menu.AddItem(new GUIContent("Add To " + Terminology.changelist), false, () => ChangeListWindow.Open(new [] { assetPath })); } if ((validActions & ValidActions.RemoveChangeList) != 0) { menu.AddItem(new GUIContent("Remove From " + Terminology.changelist), false, () => VCCommands.Instance.ChangeListRemove(new [] { assetPath })); } } else { menu.AddDisabledItem(new GUIContent("..Busy..")); } } }