Skip to content

Commit

Permalink
close #98; Remove 'custom effect' feature in UIEffect component
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Sep 29, 2018
1 parent a2ad000 commit 67c0bf9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 161 deletions.
Original file line number Diff line number Diff line change
@@ -1,81 +1 @@
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

namespace Coffee.UIExtensions
{
/// <summary>
/// UIEffect editor.
/// </summary>
[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");
}

/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
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
}
}
}

81 changes: 1 addition & 80 deletions Assets/Coffee/UIExtensions/UIEffect/Scripts/UICustomEffect.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// UIEffect.
/// </summary>
[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.
//################################
/// <summary>
/// Custom effect factor 1.
/// </summary>
public Vector4 customFactor1 { get { return m_CustomFactor1; } set { m_CustomFactor1 = value; SetDirty(); } }

/// <summary>
/// Custom effect factor 2.
/// </summary>
public Vector4 customFactor2 { get { return m_CustomFactor2; } set { m_CustomFactor2 = value; SetDirty(); } }

/// <summary>
/// Modifies the mesh.
/// </summary>
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();
}
}
}


0 comments on commit 67c0bf9

Please sign in to comment.