11using System . Collections ;
2- using System . Collections . Generic ;
32using UnityEngine ;
43using DCL ;
54
65public class AvatarAnimationEventHandler : MonoBehaviour
76{
8- const string FOOTSTEP_NAME = "footstep" , HEART_NAME = "heart" ;
9- const string ANIM_NAME_KISS = "kiss" , ANIM_NAME_MONEY = "money" , ANIM_NAME_CLAP = "clap" , ANIM_NAME_SNOWFLAKE = "snowfall" , ANIM_NAME_HOHOHO = "hohoho" ;
10- const float MIN_EVENT_WAIT_TIME = 0.1f ;
11- const float HOHOHO_OFFSET = 1.5f ;
7+ private const string FOOTSTEP_NAME = "footstep" , HEART_NAME = "heart" ;
8+ private const string ANIM_NAME_KISS = "kiss" , ANIM_NAME_MONEY = "money" , ANIM_NAME_CLAP = "clap" , ANIM_NAME_SNOWFLAKE = "snowfall" , ANIM_NAME_HOHOHO = "hohoho" ;
9+ private const float MIN_EVENT_WAIT_TIME = 0.1f ;
10+ private const float HOHOHO_OFFSET = 1.5f ;
1211
13- AudioEvent footstepLight ;
14- AudioEvent footstepSlide ;
15- AudioEvent footstepWalk ;
16- AudioEvent footstepRun ;
17- AudioEvent clothesRustleShort ;
18- AudioEvent clap ;
19- AudioEvent throwMoney ;
20- AudioEvent blowKiss ;
12+ private AudioEvent footstepLight ;
13+ private AudioEvent footstepSlide ;
14+ private AudioEvent footstepWalk ;
15+ private AudioEvent footstepRun ;
16+ private AudioEvent clothesRustleShort ;
17+ private AudioEvent clap ;
18+ private AudioEvent throwMoney ;
19+ private AudioEvent blowKiss ;
2120
22- Animation anim ;
21+ private Animation anim ;
2322
24- float lastEventTime ;
23+ private float lastEventTime ;
2524
26- StickersController stickersController ;
25+ private StickersController stickersController ;
2726
28- Transform footL ;
29- Transform footR ;
30- Transform handL ;
31- Transform handR ;
27+ private int renderingLayer ;
3228
33- public void Init ( AudioContainer audioContainer )
29+ private Transform footL ;
30+ private Transform footR ;
31+ private Transform handL ;
32+ private Transform handR ;
33+
34+ public void Init ( AudioContainer audioContainer , int renderingLayer )
3435 {
3536 if ( audioContainer == null )
3637 return ;
3738
39+ this . renderingLayer = renderingLayer ;
40+
3841 footstepLight = audioContainer . GetEvent ( "FootstepLight" ) ;
3942 footstepSlide = audioContainer . GetEvent ( "FootstepSlide" ) ;
4043 footstepWalk = audioContainer . GetEvent ( "FootstepWalk" ) ;
@@ -65,13 +68,13 @@ public void Init(AudioContainer audioContainer)
6568 public void AnimEvent_FootstepRunLeft ( )
6669 {
6770 PlayAudioEvent ( footstepRun ) ;
68- PlaySticker ( FOOTSTEP_NAME , footL . position , Vector3 . up ) ;
71+ PlaySticker ( FOOTSTEP_NAME , footL . position , Vector3 . up , renderingLayer : renderingLayer ) ;
6972 }
7073
7174 public void AnimEvent_FootstepRunRight ( )
7275 {
7376 PlayAudioEvent ( footstepRun ) ;
74- PlaySticker ( FOOTSTEP_NAME , footR . position , Vector3 . up ) ;
77+ PlaySticker ( FOOTSTEP_NAME , footR . position , Vector3 . up , renderingLayer : renderingLayer ) ;
7578 }
7679
7780 public void AnimEvent_ClothesRustleShort ( ) { PlayAudioEvent ( clothesRustleShort ) ; }
@@ -85,7 +88,7 @@ public void AnimEvent_Clap()
8588 return ;
8689
8790 PlayAudioEvent ( clap ) ;
88- PlaySticker ( ANIM_NAME_CLAP , handR . position , Vector3 . up , true ) ;
91+ PlaySticker ( ANIM_NAME_CLAP , handR . position , Vector3 . up , true , renderingLayer : renderingLayer ) ;
8992 UpdateEventTime ( ) ;
9093 }
9194
@@ -98,7 +101,7 @@ public void AnimEvent_ThrowMoney()
98101 return ;
99102
100103 PlayAudioEvent ( throwMoney ) ;
101- PlaySticker ( ANIM_NAME_MONEY , handL . position , handL . rotation . eulerAngles , true ) ;
104+ PlaySticker ( ANIM_NAME_MONEY , handL . position , handL . rotation . eulerAngles , true , renderingLayer : renderingLayer ) ;
102105 UpdateEventTime ( ) ;
103106 }
104107
@@ -115,10 +118,10 @@ public void AnimEvent_BlowKiss()
115118 UpdateEventTime ( ) ;
116119 }
117120
118- IEnumerator EmitHeartParticle ( )
121+ private IEnumerator EmitHeartParticle ( )
119122 {
120123 yield return new WaitForSeconds ( 0.8f ) ;
121- PlaySticker ( HEART_NAME , handR . position , transform . rotation . eulerAngles , true ) ;
124+ PlaySticker ( HEART_NAME , handR . position , transform . rotation . eulerAngles , true , renderingLayer : renderingLayer ) ;
122125 }
123126
124127 public void AnimEvent_Snowflakes ( )
@@ -129,27 +132,27 @@ public void AnimEvent_Snowflakes()
129132 if ( ! AnimationWeightIsOverThreshold ( 0.2f , ANIM_NAME_SNOWFLAKE ) )
130133 return ;
131134
132- PlaySticker ( "snowflakes" , transform . position , Vector3 . zero , true ) ;
135+ PlaySticker ( "snowflakes" , transform . position , Vector3 . zero , true , renderingLayer : renderingLayer ) ;
133136 }
134137
135138 public void AnimEvent_Hohoho ( )
136139 {
137140 if ( LastEventWasTooRecent ( ) )
138141 return ;
139-
142+
140143 if ( ! AnimationWeightIsOverThreshold ( 0.2f , ANIM_NAME_HOHOHO ) )
141144 return ;
142145
143- PlaySticker ( ANIM_NAME_HOHOHO , transform . position + Vector3 . up * HOHOHO_OFFSET , Vector3 . zero , true ) ;
146+ PlaySticker ( ANIM_NAME_HOHOHO , transform . position + Vector3 . up * HOHOHO_OFFSET , Vector3 . zero , true , renderingLayer : renderingLayer ) ;
144147 }
145148
146- void PlayAudioEvent ( AudioEvent audioEvent )
149+ private void PlayAudioEvent ( AudioEvent audioEvent )
147150 {
148151 if ( audioEvent != null )
149152 audioEvent . Play ( true ) ;
150153 }
151154
152- bool AnimationWeightIsOverThreshold ( float threshold , string animationName )
155+ private bool AnimationWeightIsOverThreshold ( float threshold , string animationName )
153156 {
154157 if ( anim != null )
155158 {
@@ -170,25 +173,23 @@ bool AnimationWeightIsOverThreshold(float threshold, string animationName)
170173 return false ;
171174 }
172175
173- void UpdateEventTime ( )
176+ private void UpdateEventTime ( )
174177 {
175178 lastEventTime = Time . realtimeSinceStartup ;
176179 }
177180
178- bool LastEventWasTooRecent ( )
179- {
180- return lastEventTime + MIN_EVENT_WAIT_TIME >= Time . realtimeSinceStartup ;
181- }
181+ private bool LastEventWasTooRecent ( ) =>
182+ lastEventTime + MIN_EVENT_WAIT_TIME >= Time . realtimeSinceStartup ;
182183
183184 /// <summary>
184185 /// Plays a sticker.
185186 /// </summary>
186187 /// <param name="id">ID string of sticker</param>
187188 /// <param name="position">Position in world space</param>
188189 /// <param name="rotation">Euler angles</param>
189- void PlaySticker ( string id , Vector3 position , Vector3 direction , bool followTransform = false )
190+ private void PlaySticker ( string id , Vector3 position , Vector3 direction , bool followTransform = false , int renderingLayer = 0 )
190191 {
191192 if ( stickersController != null )
192- stickersController . PlaySticker ( id , position , direction , followTransform ) ;
193+ stickersController . PlaySticker ( id , position , direction , followTransform , renderingLayer ) ;
193194 }
194- }
195+ }
0 commit comments