Esempio n. 1
0
        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);
                }
            }
        }
        public void RenderParts(ExposedList <SubmeshInstruction> instructions, int startSubmesh, int endSubmesh)
        {
            LazyIntialize();

            // STEP 1: Create instruction
            var smartMesh = buffers.GetNextMesh();

            currentInstructions.SetWithSubset(instructions, startSubmesh, endSubmesh);
            bool updateTriangles = SkeletonRendererInstruction.GeometryNotEqual(currentInstructions, smartMesh.instructionUsed);

            // STEP 2: Generate mesh buffers.
            var currentInstructionsSubmeshesItems = currentInstructions.submeshInstructions.Items;

            meshGenerator.Begin();
            if (currentInstructions.hasActiveClipping)
            {
                for (int i = 0; i < currentInstructions.submeshInstructions.Count; i++)
                {
                    meshGenerator.AddSubmesh(currentInstructionsSubmeshesItems[i], updateTriangles);
                }
            }
            else
            {
                meshGenerator.BuildMeshWithArrays(currentInstructions, updateTriangles);
            }

            buffers.UpdateSharedMaterials(currentInstructions.submeshInstructions);

            // STEP 3: modify mesh.
            var mesh = smartMesh.mesh;

            if (meshGenerator.VertexCount <= 0)               // Clear an empty mesh
            {
                updateTriangles = false;
                mesh.Clear();
            }
            else
            {
                meshGenerator.FillVertexData(mesh);
                if (updateTriangles)
                {
                    meshGenerator.FillTriangles(mesh);
                    meshRenderer.sharedMaterials = buffers.GetUpdatedSharedMaterialsArray();
                }
                else if (buffers.MaterialsChangedInLastUpdate())
                {
                    meshRenderer.sharedMaterials = buffers.GetUpdatedSharedMaterialsArray();
                }
                meshGenerator.FillLateVertexData(mesh);
            }

            meshFilter.sharedMesh = mesh;
            smartMesh.instructionUsed.Set(currentInstructions);

            if (OnMeshAndMaterialsUpdated != null)
            {
                OnMeshAndMaterialsUpdated(this);
            }
        }
Esempio n. 3
0
 public void UpdateMesh()
 {
     if (IsValid)
     {
         skeleton.SetColor(color);
         MeshRendererBuffers.SmartMesh next = meshBuffers.GetNext();
         SkeletonRendererInstruction   skeletonRendererInstruction = currentInstructions;
         MeshGenerator.GenerateSingleSubmeshInstruction(skeletonRendererInstruction, skeleton, material);
         bool flag = SkeletonRendererInstruction.GeometryNotEqual(skeletonRendererInstruction, next.instructionUsed);
         meshGenerator.Begin();
         if (skeletonRendererInstruction.hasActiveClipping)
         {
             meshGenerator.AddSubmesh(skeletonRendererInstruction.submeshInstructions.Items[0], flag);
         }
         else
         {
             meshGenerator.BuildMeshWithArrays(skeletonRendererInstruction, flag);
         }
         if (base.canvas != null)
         {
             meshGenerator.ScaleVertexData(base.canvas.referencePixelsPerUnit);
         }
         if (this.OnPostProcessVertices != null)
         {
             this.OnPostProcessVertices(meshGenerator.Buffers);
         }
         Mesh mesh = next.mesh;
         meshGenerator.FillVertexData(mesh);
         if (flag)
         {
             meshGenerator.FillTrianglesSingle(mesh);
         }
         base.canvasRenderer.SetMesh(mesh);
         next.instructionUsed.Set(skeletonRendererInstruction);
     }
 }
Esempio n. 4
0
        /// <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
        }
Esempio n. 5
0
        /// <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);
            }
        }