public virtual void Initialize(bool overwrite) { if (valid && !overwrite) { return; } if (meshFilter != null) { meshFilter.sharedMesh = null; } meshRenderer = GetComponent <MeshRenderer>(); if (meshRenderer != null) { meshRenderer.sharedMaterial = null; } currentInstructions.Clear(); rendererBuffers.Clear(); meshGenerator.Begin(); skeleton = null; valid = false; if (!skeletonDataAsset) { if (logErrors) { UnityEngine.Debug.LogError("Missing SkeletonData asset.", this); } return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(quiet: false); if (skeletonData != null) { valid = true; meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); rendererBuffers.Initialize(); skeleton = new Skeleton(skeletonData) { flipX = initialFlipX, flipY = initialFlipY }; if (!string.IsNullOrEmpty(initialSkinName) && !string.Equals(initialSkinName, "default", StringComparison.Ordinal)) { skeleton.SetSkin(initialSkinName); } separatorSlots.Clear(); for (int i = 0; i < separatorSlotNames.Length; i++) { separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i])); } LateUpdate(); if (this.OnRebuild != null) { this.OnRebuild(this); } } }
void LazyIntialize() { if (buffers == null) { buffers = new MeshRendererBuffers(); buffers.Initialize(); if (meshGenerator != null) { return; } meshGenerator = new MeshGenerator(); meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); currentInstructions.Clear(); } }
/// <summary> /// Initialize this component. Attempts to load the SkeletonData and creates the internal Skeleton object and buffers.</summary> /// <param name="overwrite">If set to <c>true</c>, it will overwrite internal objects if they were already generated. Otherwise, the initialized component will ignore subsequent calls to initialize.</param> public virtual void Initialize(bool overwrite, bool quiet = false) { if (valid && !overwrite) { return; } // Clear { // Note: do not reset meshFilter.sharedMesh or meshRenderer.sharedMaterial to null, // otherwise constant reloading will be triggered at prefabs. currentInstructions.Clear(); rendererBuffers.Clear(); meshGenerator.Begin(); skeleton = null; valid = false; } if (skeletonDataAsset == null) { return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) { return; } valid = true; meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); rendererBuffers.Initialize(); skeleton = new Skeleton(skeletonData) { ScaleX = initialFlipX ? -1 : 1, ScaleY = initialFlipY ? -1 : 1 }; if (!string.IsNullOrEmpty(initialSkinName) && !string.Equals(initialSkinName, "default", System.StringComparison.Ordinal)) { skeleton.SetSkin(initialSkinName); } separatorSlots.Clear(); for (int i = 0; i < separatorSlotNames.Length; i++) { separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i])); } LateUpdate(); // Generate mesh for the first frame it exists. if (OnRebuild != null) { OnRebuild(this); } #if UNITY_EDITOR if (!Application.isPlaying) { string errorMessage = null; if (!quiet && MaterialChecks.IsMaterialSetupProblematic(this, ref errorMessage)) { Debug.LogWarningFormat(this, "Problematic material setup at {0}: {1}", this.name, errorMessage); } } #endif }
/// <summary> /// Initialize this component. Attempts to load the SkeletonData and creates the internal Skeleton object and buffers.</summary> /// <param name="overwrite">If set to <c>true</c>, it will overwrite internal objects if they were already generated. Otherwise, the initialized component will ignore subsequent calls to initialize.</param> public virtual void Initialize(bool overwrite) { if (valid && !overwrite) { return; } // Clear { if (meshFilter != null) { meshFilter.sharedMesh = null; } meshRenderer = GetComponent <MeshRenderer>(); if (meshRenderer != null && meshRenderer.enabled) { meshRenderer.sharedMaterial = null; } currentInstructions.Clear(); rendererBuffers.Clear(); meshGenerator.Begin(); skeleton = null; valid = false; } if (skeletonDataAsset == null) { return; } SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false); if (skeletonData == null) { return; } valid = true; meshFilter = GetComponent <MeshFilter>(); meshRenderer = GetComponent <MeshRenderer>(); rendererBuffers.Initialize(); skeleton = new Skeleton(skeletonData) { scaleX = initialFlipX ? -1 : 1, scaleY = initialFlipY ? -1 : 1 }; if (!string.IsNullOrEmpty(initialSkinName) && !string.Equals(initialSkinName, "default", System.StringComparison.Ordinal)) { skeleton.SetSkin(initialSkinName); } separatorSlots.Clear(); for (int i = 0; i < separatorSlotNames.Length; i++) { separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i])); } LateUpdate(); // Generate mesh for the first frame it exists. if (OnRebuild != null) { OnRebuild(this); } }