static void SceneViewUpdate(SceneView sceneView) { EditorUpdate(); if (!shouldDraw) { return; } if (Event.current.type == EventType.Layout) { string assetPath = selectionPath; VCUtility.RequestStatus(assetPath, VCSettings.HierarchyReflectionMode); vcSceneStatus = VCCommands.Instance.GetAssetStatus(assetPath); validActions = VCGUIControls.GetValidActions(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, 800, 100); Handles.BeginGUI(); GUILayout.BeginArea(new Rect(0, 0, rect.width, rect.height)); GUILayout.BeginHorizontal(); GUILayout.TextField(AssetStatusUtils.GetLockStatusMessage(vcSceneStatus), backgroundGuiStyle); GUILayout.Label(selectionPath.Substring(selectionPath.LastIndexOf('/') + 1)); GUILayout.EndHorizontal(); int numberOfButtons = 0; const int maxButtons = 4; 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[] { selectionPath })); } } if (validActions.showOpen) { numberOfButtons++; if (GUILayout.Button(Terminology.getlock, buttonStyle)) { VCCommands.Instance.GetLockTask(new[] { selectionPath }); } } if (validActions.showCommit) { numberOfButtons++; if (GUILayout.Button(Terminology.commit, buttonStyle)) { OnNextUpdate.Do(() => VCCommands.Instance.CommitDialog(new[] { selectionPath })); } } if (validActions.showRevert) { numberOfButtons++; if (GUILayout.Button(new GUIContent(Terminology.revert, "Shift-click to " + Terminology.revert + " without confirmation"), buttonStyle)) { var sceneAssetPath = new[] { selectionPath }; if (Event.current.shift || VCUtility.VCDialog(Terminology.revert, sceneAssetPath)) { VCCommands.Instance.Revert(sceneAssetPath); } } } if (validActions.showOpenLocal) { numberOfButtons++; if (GUILayout.Button(Terminology.allowLocalEdit, buttonStyle)) { VCCommands.Instance.AllowLocalEdit(new[] { selectionPath }); } } if (validActions.showUnlock) { numberOfButtons++; if (GUILayout.Button(Terminology.unlock, buttonStyle)) { OnNextUpdate.Do(() => VCCommands.Instance.ReleaseLock(new[] { selectionPath })); } } if (validActions.showForceOpen) { numberOfButtons++; if (GUILayout.Button("Force Open", buttonStyle)) { OnNextUpdate.Do(() => VCUtility.GetLock(selectionPath, 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 SceneViewUpdate(SceneView sceneView) { using (sceneviewUpdateMarker.Auto()) { InitializeIfNeeded(); if (!shouldDraw) { return; } // This optimization is causing problems for following sceneview GUI, so removed for now. //if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDrag) // return; var stateRect = new Rect(2f, 2f, buttonWidth, buttonHeight); var selectionRect = new Rect(2f + buttonWidth, 1f, 700f, buttonHeight); var buttonRect = new Rect(2f, 2f, buttonWidth, buttonHeight); Handles.BeginGUI(); GUI.TextField(stateRect, AssetStatusUtils.GetStatusText(vcSceneStatus), backgroundGuiStyle); GUI.Label(selectionRect, selectionPath.Substring(selectionPath.LastIndexOf('/') + 1), EditorStyles.miniLabel); int numberOfButtons = 0; const int maxButtons = 4; using (new PushState <bool>(GUI.enabled, VCCommands.Instance.Ready, v => GUI.enabled = v)) { if ((validActions & ValidActions.Add) != 0) { buttonRect.y += buttonHeight; numberOfButtons++; if (GUI.Button(buttonRect, addContent, buttonStyle)) { SceneManagerUtilities.SaveActiveScene(); OnNextUpdate.Do(() => VCCommands.Instance.CommitDialog(new[] { selectionPath })); } } if ((validActions & ValidActions.Open) != 0) { buttonRect.y += buttonHeight; numberOfButtons++; if (GUI.Button(buttonRect, getLockContent, buttonStyle)) { VCCommands.Instance.GetLockTask(new[] { selectionPath }); } } if ((validActions & ValidActions.Commit) != 0) { buttonRect.y += buttonHeight; numberOfButtons++; if (GUI.Button(buttonRect, commitContent, buttonStyle)) { OnNextUpdate.Do(() => VCCommands.Instance.CommitDialog(new[] { selectionPath })); } } if ((validActions & ValidActions.Revert) != 0) { buttonRect.y += buttonHeight; numberOfButtons++; if (GUI.Button(buttonRect, revertContent, buttonStyle)) { var sceneAssetPath = new[] { selectionPath }; if (Event.current.shift || VCUtility.VCDialog(Terminology.revert, sceneAssetPath)) { VCCommands.Instance.Revert(sceneAssetPath); } } } if ((validActions & ValidActions.OpenLocal) != 0) { buttonRect.y += buttonHeight; numberOfButtons++; if (GUI.Button(buttonRect, allowLocalEditContent, buttonStyle)) { VCCommands.Instance.AllowLocalEdit(new[] { selectionPath }); } } if ((validActions & ValidActions.Unlock) != 0) { buttonRect.y += buttonHeight; numberOfButtons++; if (GUI.Button(buttonRect, unlockContent, buttonStyle)) { OnNextUpdate.Do(() => VCCommands.Instance.ReleaseLock(new[] { selectionPath })); } } // 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); } } } Handles.EndGUI(); } }
static bool drawButtons(string _strAssetPath) { var validActions = VCGUIControls.GetValidActions(_strAssetPath); int numberOfButtons = 0; const int maxButtons = 5; bool bNeedsRepaint = false; using (new PushState <bool>(GUI.enabled, VCCommands.Instance.Ready, v => GUI.enabled = v)) { numberOfButtons++; if (GUILayout.Button("Refresh", buttonStyle)) { Refresh(_strAssetPath); } if (validActions.showAdd) { numberOfButtons++; if (GUILayout.Button(Terminology.add, buttonStyle)) { bNeedsRepaint = true; SceneManagerUtilities.SaveActiveScene(); OnNextUpdate.Do(() => VCCommands.Instance.CommitDialog(new[] { _strAssetPath })); } } if (validActions.showOpen) { numberOfButtons++; if (GUILayout.Button(Terminology.getlock, buttonStyle)) { bNeedsRepaint = true; Refresh(_strAssetPath); if (!validActions.showOpen) { EditorUtility.DisplayDialog("Cannot open Scene!", "This scene has been opened by another user since the last refresh.", "Ok"); } else { VCCommands.Instance.GetLockTask(new[] { _strAssetPath }); } } } if (validActions.showCommit) { numberOfButtons++; if (GUILayout.Button(Terminology.commit, buttonStyle)) { bNeedsRepaint = true; OnNextUpdate.Do(() => VCCommands.Instance.CommitDialog(new[] { _strAssetPath })); } } if (validActions.showRevert) { numberOfButtons++; if (GUILayout.Button(new GUIContent(Terminology.revert, "Shift-click to " + Terminology.revert + " without confirmation"), buttonStyle)) { bNeedsRepaint = true; var assetPath = new[] { _strAssetPath }; if (Event.current.shift || VCUtility.VCDialog(Terminology.revert, assetPath)) { VCCommands.Instance.Revert(assetPath); OnNextUpdate.Do(AssetDatabase.Refresh); } } } if (validActions.showOpenLocal) { numberOfButtons++; if (GUILayout.Button(Terminology.allowLocalEdit, buttonStyle)) { bNeedsRepaint = true; VCCommands.Instance.AllowLocalEdit(new[] { _strAssetPath }); } } if (validActions.showUnlock) { numberOfButtons++; if (GUILayout.Button(Terminology.unlock, buttonStyle)) { bNeedsRepaint = true; OnNextUpdate.Do(() => VCCommands.Instance.ReleaseLock(new[] { _strAssetPath })); } } if (validActions.showForceOpen) { numberOfButtons++; if (GUILayout.Button("Force Open", buttonStyle)) { bNeedsRepaint = true; OnNextUpdate.Do(() => VCUtility.GetLock(_strAssetPath, 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); } } } return(bNeedsRepaint); }