mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-20 01:42:37 +08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef7ac0aaad | |||
| 2fd87e909a | |||
| 2cc5c5b68e | |||
| 4a8d341625 | |||
| a885fc5bc1 | |||
| 4fdd9636fa | |||
| 06a280ec5a | |||
| e6fb78a0f6 | |||
| 451cbe4302 | |||
| 3cae638bdd | |||
| 533d7b8c0a |
@@ -25,7 +25,7 @@ jobs:
|
||||
tag: ${{ steps.release.outputs.new_release_git_tag }}
|
||||
steps:
|
||||
- name: 🚚 Checkout (${{ github.ref_name }})
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: 🔖 Run semantic release
|
||||
uses: cycjimmy/semantic-release-action@v4
|
||||
|
||||
@@ -9,7 +9,7 @@ env:
|
||||
# MINIMUM_VERSION: The minimum version of Unity.
|
||||
MINIMUM_VERSION: 6000.0
|
||||
# EXCLUDE_FILTER: The excluded versions of Unity.
|
||||
EXCLUDE_FILTER: "(2020.2.0|2021.1|2023.2|2023.3)"
|
||||
EXCLUDE_FILTER: "(2017|2018)"
|
||||
PROJECT_PATH: UIEffectURP
|
||||
|
||||
on:
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
id: setup
|
||||
run: |
|
||||
echo "==== Target Unity Versions ===="
|
||||
LATEST_VERSIONS=`npx unity-changeset list --versions --latest-patch --min ${MINIMUM_VERSION} --json --all`
|
||||
LATEST_VERSIONS=`npx unity-changeset@latest list --versions --latest-patch --min ${MINIMUM_VERSION} --json --all`
|
||||
if [ "${{ inputs.usePeriodVersions }}" = "true" ]; then
|
||||
ADDITIONAL_VERSIONS=`npx unity-changeset list --versions --grep '0f' --min ${MINIMUM_VERSION} --json`
|
||||
else
|
||||
@@ -72,11 +72,11 @@ jobs:
|
||||
steps:
|
||||
- name: 🚚 Checkout ($${{ github.ref }})
|
||||
if: github.event_name == 'push'
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: 🚚 Checkout pull request (pull_request_target)
|
||||
if: github.event_name == 'pull_request_target'
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
@@ -86,19 +86,20 @@ jobs:
|
||||
run: |
|
||||
git config user.name "GitHub Actions"
|
||||
git config user.email "actions@github.com"
|
||||
git merge origin/${{ github.event.pull_request.base.ref }} --no-edit
|
||||
git rebase ${{ github.event.pull_request.base.sha }}
|
||||
git log --oneline -n 10
|
||||
|
||||
- name: 📥 Cache library
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: Library
|
||||
key: Library-${{ matrix.unityVersion }}-${{ github.event.pull_request.head.sha || github.sha }}
|
||||
path: ${{ env.PROJECT_PATH }}/Library
|
||||
key: ${{ env.PROJECT_PATH }}-Library-${{ matrix.unityVersion }}-${{ github.event.pull_request.head.sha || github.sha }}
|
||||
restore-keys: |
|
||||
Library-${{ matrix.unityVersion }}-
|
||||
Library-
|
||||
${{ env.PROJECT_PATH }}-Library-${{ matrix.unityVersion }}-
|
||||
${{ env.PROJECT_PATH }}-Library-
|
||||
|
||||
- name: 🛠️ Build Unity Project (Test)
|
||||
uses: game-ci/unity-builder@v4
|
||||
uses: game-ci/unity-builder@main
|
||||
timeout-minutes: 45
|
||||
with:
|
||||
customImage: ghcr.io/mob-sakai/unity3d:${{ matrix.unityVersion }}
|
||||
|
||||
@@ -9,7 +9,7 @@ env:
|
||||
# MINIMUM_VERSION: The minimum version of Unity.
|
||||
MINIMUM_VERSION: 2020.3
|
||||
# EXCLUDE_FILTER: The excluded versions of Unity.
|
||||
EXCLUDE_FILTER: "(2020.2.0|2021.1|2023.2|2023.3)"
|
||||
EXCLUDE_FILTER: "(2017|2018|2023.3)"
|
||||
PROJECT_PATH: .
|
||||
|
||||
on:
|
||||
@@ -46,7 +46,7 @@ jobs:
|
||||
id: setup
|
||||
run: |
|
||||
echo "==== Target Unity Versions ===="
|
||||
LATEST_VERSIONS=`npx unity-changeset list --versions --latest-patch --min ${MINIMUM_VERSION} --json --all`
|
||||
LATEST_VERSIONS=`npx unity-changeset@latest list --versions --latest-patch --min ${MINIMUM_VERSION} --json --all`
|
||||
if [ "${{ inputs.usePeriodVersions }}" = "true" ]; then
|
||||
ADDITIONAL_VERSIONS=`npx unity-changeset list --versions --grep '0f' --min ${MINIMUM_VERSION} --json`
|
||||
else
|
||||
@@ -72,11 +72,11 @@ jobs:
|
||||
steps:
|
||||
- name: 🚚 Checkout ($${{ github.ref }})
|
||||
if: github.event_name == 'push'
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
|
||||
- name: 🚚 Checkout pull request (pull_request_target)
|
||||
if: github.event_name == 'pull_request_target'
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
fetch-depth: 0
|
||||
@@ -92,14 +92,14 @@ jobs:
|
||||
- name: 📥 Cache library
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: Library
|
||||
key: Library-${{ matrix.unityVersion }}-${{ github.event.pull_request.head.sha || github.sha }}
|
||||
path: ${{ env.PROJECT_PATH }}/Library
|
||||
key: ${{ env.PROJECT_PATH }}-Library-${{ matrix.unityVersion }}-${{ github.event.pull_request.head.sha || github.sha }}
|
||||
restore-keys: |
|
||||
Library-${{ matrix.unityVersion }}-
|
||||
Library-
|
||||
${{ env.PROJECT_PATH }}-Library-${{ matrix.unityVersion }}-
|
||||
${{ env.PROJECT_PATH }}-Library-
|
||||
|
||||
- name: 🛠️ Build Unity Project (Test)
|
||||
uses: game-ci/unity-builder@v4
|
||||
uses: game-ci/unity-builder@main
|
||||
timeout-minutes: 45
|
||||
with:
|
||||
customImage: ghcr.io/mob-sakai/unity3d:${{ matrix.unityVersion }}
|
||||
|
||||
@@ -1,3 +1,31 @@
|
||||
## [5.10.4](https://github.com/mob-sakai/UIEffect/compare/5.10.3...5.10.4) (2025-10-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove `sealed` from `UIEffect` and `UIEffectReplica` ([2fd87e9](https://github.com/mob-sakai/UIEffect/commit/2fd87e909af65bf88a9c39cd157dfb06a56b3af0)), closes [#379](https://github.com/mob-sakai/UIEffect/issues/379)
|
||||
|
||||
## [5.10.3](https://github.com/mob-sakai/UIEffect/compare/5.10.2...5.10.3) (2025-10-22)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* displays as black rectangle when opening editor ([4a8d341](https://github.com/mob-sakai/UIEffect/commit/4a8d341625f73d70c512f7e6f0b864be1adbf459)), closes [#376](https://github.com/mob-sakai/UIEffect/issues/376)
|
||||
|
||||
## [5.10.2](https://github.com/mob-sakai/UIEffect/compare/5.10.1...5.10.2) (2025-10-16)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* [improve performance] code optimization ([e6fb78a](https://github.com/mob-sakai/UIEffect/commit/e6fb78a0f67ed6f70be08259f674ab2f83364bd7))
|
||||
|
||||
## [5.10.1](https://github.com/mob-sakai/UIEffect/compare/5.10.0...5.10.1) (2025-10-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* [improve performance] `UpdateViewMatrix` is called even though (direct-)parent canvas is disabled ([533d7b8](https://github.com/mob-sakai/UIEffect/commit/533d7b8c0a33871b1849fbda862d4fa1899822f4)), closes [#373](https://github.com/mob-sakai/UIEffect/issues/373)
|
||||
|
||||
# [5.10.0](https://github.com/mob-sakai/UIEffect/compare/5.9.7...5.10.0) (2025-09-26)
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Coffee.UIEffectInternal
|
||||
/// <summary>
|
||||
/// Object pool.
|
||||
/// </summary>
|
||||
internal class InternalObjectPool<T> where T : class
|
||||
internal sealed class InternalObjectPool<T> where T : class
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
private readonly Predicate<T> _onValid; // Delegate for checking if instances are valid
|
||||
|
||||
@@ -6,6 +6,7 @@ using UnityEngine.Profiling;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
@@ -16,7 +17,7 @@ using Object = UnityEngine.Object;
|
||||
namespace Coffee.UIEffectInternal
|
||||
{
|
||||
[Serializable]
|
||||
public class ShaderVariantRegistry
|
||||
public sealed class ShaderVariantRegistry
|
||||
{
|
||||
[Serializable]
|
||||
internal class StringPair : IEquatable<StringPair>
|
||||
@@ -26,9 +27,7 @@ namespace Coffee.UIEffectInternal
|
||||
|
||||
public bool Equals(StringPair other)
|
||||
{
|
||||
if (other == null) return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
return key == other.key && value == other.value;
|
||||
return other != null && key == other.key && value == other.value;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
@@ -88,15 +87,15 @@ namespace Coffee.UIEffectInternal
|
||||
|
||||
// Find optional shader.
|
||||
Shader optionalShader;
|
||||
foreach (var pair in m_OptionalShaders)
|
||||
var count = m_OptionalShaders.Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var pair = m_OptionalShaders[i];
|
||||
if (pair.key != shaderName) continue;
|
||||
optionalShader = Shader.Find(pair.value);
|
||||
if (optionalShader)
|
||||
{
|
||||
_cachedOptionalShaders[id] = pair.value;
|
||||
return optionalShader;
|
||||
}
|
||||
if (!optionalShader) continue;
|
||||
_cachedOptionalShaders[id] = pair.value;
|
||||
return optionalShader;
|
||||
}
|
||||
|
||||
// Find optional shader by format.
|
||||
@@ -122,10 +121,15 @@ namespace Coffee.UIEffectInternal
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private readonly HashSet<StringPair> _logVariants = new HashSet<StringPair>();
|
||||
private readonly StringBuilder _sb = new StringBuilder(1024);
|
||||
|
||||
private readonly Dictionary<Hash128, (ShaderVariantCollection.ShaderVariant, StringPair)> _cachedVariants =
|
||||
new Dictionary<Hash128, (ShaderVariantCollection.ShaderVariant, StringPair)>();
|
||||
|
||||
public void ClearCache()
|
||||
{
|
||||
_cachedOptionalShaders.Clear();
|
||||
_cachedVariants.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -213,21 +217,10 @@ namespace Coffee.UIEffectInternal
|
||||
if (!material || !material.shader || !m_Asset) return;
|
||||
|
||||
Profiler.BeginSample("(EDITOR/COF)[ShaderVariantRegistry] RegisterVariant");
|
||||
var shaderName = material.shader.name;
|
||||
var validKeywords = material.shaderKeywords
|
||||
.Where(x => !Regex.IsMatch(x, "(_EDITOR|EDITOR_)"))
|
||||
.ToArray();
|
||||
var keywords = string.Join(" ", validKeywords);
|
||||
var variant = new ShaderVariantCollection.ShaderVariant
|
||||
{
|
||||
shader = material.shader,
|
||||
keywords = validKeywords
|
||||
};
|
||||
|
||||
// Already registered.
|
||||
var pair = new StringPair() { key = shaderName, value = keywords };
|
||||
var (variant, pair) = GetVariant(material);
|
||||
if (m_Asset.Contains(variant))
|
||||
{
|
||||
// Already registered.
|
||||
m_UnregisteredVariants.Remove(pair);
|
||||
Profiler.EndSample();
|
||||
return;
|
||||
@@ -243,7 +236,8 @@ namespace Coffee.UIEffectInternal
|
||||
|
||||
if (_logVariants.Add(pair))
|
||||
{
|
||||
keywords = string.IsNullOrEmpty(keywords) ? "no keywords" : keywords;
|
||||
var shaderName = pair.key;
|
||||
var keywords = string.IsNullOrEmpty(pair.value) ? "no keywords" : pair.value;
|
||||
Debug.LogError($"Shader variant '{shaderName} <{keywords}>' is not registered.\n" +
|
||||
$"Register it in 'ProjectSettings > {path}' to use it in player.", m_Asset);
|
||||
}
|
||||
@@ -256,6 +250,44 @@ namespace Coffee.UIEffectInternal
|
||||
m_UnregisteredVariants.Remove(pair);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
private (ShaderVariantCollection.ShaderVariant, StringPair) GetVariant(Material material)
|
||||
{
|
||||
Profiler.BeginSample("(EDITOR/COF)[ShaderVariantRegistry] GetVariant");
|
||||
var shader = material.shader;
|
||||
_sb.Length = 0;
|
||||
foreach (var keyword in material.shaderKeywords)
|
||||
{
|
||||
// Ignore editor keyword.
|
||||
if (keyword.Contains("_EDITOR") || keyword.Contains("EDITOR_")) continue;
|
||||
|
||||
_sb.Append(keyword);
|
||||
_sb.Append(' ');
|
||||
}
|
||||
|
||||
if (0 < _sb.Length)
|
||||
{
|
||||
_sb.Length--; // Remove last space.
|
||||
}
|
||||
|
||||
var hash = new Hash128((uint)shader.GetInstanceID(), (uint)_sb.GetHashCode(), 0, 0);
|
||||
if (_cachedVariants.TryGetValue(hash, out var result))
|
||||
{
|
||||
Profiler.EndSample();
|
||||
return result;
|
||||
}
|
||||
|
||||
var pair = new StringPair() { key = shader.name, value = _sb.ToString() };
|
||||
var variant = new ShaderVariantCollection.ShaderVariant
|
||||
{
|
||||
shader = shader,
|
||||
keywords = pair.value.Split(' ')
|
||||
};
|
||||
|
||||
_cachedVariants.Add(hash, (variant, pair));
|
||||
Profiler.EndSample();
|
||||
return (variant, pair);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1494,7 +1494,8 @@ namespace Coffee.UIEffects
|
||||
public override void SetVerticesDirty()
|
||||
{
|
||||
base.SetVerticesDirty();
|
||||
for (var i = 0; i < replicas.Count; i++)
|
||||
var count = replicas.Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
if (!replicas[i]) continue;
|
||||
replicas[i].SetVerticesDirty();
|
||||
@@ -1504,7 +1505,8 @@ namespace Coffee.UIEffects
|
||||
public override void SetMaterialDirty()
|
||||
{
|
||||
base.SetMaterialDirty();
|
||||
for (var i = 0; i < replicas.Count; i++)
|
||||
var count = replicas.Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
if (!replicas[i]) continue;
|
||||
replicas[i].SetMaterialDirty();
|
||||
@@ -1579,7 +1581,8 @@ namespace Coffee.UIEffects
|
||||
{
|
||||
base.ApplyContextToMaterial(material);
|
||||
|
||||
for (var i = 0; i < replicas.Count; i++)
|
||||
var count = replicas.Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
if (!replicas[i]) continue;
|
||||
replicas[i].ApplyContextToMaterial(material);
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace Coffee.UIEffects
|
||||
private Action _onAfterCanvasRebuild;
|
||||
private bool _canModifyMesh;
|
||||
private Matrix4x4 _prevTransformHash;
|
||||
private Canvas _canvas;
|
||||
private bool _canvasCached = false;
|
||||
|
||||
public Material effectMaterial => _material;
|
||||
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
|
||||
@@ -39,6 +41,23 @@ namespace Coffee.UIEffects
|
||||
public virtual float actualSamplingScale => 1;
|
||||
public virtual bool canModifyShape => true;
|
||||
|
||||
protected Canvas canvas
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_canvasCached) return _canvas;
|
||||
|
||||
_canvasCached = true;
|
||||
_canvas = GetComponentInParent<Canvas>();
|
||||
if (!_canvas || !_canvas.isActiveAndEnabled)
|
||||
{
|
||||
_canvas = null;
|
||||
}
|
||||
|
||||
return _canvas;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual UIEffectContext context
|
||||
{
|
||||
get
|
||||
@@ -104,7 +123,7 @@ namespace Coffee.UIEffects
|
||||
s_ContextPool.Return(ref _context);
|
||||
}
|
||||
|
||||
protected virtual void OnBeforeCanvasRebuild()
|
||||
private void OnBeforeCanvasRebuild()
|
||||
{
|
||||
// If the mesh is not modified in the previous frame, try to modify it if possible.
|
||||
if (!_canModifyMesh && CanModifyMesh())
|
||||
@@ -114,12 +133,18 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnAfterCanvasRebuild()
|
||||
private void OnAfterCanvasRebuild()
|
||||
{
|
||||
if (!_material || !graphic || !graphic.canvas || context == null) return;
|
||||
if (!_material || !graphic || !canvas || context == null) return;
|
||||
if (!context.useViewMatrix) return;
|
||||
|
||||
context.UpdateViewMatrix(GetCurrentMaterial(), transitionRoot, graphic.canvas.rootCanvas);
|
||||
context.UpdateViewMatrix(GetCurrentMaterial(), transitionRoot, canvas.rootCanvas);
|
||||
}
|
||||
|
||||
protected override void OnCanvasHierarchyChanged()
|
||||
{
|
||||
_canvasCached = false;
|
||||
_canvas = null;
|
||||
}
|
||||
|
||||
public void ModifyMesh(Mesh mesh)
|
||||
@@ -133,13 +158,14 @@ namespace Coffee.UIEffects
|
||||
_canModifyMesh = CanModifyMesh();
|
||||
if (_canModifyMesh)
|
||||
{
|
||||
context.ModifyMesh(graphic, transitionRoot, vh, canModifyShape);
|
||||
context.ModifyMesh(graphic, canvas, transitionRoot, vh, canModifyShape);
|
||||
}
|
||||
}
|
||||
|
||||
private bool CanModifyMesh()
|
||||
{
|
||||
if (!graphic || !graphic.isActiveAndEnabled) return false;
|
||||
if (!isActiveAndEnabled) return false;
|
||||
|
||||
// The transitionRoot is same as the transform => true.
|
||||
var root = transitionRoot;
|
||||
|
||||
@@ -8,7 +8,7 @@ using UnityEngine.UI;
|
||||
|
||||
namespace Coffee.UIEffects
|
||||
{
|
||||
public class UIEffectContext
|
||||
public sealed class UIEffectContext
|
||||
{
|
||||
private static readonly UIEffectContext s_DefaultContext = new UIEffectContext();
|
||||
private static readonly List<UIVertex> s_WorkingVertices = new List<UIVertex>(1024 * 8);
|
||||
@@ -451,7 +451,7 @@ namespace Coffee.UIEffects
|
||||
{
|
||||
if (!material) return;
|
||||
|
||||
Profiler.BeginSample("(UIE)[UIEffect] GetModifiedMaterial");
|
||||
Profiler.BeginSample("(UIE)[UIEffect] ApplyToMaterial");
|
||||
|
||||
material.SetInt(s_SrcBlend, (int)m_SrcBlendMode);
|
||||
material.SetInt(s_DstBlend, (int)m_DstBlendMode);
|
||||
@@ -602,16 +602,17 @@ namespace Coffee.UIEffects
|
||||
scale.y = 0 != (m_Flip & Flip.Vertical) ? -scale.y : scale.y;
|
||||
}
|
||||
|
||||
var pivot = new Vector2(0.5f, 0.5f);
|
||||
var offset = (transitionRoot.pivot - pivot) * size;
|
||||
var pivot = new Vector3(0.5f, 0.5f);
|
||||
var offset = (transitionRoot.pivot - (Vector2)pivot) * size;
|
||||
var w2LMat = Matrix4x4.Translate(offset) * transitionRoot.worldToLocalMatrix;
|
||||
|
||||
var rootRotation = Quaternion.Euler(0, 0, m_TransitionRotation);
|
||||
var rootScale = 1f / GetMultiplier(m_TransitionRotation);
|
||||
material.SetMatrix(s_RootViewMatrix, Matrix4x4.TRS(pivot, rootRotation, scale * rootScale) * w2LMat);
|
||||
|
||||
var gradRotation = Quaternion.Euler(0, 0, GetGradationRotation());
|
||||
var gradScale = 1f / GetMultiplier(GetGradationRotation());
|
||||
var rotation = GetGradationRotation();
|
||||
var gradRotation = Quaternion.Euler(0, 0, rotation);
|
||||
var gradScale = 1f / GetMultiplier(rotation);
|
||||
material.SetMatrix(s_GradViewMatrix, Matrix4x4.TRS(pivot, gradRotation, scale * gradScale) * w2LMat);
|
||||
|
||||
if (m_ShadowMode == ShadowMode.Mirror)
|
||||
@@ -620,26 +621,25 @@ namespace Coffee.UIEffects
|
||||
var mirrorOffset = new Vector3(0, size.y / 2 * (mirrorInv + 1) - m_ShadowDistance.y * mirrorInv, 0);
|
||||
var mirrorScale = new Vector3(1, mirrorInv, 1);
|
||||
var udScale = new Vector3(scale.x, -scale.y, scale.z);
|
||||
material.SetMatrix(s_MirrorRootViewMatrix,
|
||||
Matrix4x4.TRS(pivot, rootRotation, udScale * rootScale)
|
||||
* Matrix4x4.TRS(mirrorOffset, Quaternion.identity, mirrorScale) * w2LMat);
|
||||
material.SetMatrix(s_MirrorGradViewMatrix,
|
||||
Matrix4x4.TRS(pivot, gradRotation, udScale * gradScale)
|
||||
* Matrix4x4.TRS(mirrorOffset, Quaternion.identity, mirrorScale) * w2LMat);
|
||||
var mirrorTranslation = Matrix4x4.TRS(mirrorOffset, Quaternion.identity, mirrorScale) * w2LMat;
|
||||
material.SetMatrix(
|
||||
s_MirrorRootViewMatrix,
|
||||
Matrix4x4.TRS(pivot, rootRotation, udScale * rootScale) * mirrorTranslation
|
||||
);
|
||||
material.SetMatrix(
|
||||
s_MirrorGradViewMatrix,
|
||||
Matrix4x4.TRS(pivot, gradRotation, udScale * gradScale) * mirrorTranslation
|
||||
);
|
||||
}
|
||||
|
||||
if (canvas.renderMode == RenderMode.WorldSpace)
|
||||
{
|
||||
material.SetMatrix(s_CanvasToWorldMatrix, Matrix4x4.identity);
|
||||
}
|
||||
else if (canvas.renderMode == RenderMode.ScreenSpaceOverlay || !canvas.worldCamera)
|
||||
{
|
||||
material.SetMatrix(s_CanvasToWorldMatrix, canvas.transform.localToWorldMatrix);
|
||||
}
|
||||
else
|
||||
{
|
||||
material.SetMatrix(s_CanvasToWorldMatrix, Matrix4x4.identity);
|
||||
}
|
||||
var useIdentity =
|
||||
canvas.renderMode == RenderMode.WorldSpace ||
|
||||
(canvas.renderMode != RenderMode.ScreenSpaceOverlay && canvas.worldCamera);
|
||||
|
||||
material.SetMatrix(
|
||||
s_CanvasToWorldMatrix,
|
||||
useIdentity ? Matrix4x4.identity : canvas.transform.localToWorldMatrix
|
||||
);
|
||||
}
|
||||
|
||||
private Vector4 GetGradationScaleAndOffset()
|
||||
@@ -691,22 +691,27 @@ namespace Coffee.UIEffects
|
||||
return Mathf.Max(Mathf.Abs(cos - sin), Mathf.Abs(cos + sin));
|
||||
}
|
||||
|
||||
#if UNITY_2021_2_OR_NEWER
|
||||
private static void SetKeyword(Material material, Span<string> keywords, int index)
|
||||
#else
|
||||
private static void SetKeyword(Material material, string[] keywords, int index)
|
||||
#endif
|
||||
{
|
||||
for (var i = 0; i < keywords.Length; i++)
|
||||
var length = keywords.Length;
|
||||
if (index < length && !string.IsNullOrEmpty(keywords[index]))
|
||||
{
|
||||
if (i != index)
|
||||
{
|
||||
material.DisableKeyword(keywords[i]);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(keywords[i]))
|
||||
{
|
||||
material.EnableKeyword(keywords[i]);
|
||||
}
|
||||
material.EnableKeyword(keywords[index]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
if (i == index) continue;
|
||||
material.DisableKeyword(keywords[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void ModifyMesh(Graphic graphic, RectTransform transitionRoot, VertexHelper vh, bool canModifyShape)
|
||||
public void ModifyMesh(Graphic graphic, Canvas canvas, RectTransform transitionRoot, VertexHelper vh,
|
||||
bool canModifyShape)
|
||||
{
|
||||
// Apply flip (without effect).
|
||||
ApplyFlipWithoutEffect(vh, m_Flip);
|
||||
@@ -716,7 +721,7 @@ namespace Coffee.UIEffects
|
||||
|
||||
var effectProxy = GraphicProxy.Find(graphic);
|
||||
var isText = effectProxy.IsText(graphic);
|
||||
effectProxy.OnPreModifyMesh(graphic);
|
||||
effectProxy.OnPreModifyMesh(graphic, canvas);
|
||||
|
||||
var verts = s_WorkingVertices;
|
||||
var expandSize = effectProxy.ModifyExpandSize(graphic, GetExpandSize(canModifyShape));
|
||||
|
||||
@@ -191,6 +191,15 @@ namespace Coffee.UIEffects
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh all UI Graphics in the opened scenes. (#376)
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
foreach (var g in Misc.FindObjectsOfType<UnityEngine.UI.Graphic>())
|
||||
{
|
||||
g.SetAllDirty();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -124,19 +124,20 @@ namespace Coffee.UIEffects
|
||||
{
|
||||
get
|
||||
{
|
||||
if (preset && useTargetTransform && !m_CustomRoot && graphic && graphic.canvas)
|
||||
if (useTargetTransform)
|
||||
{
|
||||
return graphic.canvas.transform as RectTransform;
|
||||
if (preset && !m_CustomRoot && graphic && canvas)
|
||||
{
|
||||
return canvas.transform as RectTransform;
|
||||
}
|
||||
|
||||
if (isTargetInScene)
|
||||
{
|
||||
return target.transitionRoot;
|
||||
}
|
||||
}
|
||||
|
||||
if (useTargetTransform && isTargetInScene)
|
||||
{
|
||||
return target.transitionRoot;
|
||||
}
|
||||
|
||||
return m_CustomRoot
|
||||
? m_CustomRoot
|
||||
: transform as RectTransform;
|
||||
return m_CustomRoot ? m_CustomRoot : transform as RectTransform;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,9 +187,9 @@ namespace Coffee.UIEffects
|
||||
target.SetEnablePreviewIfSelected(selection);
|
||||
}
|
||||
// Following the preset/preset-target.
|
||||
else if (context != null)
|
||||
else
|
||||
{
|
||||
context.SetEnablePreview(selection.Contains(gameObject), effectMaterial);
|
||||
context?.SetEnablePreview(selection.Contains(gameObject), effectMaterial);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -15,8 +15,10 @@ namespace Coffee.UIEffects
|
||||
public static void Register(GraphicProxy proxy)
|
||||
{
|
||||
// Register only once.
|
||||
foreach (var p in s_Proxies)
|
||||
var count = s_Proxies.Count;
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var p = s_Proxies[i];
|
||||
if (p.GetType() == proxy.GetType()) return;
|
||||
}
|
||||
|
||||
@@ -27,7 +29,8 @@ namespace Coffee.UIEffects
|
||||
{
|
||||
if (!graphic) return null;
|
||||
|
||||
for (var i = s_Proxies.Count - 1; i >= 0; i--)
|
||||
var count = s_Proxies.Count;
|
||||
for (var i = count - 1; i >= 0; i--)
|
||||
{
|
||||
var p = s_Proxies[i];
|
||||
if (p.IsValid(graphic)) return p;
|
||||
@@ -55,13 +58,12 @@ namespace Coffee.UIEffects
|
||||
/// <summary>
|
||||
/// Called before modifying the mesh.
|
||||
/// </summary>
|
||||
public virtual void OnPreModifyMesh(Graphic graphic)
|
||||
public virtual void OnPreModifyMesh(Graphic graphic, Canvas canvas)
|
||||
{
|
||||
UIVertexUtil.onLerpVertex = s_OnLerpVertex;
|
||||
ShadowUtil.onMarkAsShadow = s_OnMarkAsShadow;
|
||||
UIEffectContext.onModifyVertex = s_OnModifyVertex;
|
||||
|
||||
var canvas = graphic.canvas;
|
||||
if (canvas)
|
||||
{
|
||||
canvas.additionalShaderChannels |= AdditionalCanvasShaderChannels.TexCoord1;
|
||||
|
||||
@@ -4,7 +4,7 @@ using UnityEngine.UI;
|
||||
|
||||
namespace Coffee.UIEffects
|
||||
{
|
||||
internal class ImageProxy : GraphicProxy
|
||||
internal sealed class ImageProxy : GraphicProxy
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[InitializeOnLoadMethod]
|
||||
|
||||
@@ -10,7 +10,7 @@ using Object = UnityEngine.Object;
|
||||
|
||||
namespace Coffee.UIEffects
|
||||
{
|
||||
internal class TmpProxy : GraphicProxy
|
||||
internal sealed class TmpProxy : GraphicProxy
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if the graphic is valid for this proxy.
|
||||
@@ -40,13 +40,12 @@ namespace Coffee.UIEffects
|
||||
/// <summary>
|
||||
/// Called before modifying the mesh.
|
||||
/// </summary>
|
||||
public override void OnPreModifyMesh(Graphic graphic)
|
||||
public override void OnPreModifyMesh(Graphic graphic, Canvas canvas)
|
||||
{
|
||||
UIVertexUtil.onLerpVertex = s_OnLerpVertex;
|
||||
ShadowUtil.onMarkAsShadow = s_OnMarkAsShadow;
|
||||
UIEffectContext.onModifyVertex = s_OnModifyVertex;
|
||||
|
||||
var canvas = graphic.canvas;
|
||||
if (canvas)
|
||||
{
|
||||
canvas.additionalShaderChannels |= AdditionalCanvasShaderChannels.TexCoord2;
|
||||
|
||||
@@ -608,7 +608,7 @@ half4 uieffect(half4 origin, float2 uv, float4 uvMask, float4 wpos)
|
||||
uvGrad = saturate(mul(_MirrorGradViewMatrix, wpos)).xy;
|
||||
uvMask.x += 4;
|
||||
}
|
||||
|
||||
|
||||
const float isShadow = uvMask.x < 0 ? 1 : 0;
|
||||
uvMask.x += isShadow * 2;
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ Shader "CustomRenderTexture/UIEffect/Multiply (Alpha)"
|
||||
[Header(Main)]
|
||||
_MainTex ("Main Texture", 2D) = "white" {}
|
||||
_MainTex_Speed ("Main Texture Speed", Vector) = (0,0,0,0)
|
||||
|
||||
|
||||
[Header(Detail)]
|
||||
_DetailTex ("Detail Texture", 2D) = "white" {}
|
||||
_DetailTex_Speed ("Detail Texture Speed", Vector) = (0,0,0,0)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "com.coffee.ui-effect",
|
||||
"displayName": "UI Effect",
|
||||
"description": "UIEffect is an open-source package that allows you to intuitively apply rich UI effects directly from the Inspector or via code.\nCombine various filters, such as grayscale, blur, and dissolve, to decorate your UI with a unique visual style!",
|
||||
"version": "5.10.0",
|
||||
"version": "5.10.4",
|
||||
"unity": "2020.3",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user