public override void OnInspectorGUI() { if (!m_initialized) { m_initialized = true; m_linkStyle = new GUIStyle(GUIStyle.none); m_linkStyle.alignment = TextAnchor.UpperCenter; m_lableStyle = new GUIStyle(GUI.skin.label); m_lableStyle.wordWrap = true; m_lableStyle.alignment = TextAnchor.MiddleLeft; m_defaultImage = AssetDatabase.LoadAssetAtPath <Texture2D>(AssetDatabase.GUIDToAssetPath("dd17fcfd0f1d6b540a22a6b89c9e8b06")); m_imageRatio = (float)m_defaultImage.height / (float)m_defaultImage.width; m_maxheight = m_defaultImage.height; m_textLink = new GUIStyle(GUI.skin.label); m_textLink.normal.textColor = Color.white; m_textLink.alignment = TextAnchor.MiddleCenter; m_textLink.fontSize = 9; } if (m_fetchedImage != null) { m_button.image = m_fetchedImage; m_imageRatio = (float)m_fetchedImage.height / (float)m_fetchedImage.width; m_maxheight = m_fetchedImage.height; } else { m_button.image = m_defaultImage; m_imageRatio = (float)m_defaultImage.height / (float)m_defaultImage.width; m_maxheight = m_defaultImage.height; if (!m_imageLoaded) { m_imageLoaded = true; EditorApplication.update += EditorUpdateFetchInfo; coroutine = StartRequest(m_jsonURL); } } EditorGUILayout.BeginVertical("ObjectFieldThumb"); { m_currheight = Mathf.Min(m_maxheight, (EditorGUIUtility.currentViewWidth - 30) * m_imageRatio); Rect buttonRect = EditorGUILayout.GetControlRect(false, m_currheight); EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link); if (GUI.Button(buttonRect, m_button, m_linkStyle)) { Help.BrowseURL(m_info.affiliateLink); } GUILayout.BeginHorizontal(); GUILayout.Label(m_info.message, m_lableStyle); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); if (GUILayout.Button("Learn More", GUILayout.Height(25))) { Help.BrowseURL(m_info.affiliateLink); } Color cache = GUI.color; GUI.color = EditorGUIUtility.isProSkin ? LinkColorInPro : LinkColorInPersonal; if (GUILayout.Button("Affiliate Link", m_textLink)) { AboutAffiliate.Init(); } GUI.color = cache; GUILayout.EndVertical(); GUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { if (!m_initialized) { m_initialized = true; m_linkStyle = new GUIStyle(GUIStyle.none); m_linkStyle.alignment = TextAnchor.UpperCenter; m_lableStyle = new GUIStyle(GUI.skin.label); m_lableStyle.wordWrap = true; m_lableStyle.alignment = TextAnchor.MiddleLeft; m_defaultImage = AssetDatabase.LoadAssetAtPath <Texture2D>(AssetDatabase.GUIDToAssetPath("19890ee0a82f7a643b9077407a6da3db")); m_imageRatio = (float)m_defaultImage.height / (float)m_defaultImage.width; m_maxheight = m_defaultImage.height; m_textLink = new GUIStyle(GUI.skin.label); m_textLink.normal.textColor = Color.white; m_textLink.alignment = TextAnchor.MiddleCenter; m_textLink.fontSize = 9; } m_materialEditor = materialEditor; Material material = materialEditor.target as Material; if (m_fetchedImage != null) { m_button.image = m_fetchedImage; m_imageRatio = (float)m_fetchedImage.height / (float)m_fetchedImage.width; m_maxheight = m_fetchedImage.height; } else { m_button.image = m_defaultImage; m_imageRatio = 0.31818f; m_maxheight = 140; if (!m_imageLoaded) { m_imageLoaded = true; EditorApplication.update += EditorUpdateFetchInfo; coroutine = StartRequest(m_jsonURL); } } EditorGUILayout.BeginVertical("ObjectFieldThumb"); { m_currheight = Mathf.Min(m_maxheight, (EditorGUIUtility.currentViewWidth - 30) * m_imageRatio); Rect buttonRect = EditorGUILayout.GetControlRect(false, m_currheight); EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link); if (GUI.Button(buttonRect, m_button, m_linkStyle)) { Help.BrowseURL(m_info.affiliateLink); } GUILayout.BeginHorizontal(); GUILayout.Label(m_info.message, m_lableStyle /*, GUILayout.MinHeight(40)*/); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); if (GUILayout.Button("Learn More", GUILayout.Height(25))) { Help.BrowseURL(m_info.affiliateLink); } Color cache = GUI.color; GUI.color = EditorGUIUtility.isProSkin ? LinkColorInPro : LinkColorInPersonal; if (GUILayout.Button("Affiliate Link", m_textLink)) { AboutAffiliate.Init(); } GUI.color = cache; GUILayout.EndVertical(); GUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); #if AMPLIFY_SHADER_EDITOR if (Event.current.type == EventType.Repaint && material.HasProperty(IOUtils.DefaultASEDirtyCheckId) && material.GetInt(IOUtils.DefaultASEDirtyCheckId) == 1) { material.SetInt(IOUtils.DefaultASEDirtyCheckId, 0); UIUtils.ForceUpdateFromMaterial(); #if !UNITY_5_5_OR_NEWER Event.current.Use(); #endif } if (GUILayout.Button("Open in Shader Editor")) { AmplifyShaderEditorWindow.LoadMaterialToASE(material); } GUILayout.BeginHorizontal(); { if (GUILayout.Button("Copy Values")) { Shader shader = material.shader; int propertyCount = UnityEditor.ShaderUtil.GetPropertyCount(shader); string allProperties = string.Empty; for (int i = 0; i < propertyCount; i++) { UnityEditor.ShaderUtil.ShaderPropertyType type = UnityEditor.ShaderUtil.GetPropertyType(shader, i); string name = UnityEditor.ShaderUtil.GetPropertyName(shader, i); string valueStr = string.Empty; switch (type) { case UnityEditor.ShaderUtil.ShaderPropertyType.Color: { Color value = material.GetColor(name); valueStr = value.r.ToString() + IOUtils.VECTOR_SEPARATOR + value.g.ToString() + IOUtils.VECTOR_SEPARATOR + value.b.ToString() + IOUtils.VECTOR_SEPARATOR + value.a.ToString(); } break; case UnityEditor.ShaderUtil.ShaderPropertyType.Vector: { Vector4 value = material.GetVector(name); valueStr = value.x.ToString() + IOUtils.VECTOR_SEPARATOR + value.y.ToString() + IOUtils.VECTOR_SEPARATOR + value.z.ToString() + IOUtils.VECTOR_SEPARATOR + value.w.ToString(); } break; case UnityEditor.ShaderUtil.ShaderPropertyType.Float: { float value = material.GetFloat(name); valueStr = value.ToString(); } break; case UnityEditor.ShaderUtil.ShaderPropertyType.Range: { float value = material.GetFloat(name); valueStr = value.ToString(); } break; case UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv: { Texture value = material.GetTexture(name); valueStr = AssetDatabase.GetAssetPath(value); } break; } allProperties += name + IOUtils.FIELD_SEPARATOR + type + IOUtils.FIELD_SEPARATOR + valueStr; if (i < (propertyCount - 1)) { allProperties += IOUtils.LINE_TERMINATOR; } } EditorPrefs.SetString(IOUtils.MAT_CLIPBOARD_ID, allProperties); } if (GUILayout.Button("Paste Values")) { string propertiesStr = EditorPrefs.GetString(IOUtils.MAT_CLIPBOARD_ID, string.Empty); if (!string.IsNullOrEmpty(propertiesStr)) { string[] propertyArr = propertiesStr.Split(IOUtils.LINE_TERMINATOR); bool validData = true; try { for (int i = 0; i < propertyArr.Length; i++) { string[] valuesArr = propertyArr[i].Split(IOUtils.FIELD_SEPARATOR); if (valuesArr.Length != 3) { Debug.LogWarning("Material clipboard data is corrupted"); validData = false; break; } else if (material.HasProperty(valuesArr[0])) { UnityEditor.ShaderUtil.ShaderPropertyType type = (UnityEditor.ShaderUtil.ShaderPropertyType)Enum.Parse(typeof(UnityEditor.ShaderUtil.ShaderPropertyType), valuesArr[1]); switch (type) { case UnityEditor.ShaderUtil.ShaderPropertyType.Color: { string[] colorVals = valuesArr[2].Split(IOUtils.VECTOR_SEPARATOR); if (colorVals.Length != 4) { Debug.LogWarning("Material clipboard data is corrupted"); validData = false; break; } else { material.SetColor(valuesArr[0], new Color(Convert.ToSingle(colorVals[0]), Convert.ToSingle(colorVals[1]), Convert.ToSingle(colorVals[2]), Convert.ToSingle(colorVals[3]))); } } break; case UnityEditor.ShaderUtil.ShaderPropertyType.Vector: { string[] vectorVals = valuesArr[2].Split(IOUtils.VECTOR_SEPARATOR); if (vectorVals.Length != 4) { Debug.LogWarning("Material clipboard data is corrupted"); validData = false; break; } else { material.SetVector(valuesArr[0], new Vector4(Convert.ToSingle(vectorVals[0]), Convert.ToSingle(vectorVals[1]), Convert.ToSingle(vectorVals[2]), Convert.ToSingle(vectorVals[3]))); } } break; case UnityEditor.ShaderUtil.ShaderPropertyType.Float: { material.SetFloat(valuesArr[0], Convert.ToSingle(valuesArr[2])); } break; case UnityEditor.ShaderUtil.ShaderPropertyType.Range: { material.SetFloat(valuesArr[0], Convert.ToSingle(valuesArr[2])); } break; case UnityEditor.ShaderUtil.ShaderPropertyType.TexEnv: { material.SetTexture(valuesArr[0], AssetDatabase.LoadAssetAtPath <Texture>(valuesArr[2])); } break; } } } } catch (Exception e) { Debug.LogException(e); validData = false; } if (validData) { materialEditor.PropertiesChanged(); UIUtils.CopyValuesFromMaterial(material); } else { EditorPrefs.SetString(IOUtils.MAT_CLIPBOARD_ID, string.Empty); } } } } GUILayout.EndHorizontal(); GUILayout.Space(5); #endif #if AMPLIFY_SHADER_EDITOR EditorGUI.BeginChangeCheck(); ShaderPropertiesGUI(material, properties); if (EditorGUI.EndChangeCheck()) { UIUtils.CopyValuesFromMaterial(material); } #else ShaderPropertiesGUI(material, properties); #endif }