예제 #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
        //Animation.prototype.triggerEvents = function(actorComponents, fromTime, toTime, triggered)

        /*
         *                                                      name:component._Name,
         *                                                      component:component,
         *                                                      propertyType:property._Type,
         *                                                      keyFrameTime:toTime,
         *                                                      elapsed:0*/
        public void TriggerEvents(ActorComponent[] components, float fromTime, float toTime, IList <AnimationEventArgs> triggerEvents)
        {
            for (int i = 0; i < m_TriggerComponents.Length; i++)
            {
                ComponentAnimation keyedComponent = m_TriggerComponents[i];
                foreach (PropertyAnimation property in keyedComponent.Properties)
                {
                    switch (property.PropertyType)
                    {
                    case PropertyTypes.Trigger:
                        IList <KeyFrame> keyFrames = property.KeyFrames;

                        int kfl = keyFrames.Count;
                        if (kfl == 0)
                        {
                            continue;
                        }

                        int idx = 0;
                        // Binary find the keyframe index.
                        {
                            int   mid     = 0;
                            float element = 0.0f;
                            int   start   = 0;
                            int   end     = kfl - 1;

                            while (start <= end)
                            {
                                mid     = ((start + end) >> 1);
                                element = keyFrames[mid].Time;
                                if (element < toTime)
                                {
                                    start = mid + 1;
                                }
                                else if (element > toTime)
                                {
                                    end = mid - 1;
                                }
                                else
                                {
                                    start = mid;
                                    break;
                                }
                            }

                            idx = start;
                        }

                        //int idx = keyFrameLocation(toTime, keyFrames, 0, keyFrames.length-1);
                        if (idx == 0)
                        {
                            if (kfl > 0 && keyFrames[0].Time == toTime)
                            {
                                ActorComponent component = components[keyedComponent.ComponentIndex];
                                triggerEvents.Add(new AnimationEventArgs(component.Name, component, property.PropertyType, toTime, 0.0f));
                            }
                        }
                        else
                        {
                            for (int k = idx - 1; k >= 0; k--)
                            {
                                KeyFrame frame = keyFrames[k];

                                if (frame.Time > fromTime)
                                {
                                    ActorComponent component = components[keyedComponent.ComponentIndex];
                                    triggerEvents.Add(new AnimationEventArgs(component.Name, component, property.PropertyType, frame.Time, toTime - frame.Time));

                                    /*triggered.push({
                                     *      name:component._Name,
                                     *      component:component,
                                     *      propertyType:property._Type,
                                     *      keyFrameTime:frame._Time,
                                     *      elapsed:toTime-frame._Time
                                     * });*/
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }