Skip to content

Commit

Permalink
fix: fix upgrading asset system (v1 to v2)
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Jul 21, 2024
1 parent 2eaaad6 commit e6d0c60
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ protected override bool ModifyComponent(SoftMask softMask, bool dryRun)

public override string Report()
{
return " -> SoftMask.alpha API has been changed. " +
"Use CanvasGroup component and CanvasGroup.alpha instead.\n";
return " -> SoftMask.alpha API has been changed. Use Graphic.color.a instead.";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Coffee.UISoftMaskInternal;
using Coffee.UISoftMaskInternal.AssetModification;
using UnityEditor;
using UnityEngine;

#pragma warning disable CS0612, CS0618 // Type or member is obsolete

namespace Coffee.UISoftMask
Expand All @@ -13,15 +15,13 @@ protected override bool ModifyComponent(SoftMask softMask, bool dryRun)

if (!dryRun)
{
var go = softMask.gameObject;
Object.DestroyImmediate(softMask);
var shape = softMask.GetOrAddComponent<MaskingShape>();
shape.softnessRange = softMask.softnessRange;
shape.alphaHitTest = softMask.alphaHitTest;
shape.showMaskGraphic = softMask.showMaskGraphic;

if (!go.TryGetComponent<MaskingShape>(out _))
{
go.AddComponent<MaskingShape>();
}

EditorUtility.SetDirty(go);
Object.DestroyImmediate(softMask);
EditorUtility.SetDirty(shape.gameObject);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Coffee.UISoftMaskInternal;
using Coffee.UISoftMaskInternal.AssetModification;
using UnityEditor;

#pragma warning disable CS0612, CS0618 // Type or member is obsolete

namespace Coffee.UISoftMask
Expand All @@ -9,13 +10,13 @@ internal class SoftMaskComponentModifier_Softness : ComponentModifier<SoftMask>
{
protected override bool ModifyComponent(SoftMask softMask, bool dryRun)
{
if (softMask.softness < 0) return false;
if (softMask.m_Softness < 0) return false;

if (!dryRun)
{
var go = softMask.gameObject;
softMask.softnessRange = new MinMax01(0, softMask.softness);
softMask.softness = -1;
softMask.softnessRange = new MinMax01(0, softMask.m_Softness);
softMask.m_Softness = -1;
EditorUtility.SetDirty(go);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,16 @@ public static Modifier Create(string path)
}
};
}

protected override bool RunModify(bool dryRun)
{
var modified = base.RunModify(dryRun);
if (!dryRun && modified)
{
AssetDatabase.ImportAsset(path);
}

return modified;
}
}
}
12 changes: 12 additions & 0 deletions Packages/src/Editor/AssetModification/UISoftMaskModifierRunner.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Coffee.UISoftMaskInternal.AssetModification;
using UnityEditor;

namespace Coffee.UISoftMask
{
Expand Down Expand Up @@ -35,5 +36,16 @@ public UISoftMaskModifierRunner()
})
{
}

public override void Run(string[] assetPaths, bool dryRun)
{
if (!dryRun)
{
AssetDatabase.ImportAsset("Packages/com.coffee.softmask-for-ugui/Shaders",
ImportAssetOptions.ImportRecursive);
}

base.Run(assetPaths, dryRun);
}
}
}
2 changes: 1 addition & 1 deletion Packages/src/Editor/Internal/AssetModification/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void RunIfUserWantsTo()
Run(assetPaths, dryRun);
}

public void Run(string[] assetPaths, bool dryRun)
public virtual void Run(string[] assetPaths, bool dryRun)
{
var modifiers = GetModifiers(assetPaths);
var canceled = false;
Expand Down
2 changes: 1 addition & 1 deletion Packages/src/Runtime/SoftMask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public enum MaskingMode

[SerializeField]
[Obsolete]
private float m_Softness = -1;
internal float m_Softness = -1;

[SerializeField]
[Obsolete]
Expand Down
2 changes: 2 additions & 0 deletions Packages/src/Shaders/SoftMask.cginc
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ float SoftMaskSample(float2 uv, float a)

#if SOFTMASK_EDITOR
#define EDITOR_ONLY(x) x
#define SOFTMASK_EDITOR_ONLY(x) x
#define SoftMask(_, worldPos, alpha) SoftMaskSample(WorldToUv(worldPos), alpha)
#else
#define EDITOR_ONLY(_)
#define SOFTMASK_EDITOR_ONLY(_)
#define SoftMask(clipPos, _, __) SoftMaskSample(ClipToUv(clipPos), 1)
#endif
#endif // UI_SOFT_MASK_INCLUDED

0 comments on commit e6d0c60

Please sign in to comment.