public void OnAfterDeserialize() { var obj = this; EditorApplication.delayCall += () => { if (Application.isPlaying || !obj) { return; } var mat = (0 == toneMode) && (0 == colorMode) && (0 == blurMode) ? null : UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName), toneMode, colorMode, blurMode); if (m_EffectMaterial == mat) { return; } m_EffectMaterial = mat; EditorUtility.SetDirty(this); EditorApplication.delayCall += AssetDatabase.SaveAssets; }; }
void OnEnable() { uiEffect = (target as UIShadow).GetComponent <UIEffect>(); spAdditionalShadows = serializedObject.FindProperty("m_AdditionalShadows"); roAdditionalShadows = new ReorderableList(serializedObject, spAdditionalShadows, true, true, true, true); roAdditionalShadows.drawElementCallback = DrawElementCallback; roAdditionalShadows.drawHeaderCallback = (rect) => EditorGUI.LabelField(rect, "Additional Shadows"); roAdditionalShadows.onAddCallback = OnAddCallback; roAdditionalShadows.elementHeightCallback = ElementHeightCallback; }
// #if UNITY_EDITOR // protected override void OnValidate() // { // effectDistance = m_EffectDistance; // base.OnValidate(); // } // #endif // #if TMP_PRESENT // protected void OnCullStateChanged (bool state) // { // SetVerticesDirty (); // } // // Vector2 res; // protected override void LateUpdate () // { // if (res.x != Screen.width || res.y != Screen.height) // { // res.x = Screen.width; // res.y = Screen.height; // SetVerticesDirty (); // } // if (textMeshPro && transform.hasChanged) // { // transform.hasChanged = false; // } // base.LateUpdate (); // } // #endif /// <summary> /// Modifies the mesh. /// </summary> public override void ModifyMesh(VertexHelper vh, Graphic graphic) { if (!isActiveAndEnabled || vh.currentVertCount <= 0 || m_Style == ShadowStyle.None) { return; } vh.GetUIVertexStream(s_Verts); GetComponents <UIShadow>(tmpShadows); foreach (var s in tmpShadows) { if (!s.isActiveAndEnabled) { continue; } if (s == this) { foreach (var s2 in tmpShadows) { s2._graphicVertexCount = s_Verts.Count; } } break; } tmpShadows.Clear(); //================================ // Append shadow vertices. //================================ { _uiEffect = _uiEffect ? _uiEffect : GetComponent <UIEffect>(); var start = s_Verts.Count - _graphicVertexCount; var end = s_Verts.Count; if (paramTex != null && _uiEffect && _uiEffect.isActiveAndEnabled) { paramTex.SetData(this, 0, _uiEffect.effectFactor); // param.x : effect factor paramTex.SetData(this, 1, 255); // param.y : color factor paramTex.SetData(this, 2, m_BlurFactor); // param.z : blur factor } ApplyShadow(s_Verts, effectColor, ref start, ref end, effectDistance, style, useGraphicAlpha); } vh.Clear(); vh.AddUIVertexTriangleStream(s_Verts); s_Verts.Clear(); }
protected override void OnDisable() { base.OnDisable(); _uiEffect = null; if (paramTex == null) { return; } paramTex.Unregister(this); paramTex = null; }
protected override void OnEnable() { base.OnEnable(); _uiEffect = GetComponent <UIEffect>(); if (!_uiEffect) { return; } paramTex = _uiEffect.paramTex; paramTex.Register(this); }
/// <summary> /// Generates the material variants. /// </summary> static void GenerateMaterialVariants(Shader shader) { var combinations = (from tone in (ToneMode[])Enum.GetValues(typeof(ToneMode)) from color in (ColorMode[])Enum.GetValues(typeof(ColorMode)) from blur in (BlurMode[])Enum.GetValues(typeof(BlurMode)) select new { tone, color, blur }).ToArray(); for (int i = 0; i < combinations.Length; i++) { var comb = combinations[i]; EditorUtility.DisplayProgressBar("Genarate Effect Material", UIEffect.GetVariantName(shader, comb.tone, comb.color, comb.blur), (float)i / combinations.Length); UIEffect.GetOrGenerateMaterialVariant(shader, comb.tone, comb.color, comb.blur); } EditorUtility.ClearProgressBar(); }
static void GenerateMaterialVariants(Shader shader, ToneMode[] tones, ColorMode[] colors, BlurMode[] blurs) { var combinations = (from tone in tones from color in colors from blur in blurs select new { tone, color, blur }).ToArray(); for (int i = 0; i < combinations.Length; i++) { var comb = combinations[i]; EditorUtility.DisplayProgressBar("Genarate Effect Material Bundle", UIEffect.GetVariantName(shader, comb.tone, comb.color, comb.blur), (float)i / combinations.Length); UIEffect.GetOrGenerateMaterialVariant(shader, comb.tone, comb.color, comb.blur); } EditorUtility.ClearProgressBar(); }
public void OnAfterDeserialize() { var obj = this; EditorApplication.delayCall += () => { if (Application.isPlaying || !obj || !obj.graphic) { return; } var mat = UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName), UIEffect.ToneMode.None, m_ColorMode, UIEffect.BlurMode.None); if (m_EffectMaterial == mat && graphic.material == mat) { return; } graphic.material = m_EffectMaterial = mat; EditorUtility.SetDirty(this); EditorUtility.SetDirty(graphic); EditorApplication.delayCall += AssetDatabase.SaveAssets; }; }
//################################ // Constant or Static Members. //################################ /// <summary> /// Draw effect properties. /// </summary> public static void DrawEffectProperties(string shaderName, SerializedObject serializedObject) { bool changed = false; //================ // Effect material. //================ var spMaterial = serializedObject.FindProperty("m_EffectMaterial"); EditorGUI.BeginDisabledGroup(true); EditorGUILayout.PropertyField(spMaterial); EditorGUI.EndDisabledGroup(); //================ // Tone setting. //================ var spToneMode = serializedObject.FindProperty("m_ToneMode"); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(spToneMode); changed |= EditorGUI.EndChangeCheck(); // When tone is enable, show parameters. if (spToneMode.intValue != (int)UIEffect.ToneMode.None) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ToneLevel")); EditorGUI.indentLevel--; } //================ // Color setting. //================ var spColorMode = serializedObject.FindProperty("m_ColorMode"); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(spColorMode); changed |= EditorGUI.EndChangeCheck(); // When color is enable, show parameters. if (spColorMode.intValue != (int)UIEffect.ColorMode.None) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(serializedObject.FindProperty("m_EffectColor")); EditorGUI.indentLevel--; } //================ // Blur setting. //================ var spBlurMode = serializedObject.FindProperty("m_BlurMode"); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(spBlurMode); changed |= EditorGUI.EndChangeCheck(); // When blur is enable, show parameters. if (spBlurMode.intValue != (int)UIEffect.BlurMode.None) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Blur")); EditorGUI.indentLevel--; } // Set effect material. if (!serializedObject.isEditingMultipleObjects && spToneMode.intValue == 0 && spColorMode.intValue == 0 && spBlurMode.intValue == 0) { spMaterial.objectReferenceValue = null; } else if (changed || !serializedObject.isEditingMultipleObjects) { spMaterial.objectReferenceValue = UIEffect.GetOrGenerateMaterialVariant(Shader.Find(shaderName), (UIEffect.ToneMode)spToneMode.intValue, (UIEffect.ColorMode)spColorMode.intValue, (UIEffect.BlurMode)spBlurMode.intValue ); } }