Пример #1
0
        public static ComponentAnimation Read(BlockReader reader, ActorComponent[] components)
        {
            ComponentAnimation componentAnimation = new ComponentAnimation();

            componentAnimation.m_ComponentIndex = reader.ReadUInt16();
            int numProperties = (int)reader.ReadUInt16();

            componentAnimation.m_Properties = new PropertyAnimation[numProperties];
            for (int i = 0; i < numProperties; i++)
            {
                componentAnimation.m_Properties[i] = PropertyAnimation.Read(reader, components[componentAnimation.m_ComponentIndex]);
            }

            return(componentAnimation);
        }
Пример #2
0
        public static ActorAnimation Read(BlockReader reader, ActorComponent[] components)
        {
            ActorAnimation animation = new ActorAnimation();

            animation.m_Name      = Actor.ReadString(reader);
            animation.m_FPS       = (int)reader.ReadByte();
            animation.m_Duration  = reader.ReadSingle();
            animation.m_IsLooping = reader.ReadByte() != 0;

            int numKeyedComponents = reader.ReadUInt16();
            //animation.m_Components = new ComponentAnimation[numKeyedComponents];

            // We distinguish between animated and triggered components as ActorEvents are currently only used to trigger events and don't need
            // the full animation cycle. This lets them optimize them out of the regular animation cycle.
            int animatedComponentCount = 0;
            int triggerComponentCount  = 0;

            ComponentAnimation[] animatedComponents = new ComponentAnimation[numKeyedComponents];
            for (int i = 0; i < numKeyedComponents; i++)
            {
                ComponentAnimation componentAnimation = ComponentAnimation.Read(reader, components);
                animatedComponents[i] = componentAnimation;
                if (componentAnimation != null)
                {
                    ActorComponent actorComponent = components[componentAnimation.ComponentIndex];
                    if (actorComponent != null)
                    {
                        if (actorComponent is ActorEvent)
                        {
                            triggerComponentCount++;
                        }
                        else
                        {
                            animatedComponentCount++;
                        }
                    }
                }
            }

            animation.m_Components        = new ComponentAnimation[animatedComponentCount];
            animation.m_TriggerComponents = new ComponentAnimation[triggerComponentCount];

            // Put them in their respective lists.
            int animatedComponentIndex = 0;
            int triggerComponentIndex  = 0;

            for (int i = 0; i < numKeyedComponents; i++)
            {
                ComponentAnimation componentAnimation = animatedComponents[i];
                if (componentAnimation != null)
                {
                    ActorComponent actorComponent = components[componentAnimation.ComponentIndex];
                    if (actorComponent != null)
                    {
                        if (actorComponent is ActorEvent)
                        {
                            animation.m_TriggerComponents[triggerComponentIndex++] = componentAnimation;
                        }
                        else
                        {
                            animation.m_Components[animatedComponentIndex++] = componentAnimation;
                        }
                    }
                }
            }

            return(animation);
        }
Пример #3
0
        public static PropertyAnimation Read(BlockReader reader, ActorComponent component)
        {
            BlockReader propertyBlock = reader.ReadNextBlock();

            if (propertyBlock == null)
            {
                return(null);
            }
            PropertyAnimation propertyAnimation = new PropertyAnimation();
            int type = propertyBlock.BlockType;

            if (!Enum.IsDefined(typeof(PropertyTypes), type))
            {
                return(null);
            }
            else
            {
                propertyAnimation.m_Type = (PropertyTypes)type;

                Func <BinaryReader, ActorComponent, KeyFrame> keyFrameReader = null;
                switch (propertyAnimation.m_Type)
                {
                case PropertyTypes.PosX:
                    keyFrameReader = KeyFramePosX.Read;
                    break;

                case PropertyTypes.PosY:
                    keyFrameReader = KeyFramePosY.Read;
                    break;

                case PropertyTypes.ScaleX:
                    keyFrameReader = KeyFrameScaleX.Read;
                    break;

                case PropertyTypes.ScaleY:
                    keyFrameReader = KeyFrameScaleY.Read;
                    break;

                case PropertyTypes.Rotation:
                    keyFrameReader = KeyFrameRotation.Read;
                    break;

                case PropertyTypes.Opacity:
                    keyFrameReader = KeyFrameOpacity.Read;
                    break;

                case PropertyTypes.DrawOrder:
                    keyFrameReader = KeyFrameDrawOrder.Read;
                    break;

                case PropertyTypes.Length:
                    keyFrameReader = KeyFrameLength.Read;
                    break;

                case PropertyTypes.VertexDeform:
                    keyFrameReader = KeyFrameVertexDeform.Read;
                    break;

                case PropertyTypes.ConstraintStrength:
                    keyFrameReader = KeyFrameConstraintStrength.Read;
                    break;

                case PropertyTypes.Trigger:
                    keyFrameReader = KeyFrameTrigger.Read;
                    break;

                case PropertyTypes.IntProperty:
                    keyFrameReader = KeyFrameIntProperty.Read;
                    break;

                case PropertyTypes.FloatProperty:
                    keyFrameReader = KeyFrameFloatProperty.Read;
                    break;

                case PropertyTypes.StringProperty:
                    keyFrameReader = KeyFrameStringProperty.Read;
                    break;

                case PropertyTypes.BooleanProperty:
                    keyFrameReader = KeyFrameBooleanProperty.Read;
                    break;

                case PropertyTypes.CollisionEnabled:
                    keyFrameReader = KeyFrameCollisionEnabledProperty.Read;
                    break;

                case PropertyTypes.ActiveChildIndex:
                    keyFrameReader = KeyFrameActiveChild.Read;
                    break;
                }

                int keyFrameCount = propertyBlock.ReadUInt16();
                propertyAnimation.m_KeyFrames = new KeyFrame[keyFrameCount];
                KeyFrame lastKeyFrame = null;
                for (int i = 0; i < keyFrameCount; i++)
                {
                    KeyFrame frame = keyFrameReader(propertyBlock, component);
                    propertyAnimation.m_KeyFrames[i] = frame;
                    if (lastKeyFrame != null)
                    {
                        lastKeyFrame.SetNext(frame);
                    }
                    lastKeyFrame = frame;
                }
            }

            return(propertyAnimation);
        }