Exemplo n.º 1
0
        public static void VersionControlStatusGUI(GUIStyle style, VersionControlStatus assetStatus, Object obj, bool showAddCommit, bool showLockAndAllowLocalEdit, bool showRevert, bool confirmRevert = false)
        {
            using (new PushState <bool>(GUI.enabled, VCCommands.Instance.Ready, v => GUI.enabled = v))
            {
                if (assetStatus.lockStatus == VCLockStatus.LockedHere || assetStatus.ModifiedOrLocalEditAllowed() || !VCUtility.ManagedByRepository(assetStatus))
                {
                    if (!assetStatus.ModifiedOrLocalEditAllowed() && obj.GetAssetPath() != "" && showAddCommit)
                    {
                        if (GUILayout.Button((VCUtility.ManagedByRepository(assetStatus) ? Terminology.commit : Terminology.add), GetPrefabToolbarStyle(style, true)))
                        {
                            VCUtility.ApplyAndCommit(obj, Terminology.commit + " from Inspector");
                        }
                    }
                }

                if (!VCUtility.HaveVCLock(assetStatus) && VCUtility.ManagedByRepository(assetStatus) && showLockAndAllowLocalEdit)
                {
                    if (assetStatus.fileStatus == VCFileStatus.Added)
                    {
                        if (GUILayout.Button(Terminology.commit, GetPrefabToolbarStyle(style, true)))
                        {
                            VCUtility.ApplyAndCommit(obj, Terminology.commit + " from Inspector");
                        }
                    }
                    else if (assetStatus.lockStatus != VCLockStatus.LockedOther)
                    {
                        if (GUILayout.Button(Terminology.getlock, GetPrefabToolbarStyle(style, true)))
                        {
                            VCCommands.Instance.GetLockTask(obj.ToAssetPaths());
                        }
                    }
                    if (!assetStatus.LocalEditAllowed())
                    {
                        if (GUILayout.Button(Terminology.allowLocalEdit, GetPrefabToolbarStyle(style, true)))
                        {
                            VCCommands.Instance.AllowLocalEdit(obj.ToAssetPaths());
                        }
                    }
                }

                if (showRevert)
                {
                    if (GUILayout.Button(Terminology.revert, GetPrefabToolbarStyle(style, VCUtility.ShouldVCRevert(obj))))
                    {
                        if ((!confirmRevert || Event.current.shift) || VCUtility.VCDialog(Terminology.revert, obj))
                        {
                            var seletedGo   = Selection.activeGameObject;
                            var revertedObj = VCUtility.Revert(obj);
                            OnNextUpdate.Do(() => Selection.activeObject = ((obj is GameObject) ? revertedObj : seletedGo));
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        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();
        }
        private static void SubscribeToInspector(Object[] targets)
        {
            if (!VCCommands.Active || !VCSettings.MaterialGUI || targets.Length == 0)
            {
                return;
            }

            var renderer        = targets[0] as Renderer;
            var sharedMaterials = renderer.sharedMaterials;

            for (int i = 0; i < renderer.sharedMaterials.Length; ++i)
            {
                if (renderer.sharedMaterials[i] == null)
                {
                    continue;
                }
                var      material        = sharedMaterials[i];
                string   assetPath       = material.GetAssetPath();
                GUIStyle buttonStyle     = EditorStyles.toolbarButton;
                bool     builtinMaterial = EditableManager.IsBuiltinAsset(assetPath);
                var      assetStatus     = VCCommands.Instance.GetAssetStatus(assetPath);

                EditorGUILayout.BeginVertical(VCGUIControls.GetVCBox(assetStatus));
                string lockDescription     = builtinMaterial ? "" : AssetStatusUtils.GetLockStatusMessage(assetStatus);
                string materialDescription = "[" + (builtinMaterial ? "Unity Default" : material.name) + "] " + lockDescription;
                GUILayout.Label(new GUIContent(materialDescription, assetPath), VCGUIControls.GetLockStatusStyle());

                EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (GUILayout.Button(new GUIContent("Save as", "This will open a save dialog"), buttonStyle))
                {
                    int    index = i;
                    string savePath;
                    string fileName = "";
                    if (assetPath == "")
                    {
                        savePath = "Assets/Graphics/SavedMaterials/";
                    }
                    else
                    {
                        savePath = Path.GetDirectoryName(assetPath).Replace("\\", "/");
                        fileName = Path.GetFileNameWithoutExtension(assetPath);
                    }

                    OnNextUpdate.Do(() =>
                    {
                        string newMaterialName = EditorUtility.SaveFilePanel("Save Material as...", savePath, fileName, "mat");
                        newMaterialName        = newMaterialName.Substring(newMaterialName.IndexOf("/Assets/", System.StringComparison.Ordinal) + 1);
                        if (newMaterialName != "")
                        {
                            sharedMaterials[index]   = SaveMaterial(material, newMaterialName);
                            renderer.sharedMaterials = sharedMaterials;
                        }
                    });
                }

                var validActions = VCGUIControls.GetValidActions(assetPath, material);

                VCGUIControls.VersionControlStatusGUI(
                    style:                      buttonStyle,
                    assetStatus:                assetStatus, obj: material,
                    showAddCommit:              !builtinMaterial && (validActions & (ValidActions.Add | ValidActions.Commit)) != 0,
                    showLockAndAllowLocalEdit:  !builtinMaterial && (validActions & (ValidActions.OpenLocal | ValidActions.Open)) != 0,
                    showRevert:                 !builtinMaterial && (validActions & ValidActions.Revert) != 0
                    );

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
        }
Exemplo n.º 5
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);
        }