Пример #1
0
        protected override void OnCurrentAnimationChanged(IMeshAnimation meshAnimation)
        {
            ShaderMeshAnimation currentAnimation = meshAnimation as ShaderMeshAnimation;

            CreatePropertyBlock();
            meshRenderer.GetPropertyBlock(materialPropertyBlock);
            materialPropertyBlock.SetVector(_animScalarProp, currentAnimation.animScalar);
            propertyBlockData.y = currentAnimation.vertexCount;
            pixelsPerTexture    = currentAnimation.textureSize.x * currentAnimation.textureSize.y;
            textureStartIndex   = 0;
            for (int i = 0; i < currentAnimIndex; i++)
            {
                textureStartIndex += meshAnimations[i].textureCount;
            }
            textureSizeX = currentAnimation.textureSize.x;
            textureSizeY = currentAnimation.textureSize.y;
            // set animation info
            propertyBlockData.x = textureStartIndex;
            propertyBlockData.z = textureSizeX;
            propertyBlockData.w = textureSizeY;
            materialPropertyBlock.SetVector(_animInfoProp, propertyBlockData);
            // set texture index
            materialPropertyBlock.SetFloat(_animTextureIndexProp, textureStartIndex);
            // set time info
            float startTime = _shaderTime.y;

            timeBlockData = new Vector4(
                0,
                currentAnimation.TotalFrames,
                startTime,
                startTime + (currentAnimation.length / (speed * currentAnimation.playbackSpeed)));
            materialPropertyBlock.SetVector(_animTimeProp, timeBlockData);
            // set property block
            meshRenderer.SetPropertyBlock(materialPropertyBlock);
        }
Пример #2
0
        private void FireAnimationEvents(IMeshAnimation meshAnimation, float totalSpeed, bool finished)
        {
            MeshAnimationBase baseAnimation = meshAnimation as MeshAnimationBase;

            if (baseAnimation.events.Length > 0 && eventReciever != null && previousEventFrame != currentFrame)
            {
                if (finished)
                {
                    if (totalSpeed < 0)
                    {
                        // fire off animation events, including skipped frames
                        for (int i = previousEventFrame; i >= 0; i++)
                        {
                            meshAnimation.FireEvents(eventReciever, i);
                        }
                        previousEventFrame = 0;
                    }
                    else
                    {
                        // fire off animation events, including skipped frames
                        int totalFrames = meshAnimation.TotalFrames;
                        for (int i = previousEventFrame; i <= totalFrames; i++)
                        {
                            meshAnimation.FireEvents(eventReciever, i);
                        }
                        previousEventFrame = -1;
                    }
                    return;
                }
                else
                {
                    if (totalSpeed < 0)
                    {
                        // fire off animation events, including skipped frames
                        for (int i = currentFrame; i > previousEventFrame; i--)
                        {
                            meshAnimation.FireEvents(eventReciever, i);
                        }
                    }
                    else
                    {
                        // fire off animation events, including skipped frames
                        for (int i = previousEventFrame + 1; i <= currentFrame; i++)
                        {
                            meshAnimation.FireEvents(eventReciever, i);
                        }
                    }
                    previousEventFrame = currentFrame;
                }
            }
        }
Пример #3
0
        protected virtual void Start()
        {
            var animations = this.animations;

            if (animations == null || animations.Length == 0)
            {
                Debug.LogWarning("No animations for MeshAnimator on object: " + name + ". Disabling.", this);
                this.enabled   = false;
                animationCount = 0;
                return;
            }
            animationCount = animations.Length;
            for (int i = 0; i < animationCount; i++)
            {
                IMeshAnimation animation = animations[i];
                if (animation == null)
                {
                    continue;
                }
                animation.GenerateFrames(baseMesh);
                var exposedTransforms = animation.ExposedTransforms;
                if (exposedTransforms != null)
                {
                    for (int j = 0; j < exposedTransforms.Length; j++)
                    {
                        string childName = exposedTransforms[j];
                        if (string.IsNullOrEmpty(childName))
                        {
                            continue;
                        }
                        Transform childTransform = transform.Find(childName);
                        if (childTransform != null)
                        {
                            if (childMap == null)
                            {
                                childMap = new Dictionary <string, Transform>();
                            }
                            if (childMap.ContainsKey(childName) == false)
                            {
                                childMap.Add(childName, childTransform);
                                hasExposedTransforms = true;
                            }
                        }
                    }
                }
            }

            if (meshFilter == null)
            {
                meshFilter = GetComponent <MeshFilter>();
            }

            if (meshRenderer == null)
            {
                meshRenderer = GetComponent <MeshRenderer>();
            }

            if (playAutomatically)
            {
                Play(defaultAnimation.AnimationName);
            }
            else
            {
                isPaused = true;
            }

            for (int i = 0; i < LODLevels.Length; i++)
            {
                float d = LODLevels[i].distance;
                LODLevels[i].distanceSquared = d * d;
            }
            initialized = true;
        }
Пример #4
0
 protected abstract void OnCurrentAnimationChanged(IMeshAnimation meshAnimation);
Пример #5
0
 protected override void OnCurrentAnimationChanged(IMeshAnimation meshAnimation)
 {
 }