Skip to content

Commit

Permalink
change: BaseConnector is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed May 11, 2020
1 parent 7f4190c commit 34f128a
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 170 deletions.
1 change: 0 additions & 1 deletion Packages/UIEffect/Scripts/Common/BaseMaterialEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void SetMaterialDirty()
foreach (var effect in syncEffects)
{
effect.SetMaterialDirty();
// BaseConnector.FindConnector(effect.graphic).SetMaterialDirty(effect.graphic);
}
}

Expand Down
17 changes: 4 additions & 13 deletions Packages/UIEffect/Scripts/Common/BaseMeshEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public abstract class BaseMeshEffect : UIBehaviour, IMeshModifier
{
RectTransform _rectTransform;
Graphic _graphic;
BaseConnector _connector;
GraphicConnector _connector;

/// <summary>
/// The Graphic attached to this GameObject.
/// </summary>
protected BaseConnector connector
protected GraphicConnector connector
{
get { return _connector ?? (_connector = BaseConnector.FindConnector(graphic)); }
get { return _connector ?? (_connector = GraphicConnector.FindConnector(graphic)); }
}

/// <summary>
Expand All @@ -44,15 +44,6 @@ protected RectTransform rectTransform

internal readonly List<UISyncEffect> syncEffects = new List<UISyncEffect>(0);

/// <summary>
/// The material for rendering.
/// </summary>
// public virtual Material material
// {
// get { return connector.GetMaterial(graphic); }
// set { connector.SetMaterial(graphic, value); }
// }

/// <summary>
/// Call used to modify mesh. (legacy)
/// </summary>
Expand Down Expand Up @@ -146,7 +137,7 @@ protected virtual void SetVerticesDirty()
// _initialized = true;
// _graphic = _graphic ? _graphic : GetComponent<Graphic>();
//
// _connector = BaseConnector.FindConnector(_graphic);
// _connector = GraphicConnector.FindConnector(_graphic);
//
// // _canvasRenderer = _canvasRenderer ?? GetComponent<CanvasRenderer> ();
// _rectTransform = _rectTransform ? _rectTransform : GetComponent<RectTransform>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections.Generic;

namespace Coffee.UIExtensions
namespace Coffee.UIEffects
{
public class BaseConnector
public class GraphicConnector
{
private static readonly List<BaseConnector> s_Connectors = new List<BaseConnector>();
private static readonly Dictionary<Type, BaseConnector> s_ConnectorMap = new Dictionary<Type, BaseConnector>();
private static readonly BaseConnector s_EmptyConnector = new BaseConnector();
private static readonly List<GraphicConnector> s_Connectors = new List<GraphicConnector>();

private static readonly Dictionary<Type, GraphicConnector> s_ConnectorMap =
new Dictionary<Type, GraphicConnector>();

private static readonly GraphicConnector s_EmptyConnector = new GraphicConnector();

#if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod]
#endif
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Init()
{
AddConnector(s_EmptyConnector);
AddConnector(new GraphicConnector());
}

protected static void AddConnector(BaseConnector connector)
protected static void AddConnector(GraphicConnector connector)
{
s_Connectors.Add(connector);
s_Connectors.Sort((x, y) => y.priority - x.priority);
}

public static BaseConnector FindConnector(Graphic graphic)
public static GraphicConnector FindConnector(Graphic graphic)
{
if (!graphic) return s_EmptyConnector;

var type = graphic.GetType();
BaseConnector connector = null;
GraphicConnector connector = null;
if (s_ConnectorMap.TryGetValue(type, out connector)) return connector;

foreach (var c in s_Connectors)
Expand All @@ -48,23 +49,7 @@ public static BaseConnector FindConnector(Graphic graphic)
}

/// <summary>
/// The connector is valid for the component.
/// </summary>
protected virtual bool IsValid(Graphic graphic)
{
return true;
}

/// <summary>
/// Find effect shader.
/// </summary>
public virtual Shader FindShader(string shaderName)
{
return null;
}

/// <summary>
/// Priority.
/// Connector priority.
/// </summary>
protected virtual int priority
{
Expand All @@ -76,50 +61,55 @@ protected virtual int priority
/// </summary>
public virtual AdditionalCanvasShaderChannels extraChannel
{
get { return AdditionalCanvasShaderChannels.None; }
get { return AdditionalCanvasShaderChannels.TexCoord1; }
}

/// <summary>
/// Set material.
/// The connector is valid for the component.
/// </summary>
public virtual void SetMaterial(Graphic graphic, Material material)
protected virtual bool IsValid(Graphic graphic)
{
return true;
}

/// <summary>
/// Get material.
/// Find effect shader.
/// </summary>
public virtual Material GetMaterial(Graphic graphic)
public virtual Shader FindShader(string shaderName)
{
return null;
return Shader.Find("Hidden/" + shaderName);
}

/// <summary>
/// Mark the vertices as dirty.
/// This function is called when the object becomes enabled and active.
/// </summary>
public virtual void SetVerticesDirty(Graphic graphic)
public virtual void OnEnable(Graphic graphic)
{
}

/// <summary>
/// Mark the material as dirty.
/// This function is called when the behaviour becomes disabled () or inactive.
/// </summary>
public virtual void SetMaterialDirty(Graphic graphic)
public virtual void OnDisable(Graphic graphic)
{
}

/// <summary>
/// This function is called when the object becomes enabled and active.
/// Mark the vertices as dirty.
/// </summary>
public virtual void OnEnable(Graphic graphic)
public virtual void SetVerticesDirty(Graphic graphic)
{
if (graphic)
graphic.SetVerticesDirty();
}

/// <summary>
/// This function is called when the behaviour becomes disabled () or inactive.
/// Mark the material as dirty.
/// </summary>
public virtual void OnDisable(Graphic graphic)
public virtual void SetMaterialDirty(Graphic graphic)
{
if (graphic)
graphic.SetMaterialDirty();
}

/// <summary>
Expand All @@ -133,7 +123,7 @@ protected virtual void OnWillRenderCanvases()
/// <summary>
/// Gets position factor for area.
/// </summary>
public void GetPositionFactor(EffectArea area, int index, Rect rect, Vector2 position, out float x, out float y)
public virtual void GetPositionFactor(EffectArea area, int index, Rect rect, Vector2 position, out float x, out float y)
{
if (area == EffectArea.Fit)
{
Expand All @@ -147,22 +137,23 @@ public void GetPositionFactor(EffectArea area, int index, Rect rect, Vector2 pos
}
}

/// <summary>
/// Normalize vertex position by local matrix.
/// </summary>
public void GetNormalizedFactor(EffectArea area, int index, Matrix2x3 matrix, Vector2 position,
out Vector2 normalizedPos)
public virtual bool IsText(Graphic graphic)
{
normalizedPos = matrix * position;
return graphic && graphic is Text;
}

public virtual bool IsText(Graphic graphic)
public virtual void SetExtraChannel(ref UIVertex vertex, Vector2 value)
{
return false;
vertex.uv1 = value;
}

public virtual void SetExtraChannel(ref UIVertex vertex, Vector2 value)
/// <summary>
/// Normalize vertex position by local matrix.
/// </summary>
public virtual void GetNormalizedFactor(EffectArea area, int index, Matrix2x3 matrix, Vector2 position,
out Vector2 normalizedPos)
{
normalizedPos = matrix * position;
}
}
}
3 changes: 2 additions & 1 deletion Packages/UIEffect/Scripts/Common/MaterialCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ private static void ClearCache()
}
#endif

public static Material Register(Material baseMaterial, Hash128 hash, System.Action<Material, Graphic> onModifyMaterial, Graphic graphic)
public static Material Register(Material baseMaterial, Hash128 hash,
System.Action<Material, Graphic> onModifyMaterial, Graphic graphic)
{
if (!hash.isValid) return null;

Expand Down
2 changes: 1 addition & 1 deletion Packages/UIEffect/Scripts/Common/ParameterTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ParameterTexture
//################################

/// <summary>
/// Initializes a new instance of the <see cref="Coffee.UIExtensions.ParameterTexture"/> class.
/// Initializes a new instance of the <see cref="Coffee.UIEffects.ParameterTexture"/> class.
/// </summary>
/// <param name="channels">Channels.</param>
/// <param name="instanceLimit">Instance limit.</param>
Expand Down
8 changes: 0 additions & 8 deletions Packages/UIEffect/Scripts/Connectors.meta

This file was deleted.

11 changes: 0 additions & 11 deletions Packages/UIEffect/Scripts/Connectors/BaseConnector.cs.meta

This file was deleted.

70 changes: 0 additions & 70 deletions Packages/UIEffect/Scripts/Connectors/GraphicConnector.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Packages/UIEffect/Scripts/Editor/UIHsvModifierEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ public override void OnInspectorGUI()
serializedObject.ApplyModifiedProperties();
}
}
}
}
2 changes: 1 addition & 1 deletion Packages/UIEffect/Scripts/Editor/UIShinyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ public override void OnInspectorGUI()
serializedObject.ApplyModifiedProperties();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ public override void OnInspectorGUI()
serializedObject.ApplyModifiedProperties();
}
}
}
}
2 changes: 1 addition & 1 deletion Packages/UIEffect/Scripts/UIDissolve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public override Hash128 GetMaterialHash(Material material)

public override void ModifyMaterial(Material newMaterial, Graphic graphic)
{
var connector = BaseConnector.FindConnector(graphic);
var connector = GraphicConnector.FindConnector(graphic);
newMaterial.shader = connector.FindShader("UIDissolve");
SetShaderVariants(newMaterial, m_ColorMode);

Expand Down
2 changes: 1 addition & 1 deletion Packages/UIEffect/Scripts/UIEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public override Hash128 GetMaterialHash(Material material)

public override void ModifyMaterial(Material newMaterial, Graphic graphic)
{
var connector = BaseConnector.FindConnector(graphic);
var connector = GraphicConnector.FindConnector(graphic);

newMaterial.shader = connector.FindShader("UIEffect");
SetShaderVariants(newMaterial, m_EffectMode, m_ColorMode, m_BlurMode,
Expand Down
Loading

0 comments on commit 34f128a

Please sign in to comment.