chore: remove Implicit bool conversions

This commit is contained in:
mob-sakai
2026-06-25 03:15:33 +09:00
parent ec3fb13c11
commit a373cf772b
28 changed files with 138 additions and 125 deletions
@@ -14,7 +14,7 @@ namespace Coffee.UIEffects.Timeline
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region)
{
var director = TimelineEditor.inspectedDirector;
if (!director) return;
if (director == null) return;
var viewDuration = region.endTime - region.startTime;
var inDuration = (float)Math.Max(clip.easeInDuration, clip.blendInDuration);
@@ -38,7 +38,7 @@ namespace Coffee.UIEffects.Timeline
}
var floatClip = clip.asset as UIEffectFloatClip;
if (floatClip)
if (floatClip != null)
{
if (track is GradationRotationTrack || track is GradationOffsetTrack)
{
@@ -60,7 +60,7 @@ namespace Coffee.UIEffects.Timeline
protected override void DrawBackground(Rect rect, TimelineClip clip)
{
var asset = clip.asset as UIEffectFloatClip;
if (!asset) return;
if (asset == null) return;
if (s_FromStyle == null)
{
@@ -97,7 +97,7 @@ namespace Coffee.UIEffects.Timeline
protected override void DrawBackground(Rect p, TimelineClip clip)
{
var asset = clip.asset as UIEffectColorClip;
if (!asset) return;
if (asset == null) return;
var d = asset.m_Data;
if (d.m_Tween)
@@ -38,7 +38,7 @@ namespace Coffee.UIEffects.Editors
rect.y += 2;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.BeginDisabledGroup(effect && effect.hideFlags == HideFlags.NotEditable);
EditorGUI.BeginDisabledGroup(effect != null && effect.hideFlags == HideFlags.NotEditable);
EditorGUI.PropertyField(rect, element, GUIContent.none);
EditorGUI.EndDisabledGroup();
};
@@ -88,7 +88,7 @@ namespace Coffee.UIEffects.Editors
{
for (var i = _runtimePresets.arraySize - 1; 0 <= i; i--)
{
if (!_runtimePresets.GetArrayElementAtIndex(i).objectReferenceValue)
if (_runtimePresets.GetArrayElementAtIndex(i).objectReferenceValue == null)
{
_runtimePresets.DeleteArrayElementAtIndex(i);
}
+2 -2
View File
@@ -34,7 +34,7 @@ namespace Coffee.UIEffects.Editors
var r = EditorGUILayout.GetControlRect();
r.width -= 120;
if (_preset.objectReferenceValue)
if (_preset.objectReferenceValue != null)
{
EditorGUI.PropertyField(r, _preset);
}
@@ -81,7 +81,7 @@ namespace Coffee.UIEffects.Editors
EditorGUILayout.PropertyField(_allowToModifyMeshShape);
var parent = _target.objectReferenceValue ?? _preset.objectReferenceValue;
if (parent)
if (parent != null)
{
EditorGUI.BeginDisabledGroup(true);
CreateCachedEditor(parent, null, ref _uiEffectEditor);
+1 -1
View File
@@ -90,7 +90,7 @@ namespace Coffee.UIEffects.Editors
private void DrawPlayer(UIEffectTweener tweener)
{
if (!tweener) return;
if (tweener == null) return;
EditorGUILayout.Space(4);
GUILayout.Label(GUIContent.none, "sv_iconselector_sep", GUILayout.ExpandWidth(true));
@@ -99,7 +99,7 @@ namespace Coffee.UIEffectInternal
{
T component = null;
var transform = self.transform;
while (transform)
while (transform != null)
{
if (transform.TryGetComponent<T>(out var c))
{
@@ -120,7 +120,7 @@ namespace Coffee.UIEffectInternal
where T : Component
{
var tr = includeSelf ? self.transform : self.transform.parent;
while (tr)
while (tr != null)
{
if (tr.TryGetComponent<T>(out var c) && valid(c)) return c;
if (tr == stopAfter) return null;
@@ -197,7 +197,7 @@ namespace Coffee.UIEffectInternal
if (!includeInactive) return self.GetComponentInParent<T>();
var current = self.transform;
while (current)
while (current != null)
{
if (current.TryGetComponent<T>(out var c)) return c;
current = current.parent;
@@ -19,7 +19,7 @@ namespace Coffee.UIEffectInternal
mesh => mesh,
mesh =>
{
if (mesh)
if (mesh != null)
{
mesh.Clear();
}
@@ -37,7 +37,7 @@ namespace Coffee.UIEffectInternal
public static void CopyTo(this Mesh self, Mesh dst)
{
if (!self || !dst) return;
if (self == null || dst == null) return;
var vector3List = InternalListPool<Vector3>.Rent();
var vector4List = InternalListPool<Vector4>.Rent();
@@ -91,7 +91,7 @@ namespace Coffee.UIEffectInternal
public static void CopyTo(this Mesh self, VertexHelper dst)
{
if (!self || dst == null) return;
if (self == null || dst == null) return;
var vertexCount = self.vertexCount;
var indexCount = self.triangles.Length;
@@ -100,7 +100,7 @@ namespace Coffee.UIEffectInternal
public static void CopyTo(this Mesh self, VertexHelper dst, int vertexCount, int indexCount)
{
if (!self || dst == null) return;
if (self == null || dst == null) return;
var positions = InternalListPool<Vector3>.Rent();
var normals = InternalListPool<Vector3>.Rent();
@@ -41,11 +41,11 @@ namespace Coffee.UIEffectInternal
foreach (var t in TypeCache.GetTypesDerivedFrom(typeof(PreloadedProjectSettings<>)))
{
var settings = GetDefaultSettings(t);
if (!settings || settings.m_PreLoadSettingsInBuild) continue;
if (settings == null || settings.m_PreLoadSettingsInBuild) continue;
PlayerSettings.SetPreloadedAssets(
PlayerSettings.GetPreloadedAssets()
.Where(x => x && x.GetType() != t)
.Where(x => x != null && x.GetType() != t)
.ToArray());
Debug.Log($"[PreloadedProjectSettings] Build started: removed '{settings.name}' " +
@@ -238,7 +238,7 @@ namespace Coffee.UIEffectInternal
private void OnPlayModeStateChanged(PlayModeStateChange state)
{
if (!this) return;
if (this == null) return;
switch (state)
{
@@ -280,7 +280,7 @@ namespace Coffee.UIEffectInternal
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
#else
if (s_Instance && s_Instance != this)
if (s_Instance != null && s_Instance != this)
{
Destroy(s_Instance);
}
@@ -315,7 +315,7 @@ namespace Coffee.UIEffectInternal
{
if (_target == null)
{
if (_editor)
if (_editor != null)
{
DestroyImmediate(_editor);
_editor = null;
@@ -36,7 +36,7 @@ namespace Coffee.UIEffectInternal
foreach (var shaderName in s_ShaderNames)
{
var shader = Shader.Find(shaderName);
if (!shader) continue;
if (shader == null) continue;
var hasCgincError = ShaderUtil.GetShaderMessages(shader)
.Any(x => Regex.IsMatch(x.message, $"Couldn't open include file.*{s_CgincPattern}"));
@@ -120,7 +120,7 @@ namespace Coffee.UIEffectInternal
if (string.IsNullOrEmpty(shaderName)) return null;
var shader = Shader.Find(shaderName);
if (!shader) return null;
if (shader == null) return null;
var path = AssetDatabase.GetAssetPath(shader);
if (string.IsNullOrEmpty(path)) return null;
@@ -131,7 +131,7 @@ namespace Coffee.UIEffectInternal
private static void DeleteShader(string shaderName)
{
var shader = Shader.Find(shaderName);
if (shader)
if (shader != null)
{
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(shader));
}
@@ -90,7 +90,7 @@ namespace Coffee.UIEffectInternal
for (var i = 0; i < count; i++)
{
var s = m_RegisteredShaders[i];
if (s)
if (s != null)
{
_shaderByName[s.name] = s;
}
@@ -105,7 +105,7 @@ namespace Coffee.UIEffectInternal
/// </summary>
public Shader FindShaderByName(string name)
{
if (_shaderByName != null && _shaderByName.TryGetValue(name, out var shader) && shader)
if (_shaderByName != null && _shaderByName.TryGetValue(name, out var shader) && shader != null)
{
return shader;
}
@@ -118,7 +118,7 @@ namespace Coffee.UIEffectInternal
string format,
string defaultOptionalShaderName)
{
if (!shader) return null;
if (shader == null) return null;
// Already cached.
var id = shader.GetHashCode();
@@ -143,7 +143,7 @@ namespace Coffee.UIEffectInternal
var pair = m_OptionalShaders[i];
if (pair.key != shaderName) continue;
optionalShader = FindShaderByName(pair.value);
if (!optionalShader) continue;
if (optionalShader == null) continue;
_cachedOptionalShaders[id] = pair.value;
return optionalShader;
}
@@ -151,7 +151,7 @@ namespace Coffee.UIEffectInternal
// Find optional shader by format.
optionalShaderName = string.Format(format, shaderName);
optionalShader = FindShaderByName(optionalShaderName);
if (optionalShader)
if (optionalShader != null)
{
_cachedOptionalShaders[id] = optionalShaderName;
return optionalShader;
@@ -224,7 +224,7 @@ namespace Coffee.UIEffectInternal
{
// Find shader.
var shader = AssetDatabase.LoadAssetAtPath<Shader>(path);
if (!shader) return;
if (shader == null) return;
var shaderName = shader.name;
foreach (var key in keys)
@@ -241,12 +241,12 @@ namespace Coffee.UIEffectInternal
if (owner == null) return;
Profiler.BeginSample("(EDITOR/COF)[ShaderVariantRegistry] InitializeIfNeeded");
if (!m_Asset && AssetDatabase.IsMainAsset(owner))
if (m_Asset == null && AssetDatabase.IsMainAsset(owner))
{
// Find ShaderVariantCollection in owner.
var path = AssetDatabase.GetAssetPath(owner);
var collection = AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(path);
if (collection)
if (collection != null)
{
m_Asset = collection;
}
@@ -284,7 +284,7 @@ namespace Coffee.UIEffectInternal
var shaderRef = shaders.GetArrayElementAtIndex(i)
.FindPropertyRelative("first")
.objectReferenceValue as Shader;
if (shaderRef && !m_RegisteredShaders.Contains(shaderRef))
if (shaderRef != null && !m_RegisteredShaders.Contains(shaderRef))
{
m_RegisteredShaders.Add(shaderRef);
}
@@ -295,7 +295,7 @@ namespace Coffee.UIEffectInternal
internal void RegisterVariant(Material material, string path)
{
if (!material || !material.shader || !m_Asset) return;
if (material == null || material.shader == null || m_Asset == null) return;
Profiler.BeginSample("(EDITOR/COF)[ShaderVariantRegistry] RegisterVariant");
var (variant, pair) = GetVariant(material);
@@ -548,7 +548,7 @@ namespace Coffee.UIEffectInternal
if (collection == null) return;
var shader = Shader.Find(shaderName);
if (!shader) return;
if (shader == null) return;
collection.Add(new ShaderVariantCollection.ShaderVariant
{
@@ -47,12 +47,12 @@ namespace Coffee.UIEffectInternal
private static bool HasChanged_Internal(this Transform self, Transform baseTransform, ref Matrix4x4 prev,
float epsilon)
{
if (!self) return false;
if (self == null) return false;
var hash = baseTransform ? baseTransform.GetHashCode() : 0;
var hash = baseTransform != null ? baseTransform.GetHashCode() : 0;
if (FrameCache.TryGet(self, nameof(HasChanged), hash, out bool result)) return result;
var matrix = baseTransform
var matrix = baseTransform != null
? baseTransform.worldToLocalMatrix * self.localToWorldMatrix
: self.localToWorldMatrix;
var current = matrix * Matrix4x4.Scale(Vector3.one * 10000);
@@ -62,7 +62,7 @@ namespace Coffee.UIEffects.Timeline
public override void GatherProperties(PlayableDirector director, IPropertyCollector driver)
{
var trackBinding = director.GetGenericBinding(this) as UIEffect;
if (!trackBinding) return;
if (trackBinding == null) return;
driver.AddFromName<UIEffect>(trackBinding.gameObject, fieldName);
base.GatherProperties(director, driver);
@@ -113,7 +113,7 @@ namespace Coffee.UIEffects.Timeline
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
{
InitializeIfNeeded(playerData as UIEffect);
if (!effect) return;
if (effect == null) return;
var inputCount = playable.GetInputCount();
var value = default(T);
@@ -137,7 +137,7 @@ namespace Coffee.UIEffects.Timeline
public override void OnPlayableDestroy(Playable playable)
{
if (effect)
if (effect != null)
{
currentValue = _defaultValue;
}
@@ -159,13 +159,13 @@ namespace Coffee.UIEffects.Timeline
{
if (effect == newEffect) return;
if (effect)
if (effect != null)
{
currentValue = _defaultValue;
}
effect = newEffect;
_defaultValue = newEffect ? currentValue : default;
_defaultValue = newEffect != null ? currentValue : default;
}
protected abstract T Add(T current, T value, float weight);
+9 -9
View File
@@ -1451,7 +1451,7 @@ namespace Coffee.UIEffects
}
}
public override RectTransform transitionRoot => m_CustomRoot
public override RectTransform transitionRoot => m_CustomRoot != null
? m_CustomRoot
: transform as RectTransform;
@@ -1489,12 +1489,12 @@ namespace Coffee.UIEffects
{
var selected = 0 < selection.Length
&& (selection.Contains(gameObject)
|| replicas.Any(x => x && selection.Contains(x.gameObject)));
|| replicas.Any(x => x != null && selection.Contains(x.gameObject)));
context.SetEnablePreview(selected, effectMaterial);
foreach (var r in replicas)
{
if (!r || !r.isActiveAndEnabled || r.context == null) continue;
if (r == null || !r.isActiveAndEnabled || r.context == null) continue;
r.context.SetEnablePreview(selected, r.effectMaterial);
}
}
@@ -1506,7 +1506,7 @@ namespace Coffee.UIEffects
var count = replicas.Count;
for (var i = 0; i < count; i++)
{
if (!replicas[i]) continue;
if (replicas[i] == null) continue;
replicas[i].SetVerticesDirty();
}
}
@@ -1517,7 +1517,7 @@ namespace Coffee.UIEffects
var count = replicas.Count;
for (var i = 0; i < count; i++)
{
if (!replicas[i]) continue;
if (replicas[i] == null) continue;
replicas[i].SetMaterialDirty();
}
}
@@ -1528,7 +1528,7 @@ namespace Coffee.UIEffects
var count = replicas.Count;
for (var i = 0; i < count; i++)
{
if (!replicas[i]) continue;
if (replicas[i] == null) continue;
replicas[i].SetMaterialContextDirty();
}
}
@@ -1716,7 +1716,7 @@ namespace Coffee.UIEffects
/// </summary>
public void LoadPreset(UIEffect src, bool append)
{
if (!src) return;
if (src == null) return;
var dst = this;
if (!append || src.m_ToneFilter != ToneFilter.None)
@@ -1848,7 +1848,7 @@ namespace Coffee.UIEffects
/// </summary>
public void LoadPreset(UIEffectPreset src, bool append)
{
if (!src) return;
if (src == null) return;
var dst = this;
if (!append || src.m_ToneFilter != ToneFilter.None)
@@ -1977,7 +1977,7 @@ namespace Coffee.UIEffects
public void SavePreset(UIEffectPreset dst, bool append)
{
if (!dst) return;
if (dst == null) return;
var src = this;
if (!append || src.m_ToneFilter != ToneFilter.None)
+12 -12
View File
@@ -37,7 +37,7 @@ namespace Coffee.UIEffects
private bool _isContextDirty;
public Material effectMaterial => _material;
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
public Graphic graphic => _graphic != null ? _graphic : _graphic = GetComponent<Graphic>();
public virtual uint effectId => (uint)GetHashCode();
public virtual float actualSamplingScale => 1;
public virtual bool canModifyShape => true;
@@ -50,7 +50,7 @@ namespace Coffee.UIEffects
_canvasCached = true;
_canvas = GetComponentInParent<Canvas>();
if (!_canvas || !_canvas.isActiveAndEnabled)
if (_canvas == null || !_canvas.isActiveAndEnabled)
{
_canvas = null;
_canvasCached = false;
@@ -79,10 +79,10 @@ namespace Coffee.UIEffects
if (!isActiveAndEnabled) return null;
var g = graphic;
if (!g) return null;
if (g == null) return null;
var canvasRenderer = g.canvasRenderer;
if (!canvasRenderer || canvasRenderer.materialCount == 0) return null;
if (canvasRenderer == null || canvasRenderer.materialCount == 0) return null;
return canvasRenderer.GetMaterial();
}
@@ -137,7 +137,7 @@ namespace Coffee.UIEffects
private void OnAfterCanvasRebuild()
{
if (!_material || !graphic || !canvas || context == null) return;
if (_material == null || graphic == null || canvas == null || context == null) return;
if (_isContextDirty)
{
@@ -173,7 +173,7 @@ namespace Coffee.UIEffects
private bool CanModifyMesh()
{
if (!graphic || !graphic.isActiveAndEnabled) return false;
if (graphic == null || !graphic.isActiveAndEnabled) return false;
if (!isActiveAndEnabled) return false;
// The transitionRoot is same as the transform => true.
@@ -196,7 +196,7 @@ namespace Coffee.UIEffects
Profiler.BeginSample("(UIE)[UIEffect] GetModifiedMaterial");
var samplingScaleId = (uint)(Mathf.InverseLerp(0.01f, 100, actualSamplingScale) * uint.MaxValue);
var rootId = (uint)(transitionRoot ? transitionRoot.GetHashCode() : 0);
var rootId = (uint)(transitionRoot != null ? transitionRoot.GetHashCode() : 0);
var hash = new Hash128((uint)baseMaterial.GetHashCode(), effectId, samplingScaleId, rootId);
if (!MaterialRepository.Valid(hash, _material))
{
@@ -251,7 +251,7 @@ namespace Coffee.UIEffects
public virtual void SetVerticesDirty()
{
if (graphic)
if (graphic != null)
{
graphic.SetVerticesDirty();
GraphicProxy.Find(graphic).SetVerticesDirty(graphic, enabled);
@@ -261,7 +261,7 @@ namespace Coffee.UIEffects
public virtual void SetMaterialDirty()
{
if (graphic)
if (graphic != null)
{
graphic.SetMaterialDirty();
SetMaterialContextDirty();
@@ -283,7 +283,7 @@ namespace Coffee.UIEffects
public virtual void ApplyContextToMaterial(Material material)
{
if (!isActiveAndEnabled || context == null || !material) return;
if (!isActiveAndEnabled || context == null || material == null) return;
_isContextDirty = false;
context.ApplyToMaterial(material, actualSamplingScale);
@@ -310,7 +310,7 @@ namespace Coffee.UIEffects
public void OnControlTimeStart()
{
if (this)
if (this != null)
{
enabled = true;
}
@@ -318,7 +318,7 @@ namespace Coffee.UIEffects
public void OnControlTimeStop()
{
if (this)
if (this != null)
{
enabled = false;
}
+5 -5
View File
@@ -290,7 +290,7 @@ namespace Coffee.UIEffects
get
{
if (m_GradationGradient == null) return null;
if (!_gradationRampTex) _gradationRampTex = s_TexturePool.Rent();
if (_gradationRampTex == null) _gradationRampTex = s_TexturePool.Rent();
if (!_isGradientDirty) return _gradationRampTex;
_isGradientDirty = false;
@@ -317,7 +317,7 @@ namespace Coffee.UIEffects
get
{
if (m_TransitionGradient == null) return null;
if (!_transitionRampTex) _transitionRampTex = s_TexturePool.Rent();
if (_transitionRampTex == null) _transitionRampTex = s_TexturePool.Rent();
if (!_isTransitionGradientDirty) return _transitionRampTex;
_isTransitionGradientDirty = false;
@@ -449,7 +449,7 @@ namespace Coffee.UIEffects
public void ApplyToMaterial(Material material, float actualSamplingScale = 1f)
{
if (!material) return;
if (material == null) return;
Profiler.BeginSample("(UIE)[UIEffect] ApplyToMaterial");
@@ -580,7 +580,7 @@ namespace Coffee.UIEffects
public void SetEnablePreview(bool enable, Material material)
{
if (!material) return;
if (material == null) return;
material.SetVector(s_TransitionTex_Speed, enable ? (Vector4)m_TransitionTexSpeed : Vector4.zero);
material.SetVector(s_DetailTex_Speed, enable ? (Vector4)m_DetailTexSpeed : Vector4.zero);
material.SetFloat(s_TransitionAutoPlaySpeed, enable ? m_TransitionAutoPlaySpeed : 0);
@@ -589,7 +589,7 @@ namespace Coffee.UIEffects
public void UpdateViewMatrix(Material material, RectTransform transitionRoot, Canvas canvas)
{
if (!material) return;
if (material == null) return;
var size = transitionRoot.rect.size;
var scale = new Vector3(1f / size.x, 1f / size.y, 1f);
+15 -2
View File
@@ -8,11 +8,24 @@ namespace Coffee.UIEffects
[ExecuteAlways]
public class UIEffectPreset : ScriptableObject
{
internal static UIEffectPreset s_DefaultPreset;
private static UIEffectPreset s_DefaultPreset;
#if UNITY_EDITOR && UNITY_2019_3_OR_NEWER
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void OnDomainReload()
{
if (s_DefaultPreset != null)
{
Misc.DestroyImmediate(s_DefaultPreset);
}
s_DefaultPreset = null;
}
#endif
internal static UIEffectPreset GetDefaultPreset()
{
if (!s_DefaultPreset)
if (s_DefaultPreset == null)
{
s_DefaultPreset = CreateInstance<UIEffectPreset>();
s_DefaultPreset.hideFlags = HideFlags.HideAndDontSave;
@@ -45,7 +45,7 @@ namespace Coffee.UIEffects
public static void RegisterRuntimePreset(UIEffectPreset preset)
{
// Already registered.
if (!preset || instance.m_RuntimePresetsV2.Contains(preset)) return;
if (preset == null || instance.m_RuntimePresetsV2.Contains(preset)) return;
instance.m_RuntimePresetsV2.Add(preset);
#if UNITY_EDITOR
@@ -59,7 +59,7 @@ namespace Coffee.UIEffects
for (var i = 0; i < instance.m_RuntimePresets.Count; i++)
{
var preset = instance.m_RuntimePresets[i];
if (preset && preset.name == presetName)
if (preset != null && preset.name == presetName)
{
return preset;
}
@@ -73,7 +73,7 @@ namespace Coffee.UIEffects
for (var i = 0; i < instance.m_RuntimePresetsV2.Count; i++)
{
var preset = instance.m_RuntimePresetsV2[i];
if (preset && preset.name == presetName)
if (preset != null && preset.name == presetName)
{
return preset;
}
+17 -17
View File
@@ -99,9 +99,9 @@ namespace Coffee.UIEffects
public override bool canModifyShape => m_AllowToModifyMeshShape;
public override uint effectId => target
public override uint effectId => target != null
? target.effectId
: preset
: preset != null
? (uint)preset.GetHashCode()
: (uint)GetHashCode();
@@ -111,10 +111,10 @@ namespace Coffee.UIEffects
get
{
// Following the preset/preset-target.
if (preset || (target && !isTargetInScene)) return base.context;
if (preset != null || (target != null && !isTargetInScene)) return base.context;
// Following the instantiated target.
return target && target.isActiveAndEnabled && isTargetInScene
return target != null && target.isActiveAndEnabled && isTargetInScene
? target.context
: null;
}
@@ -126,7 +126,7 @@ namespace Coffee.UIEffects
{
if (useTargetTransform)
{
if (preset && !m_CustomRoot && graphic && canvas)
if (preset != null && m_CustomRoot == null && graphic != null && canvas != null)
{
return canvas.transform as RectTransform;
}
@@ -137,15 +137,15 @@ namespace Coffee.UIEffects
}
}
return m_CustomRoot ? m_CustomRoot : transform as RectTransform;
return m_CustomRoot != null ? m_CustomRoot : transform as RectTransform;
}
}
private bool isTargetInScene => target && target.gameObject.scene.IsValid();
private bool isTargetInScene => target != null && target.gameObject.scene.IsValid();
protected override void OnEnable()
{
if (!preset)
if (preset == null)
{
RefreshTarget(target);
}
@@ -170,7 +170,7 @@ namespace Coffee.UIEffects
{
RefreshTarget(target);
if (preset || (target && !isTargetInScene))
if (preset != null || (target != null && !isTargetInScene))
{
context?.SetGradationDirty();
context?.SetTransitionGradationDirty();
@@ -197,12 +197,12 @@ namespace Coffee.UIEffects
private void RefreshTarget(UIEffect newTarget)
{
if (_currentTarget == newTarget) return;
if (_currentTarget)
if (_currentTarget != null)
{
_currentTarget.replicas.Remove(this);
}
if (newTarget)
if (newTarget != null)
{
_currentTarget = newTarget;
if (isTargetInScene)
@@ -219,12 +219,12 @@ namespace Coffee.UIEffects
internal override void UpdateContext(UIEffectContext dst)
{
// Following the preset.
if (preset)
if (preset != null)
{
preset.UpdateContext(dst);
}
// Following the preset-target.
else if (target && !isTargetInScene)
else if (target != null && !isTargetInScene)
{
target.UpdateContext(dst);
}
@@ -232,10 +232,10 @@ namespace Coffee.UIEffects
public override void ApplyContextToMaterial(Material material)
{
if (!isActiveAndEnabled && !preset && !target) return;
if (!isActiveAndEnabled && preset == null && target == null) return;
// Following the preset/preset-target.
if (preset || (target && !isTargetInScene))
if (preset != null || (target != null && !isTargetInScene))
{
base.ApplyContextToMaterial(material);
}
@@ -264,11 +264,11 @@ namespace Coffee.UIEffects
public void OnAfterDeserialize()
{
if (m_Preset)
if (m_Preset != null)
{
m_Target = null;
}
else if (m_Target)
else if (m_Target != null)
{
m_Preset = null;
}
+2 -2
View File
@@ -134,7 +134,7 @@ namespace Coffee.UIEffects
/// <summary>
/// The target UIMaterialPropertyInjector to tween.
/// </summary>
private UIEffectBase target => _target ? _target : _target = GetComponent<UIEffectBase>();
private UIEffectBase target => _target != null ? _target : _target = GetComponent<UIEffectBase>();
/// <summary>
/// The culling mask of the tween.
@@ -167,7 +167,7 @@ namespace Coffee.UIEffects
_rate = value;
if (!target || cullingMask == 0) return;
if (target == null || cullingMask == 0) return;
var currentCurve = curve;
if (separateReverseCurve)
@@ -27,7 +27,7 @@ namespace Coffee.UIEffects
public static GraphicProxy Find(Graphic graphic)
{
if (!graphic) return null;
if (graphic == null) return null;
var count = s_Proxies.Count;
for (var i = count - 1; i >= 0; i--)
@@ -44,7 +44,7 @@ namespace Coffee.UIEffects
/// </summary>
protected virtual bool IsValid(Graphic graphic)
{
return graphic;
return graphic != null;
}
/// <summary>
@@ -64,7 +64,7 @@ namespace Coffee.UIEffects
ShadowUtil.onMarkAsShadow = s_OnMarkAsShadow;
UIEffectContext.onModifyVertex = s_OnModifyVertex;
if (canvas)
if (canvas != null)
{
canvas.additionalShaderChannels |= AdditionalCanvasShaderChannels.TexCoord1;
}
+1 -1
View File
@@ -20,7 +20,7 @@ namespace Coffee.UIEffects
/// </summary>
protected override bool IsValid(Graphic graphic)
{
if (!graphic) return false;
if (graphic == null) return false;
if (graphic is Image) return true;
return false;
}
+13 -13
View File
@@ -17,12 +17,12 @@ namespace Coffee.UIEffects
/// </summary>
protected override bool IsValid(Graphic graphic)
{
if (!graphic) return false;
if (graphic == null) return false;
if (graphic is TextMeshProUGUI) return true;
if (graphic is TMP_SubMeshUI sub)
{
// If TMP_SubMeshUI is used for text
return !sub.spriteAsset
return sub.spriteAsset == null
|| sub.sharedMaterial != sub.spriteAsset.material;
}
@@ -46,7 +46,7 @@ namespace Coffee.UIEffects
ShadowUtil.onMarkAsShadow = s_OnMarkAsShadow;
UIEffectContext.onModifyVertex = s_OnModifyVertex;
if (canvas)
if (canvas != null)
{
canvas.additionalShaderChannels |= AdditionalCanvasShaderChannels.TexCoord2;
}
@@ -145,7 +145,7 @@ namespace Coffee.UIEffects
var toRemove = InternalListPool<TextMeshProUGUI>.Rent();
foreach (var textMeshProUGUI in s_RegisteredInstances)
{
if (textMeshProUGUI
if (textMeshProUGUI != null
&& textMeshProUGUI.isActiveAndEnabled
&& !textMeshProUGUI.isTextObjectScaleStatic)
{
@@ -183,7 +183,7 @@ namespace Coffee.UIEffects
{
foreach (var textMeshProUGUI in s_ChangedInstances)
{
if (!textMeshProUGUI || !textMeshProUGUI.isActiveAndEnabled) continue;
if (textMeshProUGUI == null || !textMeshProUGUI.isActiveAndEnabled) continue;
if (!textMeshProUGUI.TryGetComponent<IMeshModifier>(out var _)) continue;
s_RegisteredInstances.Add(textMeshProUGUI);
@@ -198,7 +198,7 @@ namespace Coffee.UIEffects
{
foreach (var textMeshProUGUI in s_RegisteredInstances)
{
if (!textMeshProUGUI || !textMeshProUGUI.isActiveAndEnabled) continue;
if (textMeshProUGUI == null || !textMeshProUGUI.isActiveAndEnabled) continue;
if (textMeshProUGUI.TryGetComponent<UIEffectBase>(out var effect) && effect.isActiveAndEnabled)
{
effect.ReleaseMaterial();
@@ -213,7 +213,7 @@ namespace Coffee.UIEffects
private static void ModifyMesh(TextMeshProUGUI textMeshProUGUI)
{
if (!s_Mesh)
if (s_Mesh == null)
{
s_Mesh = new Mesh();
s_Mesh.MarkDynamic();
@@ -240,7 +240,7 @@ namespace Coffee.UIEffects
else
{
var subMeshUI = GetSubMeshUI(subMeshes, meshInfo.material, meshInfo.mesh, i - 1);
if (subMeshUI)
if (subMeshUI != null)
{
subMeshUI.canvasRenderer.SetMesh(s_Mesh);
}
@@ -270,7 +270,7 @@ namespace Coffee.UIEffects
}
var subMeshUI = GetSubMeshUI(subMeshes, meshInfo.material, meshInfo.mesh, i - 1);
if (!subMeshUI) break;
if (subMeshUI == null) break;
// fix: TMP Text sprite submesh lost when changing fontMaterial (#368)
if (!subMeshUI.TryGetComponent<UIEffectReplica>(out var replica))
@@ -278,7 +278,7 @@ namespace Coffee.UIEffects
replica = subMeshUI.gameObject.AddComponent<UIEffectReplica>();
textMeshProUGUI.RegisterDirtyMaterialCallback(() =>
{
if (subMeshUI) subMeshUI.SetMaterialDirty();
if (subMeshUI != null) subMeshUI.SetMaterialDirty();
});
}
@@ -309,12 +309,12 @@ namespace Coffee.UIEffects
int start)
{
var count = subMeshes.Count;
if (mesh)
if (mesh != null)
{
for (var j = 0; j < count; j++)
{
var s = subMeshes[(j + start + count) % count];
if (!s) continue;
if (s == null) continue;
if (s.mesh == mesh) return s;
}
}
@@ -322,7 +322,7 @@ namespace Coffee.UIEffects
for (var j = 0; j < count; j++)
{
var s = subMeshes[(j + start + count) % count];
if (!s) continue;
if (s == null) continue;
if (s.sharedMaterial == material) return s;
}
@@ -25,29 +25,29 @@ public class UIEffect_TweenerControler : MonoBehaviour
private void Update()
{
if (m_Info)
if (m_Info != null)
{
var tw = tweener;
m_Info.text =
$"{tw.time:F2}/{tw.totalTime:F2} ({tw.rate:F2}), {tw.direction}, isTweening={tw.isTweening}, isDelaying={tw.isDelaying}, isPaused={tw.isPaused}";
}
if (m_SeekBar)
if (m_SeekBar != null)
{
m_SeekBar.value = tweener.time / tweener.totalTime;
}
if (m_SeekBarBgInterval1)
if (m_SeekBarBgInterval1 != null)
{
m_SeekBarBgInterval1.SetActive(UIEffectTweener.WrapMode.Loop <= tweener.wrapMode);
}
if (m_SeekBarBgDuration2)
if (m_SeekBarBgDuration2 != null)
{
m_SeekBarBgDuration2.SetActive(UIEffectTweener.WrapMode.PingPongOnce <= tweener.wrapMode);
}
if (m_SeekBarBgInterval2)
if (m_SeekBarBgInterval2 != null)
{
m_SeekBarBgInterval2.SetActive(UIEffectTweener.WrapMode.PingPongLoop <= tweener.wrapMode);
}
@@ -82,7 +82,7 @@ namespace Coffee.UIEffects
{
play = true;
SetupProperty();
if (reset && _tweener)
if (reset && _tweener != null)
{
_tweener.direction = UIEffectTweener.Direction.Forward;
_tweener.SetTime(0);
@@ -93,7 +93,7 @@ namespace Coffee.UIEffects
{
play = true;
SetupProperty();
if (reset && _tweener)
if (reset && _tweener != null)
{
_tweener.direction = UIEffectTweener.Direction.Reverse;
_tweener.SetTime(_tweener.totalTime);
@@ -106,7 +106,7 @@ namespace Coffee.UIEffects
public void Stop(bool reset)
{
play = false;
if (reset && _tweener)
if (reset && _tweener != null)
{
SetupProperty();
_tweener.SetTime(0);
@@ -121,7 +121,7 @@ namespace Coffee.UIEffects
private void SetupProperty()
{
if (!_target) return;
if (_target == null) return;
_tweener = _target.GetOrAddComponent<UIEffectTweener>();
_tweener.enabled = play;
_tweener.duration = duration;
@@ -226,7 +226,7 @@ namespace Coffee.UIEffects
private void LoadDefaultTransitionTextureIfNeeded()
{
if (m_TransitionTexture) return;
if (m_TransitionTexture != null) return;
var preset = UIEffectProjectSettings.LoadPreset("Legacy-UIDissolve");
if (preset is UIEffect presetV1)
{
@@ -20,7 +20,7 @@ namespace Coffee.UIEffects
private bool m_Vertical = false;
private Graphic _graphic;
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
public Graphic graphic => _graphic != null ? _graphic : _graphic = GetComponent<Graphic>();
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Coffee.UIEffects.UIFlip"/> should be flipped horizontally.
@@ -64,7 +64,7 @@ namespace Coffee.UIEffects
public void SetVerticesDirty()
{
if (graphic)
if (graphic != null)
{
graphic.SetVerticesDirty();
GraphicProxy.Find(graphic).SetVerticesDirty(graphic, enabled);
@@ -78,7 +78,7 @@ namespace Coffee.UIEffects
public void ModifyMesh(VertexHelper vh)
{
if (!isActiveAndEnabled || !graphic || !graphic.IsActive() || (!horizontal && !vertical)) return;
if (!isActiveAndEnabled || graphic == null || !graphic.IsActive() || (!horizontal && !vertical)) return;
var count = vh.currentVertCount;
var vt = default(UIVertex);
@@ -207,7 +207,7 @@ namespace Coffee.UIEffects
private void LoadDefaultTransitionTextureIfNeeded()
{
if (m_TransitionTexture) return;
if (m_TransitionTexture != null) return;
var preset = UIEffectProjectSettings.LoadPreset("Legacy-UIShiny");
if (preset is UIEffect presetV1)
{
@@ -251,7 +251,7 @@ namespace Coffee.UIEffects
private void LoadDefaultTransitionTextureIfNeeded()
{
if (m_TransitionTexture) return;
if (m_TransitionTexture != null) return;
var preset = UIEffectProjectSettings.LoadPreset("Legacy-UIDissolve");
if (preset is UIEffect presetV1)
{