Пример #1
0
 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));
         }
     }
 }
        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();
        }