示例#1
0
        public void Jump(int index)
        {
            // get the previous index
            int previous = this.CurrentIndex;

            // set the current index
            this.CurrentIndex = index;

            // check if the index changed
            bool dirty = (this.CurrentIndex != previous);


            // update mesh filters
            if (this.Layers != null)
            {
                for (int layerIndex = 0; layerIndex < this.Layers.Length; layerIndex++)
                {
                    MeshAnimatorLayer layer  = null;
                    MeshFilter        filter = null;
                    if ((layer = this.Layers[layerIndex]) && (filter = layer.MeshFilter))
                    {
                        filter.sharedMesh = this.Animation ? this.Animation.Frames[this.CurrentIndex].Meshes[layerIndex] : null;
                    }
                }
            }

            if (dirty)
            {
                this.OnJump();
            }
        }
示例#2
0
        // ================================================================= //
        // Helper Methods
        // ================================================================= //

        protected void Build()
        {
            MeshAnimatorLayer[] layers;
            layers = new MeshAnimatorLayer[this.Animation ? this.Animation.Layers.Length : 0];

            // find existing layers, remove unused layers
            for (int childIndex = this.GetComponent <Transform>().childCount - 1; childIndex >= 0; childIndex--)
            {
                MeshAnimatorLayer layer;
                layer = this.GetComponent <Transform>().GetChild(childIndex).GetComponent <MeshAnimatorLayer>();

                if (layer != null)
                {
                    int layerIndex;
                    layerIndex = MeshAnimatorLayer.NameToIndex(layer.name);

                    if (layerIndex >= 0 && layerIndex < layers.Length && layers[layerIndex] == null)
                    {
                        layers[layerIndex] = layer;
                    }
                    else if (Application.isPlaying)
                    {
                        Destroy(layer.gameObject);
                    }
                    else
                    {
                        DestroyImmediate(layer.gameObject, false);
                    }
                }
            }

            // create missing layers
            for (int layerIndex = 0; layerIndex < layers.Length; layerIndex++)
            {
                MeshAnimatorLayer layer;
                layer = layers[layerIndex];

                if (layer == null)
                {
                    Transform layerTransform;
                    layerTransform                  = new GameObject().GetComponent <Transform>();
                    layerTransform.name             = MeshAnimatorLayer.IndexToName(layerIndex);
                    layerTransform.parent           = this.GetComponent <Transform>();
                    layerTransform.localEulerAngles = Vector3.zero;
                    layerTransform.localPosition    = Vector3.zero;
                    layerTransform.localScale       = Vector3.one;

                    MeshRenderer layerRenderer;
                    layerRenderer = layerTransform.gameObject.AddComponent <MeshRenderer>();
                    layerRenderer.shadowCastingMode    = ShadowCastingMode.Off;
                    layerRenderer.receiveShadows       = false;
                    layerRenderer.lightProbeUsage      = LightProbeUsage.Off;
                    layerRenderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
                    layerRenderer.sharedMaterial       = this.FindDefaultMaterial();

                    layer = layerTransform.gameObject.AddComponent <MeshAnimatorLayer>();
                    layers[layerIndex] = layer;
                }
            }

            this.Layers = layers;
        }