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