示例#1
0
        // 'walk'
        private static EventAction <GameEntityModel> .ExecutionDelegate BuildSetAnimation(Storage.GenericParameter parameter)
        {
            string     animationName  = parameter.SafeString(0);
            FixedFloat transitionTime = parameter.SafeFloat(0);

            return(delegate(GameEntityModel model, List <GameEntityModel>[] subjectModels){
                AnimationModel animModel = StateManager.state.GetModel(model.animationModelId) as AnimationModel;
                if (animModel == null)
                {
                    return;
                }
                animModel.SetNextAnimation(animationName, 0);
                AnimationView view = animModel.View() as AnimationView;
                if (view != null)
                {
                    view.transitionTime = (float)transitionTime;
                }
            });
        }
示例#2
0
        private static void SetupCharacter(Storage.Character charData)
        {
            string charName = charData.name;

            // Register animation view for this character
            AnimationView view = new AnimationView();

            AnimationsVCPool.Instance.SetDefaultView(charName, view);

            // Setup each animation
            AnimationController controller;
            ConditionalEvent <GameEntityModel> animEvent;
            int keyFrame;

            foreach (Storage.CharacterAnimation animation in charData.animations)
            {
                // Register controller for this animation
                controller = new AnimationController();
                AnimationsVCPool.Instance.RegisterController(charName, animation.name, controller);

                // Setup animation events
                if (animation.events != null)
                {
                    foreach (Storage.GenericEvent e in animation.events)
                    {
                        animEvent = ReadEvent(charData, e, out keyFrame, animation);
                        if (keyFrame != CharacterConditionsBuilder.InvalidKeyframe)
                        {
                            controller.AddKeyframeEvent((uint)keyFrame, animEvent);
                        }
                        else
                        {
                            controller.AddGeneralEvent(animEvent);
                        }
                    }
                }


                // Setup frame data
                // WARNING TODO: pool of boxes and pool of HitData
                FrameData[] framesData = new FrameData[animation.numFrames];
                FrameData   frameData;

                // Collisions
                if (animation.collisionBoxes != null)
                {
                    Storage.Box storageBox;
                    int         boxIndex;
                    // For each box
                    Storage.CollisionBox storageCollisionBox;
                    for (int collisionId = 0; collisionId < animation.collisionBoxes.Length; ++collisionId)
                    {
                        storageCollisionBox = animation.collisionBoxes[collisionId];
                        // for each frame of each box
                        for (int frame = 0; frame < storageCollisionBox.boxIds.Length; ++frame)
                        {
                            boxIndex = storageCollisionBox.boxIds[frame];
                            if (boxIndex != invalidBoxId)
                            {
                                storageBox = charData.boxes[boxIndex];
                                frameData  = GetFrameData(framesData, frame);
                                frameData.collisions.Add(new CollisionBox(new Box(storageBox.pointOne, storageBox.pointTwo), collisionId));
                            }
                        }         // each frame
                    }             // each storageCollisionBox
                }

                // Hits
                if (animation.hitBoxes != null)
                {
                    Storage.Box storageBox;
                    Storage.GenericParameter param;
                    HitData hitData;
                    int     boxIndex;
                    // For each box
                    Storage.HitBox storageHitBox;
                    for (int hitId = 0; hitId < animation.hitBoxes.Length; ++hitId)
                    {
                        storageHitBox = animation.hitBoxes[hitId];
                        param         = charData.genericParameters[storageHitBox.paramId];
                        hitData       = CharacterHitsBuilder.Build(param);
                        if (hitData == null)
                        {
                            continue;
                        }
                        hitData.hitboxID = hitId;
                        // for each frame of each box
                        for (int i = 0; i < storageHitBox.boxIds.Length; ++i)
                        {
                            boxIndex = storageHitBox.boxIds[i];
                            if (boxIndex != invalidBoxId)
                            {
                                storageBox = charData.boxes[boxIndex];
                                frameData  = GetFrameData(framesData, i);
                                frameData.hits.Add(new HitBox(new Box(storageBox.pointOne, storageBox.pointTwo), hitData));
                            }
                        }         // each frame
                    }             // each storageHitBox
                }

                // Precompute bounding boxes
                foreach (FrameData finalFramedata in framesData)
                {
                    if (finalFramedata != null)
                    {
                        finalFramedata.ComputeBoundingBoxes();
                    }
                }
                // Store frames data on animation controller
                controller.SetFramesData(framesData);
            }

            // Note: for now storage character data is stored locally,
            // Skins and anchor names accessed through storage data
            // TODO: Perhaps store skins and anchor names separatedly, maybe somewhere else,
            // instead of keeping storage data in memory..
        }