Пример #1
0
        void DoOnePreset(Rect rect, int index, ref bool even)
        {
            bool apply;
            bool removeChanged;
            var  presetName = m_PresetNames[index];

            DoPresetEntry(rect, presetName, even, out apply, out removeChanged);
            if (apply)
            {
                Close();
                if (MeshImporterWindow.Instance != null)
                {
                    MeshImporterWindow.Instance.ApplyVertexAttributeMappingPreset(VertexAttributeMapping.ReadPreset(presetName));
                }
                GUIUtility.ExitGUI();
            }
            if (removeChanged)
            {
                if (EditorUtility.DisplayDialog("Delete Preset", $"Do you want to delete preset \"{presetName}\"", "Yes", "No"))
                {
                    VertexAttributeMapping.DeletePreset(presetName);
                }
                Close();
                GUIUtility.ExitGUI();
            }
            even = !even;
        }
        void OnGUI()
        {
            GUILayout.Space(5);
            Event evt      = Event.current;
            bool  hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter);

            GUI.SetNextControlName("m_PreferencesName");
            EditorGUI.BeginChangeCheck();
            s_TargetName = EditorGUILayout.TextField(s_TargetName);
            s_TargetName = s_TargetName.TrimEnd();
            if (EditorGUI.EndChangeCheck())
            {
                UpdateCurrentInvalidChars();
            }

            if (!m_DidFocus)
            {
                m_DidFocus = true;
                EditorGUI.FocusTextInControl("m_PreferencesName");
            }

            if (s_CurrentInvalidChars.Length != 0)
            {
                EditorGUILayout.HelpBox(string.Format(s_InvalidCharsFormatString, s_CurrentInvalidChars), MessageType.Warning);
                minSize = new Vector2(k_Width, k_Height + k_HelpBoxHeight);
            }
            else
            {
                minSize = new Vector2(k_Width, k_Height);
            }

            bool canSaveLayout = s_TargetName.Length > 0 && s_CurrentInvalidChars.Length == 0;

            EditorGUI.BeginDisabledGroup(!canSaveLayout);

            if (GUILayout.Button("Save") || hitEnter && canSaveLayout)
            {
                Close();

                VertexAttributeMapping.SavePreset(s_TargetPreset, s_TargetName);
                GUIUtility.ExitGUI();
            }
            else
            {
                m_DidFocus = false;
            }

            EditorGUI.EndDisabledGroup();
        }
        public static VertexAttributeMappingPreset ReadPreset(string name)
        {
            string path = VertexAttributeMapping.GetPresetFullPath(name);

            if (System.IO.File.Exists(path))
            {
                var json = System.IO.File.ReadAllText(path);
                if (!string.IsNullOrEmpty(json))
                {
                    VertexAttributeMappingPreset preset = new VertexAttributeMappingPreset();
                    EditorJsonUtility.FromJsonOverwrite(json, preset);
                    return(preset);
                }
            }
            return(null);
        }
Пример #4
0
        private void Init(Rect buttonRect)
        {
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            // Has to be done before calling Show / ShowWithMode
            buttonRect = GUIUtility.GUIToScreenRect(buttonRect);

            m_PresetNames.Clear();
            VertexAttributeMapping.GetAllPresetNames(m_PresetNames);

            var   toggleSize = s_Styles.statusIcon.CalcSize(s_Styles.trash);
            float widthMax   = 0.0f;

            for (int i = 0; i < m_PresetNames.Count; ++i)
            {
                var size = s_Styles.menuItem.CalcSize(EditorGUIUtility.TrTempContent(m_PresetNames[i]));
                widthMax = Mathf.Max(widthMax, size.x + toggleSize.x);
            }
            {
                var size = s_Styles.menuItem.CalcSize(s_Styles.saveCurrentToPreset);
                widthMax = Mathf.Max(widthMax, size.x);
            }
            {
                var size = s_Styles.menuItem.CalcSize(s_Styles.revealSavePreset);
                widthMax = Mathf.Max(widthMax, size.x);
            }
            widthMax = Mathf.Min(widthMax, 400f);

            // БъЬт
            var rowCount = (m_PresetNames.Count + 1 + 1 + 1);

            var windowHeight = rowCount * EditorGUIUtility.singleLineHeight + kSeparatorHeight;

            m_ContentHeight = windowHeight;
            windowHeight   += 2 * kFrameWidth;
            windowHeight    = Mathf.Min(windowHeight, 600);

            var windowSize = new Vector2(widthMax, windowHeight);

            ShowAsDropDown(buttonRect, windowSize);
        }
        public static void SavePreset(VertexAttributeMappingPreset preset, string name)
        {
            if (preset == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(name))
            {
                return;
            }
            if (!System.IO.Directory.Exists(VertexAttributeMapping.preferencesPath))
            {
                System.IO.Directory.CreateDirectory(VertexAttributeMapping.preferencesPath);
            }

            string path = VertexAttributeMapping.GetPresetFullPath(name);

            var json = EditorJsonUtility.ToJson(preset, true);

            System.IO.File.WriteAllText(path, json);
        }