Beispiel #1
0
        private static void HierarchyWindowListElementOnGUI(int instanceID, Rect selectionRect)
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode || !VCSettings.HierarchyIcons || !VCCommands.Active)
            {
                return;
            }
            var obj = EditorUtility.InstanceIDToObject(instanceID);

            if (obj == null)
            {
                string sceneAssetPath = SceneManagerUtilities.GetSceneAssetPathFromHandle(instanceID);
                if (!string.IsNullOrEmpty(sceneAssetPath))
                {
                    VCUtility.RequestStatus(sceneAssetPath, VCSettings.HierarchyReflectionMode);
                    DrawIcon(selectionRect, IconUtils.rubyIcon, sceneAssetPath, null, -20f);
                }
            }
            else
            {
                var    objectIndirection = ObjectUtilities.GetObjectIndirection(obj);
                string sceneAssetPath    = ObjectUtilities.ObjectToAssetPath(obj, false);
                //DrawIcon(selectionRect, IconUtils.childIcon, sceneAssetPath, null, -20f);

                if (ObjectUtilities.ChangesStoredInPrefab(obj) && VCSettings.PrefabGUI)
                {
                    string prefabPath = obj.GetAssetPath();
                    VCUtility.RequestStatus(prefabPath, VCSettings.HierarchyReflectionMode);
                    DrawIcon(selectionRect, IconUtils.squareIcon, prefabPath, objectIndirection);
                }
            }
        }
        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 (changesStoredInPrefab && guiLockForPrefabs)
            {
                VCUtility.RequestStatus(assetPath, VCSettings.HierarchyReflectionMode);
                DrawIcon(selectionRect, GetHierarchyIcon(obj), assetPath, objectIndirection);
            }
        }
Beispiel #3
0
        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.."));
                }
            }
        }
Beispiel #4
0
        private static void HierarchyWindowListElementOnGUI(int instanceID, Rect selectionRect)
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode || !VCSettings.HierarchyIcons || !VCCommands.Active)
            {
                return;
            }
            var obj = EditorUtility.InstanceIDToObject(instanceID);

            if (obj == null)
            {
                string sceneAssetPath = SceneManagerUtilities.GetSceneAssetPathFromHandle(instanceID);
                if (!string.IsNullOrEmpty(sceneAssetPath))
                {
                    VCUtility.RequestStatus(sceneAssetPath, VCSettings.HierarchyReflectionMode);
                    DrawIcon(selectionRect, IconUtils.rubyIcon, sceneAssetPath, null, -20f);
                }
            }
            else
            {
                var currentPrefabStage = PrefabStageUtility.GetCurrentPrefabStage();
                if (currentPrefabStage != null)
                {
                    var go = obj as GameObject;
                    if (go)
                    {
                        if (PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot == go)
                        {
                            DrawIcon(selectionRect, IconUtils.squareIcon, PrefabStageUtility.GetCurrentPrefabStage().prefabAssetPath, PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot, 0f);
                        }
                    }
                }
            }
        }
        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 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();
        }
Beispiel #7
0
 static void EditorUpdate()
 {
     shouldDraw = VCSettings.SceneviewGUI && VCCommands.Active && VCUtility.ValidAssetPath(SceneManagerUtilities.GetCurrentScenePath());
 }
Beispiel #8
0
 static void Refresh()
 {
     VCUtility.RequestStatus(SceneManagerUtilities.GetCurrentScenePath(), VCSettings.HierarchyReflectionMode);
     SceneView.RepaintAll();
 }
Beispiel #9
0
        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);
        }
        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.."));
                }
            }
        }