static void EditorUpdate()
 {
     selectionPath = GetSelectionsPersistentAssetPath();
     shouldDraw    = VCSettings.SceneviewGUI && VCCommands.Active && VCUtility.ValidAssetPath(selectionPath);
     if (shouldDraw)
     {
         string assetPath = selectionPath;
         VCUtility.RequestStatus(assetPath, VCSettings.HierarchyReflectionMode);
         vcSceneStatus = VCCommands.Instance.GetAssetStatus(assetPath);
         validActions  = VCGUIControls.GetValidActions(assetPath);
         if (backgroundGuiStyle != null)
         {
             backgroundGuiStyle.normal.background = IconUtils.boxIcon.GetTexture(AssetStatusUtils.GetStatusColor(vcSceneStatus, true));
         }
     }
 }
 static void InitializeIfNeeded()
 {
     if (!initialized)
     {
         initialized = true;
         buttonStyle = new GUIStyle(EditorStyles.miniButton)
         {
             margin     = new RectOffset(0, 0, 0, 0),
             fixedWidth = buttonWidth,
             fontSize   = fontsize
         };
         backgroundGuiStyle           = VCGUIControls.GetVCBox(vcSceneStatus);
         backgroundGuiStyle.padding   = new RectOffset(4, 4, 1, 1);
         backgroundGuiStyle.margin    = new RectOffset(1, 1, 1, 1);
         backgroundGuiStyle.border    = new RectOffset(1, 1, 1, 1);
         backgroundGuiStyle.alignment = TextAnchor.MiddleCenter;
         backgroundGuiStyle.fontSize  = fontsize;
     }
 }
