Skip to content

Commit 9e6d99a

Browse files
committed
Add enter/exit sound for gcomponent
1 parent 9872e47 commit 9e6d99a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Assets/Scripts/UI/GComponent.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,17 @@ internal void ConstructFromResource(List<GObject> objectPool, int poolIndex)
15341534
}
15351535
}
15361536

1537+
if (buffer.version >= 5)
1538+
{
1539+
string str = buffer.ReadS();
1540+
if (!string.IsNullOrEmpty(str))
1541+
this.onAddedToStage.Add(() => __playSound(str, 1));
1542+
1543+
string str2 = buffer.ReadS();
1544+
if (!string.IsNullOrEmpty(str2))
1545+
this.onRemovedFromStage.Add(() => __playSound(str2, 1));
1546+
}
1547+
15371548
buffer.Seek(0, 5);
15381549

15391550
int transitionCount = buffer.ReadShort();
@@ -1628,6 +1639,13 @@ public override void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
16281639
}
16291640
}
16301641

1642+
void __playSound(string soundRes, float volumeScale)
1643+
{
1644+
NAudioClip sound = UIPackage.GetItemAssetByURL(soundRes) as NAudioClip;
1645+
if (sound != null && sound.nativeClip != null)
1646+
Stage.inst.PlayOneShotSound(sound.nativeClip, volumeScale);
1647+
}
1648+
16311649
void __addedToStage()
16321650
{
16331651
int cnt = _transitions.Count;

0 commit comments

Comments
 (0)