| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using AvatarSystem; |
| | 4 | | using DCL; |
| | 5 | | using DCL.Components; |
| | 6 | | using DCL.Emotes; |
| | 7 | | using DCL.Helpers; |
| | 8 | | using UnityEngine; |
| | 9 | | using Environment = DCL.Environment; |
| | 10 | |
|
| | 11 | | public enum AvatarAnimation |
| | 12 | | { |
| | 13 | | IDLE, |
| | 14 | | RUN, |
| | 15 | | WALK, |
| | 16 | | EMOTE, |
| | 17 | | JUMP, |
| | 18 | | FALL, |
| | 19 | | } |
| | 20 | |
|
| | 21 | | public class AvatarAnimatorLegacy : MonoBehaviour, IPoolLifecycleHandler, IAnimator |
| | 22 | | { |
| | 23 | | const float IDLE_TRANSITION_TIME = 0.2f; |
| | 24 | | const float STRAFE_TRANSITION_TIME = 0.25f; |
| | 25 | | const float RUN_TRANSITION_TIME = 0.15f; |
| | 26 | | const float WALK_TRANSITION_TIME = 0.15f; |
| | 27 | | const float JUMP_TRANSITION_TIME = 0.01f; |
| | 28 | | const float FALL_TRANSITION_TIME = 0.5f; |
| | 29 | | const float EXPRESSION_EXIT_TRANSITION_TIME = 0.2f; |
| | 30 | | const float EXPRESSION_ENTER_TRANSITION_TIME = 0.1f; |
| | 31 | | const float OTHER_PLAYER_MOVE_THRESHOLD = 0.07f; |
| | 32 | |
|
| | 33 | | const float AIR_EXIT_TRANSITION_TIME = 0.2f; |
| | 34 | | const float GROUND_BLENDTREE_TRANSITION_TIME = 0.15f; |
| | 35 | |
|
| | 36 | | const float RUN_SPEED_THRESHOLD = 0.05f; |
| | 37 | | const float WALK_SPEED_THRESHOLD = 0.03f; |
| | 38 | |
|
| | 39 | | const float ELEVATION_OFFSET = 0.6f; |
| | 40 | | const float RAY_OFFSET_LENGTH = 3.0f; |
| | 41 | |
|
| | 42 | | const float MAX_VELOCITY = 6.25f; |
| | 43 | |
|
| | 44 | | // Time it takes to determine if a character is grounded when vertical velocity is 0 |
| | 45 | | const float FORCE_GROUND_TIME = 0.05f; |
| | 46 | |
|
| | 47 | | // Minimum vertical speed used to consider whether an avatar is on air |
| | 48 | | const float MIN_VERTICAL_SPEED_AIR = 0.025f; |
| | 49 | |
|
| | 50 | | [System.Serializable] |
| | 51 | | public class AvatarLocomotion |
| | 52 | | { |
| | 53 | | public AnimationClip idle; |
| | 54 | | public AnimationClip walk; |
| | 55 | | public AnimationClip run; |
| | 56 | | public AnimationClip jump; |
| | 57 | | public AnimationClip fall; |
| | 58 | | } |
| | 59 | |
|
| | 60 | | [System.Serializable] |
| | 61 | | public class BlackBoard |
| | 62 | | { |
| | 63 | | public float walkSpeedFactor; |
| | 64 | | public float runSpeedFactor; |
| | 65 | | public float movementSpeed; |
| | 66 | | public float verticalSpeed; |
| | 67 | | public bool isGrounded; |
| | 68 | | public string expressionTriggerId; |
| | 69 | | public long expressionTriggerTimestamp; |
| | 70 | | public float deltaTime; |
| | 71 | | public bool shouldLoop; |
| | 72 | | } |
| | 73 | |
|
| | 74 | | [SerializeField] internal AvatarLocomotion femaleLocomotions; |
| | 75 | | [SerializeField] internal AvatarLocomotion maleLocomotions; |
| | 76 | | AvatarLocomotion currentLocomotions; |
| | 77 | |
|
| | 78 | | public new Animation animation; |
| | 79 | | public BlackBoard blackboard; |
| | 80 | | public Transform target; |
| | 81 | |
|
| 1078 | 82 | | [SerializeField] float runMinSpeed = 6f; |
| 1078 | 83 | | [SerializeField] float walkMinSpeed = 0.1f; |
| | 84 | |
|
| | 85 | | internal System.Action<BlackBoard> currentState; |
| | 86 | |
|
| | 87 | | Vector3 lastPosition; |
| | 88 | | bool isOwnPlayer = false; |
| | 89 | | private AvatarAnimationEventHandler animEventHandler; |
| | 90 | |
|
| | 91 | | private float lastOnAirTime = 0; |
| | 92 | |
|
| 1078 | 93 | | private Dictionary<string, EmoteClipData> emoteClipDataMap = |
| | 94 | | new Dictionary<string, EmoteClipData>(); |
| | 95 | |
|
| | 96 | | private string runAnimationName; |
| | 97 | | private string walkAnimationName; |
| | 98 | | private string idleAnimationName; |
| | 99 | | private string jumpAnimationName; |
| | 100 | | private string fallAnimationName; |
| | 101 | | private AvatarAnimation latestAnimation; |
| | 102 | | private AnimationState runAnimationState; |
| | 103 | | private AnimationState walkAnimationState; |
| | 104 | | private bool isUpdateRegistered = false; |
| | 105 | |
|
| | 106 | | private Ray rayCache; |
| | 107 | |
|
| 1140 | 108 | | public void Start() { OnPoolGet(); } |
| | 109 | |
|
| | 110 | | // AvatarSystem entry points |
| | 111 | | public bool Prepare(string bodyshapeId, GameObject container) |
| | 112 | | { |
| 0 | 113 | | if (!container.transform.TryFindChildRecursively("Armature", out Transform armature)) |
| | 114 | | { |
| 0 | 115 | | Debug.LogError($"Couldn't find Armature for AnimatorLegacy in path: {transform.GetHierarchyPath()}"); |
| | 116 | |
|
| 0 | 117 | | return false; |
| | 118 | | } |
| | 119 | |
|
| 0 | 120 | | Transform armatureParent = armature.parent; |
| 0 | 121 | | animation = armatureParent.gameObject.GetOrCreateComponent<Animation>(); |
| 0 | 122 | | armatureParent.gameObject.GetOrCreateComponent<StickerAnimationListener>(); |
| | 123 | |
|
| 0 | 124 | | PrepareLocomotionAnims(bodyshapeId); |
| 0 | 125 | | SetIdleFrame(); |
| 0 | 126 | | animation.Sample(); |
| 0 | 127 | | InitializeAvatarAudioAndParticleHandlers(animation); |
| | 128 | |
|
| | 129 | | // since the avatar can be updated when changing a wearable we shouldn't register to the update event twice |
| 0 | 130 | | if (!isUpdateRegistered) |
| | 131 | | { |
| 0 | 132 | | isUpdateRegistered = true; |
| | 133 | |
|
| 0 | 134 | | if (isOwnPlayer) |
| | 135 | | { |
| 0 | 136 | | DCLCharacterController.i.OnUpdateFinish += OnUpdateWithDeltaTime; |
| 0 | 137 | | } |
| | 138 | | else |
| | 139 | | { |
| 0 | 140 | | Environment.i.platform.updateEventHandler.AddListener(IUpdateEventHandler.EventType.Update, OnEventHandl |
| | 141 | | } |
| | 142 | |
|
| | 143 | | } |
| | 144 | |
|
| 0 | 145 | | return true; |
| | 146 | | } |
| | 147 | |
|
| | 148 | | private void PrepareLocomotionAnims(string bodyshapeId) |
| | 149 | | { |
| 0 | 150 | | if (bodyshapeId.Contains(WearableLiterals.BodyShapes.MALE)) |
| | 151 | | { |
| 0 | 152 | | currentLocomotions = maleLocomotions; |
| 0 | 153 | | } |
| 0 | 154 | | else if (bodyshapeId.Contains(WearableLiterals.BodyShapes.FEMALE)) |
| | 155 | | { |
| 0 | 156 | | currentLocomotions = femaleLocomotions; |
| | 157 | | } |
| | 158 | |
|
| 0 | 159 | | EquipBaseClip(currentLocomotions.idle); |
| 0 | 160 | | EquipBaseClip(currentLocomotions.walk); |
| 0 | 161 | | EquipBaseClip(currentLocomotions.run); |
| 0 | 162 | | EquipBaseClip(currentLocomotions.jump); |
| 0 | 163 | | EquipBaseClip(currentLocomotions.fall); |
| | 164 | |
|
| 0 | 165 | | idleAnimationName = currentLocomotions.idle.name; |
| 0 | 166 | | walkAnimationName = currentLocomotions.walk.name; |
| 0 | 167 | | runAnimationName = currentLocomotions.run.name; |
| 0 | 168 | | jumpAnimationName = currentLocomotions.jump.name; |
| 0 | 169 | | fallAnimationName = currentLocomotions.fall.name; |
| | 170 | |
|
| 0 | 171 | | runAnimationState = animation[runAnimationName]; |
| 0 | 172 | | walkAnimationState = animation[walkAnimationName]; |
| 0 | 173 | | } |
| 0 | 174 | | private void OnEventHandlerUpdate() { OnUpdateWithDeltaTime(Time.deltaTime); } |
| | 175 | |
|
| | 176 | | public void OnPoolGet() |
| | 177 | | { |
| 570 | 178 | | if (DCLCharacterController.i != null) |
| | 179 | | { |
| 570 | 180 | | isOwnPlayer = DCLCharacterController.i.transform == transform.parent; |
| | 181 | |
|
| | 182 | | // NOTE: disable MonoBehaviour's update to use DCLCharacterController event instead |
| 570 | 183 | | this.enabled = !isOwnPlayer; |
| | 184 | | } |
| | 185 | |
|
| 570 | 186 | | currentState = State_Init; |
| 570 | 187 | | } |
| | 188 | |
|
| | 189 | | public void OnPoolRelease() |
| | 190 | | { |
| 0 | 191 | | if (isUpdateRegistered) |
| | 192 | | { |
| 0 | 193 | | isUpdateRegistered = false; |
| | 194 | |
|
| 0 | 195 | | if (isOwnPlayer && DCLCharacterController.i) |
| | 196 | | { |
| 0 | 197 | | DCLCharacterController.i.OnUpdateFinish -= OnUpdateWithDeltaTime; |
| 0 | 198 | | } |
| | 199 | | else |
| | 200 | | { |
| 0 | 201 | | Environment.i.platform.updateEventHandler.RemoveListener(IUpdateEventHandler.EventType.Update, OnEventHa |
| | 202 | | } |
| | 203 | | } |
| 0 | 204 | | } |
| | 205 | |
|
| | 206 | | void OnUpdateWithDeltaTime(float deltaTime) |
| | 207 | | { |
| 0 | 208 | | blackboard.deltaTime = deltaTime; |
| 0 | 209 | | UpdateInterface(); |
| 0 | 210 | | currentState?.Invoke(blackboard); |
| 0 | 211 | | } |
| | 212 | |
|
| | 213 | | void UpdateInterface() |
| | 214 | | { |
| 0 | 215 | | Vector3 velocityTargetPosition = target.position; |
| 0 | 216 | | Vector3 flattenedVelocity = velocityTargetPosition - lastPosition; |
| | 217 | |
|
| | 218 | | //NOTE(Brian): Vertical speed |
| 0 | 219 | | float verticalVelocity = flattenedVelocity.y; |
| | 220 | |
|
| | 221 | | //NOTE(Kinerius): if we have more or less than zero we consider that we are either jumping or falling |
| 0 | 222 | | if (Mathf.Abs(verticalVelocity) > MIN_VERTICAL_SPEED_AIR) |
| | 223 | | { |
| 0 | 224 | | lastOnAirTime = Time.time; |
| | 225 | | } |
| | 226 | |
|
| 0 | 227 | | blackboard.verticalSpeed = verticalVelocity; |
| | 228 | |
|
| 0 | 229 | | flattenedVelocity.y = 0; |
| | 230 | |
|
| 0 | 231 | | if (isOwnPlayer) |
| 0 | 232 | | blackboard.movementSpeed = flattenedVelocity.magnitude - DCLCharacterController.i.movingPlatformSpeed; |
| | 233 | | else |
| 0 | 234 | | blackboard.movementSpeed = flattenedVelocity.magnitude; |
| | 235 | |
|
| 0 | 236 | | Vector3 rayOffset = Vector3.up * RAY_OFFSET_LENGTH; |
| | 237 | |
|
| | 238 | | //NOTE(Kinerius): This check is just for the playing character, it uses a combination of collision flags and ray |
| 0 | 239 | | bool isGroundedByCharacterController = isOwnPlayer && DCLCharacterController.i.isGrounded; |
| | 240 | |
|
| | 241 | | //NOTE(Kinerius): This check is for interpolated avatars (the other players) as we dont have a Character Control |
| | 242 | | // this check is cheap and fast but not precise |
| 0 | 243 | | bool isGroundedByVelocity = !isOwnPlayer && Time.time - lastOnAirTime > FORCE_GROUND_TIME; |
| | 244 | |
|
| | 245 | | //NOTE(Kinerius): This additional check is both for the player and interpolated avatars, we cast an additional r |
| 0 | 246 | | bool isGroundedByRaycast = false; |
| | 247 | |
|
| 0 | 248 | | if (!isGroundedByCharacterController && !isGroundedByVelocity) |
| | 249 | | { |
| 0 | 250 | | rayCache.origin = velocityTargetPosition + rayOffset; |
| 0 | 251 | | rayCache.direction = Vector3.down; |
| | 252 | |
|
| 0 | 253 | | isGroundedByRaycast = Physics.Raycast(rayCache, |
| | 254 | | RAY_OFFSET_LENGTH - ELEVATION_OFFSET, |
| | 255 | | DCLCharacterController.i.groundLayers); |
| | 256 | |
|
| | 257 | | } |
| | 258 | |
|
| 0 | 259 | | blackboard.isGrounded = isGroundedByCharacterController || isGroundedByVelocity || isGroundedByRaycast; |
| | 260 | |
|
| 0 | 261 | | lastPosition = velocityTargetPosition; |
| 0 | 262 | | } |
| | 263 | |
|
| | 264 | | void State_Init(BlackBoard bb) |
| | 265 | | { |
| 0 | 266 | | if (bb.isGrounded) |
| | 267 | | { |
| 0 | 268 | | currentState = State_Ground; |
| 0 | 269 | | } |
| | 270 | | else |
| | 271 | | { |
| 0 | 272 | | currentState = State_Air; |
| | 273 | | } |
| 0 | 274 | | } |
| | 275 | |
|
| | 276 | | void State_Ground(BlackBoard bb) |
| | 277 | | { |
| 0 | 278 | | if (bb.deltaTime <= 0) |
| 0 | 279 | | return; |
| | 280 | |
|
| 0 | 281 | | float movementSpeed = bb.movementSpeed / bb.deltaTime; |
| | 282 | |
|
| 0 | 283 | | runAnimationState.normalizedSpeed = movementSpeed * bb.runSpeedFactor; |
| 0 | 284 | | walkAnimationState.normalizedSpeed = movementSpeed * bb.walkSpeedFactor; |
| | 285 | |
|
| 0 | 286 | | if (movementSpeed > runMinSpeed) |
| | 287 | | { |
| 0 | 288 | | CrossFadeTo(AvatarAnimation.RUN, runAnimationName, RUN_TRANSITION_TIME); |
| 0 | 289 | | } |
| 0 | 290 | | else if (movementSpeed > walkMinSpeed) |
| | 291 | | { |
| 0 | 292 | | CrossFadeTo(AvatarAnimation.WALK, walkAnimationName, WALK_TRANSITION_TIME); |
| 0 | 293 | | } |
| | 294 | | else |
| | 295 | | { |
| 0 | 296 | | CrossFadeTo(AvatarAnimation.IDLE, idleAnimationName, IDLE_TRANSITION_TIME); |
| | 297 | | } |
| | 298 | |
|
| 0 | 299 | | if (!bb.isGrounded) |
| | 300 | | { |
| 0 | 301 | | currentState = State_Air; |
| 0 | 302 | | OnUpdateWithDeltaTime(bb.deltaTime); |
| | 303 | | } |
| 0 | 304 | | } |
| | 305 | | private void CrossFadeTo(AvatarAnimation avatarAnimation, string animationName, |
| | 306 | | float runTransitionTime, PlayMode playMode = PlayMode.StopSameLayer) |
| | 307 | | { |
| 0 | 308 | | if (latestAnimation == avatarAnimation) |
| 0 | 309 | | return; |
| | 310 | |
|
| 0 | 311 | | animation.CrossFade(animationName, runTransitionTime, playMode); |
| 0 | 312 | | latestAnimation = avatarAnimation; |
| 0 | 313 | | } |
| | 314 | |
|
| | 315 | | void State_Air(BlackBoard bb) |
| | 316 | | { |
| 0 | 317 | | if (bb.verticalSpeed > 0) |
| | 318 | | { |
| 0 | 319 | | CrossFadeTo(AvatarAnimation.JUMP, jumpAnimationName, JUMP_TRANSITION_TIME, PlayMode.StopAll); |
| 0 | 320 | | } |
| | 321 | | else |
| | 322 | | { |
| 0 | 323 | | CrossFadeTo(AvatarAnimation.FALL, fallAnimationName, FALL_TRANSITION_TIME, PlayMode.StopAll); |
| | 324 | | } |
| | 325 | |
|
| 0 | 326 | | if (bb.isGrounded) |
| | 327 | | { |
| 0 | 328 | | animation.Blend(jumpAnimationName, 0, AIR_EXIT_TRANSITION_TIME); |
| 0 | 329 | | animation.Blend(fallAnimationName, 0, AIR_EXIT_TRANSITION_TIME); |
| 0 | 330 | | currentState = State_Ground; |
| 0 | 331 | | OnUpdateWithDeltaTime(bb.deltaTime); |
| | 332 | | } |
| 0 | 333 | | } |
| | 334 | |
|
| | 335 | | private static bool ExpressionGroundTransitionCondition(AnimationState animationState, |
| | 336 | | BlackBoard bb, |
| | 337 | | DCLCharacterController dclCharacterController, |
| | 338 | | bool ownPlayer) |
| | 339 | | { |
| 0 | 340 | | float timeTillEnd = animationState.length - animationState.time; |
| 0 | 341 | | if (timeTillEnd < EXPRESSION_EXIT_TRANSITION_TIME) |
| | 342 | | { |
| 0 | 343 | | return ownPlayer ? dclCharacterController.isMovingByUserInput : |
| | 344 | | Math.Abs(bb.movementSpeed) > OTHER_PLAYER_MOVE_THRESHOLD; |
| | 345 | | } |
| | 346 | |
|
| 0 | 347 | | return false; |
| | 348 | | } |
| | 349 | |
|
| | 350 | | private static bool ExpressionAirTransitionCondition(BlackBoard bb) |
| | 351 | | { |
| 0 | 352 | | return !bb.isGrounded; |
| | 353 | | } |
| | 354 | |
|
| | 355 | | internal void State_Expression(BlackBoard bb) |
| | 356 | | { |
| 0 | 357 | | var animationState = animation[bb.expressionTriggerId]; |
| | 358 | |
|
| 0 | 359 | | var prevAnimation = latestAnimation; |
| 0 | 360 | | CrossFadeTo(AvatarAnimation.EMOTE, bb.expressionTriggerId, EXPRESSION_EXIT_TRANSITION_TIME, PlayMode.StopAll); |
| | 361 | |
|
| 0 | 362 | | bool exitTransitionStarted = false; |
| | 363 | |
|
| 0 | 364 | | if (ExpressionAirTransitionCondition(bb)) |
| | 365 | | { |
| 0 | 366 | | currentState = State_Air; |
| 0 | 367 | | exitTransitionStarted = true; |
| | 368 | | } |
| | 369 | |
|
| 0 | 370 | | if (ExpressionGroundTransitionCondition(animationState, bb, DCLCharacterController.i, isOwnPlayer)) |
| | 371 | | { |
| 0 | 372 | | currentState = State_Ground; |
| 0 | 373 | | exitTransitionStarted = true; |
| | 374 | | } |
| | 375 | |
|
| 0 | 376 | | if (exitTransitionStarted) |
| | 377 | | { |
| 0 | 378 | | animation.wrapMode = WrapMode.Default; |
| 0 | 379 | | animation.Blend(bb.expressionTriggerId, 0, EXPRESSION_EXIT_TRANSITION_TIME); |
| | 380 | |
|
| 0 | 381 | | bb.expressionTriggerId = null; |
| 0 | 382 | | bb.shouldLoop = false; |
| 0 | 383 | | OnUpdateWithDeltaTime(bb.deltaTime); |
| 0 | 384 | | } |
| | 385 | | else |
| | 386 | | { |
| | 387 | | //this condition makes Blend be called only in first frame of the state |
| 0 | 388 | | if (prevAnimation != AvatarAnimation.EMOTE) |
| | 389 | | { |
| 0 | 390 | | animation.wrapMode = bb.shouldLoop ? WrapMode.Loop : WrapMode.Once; |
| 0 | 391 | | animation.Blend(bb.expressionTriggerId, 1, EXPRESSION_ENTER_TRANSITION_TIME); |
| | 392 | | } |
| | 393 | | } |
| 0 | 394 | | } |
| | 395 | |
|
| | 396 | | private void SetExpressionValues(string expressionTriggerId, long expressionTriggerTimestamp) |
| | 397 | | { |
| 2 | 398 | | if (animation == null) |
| 2 | 399 | | return; |
| | 400 | |
|
| 0 | 401 | | if (string.IsNullOrEmpty(expressionTriggerId)) |
| 0 | 402 | | return; |
| | 403 | |
|
| 0 | 404 | | if (animation.GetClip(expressionTriggerId) == null) |
| 0 | 405 | | return; |
| | 406 | |
|
| 0 | 407 | | var mustTriggerAnimation = !string.IsNullOrEmpty(expressionTriggerId) |
| | 408 | | && blackboard.expressionTriggerTimestamp != expressionTriggerTimestamp; |
| 0 | 409 | | blackboard.expressionTriggerId = expressionTriggerId; |
| 0 | 410 | | blackboard.expressionTriggerTimestamp = expressionTriggerTimestamp; |
| | 411 | |
|
| 0 | 412 | | if (mustTriggerAnimation) |
| | 413 | | { |
| 0 | 414 | | if (!string.IsNullOrEmpty(expressionTriggerId)) |
| | 415 | | { |
| 0 | 416 | | animation.Stop(expressionTriggerId); |
| | 417 | | } |
| | 418 | |
|
| 0 | 419 | | blackboard.shouldLoop = emoteClipDataMap.TryGetValue(expressionTriggerId, out var clipData) |
| | 420 | | && clipData.loop; |
| | 421 | |
|
| 0 | 422 | | currentState = State_Expression; |
| 0 | 423 | | OnUpdateWithDeltaTime(Time.deltaTime); |
| | 424 | | } |
| 0 | 425 | | } |
| | 426 | |
|
| | 427 | | public void Reset() |
| | 428 | | { |
| 0 | 429 | | if (animation == null) |
| 0 | 430 | | return; |
| | 431 | |
|
| | 432 | | //It will set the animation to the first frame, but due to the nature of the script and its Update. It wont stop |
| 0 | 433 | | animation.Stop(); |
| 0 | 434 | | } |
| | 435 | |
|
| 0 | 436 | | public void SetIdleFrame() { animation.Play(currentLocomotions.idle.name); } |
| | 437 | |
|
| | 438 | | public void PlayEmote(string emoteId, long timestamps) |
| | 439 | | { |
| 2 | 440 | | SetExpressionValues(emoteId, timestamps); |
| 2 | 441 | | } |
| | 442 | |
|
| | 443 | | public void EquipBaseClip(AnimationClip clip) |
| | 444 | | { |
| 0 | 445 | | var clipId = clip.name; |
| 0 | 446 | | if (animation == null) |
| 0 | 447 | | return; |
| | 448 | |
|
| 0 | 449 | | if (animation.GetClip(clipId) != null) |
| 0 | 450 | | animation.RemoveClip(clipId); |
| | 451 | |
|
| 0 | 452 | | animation.AddClip(clip, clipId); |
| 0 | 453 | | } |
| | 454 | |
|
| | 455 | | public void EquipEmote(string emoteId, EmoteClipData emoteClipData) |
| | 456 | | { |
| 0 | 457 | | if (animation == null) |
| 0 | 458 | | return; |
| | 459 | |
|
| 0 | 460 | | if (animation.GetClip(emoteId) != null) |
| 0 | 461 | | animation.RemoveClip(emoteId); |
| | 462 | |
|
| 0 | 463 | | emoteClipDataMap[emoteId] = emoteClipData; |
| | 464 | |
|
| 0 | 465 | | animation.AddClip(emoteClipData.clip, emoteId); |
| 0 | 466 | | } |
| | 467 | |
|
| | 468 | | public void UnequipEmote(string emoteId) |
| | 469 | | { |
| 0 | 470 | | if (animation == null) |
| 0 | 471 | | return; |
| | 472 | |
|
| 0 | 473 | | if (animation.GetClip(emoteId) == null) |
| 0 | 474 | | return; |
| | 475 | |
|
| 0 | 476 | | animation.RemoveClip(emoteId); |
| 0 | 477 | | } |
| | 478 | |
|
| | 479 | | private void InitializeAvatarAudioAndParticleHandlers(Animation createdAnimation) |
| | 480 | | { |
| | 481 | | //NOTE(Mordi): Adds handler for animation events, and passes in the audioContainer for the avatar |
| 0 | 482 | | AvatarAnimationEventHandler animationEventHandler = createdAnimation.gameObject.GetOrCreateComponent<AvatarAnima |
| 0 | 483 | | AudioContainer audioContainer = transform.GetComponentInChildren<AudioContainer>(); |
| | 484 | |
|
| 0 | 485 | | if (audioContainer != null) |
| | 486 | | { |
| 0 | 487 | | animationEventHandler.Init(audioContainer); |
| | 488 | |
|
| | 489 | | //NOTE(Mordi): If this is a remote avatar, pass the animation component so we can keep track of whether it i |
| 0 | 490 | | AvatarAudioHandlerRemote audioHandlerRemote = audioContainer.GetComponent<AvatarAudioHandlerRemote>(); |
| | 491 | |
|
| 0 | 492 | | if (audioHandlerRemote != null) |
| | 493 | | { |
| 0 | 494 | | audioHandlerRemote.Init(createdAnimation.gameObject); |
| | 495 | | } |
| | 496 | | } |
| | 497 | |
|
| 0 | 498 | | animEventHandler = animationEventHandler; |
| 0 | 499 | | } |
| | 500 | |
|
| | 501 | | private void OnDestroy() |
| | 502 | | { |
| 1059 | 503 | | if (animEventHandler != null) |
| 0 | 504 | | Destroy(animEventHandler); |
| 1059 | 505 | | } |
| | 506 | | } |