Example #3
0
 private static void DrawIcon(Rect rect, IconUtils.Icon iconType, string assetPath, Object instance = null, float xOffset = 0f)
 {
     if (VCSettings.VCEnabled)
     {
         var       assetStatus = VCCommands.Instance.GetAssetStatus(assetPath);
         string    statusText  = AssetStatusUtils.GetStatusText(assetStatus);
         Texture2D texture     = iconType.GetTexture(AssetStatusUtils.GetStatusColor(assetStatus, true));
         Rect      placement   = GetRightAligned(rect, iconType.Size);
         placement.x += xOffset;
         var clickRect = placement;
         //clickRect.xMax += iconType.Size * 0.25f;
         //clickRect.xMin -= rect.width * 0.15f;
         if (texture)
         {
             GUI.DrawTexture(placement, texture);
         }
         if (GUI.Button(clickRect, new GUIContent("", statusText), GUIStyle.none))
         {
             VCGUIControls.DiaplayVCContextMenu(assetPath, instance, 10.0f, -40.0f, true);
         }
     }
 }
        private void Initialize()
        {
            baseFilter = s => false;
            guiFilter  = s => true;

            columnSelection  = new MultiColumnState.Column(new GUIContent("[]"), data => new GUIContent(masterSelection.Contains(data) ? " ☑" : " ☐"));
            columnAssetPath  = new MultiColumnState.Column(new GUIContent("AssetPath"), data => new GUIContent(data.assetPath.Compose()));
            columnOwner      = new MultiColumnState.Column(new GUIContent("Owner"), data => new GUIContent(data.owner, data.lockToken));
            columnFileStatus = new MultiColumnState.Column(new GUIContent("Status"), GetFileStatusContent);
            columnMetaStatus = new MultiColumnState.Column(new GUIContent("Meta"), data => GetFileStatusContent(data.MetaStatus()));
            columnFileType   = new MultiColumnState.Column(new GUIContent("Type"), data => new GUIContent(GetFileType(data.assetPath.Compose())));
            columnConflict   = new MultiColumnState.Column(new GUIContent("Conflict"), data => new GUIContent(data.treeConflictStatus.ToString()));
            columnChangelist = new MultiColumnState.Column(new GUIContent("ChangeList"), data => new GUIContent(data.changelist.Compose()));

            var guiSkin = EditorGUIUtility.GetBuiltinSkin(EditorGUIUtility.isProSkin ? EditorSkin.Scene : EditorSkin.Inspector);

            multiColumnState = new MultiColumnState();

            multiColumnState.Comparer = (r1, r2, c) =>
            {
                var r1Text = c.GetContent(r1.data).text;
                var r2Text = c.GetContent(r2.data).text;
                if (r1Text == null)
                {
                    r1Text = "";
                }
                if (r2Text == null)
                {
                    r2Text = "";
                }
                //D.Log("Comparing: " + r1Text + " with " + r2Text + " : " + r1Text.CompareTo(r2Text));
                return(String.CompareOrdinal(r1Text, r2Text));
            };

            Func <GenericMenu> rowRightClickMenu = () =>
            {
                var selected = multiColumnState.GetSelected().Select(status => status.assetPath.Compose());
                if (!selected.Any())
                {
                    return(new GenericMenu());
                }
                GenericMenu menu = new GenericMenu();
                if (selected.Count() == 1)
                {
                    VCGUIControls.CreateVCContextMenu(ref menu, selected.First());
                }
                else
                {
                    VCGUIControls.CreateVCContextMenu(ref menu, selected);
                }
                var selectedObjs = selected.Select(a => AssetDatabase.LoadMainAssetAtPath(a)).ToArray();
                menu.AddSeparator("");
                menu.AddItem(new GUIContent("Show in Project"), false, () =>
                {
                    Selection.objects = selectedObjs;
                    EditorGUIUtility.PingObject(Selection.activeObject);
                });
                menu.AddItem(new GUIContent("Show on Harddisk"), false, () =>
                {
                    Selection.objects = selectedObjs;
                    EditorApplication.ExecuteMenuItem((Application.platform == RuntimePlatform.OSXEditor ? "Assets/Reveal in Finder" : "Assets/Show in Explorer"));
                });
                return(menu);
            };

            Func <MultiColumnState.Column, GenericMenu> headerRightClickMenu = column =>
            {
                var menu = new GenericMenu();
                //menu.AddItem(new GUIContent("Remove"), false, () => { ToggleColumn(column); });
                return(menu);
            };

            // Return value of true steals the click from normal selection, false does not.
            Func <MultiColumnState.Row, MultiColumnState.Column, bool> cellClickAction = (row, column) =>
            {
                GUI.FocusControl("");
                if (column == columnSelection)
                {
                    var currentSelection = multiColumnState.GetSelected();
                    if (currentSelection.Contains(row.data))
                    {
                        bool currentRowSelection = masterSelection.Contains(row.data);
                        foreach (var selectionIt in currentSelection)
                        {
                            if (currentRowSelection)
                            {
                                masterSelection.Remove(selectionIt);
                            }
                            else
                            {
                                masterSelection.Add(selectionIt);
                            }
                        }
                    }
                    else
                    {
                        if (masterSelection.Contains(row.data))
                        {
                            masterSelection.Remove(row.data);
                        }
                        else
                        {
                            masterSelection.Add(row.data);
                        }
                    }
                    return(true);
                }
                return(false);
                //D.Log(row.data.assetPath.Compose() + " : "  + column.GetContent(row.data).text);
            };

            options = new MultiColumnViewOption
            {
                headerStyle          = new GUIStyle(guiSkin.button),
                rowStyle             = new GUIStyle(guiSkin.label),
                rowRightClickMenu    = rowRightClickMenu,
                headerRightClickMenu = headerRightClickMenu,
                cellClickAction      = cellClickAction,
                widths            = new float[] { 200 },
                doubleClickAction = status =>
                {
                    if (VCUtility.IsDiffableAsset(status.assetPath) && VCUtility.ManagedByRepository(status) && status.fileStatus == VCFileStatus.Modified)
                    {
                        VCUtility.DiffWithBase(status.assetPath.Compose());
                    }
                    else
                    {
                        AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(status.assetPath.Compose()));
                    }
                }
            };

            options.headerStyle.fixedHeight      = 20.0f;
            options.rowStyle.onNormal.background = IconUtils.CreateSquareTexture(4, 1, new Color(0.24f, 0.5f, 0.87f, 0.75f));
            options.rowStyle.margin  = new RectOffset(2, 2, 2, 1);
            options.rowStyle.border  = new RectOffset(0, 0, 0, 0);
            options.rowStyle.padding = new RectOffset(0, 0, 0, 0);

            if (showMasterSelection)
            {
                multiColumnState.AddColumn(columnSelection);
                options.widthTable.Add(columnSelection.GetHeader().text, 25);
            }

            multiColumnState.AddColumn(columnAssetPath);
            options.widthTable.Add(columnAssetPath.GetHeader().text, 500);

            multiColumnState.AddColumn(columnFileStatus);
            options.widthTable.Add(columnFileStatus.GetHeader().text, 90);

            multiColumnState.AddColumn(columnMetaStatus);
            options.widthTable.Add(columnMetaStatus.GetHeader().text, 100);

            multiColumnState.AddColumn(columnFileType);
            options.widthTable.Add(columnFileType.GetHeader().text, 80);

            multiColumnState.AddColumn(columnOwner);
            options.widthTable.Add(columnOwner.GetHeader().text, 60);

            multiColumnState.AddColumn(columnChangelist);
            options.widthTable.Add(columnChangelist.GetHeader().text, 120);

            //columnConflictState.AddColumn(columnConflict);
            options.widthTable.Add(columnConflict.GetHeader().text, 80);
        }
        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();
            }
        }
        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();
        }