| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using UnityEngine; |
| | 6 | | using static WearableLiterals; |
| | 7 | |
|
| | 8 | | namespace DCL |
| | 9 | | { |
| | 10 | | public class AvatarRenderer : MonoBehaviour |
| | 11 | | { |
| | 12 | | public enum VisualCue |
| | 13 | | { |
| | 14 | | CleanedUp, |
| | 15 | | Loaded |
| | 16 | | } |
| | 17 | |
|
| | 18 | | private const int MAX_RETRIES = 5; |
| | 19 | |
|
| | 20 | | public Material defaultMaterial; |
| | 21 | | public Material eyeMaterial; |
| | 22 | | public Material eyebrowMaterial; |
| | 23 | | public Material mouthMaterial; |
| | 24 | |
|
| | 25 | | private AvatarModel model; |
| | 26 | |
|
| | 27 | | public event Action<VisualCue> OnVisualCue; |
| | 28 | | public event Action OnSuccessEvent; |
| | 29 | | public event Action<bool> OnFailEvent; |
| | 30 | |
|
| | 31 | | internal BodyShapeController bodyShapeController; |
| 892 | 32 | | internal Dictionary<WearableItem, WearableController> wearableControllers = new Dictionary<WearableItem, Wearabl |
| | 33 | | internal FacialFeatureController eyesController; |
| | 34 | | internal FacialFeatureController eyebrowsController; |
| | 35 | | internal FacialFeatureController mouthController; |
| | 36 | | internal AvatarAnimatorLegacy animator; |
| | 37 | | internal StickersController stickersController; |
| | 38 | |
|
| 892 | 39 | | private long lastStickerTimestamp = -1; |
| | 40 | |
|
| | 41 | | internal bool isLoading = false; |
| | 42 | |
|
| | 43 | | private Coroutine loadCoroutine; |
| 892 | 44 | | private List<string> wearablesInUse = new List<string>(); |
| | 45 | |
|
| | 46 | | private void Awake() |
| | 47 | | { |
| 167 | 48 | | animator = GetComponent<AvatarAnimatorLegacy>(); |
| 167 | 49 | | stickersController = GetComponent<StickersController>(); |
| 167 | 50 | | } |
| | 51 | |
|
| | 52 | | public void ApplyModel(AvatarModel model, Action onSuccess, Action onFail) |
| | 53 | | { |
| 123 | 54 | | if (this.model != null && model != null && this.model.Equals(model)) |
| | 55 | | { |
| 45 | 56 | | onSuccess?.Invoke(); |
| 33 | 57 | | return; |
| | 58 | | } |
| | 59 | |
|
| 78 | 60 | | this.model = new AvatarModel(); |
| 78 | 61 | | this.model.CopyFrom(model); |
| | 62 | |
|
| | 63 | | void onSuccessWrapper() |
| | 64 | | { |
| 0 | 65 | | onSuccess?.Invoke(); |
| 0 | 66 | | this.OnSuccessEvent -= onSuccessWrapper; |
| 0 | 67 | | } |
| | 68 | |
|
| 78 | 69 | | this.OnSuccessEvent += onSuccessWrapper; |
| | 70 | |
|
| | 71 | | void onFailWrapper(bool isFatalError) |
| | 72 | | { |
| 5 | 73 | | onFail?.Invoke(); |
| 5 | 74 | | this.OnFailEvent -= onFailWrapper; |
| 5 | 75 | | } |
| | 76 | |
|
| 78 | 77 | | this.OnFailEvent += onFailWrapper; |
| | 78 | |
|
| 78 | 79 | | isLoading = false; |
| | 80 | |
|
| 78 | 81 | | if (model == null) |
| | 82 | | { |
| 0 | 83 | | CleanupAvatar(); |
| 0 | 84 | | this.OnSuccessEvent?.Invoke(); |
| 0 | 85 | | return; |
| | 86 | | } |
| | 87 | |
|
| 78 | 88 | | StopLoadingCoroutines(); |
| 78 | 89 | | isLoading = true; |
| 78 | 90 | | loadCoroutine = CoroutineStarter.Start(LoadAvatar()); |
| 78 | 91 | | } |
| | 92 | |
|
| | 93 | | void StopLoadingCoroutines() |
| | 94 | | { |
| 247 | 95 | | if (loadCoroutine != null) |
| 77 | 96 | | CoroutineStarter.Stop(loadCoroutine); |
| | 97 | |
|
| 247 | 98 | | loadCoroutine = null; |
| 247 | 99 | | } |
| | 100 | |
|
| | 101 | | public void CleanupAvatar() |
| | 102 | | { |
| 169 | 103 | | StopLoadingCoroutines(); |
| | 104 | |
|
| 169 | 105 | | eyebrowsController?.CleanUp(); |
| 169 | 106 | | eyebrowsController = null; |
| | 107 | |
|
| 169 | 108 | | eyesController?.CleanUp(); |
| 169 | 109 | | eyesController = null; |
| | 110 | |
|
| 169 | 111 | | mouthController?.CleanUp(); |
| 169 | 112 | | mouthController = null; |
| | 113 | |
|
| 169 | 114 | | bodyShapeController?.CleanUp(); |
| 169 | 115 | | bodyShapeController = null; |
| | 116 | |
|
| 169 | 117 | | using (var iterator = wearableControllers.GetEnumerator()) |
| | 118 | | { |
| 169 | 119 | | while (iterator.MoveNext()) |
| | 120 | | { |
| 0 | 121 | | iterator.Current.Value.CleanUp(); |
| | 122 | | } |
| 169 | 123 | | } |
| | 124 | |
|
| 169 | 125 | | wearableControllers.Clear(); |
| 169 | 126 | | model = null; |
| 169 | 127 | | isLoading = false; |
| 169 | 128 | | OnFailEvent = null; |
| 169 | 129 | | OnSuccessEvent = null; |
| | 130 | |
|
| 169 | 131 | | CatalogController.RemoveWearablesInUse(wearablesInUse); |
| 169 | 132 | | wearablesInUse.Clear(); |
| 169 | 133 | | OnVisualCue?.Invoke(VisualCue.CleanedUp); |
| 125 | 134 | | } |
| | 135 | |
|
| | 136 | | void CleanUpUnusedItems() |
| | 137 | | { |
| 0 | 138 | | if (model.wearables == null) |
| 0 | 139 | | return; |
| | 140 | |
|
| 0 | 141 | | var ids = wearableControllers.Keys.ToArray(); |
| | 142 | |
|
| 0 | 143 | | for (var i = 0; i < ids.Length; i++) |
| | 144 | | { |
| 0 | 145 | | var currentId = ids[i]; |
| 0 | 146 | | var wearable = wearableControllers[currentId]; |
| | 147 | |
|
| 0 | 148 | | if (!model.wearables.Contains(wearable.id) || !wearable.IsLoadedForBodyShape(model.bodyShape)) |
| | 149 | | { |
| 0 | 150 | | wearable.CleanUp(); |
| 0 | 151 | | wearableControllers.Remove(currentId); |
| | 152 | | } |
| | 153 | | } |
| 0 | 154 | | } |
| | 155 | |
|
| | 156 | | private IEnumerator LoadAvatar() |
| | 157 | | { |
| 156 | 158 | | yield return new WaitUntil(() => gameObject.activeSelf); |
| | 159 | |
|
| 5 | 160 | | bool loadSoftFailed = false; |
| | 161 | |
|
| 5 | 162 | | WearableItem resolvedBody = null; |
| 5 | 163 | | Helpers.Promise<WearableItem> avatarBodyPromise = null; |
| 5 | 164 | | if (!string.IsNullOrEmpty(model.bodyShape)) |
| | 165 | | { |
| 0 | 166 | | avatarBodyPromise = CatalogController.RequestWearable(model.bodyShape); |
| 0 | 167 | | } |
| | 168 | | else |
| | 169 | | { |
| 5 | 170 | | OnFailEvent?.Invoke(true); |
| 5 | 171 | | yield break; |
| | 172 | | } |
| | 173 | |
|
| 0 | 174 | | List<WearableItem> resolvedWearables = new List<WearableItem>(); |
| 0 | 175 | | List<Helpers.Promise<WearableItem>> avatarWearablePromises = new List<Helpers.Promise<WearableItem>>(); |
| 0 | 176 | | if (model.wearables != null) |
| | 177 | | { |
| 0 | 178 | | for (int i = 0; i < model.wearables.Count; i++) |
| | 179 | | { |
| 0 | 180 | | avatarWearablePromises.Add(CatalogController.RequestWearable(model.wearables[i])); |
| | 181 | | } |
| | 182 | | } |
| | 183 | |
|
| | 184 | | // In this point, all the requests related to the avatar's wearables have been collected and sent to the Cat |
| | 185 | | // From here we wait for the response of the requested wearables and process them. |
| 0 | 186 | | if (avatarBodyPromise != null) |
| | 187 | | { |
| 0 | 188 | | yield return avatarBodyPromise; |
| | 189 | |
|
| 0 | 190 | | if (!string.IsNullOrEmpty(avatarBodyPromise.error)) |
| | 191 | | { |
| 0 | 192 | | Debug.LogError(avatarBodyPromise.error); |
| 0 | 193 | | loadSoftFailed = true; |
| 0 | 194 | | } |
| | 195 | | else |
| | 196 | | { |
| 0 | 197 | | resolvedBody = avatarBodyPromise.value; |
| 0 | 198 | | wearablesInUse.Add(avatarBodyPromise.value.id); |
| | 199 | | } |
| | 200 | | } |
| | 201 | |
|
| 0 | 202 | | if (resolvedBody == null) |
| | 203 | | { |
| 0 | 204 | | isLoading = false; |
| 0 | 205 | | OnFailEvent?.Invoke(true); |
| 0 | 206 | | yield break; |
| | 207 | | } |
| | 208 | |
|
| 0 | 209 | | List<Helpers.Promise<WearableItem>> replacementPromises = new List<Helpers.Promise<WearableItem>>(); |
| 0 | 210 | | foreach (var avatarWearablePromise in avatarWearablePromises) |
| | 211 | | { |
| 0 | 212 | | yield return avatarWearablePromise; |
| | 213 | |
|
| 0 | 214 | | if (!string.IsNullOrEmpty(avatarWearablePromise.error)) |
| | 215 | | { |
| 0 | 216 | | Debug.LogError(avatarWearablePromise.error); |
| 0 | 217 | | loadSoftFailed = true; |
| 0 | 218 | | } |
| | 219 | | else |
| | 220 | | { |
| 0 | 221 | | WearableItem wearableItem = avatarWearablePromise.value; |
| 0 | 222 | | wearablesInUse.Add(wearableItem.id); |
| 0 | 223 | | if (wearableItem.GetRepresentation(model.bodyShape) != null) |
| 0 | 224 | | resolvedWearables.Add(wearableItem); |
| | 225 | | else |
| | 226 | | { |
| 0 | 227 | | model.wearables.Remove(wearableItem.id); |
| 0 | 228 | | string defaultReplacement = DefaultWearables.GetDefaultWearable(model.bodyShape, wearableItem.da |
| 0 | 229 | | if (!string.IsNullOrEmpty(defaultReplacement)) |
| | 230 | | { |
| 0 | 231 | | model.wearables.Add(defaultReplacement); |
| 0 | 232 | | replacementPromises.Add(CatalogController.RequestWearable(defaultReplacement)); |
| | 233 | | } |
| | 234 | | } |
| | 235 | | } |
| 0 | 236 | | } |
| | 237 | |
|
| 0 | 238 | | foreach (var wearablePromise in replacementPromises) |
| | 239 | | { |
| 0 | 240 | | yield return wearablePromise; |
| | 241 | |
|
| 0 | 242 | | if (!string.IsNullOrEmpty(wearablePromise.error)) |
| | 243 | | { |
| 0 | 244 | | Debug.LogError(wearablePromise.error); |
| 0 | 245 | | loadSoftFailed = true; |
| 0 | 246 | | } |
| | 247 | | else |
| | 248 | | { |
| 0 | 249 | | WearableItem wearableItem = wearablePromise.value; |
| 0 | 250 | | wearablesInUse.Add(wearableItem.id); |
| 0 | 251 | | resolvedWearables.Add(wearableItem); |
| | 252 | | } |
| 0 | 253 | | } |
| | 254 | |
|
| 0 | 255 | | bool bodyIsDirty = false; |
| 0 | 256 | | if (bodyShapeController != null && bodyShapeController.id != model?.bodyShape) |
| | 257 | | { |
| 0 | 258 | | bodyShapeController.CleanUp(); |
| 0 | 259 | | bodyShapeController = null; |
| 0 | 260 | | bodyIsDirty = true; |
| | 261 | | } |
| | 262 | |
|
| 0 | 263 | | if (bodyShapeController == null) |
| | 264 | | { |
| 0 | 265 | | HideAll(); |
| 0 | 266 | | bodyShapeController = new BodyShapeController(resolvedBody); |
| 0 | 267 | | eyesController = FacialFeatureController.CreateDefaultFacialFeature(bodyShapeController.bodyShapeId, Cat |
| 0 | 268 | | eyebrowsController = FacialFeatureController.CreateDefaultFacialFeature(bodyShapeController.bodyShapeId, |
| 0 | 269 | | mouthController = FacialFeatureController.CreateDefaultFacialFeature(bodyShapeController.bodyShapeId, Ca |
| 0 | 270 | | } |
| | 271 | | else |
| | 272 | | { |
| | 273 | | //If bodyShape is downloading will call OnWearableLoadingSuccess (and therefore SetupDefaultMaterial) on |
| 0 | 274 | | if (bodyShapeController.isReady) |
| 0 | 275 | | bodyShapeController.SetupDefaultMaterial(defaultMaterial, model.skinColor, model.hairColor); |
| | 276 | | } |
| | 277 | |
|
| 0 | 278 | | bool wearablesIsDirty = false; |
| 0 | 279 | | HashSet<string> unusedCategories = new HashSet<string>(Categories.ALL); |
| 0 | 280 | | int wearableCount = resolvedWearables.Count; |
| 0 | 281 | | for (int index = 0; index < wearableCount; index++) |
| | 282 | | { |
| 0 | 283 | | WearableItem wearable = resolvedWearables[index]; |
| 0 | 284 | | if (wearable == null) |
| | 285 | | continue; |
| | 286 | |
|
| 0 | 287 | | unusedCategories.Remove(wearable.data.category); |
| 0 | 288 | | if (wearableControllers.ContainsKey(wearable)) |
| | 289 | | { |
| 0 | 290 | | if (wearableControllers[wearable].IsLoadedForBodyShape(bodyShapeController.bodyShapeId)) |
| 0 | 291 | | UpdateWearableController(wearable); |
| | 292 | | else |
| 0 | 293 | | wearableControllers[wearable].CleanUp(); |
| 0 | 294 | | } |
| | 295 | | else |
| | 296 | | { |
| 0 | 297 | | AddWearableController(wearable); |
| 0 | 298 | | if (wearable.data.category != Categories.EYES && wearable.data.category != Categories.MOUTH && weara |
| 0 | 299 | | wearablesIsDirty = true; |
| | 300 | | } |
| | 301 | | } |
| | 302 | |
|
| 0 | 303 | | foreach (var category in unusedCategories) |
| | 304 | | { |
| | 305 | | switch (category) |
| | 306 | | { |
| | 307 | | case Categories.EYES: |
| 0 | 308 | | eyesController = FacialFeatureController.CreateDefaultFacialFeature(bodyShapeController.bodyShap |
| 0 | 309 | | break; |
| | 310 | | case Categories.MOUTH: |
| 0 | 311 | | mouthController = FacialFeatureController.CreateDefaultFacialFeature(bodyShapeController.bodySha |
| 0 | 312 | | break; |
| | 313 | | case Categories.EYEBROWS: |
| 0 | 314 | | eyebrowsController = FacialFeatureController.CreateDefaultFacialFeature(bodyShapeController.body |
| | 315 | | break; |
| | 316 | | } |
| | 317 | | } |
| | 318 | |
|
| | 319 | |
|
| 0 | 320 | | HashSet<string> hiddenList = WearableItem.CompoundHidesList(bodyShapeController.bodyShapeId, resolvedWearabl |
| 0 | 321 | | if (!bodyShapeController.isReady) |
| | 322 | | { |
| 0 | 323 | | bodyShapeController.Load(bodyShapeController.bodyShapeId, transform, OnWearableLoadingSuccess, OnBodySha |
| | 324 | | } |
| | 325 | |
|
| 0 | 326 | | foreach (WearableController wearable in wearableControllers.Values) |
| | 327 | | { |
| 0 | 328 | | if (bodyIsDirty) |
| 0 | 329 | | wearable.boneRetargetingDirty = true; |
| | 330 | |
|
| 0 | 331 | | wearable.Load(bodyShapeController.bodyShapeId, transform, OnWearableLoadingSuccess, x => OnWearableLoadi |
| 0 | 332 | | yield return null; |
| | 333 | | } |
| | 334 | |
|
| 0 | 335 | | yield return new WaitUntil(() => bodyShapeController.isReady && wearableControllers.Values.All(x => x.isRead |
| | 336 | |
|
| 0 | 337 | | eyesController?.Load(bodyShapeController, model.eyeColor); |
| 0 | 338 | | eyebrowsController?.Load(bodyShapeController, model.hairColor); |
| 0 | 339 | | mouthController?.Load(bodyShapeController, model.skinColor); |
| | 340 | |
|
| 0 | 341 | | yield return new WaitUntil(() => |
| 0 | 342 | | (eyebrowsController == null || (eyebrowsController != null && eyebrowsController.isReady)) && |
| | 343 | | (eyesController == null || (eyesController != null && eyesController.isReady)) && |
| | 344 | | (mouthController == null || (mouthController != null && mouthController.isReady))); |
| | 345 | |
|
| 0 | 346 | | if (bodyIsDirty || wearablesIsDirty) |
| | 347 | | { |
| 0 | 348 | | OnVisualCue?.Invoke(VisualCue.Loaded); |
| | 349 | | } |
| | 350 | |
|
| 0 | 351 | | bodyShapeController.SetActiveParts(unusedCategories.Contains(Categories.LOWER_BODY), unusedCategories.Contai |
| 0 | 352 | | bodyShapeController.UpdateVisibility(hiddenList); |
| 0 | 353 | | foreach (WearableController wearableController in wearableControllers.Values) |
| | 354 | | { |
| 0 | 355 | | wearableController.UpdateVisibility(hiddenList); |
| | 356 | | } |
| | 357 | |
|
| 0 | 358 | | CleanUpUnusedItems(); |
| | 359 | |
|
| 0 | 360 | | isLoading = false; |
| | 361 | |
|
| 0 | 362 | | SetWearableBones(); |
| 0 | 363 | | UpdateExpressions(model.expressionTriggerId, model.expressionTriggerTimestamp); |
| 0 | 364 | | if (lastStickerTimestamp != model.stickerTriggerTimestamp && model.stickerTriggerId != null) |
| | 365 | | { |
| 0 | 366 | | lastStickerTimestamp = model.stickerTriggerTimestamp; |
| 0 | 367 | | stickersController?.PlayEmote(model.stickerTriggerId); |
| | 368 | | } |
| | 369 | |
|
| 0 | 370 | | if (loadSoftFailed) |
| | 371 | | { |
| 0 | 372 | | OnFailEvent?.Invoke(false); |
| 0 | 373 | | } |
| | 374 | | else |
| | 375 | | { |
| 0 | 376 | | OnSuccessEvent?.Invoke(); |
| | 377 | | } |
| 0 | 378 | | } |
| | 379 | |
|
| | 380 | | void OnWearableLoadingSuccess(WearableController wearableController) |
| | 381 | | { |
| 0 | 382 | | if (wearableController == null || model == null) |
| | 383 | | { |
| 0 | 384 | | Debug.LogWarning($"WearableSuccess was called wrongly: IsWearableControllerNull=>{wearableController == |
| 0 | 385 | | OnWearableLoadingFail(wearableController, 0); |
| 0 | 386 | | return; |
| | 387 | | } |
| | 388 | |
|
| 0 | 389 | | wearableController.SetupDefaultMaterial(defaultMaterial, model.skinColor, model.hairColor); |
| 0 | 390 | | } |
| | 391 | |
|
| | 392 | | void OnBodyShapeLoadingFail(WearableController wearableController) |
| | 393 | | { |
| 0 | 394 | | Debug.LogError($"Avatar: {model?.name} - Failed loading bodyshape: {wearableController?.id}"); |
| 0 | 395 | | CleanupAvatar(); |
| 0 | 396 | | OnFailEvent?.Invoke(true); |
| 0 | 397 | | } |
| | 398 | |
|
| | 399 | | void OnWearableLoadingFail(WearableController wearableController, int retriesCount = MAX_RETRIES) |
| | 400 | | { |
| 0 | 401 | | if (retriesCount <= 0) |
| | 402 | | { |
| 0 | 403 | | Debug.LogError($"Avatar: {model?.name} - Failed loading wearable: {wearableController?.id}"); |
| 0 | 404 | | CleanupAvatar(); |
| 0 | 405 | | OnFailEvent?.Invoke(false); |
| 0 | 406 | | return; |
| | 407 | | } |
| | 408 | |
|
| 0 | 409 | | wearableController.Load(bodyShapeController.id, transform, OnWearableLoadingSuccess, x => OnWearableLoadingF |
| 0 | 410 | | } |
| | 411 | |
|
| | 412 | | private void SetWearableBones() |
| | 413 | | { |
| | 414 | | //NOTE(Brian): Set bones/rootBone of all wearables to be the same of the baseBody, |
| | 415 | | // so all of them are animated together. |
| 0 | 416 | | var mainSkinnedRenderer = bodyShapeController.skinnedMeshRenderer; |
| | 417 | |
|
| 0 | 418 | | using (var enumerator = wearableControllers.GetEnumerator()) |
| | 419 | | { |
| 0 | 420 | | while (enumerator.MoveNext()) |
| | 421 | | { |
| 0 | 422 | | enumerator.Current.Value.SetAnimatorBones(mainSkinnedRenderer); |
| | 423 | | } |
| 0 | 424 | | } |
| 0 | 425 | | } |
| | 426 | |
|
| | 427 | | public void UpdateExpressions(string id, long timestamp) |
| | 428 | | { |
| 2 | 429 | | model.expressionTriggerId = id; |
| 2 | 430 | | model.expressionTriggerTimestamp = timestamp; |
| 2 | 431 | | animator.SetExpressionValues(id, timestamp); |
| 2 | 432 | | } |
| | 433 | |
|
| | 434 | | private void AddWearableController(WearableItem wearable) |
| | 435 | | { |
| 0 | 436 | | if (wearable == null) |
| 0 | 437 | | return; |
| 0 | 438 | | switch (wearable.data.category) |
| | 439 | | { |
| | 440 | | case Categories.EYES: |
| 0 | 441 | | eyesController = new FacialFeatureController(wearable, eyeMaterial); |
| 0 | 442 | | break; |
| | 443 | | case Categories.EYEBROWS: |
| 0 | 444 | | eyebrowsController = new FacialFeatureController(wearable, eyebrowMaterial); |
| 0 | 445 | | break; |
| | 446 | | case Categories.MOUTH: |
| 0 | 447 | | mouthController = new FacialFeatureController(wearable, mouthMaterial); |
| 0 | 448 | | break; |
| | 449 | | case Categories.BODY_SHAPE: |
| | 450 | | break; |
| | 451 | |
|
| | 452 | | default: |
| 0 | 453 | | var wearableController = new WearableController(wearable); |
| 0 | 454 | | wearableControllers.Add(wearable, wearableController); |
| | 455 | | break; |
| | 456 | | } |
| 0 | 457 | | } |
| | 458 | |
|
| | 459 | | private void UpdateWearableController(WearableItem wearable) |
| | 460 | | { |
| 0 | 461 | | var wearableController = wearableControllers[wearable]; |
| 0 | 462 | | switch (wearableController.category) |
| | 463 | | { |
| | 464 | | case Categories.EYES: |
| | 465 | | case Categories.EYEBROWS: |
| | 466 | | case Categories.MOUTH: |
| | 467 | | case Categories.BODY_SHAPE: |
| | 468 | | break; |
| | 469 | | default: |
| | 470 | | //If wearable is downloading will call OnWearableLoadingSuccess(and therefore SetupDefaultMaterial) |
| 0 | 471 | | if (wearableController.isReady) |
| 0 | 472 | | wearableController.SetupDefaultMaterial(defaultMaterial, model.skinColor, model.hairColor); |
| | 473 | | break; |
| | 474 | | } |
| 0 | 475 | | } |
| | 476 | |
|
| | 477 | | //TODO: Remove/replace once the class is easily mockable. |
| | 478 | | protected void CopyFrom(AvatarRenderer original) |
| | 479 | | { |
| 0 | 480 | | this.wearableControllers = original.wearableControllers; |
| 0 | 481 | | this.mouthController = original.mouthController; |
| 0 | 482 | | this.bodyShapeController = original.bodyShapeController; |
| 0 | 483 | | this.eyebrowsController = original.eyebrowsController; |
| 0 | 484 | | this.eyesController = original.eyesController; |
| 0 | 485 | | } |
| | 486 | |
|
| | 487 | | public void SetVisibility(bool newVisibility) |
| | 488 | | { |
| | 489 | | //NOTE(Brian): Avatar being loaded needs the renderer.enabled as false until the loading finishes. |
| | 490 | | // So we can' manipulate the values because it'd show an incomplete avatar. Its easier to just d |
| 7 | 491 | | if (gameObject.activeSelf != newVisibility) |
| 7 | 492 | | gameObject.SetActive(newVisibility); |
| 7 | 493 | | } |
| | 494 | |
|
| | 495 | | private void HideAll() |
| | 496 | | { |
| 0 | 497 | | Renderer[] renderers = gameObject.GetComponentsInChildren<Renderer>(); |
| | 498 | |
|
| 0 | 499 | | for (int i = 0; i < renderers.Length; i++) |
| | 500 | | { |
| 0 | 501 | | renderers[i].enabled = false; |
| | 502 | | } |
| 0 | 503 | | } |
| | 504 | |
|
| 332 | 505 | | protected virtual void OnDestroy() { CleanupAvatar(); } |
| | 506 | | } |
| | 507 | | } |