diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UICustomEffectEditor.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UICustomEffectEditor.cs index 3f28c0a..5f28270 100644 --- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UICustomEffectEditor.cs +++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/Editor/UICustomEffectEditor.cs @@ -1,81 +1 @@ -using UnityEditor; -using UnityEditorInternal; -using UnityEngine; - -namespace Coffee.UIExtensions -{ - /// - /// UIEffect editor. - /// - [CustomEditor(typeof(UICustomEffect))] - [CanEditMultipleObjects] - public class UICustomEffectEditor : Editor - { - //################################ - // Private Members. - //################################ - SerializedProperty spCustomFactor1X; - SerializedProperty spCustomFactor1Y; - SerializedProperty spCustomFactor1Z; - SerializedProperty spCustomFactor1W; - SerializedProperty spCustomFactor2X; - SerializedProperty spCustomFactor2Y; - SerializedProperty spCustomFactor2Z; - SerializedProperty spCustomFactor2W; - SerializedProperty _spEffectMaterial; - - void OnEnable() - { - var spCustomFactor1 = serializedObject.FindProperty("m_CustomFactor1"); - spCustomFactor1X = spCustomFactor1.FindPropertyRelative("x"); - spCustomFactor1Y = spCustomFactor1.FindPropertyRelative("y"); - spCustomFactor1Z = spCustomFactor1.FindPropertyRelative("z"); - spCustomFactor1W = spCustomFactor1.FindPropertyRelative("w"); - - var spCustomFactor2 = serializedObject.FindProperty("m_CustomFactor2"); - spCustomFactor2X = spCustomFactor2.FindPropertyRelative("x"); - spCustomFactor2Y = spCustomFactor2.FindPropertyRelative("y"); - spCustomFactor2Z = spCustomFactor2.FindPropertyRelative("z"); - spCustomFactor2W = spCustomFactor2.FindPropertyRelative("w"); - - _spEffectMaterial = serializedObject.FindProperty("m_EffectMaterial"); - } - - /// - /// Implement this function to make a custom inspector. - /// - public override void OnInspectorGUI() - { - serializedObject.Update(); - EditorGUILayout.PropertyField(_spEffectMaterial); - - EditorGUILayout.Slider(spCustomFactor1X, 0, 1, "CustomFactor1.X"); - EditorGUILayout.Slider(spCustomFactor1Y, 0, 1, "CustomFactor1.Y"); - EditorGUILayout.Slider(spCustomFactor1Z, 0, 1, "CustomFactor1.Z"); - EditorGUILayout.Slider(spCustomFactor1W, 0, 1, "CustomFactor1.W"); - EditorGUILayout.Slider(spCustomFactor2X, 0, 1, "CustomFactor2.X"); - EditorGUILayout.Slider(spCustomFactor2Y, 0, 1, "CustomFactor2.Y"); - EditorGUILayout.Slider(spCustomFactor2Z, 0, 1, "CustomFactor2.Z"); - EditorGUILayout.Slider(spCustomFactor2W, 0, 1, "CustomFactor2.W"); - - serializedObject.ApplyModifiedProperties(); - -#if UNITY_5_6_OR_NEWER - var graphic = (target as UIEffectBase).targetGraphic; - if(graphic) - { - var canvas = graphic.canvas; - if( canvas && 0 == (canvas.additionalShaderChannels & AdditionalCanvasShaderChannels.TexCoord1)) - { - using (new GUILayout.HorizontalScope()) - { - EditorGUILayout.HelpBox("[Unity5.6+] Enable TexCoord1 of Canvas.additionalShaderChannels to use UICustomEffect.", MessageType.Warning); - if (GUILayout.Button("Fix")) - canvas.additionalShaderChannels |= AdditionalCanvasShaderChannels.TexCoord1; - } - } - } -#endif - } - } -} \ No newline at end of file + \ No newline at end of file diff --git a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs index c339d62..5f28270 100644 --- a/Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs +++ b/Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs @@ -1,80 +1 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; - -#if UNITY_EDITOR -using System.IO; -using System.Linq; -using UnityEditor; -#endif - -namespace Coffee.UIExtensions -{ - /// - /// UIEffect. - /// - [ExecuteInEditMode] - [RequireComponent(typeof(Graphic))] - [DisallowMultipleComponent] - public class UICustomEffect : UIEffectBase - { - //################################ - // Serialize Members. - //################################ - [SerializeField] Vector4 m_CustomFactor1 = new Vector4(); - [SerializeField] Vector4 m_CustomFactor2 = new Vector4(); - - //################################ - // Public Members. - //################################ - /// - /// Custom effect factor 1. - /// - public Vector4 customFactor1 { get { return m_CustomFactor1; } set { m_CustomFactor1 = value; SetDirty(); } } - - /// - /// Custom effect factor 2. - /// - public Vector4 customFactor2 { get { return m_CustomFactor2; } set { m_CustomFactor2 = value; SetDirty(); } } - - /// - /// Modifies the mesh. - /// - public override void ModifyMesh(VertexHelper vh) - { - if (!isActiveAndEnabled) - { - return; - } - - UIVertex vt; - vh.GetUIVertexStream(tempVerts); - - //================================ - // Effect modify original vertices. - //================================ - { - // Pack some effect factors to 1 float. - Vector2 factor = new Vector2( - Packer.ToFloat(m_CustomFactor1), - Packer.ToFloat(m_CustomFactor2) - ); - - for (int i = 0; i < tempVerts.Count; i++) - { - vt = tempVerts[i]; - - // Set prameters to vertex. - vt.uv1 = factor; - tempVerts[i] = vt; - } - } - - vh.Clear(); - vh.AddUIVertexTriangleStream(tempVerts); - - tempVerts.Clear(); - } - } -} + \ No newline at end of file