From 7ce77b5d3b19e4ba252ce812b171b472c86af2ee Mon Sep 17 00:00:00 2001 From: lilxyzw Date: Thu, 19 Aug 2021 16:06:44 +0900 Subject: [PATCH] fix upm & hdr colorpicker --- .../lilFurGenerator/Editor/lilFurGenerator.cs | 16 ++++++------ .../Editor/lilFurGeneratorInspector.cs | 26 +++++++++---------- .../Editor/lilFurGeneratorPropertyDrawer.cs | 23 ++++++++++++++++ 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/Assets/lilFurGenerator/Editor/lilFurGenerator.cs b/Assets/lilFurGenerator/Editor/lilFurGenerator.cs index 7fc4049..cbe3346 100644 --- a/Assets/lilFurGenerator/Editor/lilFurGenerator.cs +++ b/Assets/lilFurGenerator/Editor/lilFurGenerator.cs @@ -72,21 +72,21 @@ void OnGUI() GUIStyle customBox = GUI.skin.box; GUIStyle customToggleFont = EditorStyles.label; GUIStyle offsetButton = new GUIStyle(GUI.skin.button); - string mainFolderPath = GetMainFolderPath(); + string editorFolderPath = GetEditorFolderPath(); if(EditorGUIUtility.isProSkin) { - boxOuter = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_outer_2019.guiskin", typeof(GUISkin))).box); - boxInnerHalf = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_inner_half_2019.guiskin", typeof(GUISkin))).box); - boxInner = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_inner_2019.guiskin", typeof(GUISkin))).box); - customBox = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_custom_box_2019.guiskin", typeof(GUISkin))).box); + boxOuter = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_outer_2019.guiskin", typeof(GUISkin))).box); + boxInnerHalf = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_inner_half_2019.guiskin", typeof(GUISkin))).box); + boxInner = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_inner_2019.guiskin", typeof(GUISkin))).box); + customBox = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_custom_box_2019.guiskin", typeof(GUISkin))).box); customToggleFont = EditorStyles.label; offsetButton.margin.left = 24; } else { - boxOuter = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_outer_2018.guiskin", typeof(GUISkin))).box); - boxInnerHalf = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_inner_half_2018.guiskin", typeof(GUISkin))).box); - boxInner = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_inner_2018.guiskin", typeof(GUISkin))).box); + boxOuter = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_outer_2018.guiskin", typeof(GUISkin))).box); + boxInnerHalf = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_inner_half_2018.guiskin", typeof(GUISkin))).box); + boxInner = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_inner_2018.guiskin", typeof(GUISkin))).box); customBox = GUI.skin.box; customToggleFont = new GUIStyle(); customToggleFont.normal.textColor = Color.white; diff --git a/Assets/lilFurGenerator/Editor/lilFurGeneratorInspector.cs b/Assets/lilFurGenerator/Editor/lilFurGeneratorInspector.cs index a208c4f..48eac47 100644 --- a/Assets/lilFurGenerator/Editor/lilFurGeneratorInspector.cs +++ b/Assets/lilFurGenerator/Editor/lilFurGeneratorInspector.cs @@ -27,17 +27,17 @@ public enum lilRenderPipeline public const string boothURL = "https://lilxyzw.booth.pm/"; public const string githubURL = "https://github.com/lilxyzw/lilFurGenerator"; public const string versionInfoURL = "https://raw.githubusercontent.com/lilxyzw/lilFurGenerator/master/version.json"; - public const string mainFolderGUID = "edc3c051bb926d146b24e1b52d6615a5"; // "Assets/lilFurGenerator" + public const string editorFolderGUID = "59970fc0d266132478e5327940963258"; // "Assets/lilFurGenerator/Editor" public const string languageFileGUID = "31b8eeba6110d59439de5782850a4574"; // "Assets/lilFurGenerator/Editor/lang.txt" - public const string fgShaderGUID = "2c540356c3ded7340b263ceb4ace7e37"; // "Assets/lilFurGenerator/Shader/lilFurGenerator.shader" - public const string hqfgShaderGUID = "7fc1943976840044e82d0503f1f70d23"; // "Assets/lilFurGenerator/Shader/lilFurGenerator.shader" + public const string fgShaderGUID = "2c540356c3ded7340b263ceb4ace7e37"; // "Assets/lilFurGenerator/Shader/lilFurGenerator.shader" + public const string hqfgShaderGUID = "7fc1943976840044e82d0503f1f70d23"; // "Assets/lilFurGenerator/Shader/lilFurGenerator.shader" public const string editorSettingTempPath = "Temp/lilFurGeneratorEditorSetting"; public const string versionInfoTempPath = "Temp/lilFurGeneratorVersion"; public const string windowName = "lilFurGenerator"; - public static string GetMainFolderPath() + public static string GetEditorFolderPath() { - return AssetDatabase.GUIDToAssetPath(mainFolderGUID); + return AssetDatabase.GUIDToAssetPath(editorFolderGUID); } public static readonly Vector2 defaultTextureOffset = new Vector2(0.0f,0.0f); @@ -170,21 +170,21 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro GUIStyle customBox = GUI.skin.box; GUIStyle customToggleFont = EditorStyles.label; GUIStyle offsetButton = new GUIStyle(GUI.skin.button); - string mainFolderPath = GetMainFolderPath(); + string editorFolderPath = GetEditorFolderPath(); if(EditorGUIUtility.isProSkin) { - boxOuter = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_outer_2019.guiskin", typeof(GUISkin))).box); - boxInnerHalf = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_inner_half_2019.guiskin", typeof(GUISkin))).box); - boxInner = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_inner_2019.guiskin", typeof(GUISkin))).box); - customBox = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_custom_box_2019.guiskin", typeof(GUISkin))).box); + boxOuter = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_outer_2019.guiskin", typeof(GUISkin))).box); + boxInnerHalf = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_inner_half_2019.guiskin", typeof(GUISkin))).box); + boxInner = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_inner_2019.guiskin", typeof(GUISkin))).box); + customBox = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_custom_box_2019.guiskin", typeof(GUISkin))).box); customToggleFont = EditorStyles.label; offsetButton.margin.left = 24; } else { - boxOuter = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_outer_2018.guiskin", typeof(GUISkin))).box); - boxInnerHalf = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_inner_half_2018.guiskin", typeof(GUISkin))).box); - boxInner = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(mainFolderPath + "/Editor/gui_box_inner_2018.guiskin", typeof(GUISkin))).box); + boxOuter = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_outer_2018.guiskin", typeof(GUISkin))).box); + boxInnerHalf = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_inner_half_2018.guiskin", typeof(GUISkin))).box); + boxInner = new GUIStyle(((GUISkin)AssetDatabase.LoadAssetAtPath(editorFolderPath + "/gui_box_inner_2018.guiskin", typeof(GUISkin))).box); customBox = GUI.skin.box; customToggleFont = new GUIStyle(); customToggleFont.normal.textColor = Color.white; diff --git a/Assets/lilFurGenerator/Editor/lilFurGeneratorPropertyDrawer.cs b/Assets/lilFurGenerator/Editor/lilFurGeneratorPropertyDrawer.cs index 978e8cd..2ecd1a4 100644 --- a/Assets/lilFurGenerator/Editor/lilFurGeneratorPropertyDrawer.cs +++ b/Assets/lilFurGenerator/Editor/lilFurGeneratorPropertyDrawer.cs @@ -15,6 +15,8 @@ public class lilHDRDrawer : MaterialPropertyDrawer // [lilHDR] public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor editor) { + float xMax = position.xMax; + position.width = Mathf.Min(position.width, EditorGUIUtility.labelWidth + EditorGUIUtility.fieldWidth); Color value = prop.colorValue; EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; @@ -29,6 +31,27 @@ public override void OnGUI(Rect position, MaterialProperty prop, String label, M { prop.colorValue = value; } + + #if UNITY_2019_1_OR_NEWER + // Hex + EditorGUI.BeginChangeCheck(); + EditorGUI.showMixedValue = prop.hasMixedValue; + float intensity = value.maxColorComponent > 1.0f ? value.maxColorComponent : 1.0f; + Color value2 = new Color(value.r / intensity, value.g / intensity, value.b / intensity, 1.0f); + string hex = ColorUtility.ToHtmlStringRGB(value2); + position.x += position.width + 4.0f; + position.width = Mathf.Max(50.0f, xMax - position.x); + hex = "#" + EditorGUI.TextField(position, GUIContent.none, hex); + if(EditorGUI.EndChangeCheck()) + { + if(!ColorUtility.TryParseHtmlString(hex, out value2)) return; + value.r = value2.r * intensity; + value.g = value2.g * intensity; + value.b = value2.b * intensity; + prop.colorValue = value; + } + EditorGUI.showMixedValue = false; + #endif } }