private Sprite GetCurrentSprite(AnimationData d)
 {
     var currentIndex = GetCurrentIndex(d);
     currentIndex += d.offset;
     currentIndex = (int)Mathf.Repeat((float)currentIndex, (float)d.spriteEditors.Count);
     return (Sprite)d.spriteEditors[currentIndex].target;
 }
        /// <summary>
        /// Gets the animation data object based on the xml file name given
        /// </summary>
        /// <param name="xmlName">The asset name for the xml file to get</param>
        /// <returns>An AnimationData object that has all the information for animating a specific sprite</returns>
        public AnimationData GetAnimationData(string xmlName)
        {
            if (!data.ContainsKey(xmlName))
            {
                data[xmlName] = new AnimationData(xmlName);
            }

            return data[xmlName];
        }
 public void SetAnimation(string name)
 {
     foreach(AnimationData ad in animations) {
         if(ad.animationName == name) {
             currentAnimation = ad;
             renderer.material.SetTexture("_MainTex", Resources.Load(ad.animationName) as Texture2D);
         }
     }
 }
Beispiel #4
0
 public void DefineAnimation( int tileX, int tileY, int frameX, int frameY, int frameSize,
     int statesNum, int tickDelay)
 {
     AnimationData data = new AnimationData();
     data.TileX = tileX; data.TileY = tileY;
     data.FrameX = frameX; data.FrameY = frameY;
     data.FrameSize = frameSize; data.StatesCount = statesNum;
     data.TickDelay = tickDelay;
     animations.Add( data );
 }
Beispiel #5
0
        public CheckPoint(int x, int y)
        {
            Texture = ContentHelper.LoadTexture("Objects/checkPoint");
            SourceRectangle = new Rectangle(0, 0, 16, 48);
            CollRectangle = new Rectangle(x - 50, y - Main.Tilesize * 2, 100, DrawRectangle.Height);

            _opening = new AnimationData(32, 4, 0, AnimationType.PlayOnce);
            _animation = new Animation(Texture, DrawRectangle, SourceRectangle);

            _quack = new SoundFx("Backgrounds/Splash/quack");
            _openSound = new SoundFx("Sounds/Menu/checkPoint");
        }
        public void TransitionAnimation(string name, bool loop, float mixTime, float startTime)
        {
            AnimationData animationData = new AnimationData();
            animationData.animation = skeletonData.FindAnimation(name);
            animationData.currentApplyTime = startTime;
            animationData.previousApplyTime = startTime;
            animationData.transitionPosition = 0;
            animationData.transitionDuration = mixTime;
            animationData.loop = loop;

            if (animationStates.Count > 0)
                animationStates[animationStates.Count - 1].previousApplyTime = animationStates[animationStates.Count - 1].currentApplyTime;

            animationStates.Add(animationData);
        }
 public void moveTo(Vector3 target, float time, string ease = LINEAR, float delay = 0)
 {
     if(currentAnimations == null){
         init();
     }
     if(time < 0){
         Debug.Log("Cannot create an animation with negative time.");
         return;
     }
     AnimationData data = new AnimationData();
     data.startValue = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
     data.endValue = new Vector3(target.x, target.y, target.z);
     data.time = time;
     data.progress = 0;
     data.type = MOVE;
     data.ease = ease;
     data.delay = delay;
     data.timeAtStart = Time.realtimeSinceStartup;
     currentAnimations.Add(data);
     mInProgress = true;
 }
 public void moveBy(Vector3 distance, float time, string ease = LINEAR, float delay = 0)
 {
     // factor will be used when easeIn and stuff like that want to be customized
     if(currentAnimations == null){
         init();
     }
     if(time < 0){
         Debug.Log("Cannot create an animation with negative time.");
         return;
     }
     AnimationData data = new AnimationData();
     data.startValue = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
     data.endValue = new Vector3(data.startValue.x + distance.x, data.startValue.y + distance.y, data.startValue.z + distance.z);
     data.time = time;
     data.progress = 0;
     data.type = MOVE;
     data.ease = ease;
     data.delay = delay;
     data.timeAtStart = Time.realtimeSinceStartup;
     currentAnimations.Add(data);
     mInProgress = true;
 }
Beispiel #9
0
 public static void AnimationData(string title, ref AnimationData data)
 {
     EditorGUILayout.BeginHorizontal("box");
     data.name = EditorGUILayout.TextField(title, data.name, GUILayout.Width(mWidth));
     if(data.name != "")
     {
         data.layer = EditorGUILayout.IntField("Layer", data.layer, GUILayout.Width(mWidth*0.6f));
         data.setSpeed = EditorGUILayout.Toggle("Set speed", data.setSpeed, GUILayout.Width(mWidth));
         if(data.setSpeed)
         {
             data.speedFormula = EditorGUILayout.Popup("Formula",
                     data.speedFormula, DataHolder.Formulas().GetNameList(true), GUILayout.Width(mWidth));
         }
     }
     GUILayout.FlexibleSpace();
     EditorGUILayout.EndHorizontal();
 }
 public InteractableSliceComponent(AnimationData image, string slice) : base(image, slice)
 {
 }
Beispiel #11
0
 public void playAnimation(int animationIndex, Mesh pMesh)
 {
     //print(animationName);
     if (nowAnimationData.index == animationIndex)
         return;
     //nowListener.endTheAnimationCallback();
     //nowAnimationData = animationDatas[animationName] as AnimationData;
     nowAnimationData = animationDatas.getData(animationIndex);
     nowListener = animationListeners[animationIndex] ;
     if (nowListener == null)
         nowListener = new AnimationListener();
     nowListener.beginTheAnimationCallback();
     meshRenderer.material = nowAnimationData.material;
     playTime = 0;
     updateMesh(pMesh);
 }
    void Start()
    {
        if (defaultAnimation.clip == null && animations.Length > 0){
            SetDefaultClip(animations[0].clip, "Default", animations[0].speed, animations[0].wrapMode, false);
        }

        if (defaultAnimation.clip != null){
            foreach(AnimationData animData in animations) {
                if (animData.clip == defaultAnimation.clip)
                    defaultAnimation.clip = (AnimationClip) Instantiate(defaultAnimation.clip);
            }
            AnimatorOverrideController overrideController = new AnimatorOverrideController();
            overrideController.runtimeAnimatorController = controller1;

            currentAnimationData = defaultAnimation;
            currentAnimationData.stateName = "State2";
            currentAnimationData.length = currentAnimationData.clip.length;

            overrideController["State1"] = currentAnimationData.clip;
            overrideController["State2"] = currentAnimationData.clip;

            animator.runtimeAnimatorController = overrideController;
            animator.Play("State2", 0, 0);

            if (overrideRootMotion) animator.applyRootMotion = currentAnimationData.applyRootMotion;
            SetSpeed(currentAnimationData.speed);
        }
    }
Beispiel #13
0
        unsafe void ApplyAnimation( AnimationData data )
        {
            data.Tick--;
            if( data.Tick >= 0 ) return;
            data.CurrentState++;
            data.CurrentState %= data.StatesCount;
            data.Tick = data.TickDelay;

            TerrainAtlas1D atlas = game.TerrainAtlas1D;
            int texId = ( data.TileY << 4 ) | data.TileX;
            int index = atlas.Get1DIndex( texId );
            int rowNum = atlas.Get1DRowId( texId );

            int size = data.FrameSize;
            byte* temp = stackalloc byte[size * size * 4];
            FastBitmap part = new FastBitmap( size, size, size * 4, (IntPtr)temp );
            FastBitmap.MovePortion( data.FrameX + data.CurrentState * size, data.FrameY, 0, 0, fastBmp, part, size );
            api.UpdateTexturePart( atlas.TexIds[index], 0, rowNum * game.TerrainAtlas.elementSize, part );
        }
 public bool IsPlaying(AnimationData animData)
 {
     return (currentAnimationData == animData);
 }
 public void Play(AnimationData animationData, float blendingTime, float normalizedTime, bool mirror)
 {
     _playAnimation(animationData, blendingTime, normalizedTime, mirror);
 }
Beispiel #16
0
 public void Play(AnimationData animationData)
 {
     _playAnimation(animationData, animationData.transitionDuration, 0, currentMirror);
 }
Beispiel #17
0
 public void Play(AnimationData animationData, float blendingTime, float normalizedTime, bool mirror)
 {
     _playAnimation(animationData, blendingTime, normalizedTime, mirror);
 }
    public float GetSpeed(string clipName)
    {
        AnimationData animData = GetAnimationData(clipName);

        return(animData.speed);
    }
Beispiel #19
0
 public void Play(AnimationData animationData, bool mirror)
 {
     _playAnimation(animationData, animationData.transitionDuration, 0, mirror);
 }
    public float GetSpeed(AnimationClip clip)
    {
        AnimationData animData = GetAnimationData(clip);

        return(animData.speed);
    }
 public bool IsPlaying(AnimationData animData)
 {
     return(IsPlaying(animData, 0));
 }
    private void _playAnimation(AnimationData targetAnimationData, float blendingTime, float normalizedTime, bool mirror)
    {
        //The overrite machine. Creates an overrideController, replace its core animations and restate it back in
        if (targetAnimationData == null || targetAnimationData.clip == null)
        {
            return;
        }

        AnimatorOverrideController overrideController = new AnimatorOverrideController();

        currentMirror = mirror;

        float newAnimatorSpeed      = Mathf.Abs(targetAnimationData.speed);
        float currentNormalizedTime = GetCurrentClipPosition();

        if (mirror)
        {
            if (targetAnimationData.speed > 0)
            {
                overrideController.runtimeAnimatorController = controller2;
            }
            else
            {
                overrideController.runtimeAnimatorController = controller4;
            }
        }
        else
        {
            if (targetAnimationData.speed > 0)
            {
                overrideController.runtimeAnimatorController = controller1;
            }
            else
            {
                overrideController.runtimeAnimatorController = controller3;
            }
        }

        overrideController["State1"] = currentAnimationData.clip;
        overrideController["State2"] = targetAnimationData.clip;


        if (blendingTime == -1)
        {
            blendingTime = currentAnimationData.transitionDuration;
        }
        if (blendingTime == -1)
        {
            blendingTime = defaultTransitionDuration;
        }

        if (blendingTime <= 0)
        {
            animator.runtimeAnimatorController = overrideController;
            animator.Play("State2", 0, normalizedTime);
        }
        else
        {
            animator.runtimeAnimatorController = overrideController;

            //animator.Play(state1Hash, 0, currentNormalizedTime);
            //currentAnimationData.secondsPlayed = currentNormalizedTime * currentAnimationData.length;

            //currentAnimationData.stateHash = state1Hash;
            currentAnimationData.stateName = "State1";
            SetCurrentClipPosition(currentNormalizedTime);

            animator.Update(0);
            animator.CrossFade("State2", 5 * blendingTime / (newAnimatorSpeed * currentAnimationData.clip.length), 0, normalizedTime);
        }


        targetAnimationData.timesPlayed   = 0;
        targetAnimationData.secondsPlayed = (normalizedTime * targetAnimationData.clip.length) / newAnimatorSpeed;
        targetAnimationData.length        = targetAnimationData.clip.length;

        if (overrideRootMotion)
        {
            animator.applyRootMotion = targetAnimationData.applyRootMotion;
        }
        SetSpeed(targetAnimationData.speed);

        currentAnimationData           = targetAnimationData;
        currentAnimationData.stateName = "State2";
        //currentAnimationData.stateHash = state2Hash;

        if (MecanimControl.OnAnimationBegin != null)
        {
            MecanimControl.OnAnimationBegin(currentAnimationData);
        }
    }
 public ZSliceComponent(AnimationData image, string slice)
 {
     Sprite = image.GetSlice(slice);
 }
Beispiel #24
0
    //The overrite machine. Creates an overrideController, replace its core animations and restate it back in
    private void _playAnimation(AnimationData targetAnimationData, float blendingTime, float normalizedTime, bool mirror)
    {
        if (targetAnimationData == null || targetAnimationData.clip == null)
        {
            return;
        }
        AnimatorOverrideController overrideController = new AnimatorOverrideController();

        float newAnimatorSpeed      = Mathf.Abs(targetAnimationData.originalSpeed);
        float currentNormalizedTime = GetCurrentClipPosition();

        currentMirror = mirror;
        if (mirror)
        {
            if (targetAnimationData.originalSpeed >= 0)
            {
                overrideController.runtimeAnimatorController = controller2;
            }
            else
            {
                overrideController.runtimeAnimatorController = controller4;
            }
        }
        else
        {
            if (targetAnimationData.originalSpeed >= 0)
            {
                overrideController.runtimeAnimatorController = controller1;
            }
            else
            {
                overrideController.runtimeAnimatorController = controller3;
            }
        }

        if (currentAnimationData != null)
        {
            overrideController["State1"] = currentAnimationData.clip;
        }
        overrideController["State2"] = targetAnimationData.clip;


        if (blendingTime == -1)
        {
            blendingTime = currentAnimationData.transitionDuration;
        }
        if (blendingTime == -1)
        {
            blendingTime = defaultTransitionDuration;
        }

        if (blendingTime <= 0 || currentAnimationData == null)
        {
            animator.runtimeAnimatorController = overrideController;
            animator.Play("State2", 0, normalizedTime);
        }
        else
        {
            animator.runtimeAnimatorController = overrideController;
            currentAnimationData.stateName     = "State1";
            SetCurrentClipPosition(currentNormalizedTime);

            animator.Update(0);
            animator.CrossFade("State2", blendingTime / newAnimatorSpeed, 0, normalizedTime);
        }


        targetAnimationData.secondsPlayed  = (normalizedTime * targetAnimationData.clip.length) / newAnimatorSpeed;
        targetAnimationData.length         = targetAnimationData.clip.length;
        targetAnimationData.normalizedTime = normalizedTime;

        if (overrideRootMotion)
        {
            animator.applyRootMotion = targetAnimationData.applyRootMotion;
        }
        SetSpeed(targetAnimationData.originalSpeed);

        if (currentAnimationData != null)
        {
            currentAnimationData.speed           = currentAnimationData.originalSpeed;
            currentAnimationData.normalizedSpeed = 1;
            currentAnimationData.timesPlayed     = 0;
        }

        currentAnimationData           = targetAnimationData;
        currentAnimationData.stateName = "State2";

        if (MecanimControl.OnAnimationBegin != null)
        {
            MecanimControl.OnAnimationBegin(currentAnimationData);
        }
    }
 public float GetNormalizedSpeed(AnimationData animData)
 {
     return animData.normalizedSpeed;
 }
Beispiel #26
0
 public bool IsPlaying(AnimationData animData)
 {
     return(currentAnimationData == animData);
 }
 public void Play(AnimationData animationData, bool mirror)
 {
     _playAnimation(animationData, animationData.transitionDuration, 0, mirror);
 }
Beispiel #28
0
 public void SetWrapMode(AnimationData animationData, WrapMode wrapMode)
 {
     animationData.wrapMode      = wrapMode;
     animationData.clip.wrapMode = wrapMode;
 }
 public void SetSpeed(AnimationData animData, float speed)
 {
     if (animData != null) {
         animData.normalizedSpeed = speed / animData.originalSpeed;
         animData.speed = speed;
         if (IsPlaying(animData)) SetSpeed(speed);
     }
 }
Beispiel #30
0
 public float GetSpeed(AnimationData animData)
 {
     return(animData.speed);
 }
 public void Play(AnimationData animationData, float blendingTime)
 {
     _playAnimation(animationData, blendingTime, 0, currentMirror);
 }
Beispiel #32
0
 public float GetNormalizedSpeed(AnimationData animData)
 {
     return(animData.normalizedSpeed);
 }
Beispiel #33
0
 public void SetAnimationData(AnimationData inData)
 {
     _animationData = inData;
 }
    // ** name
    // !! anim size
    // <> anim hitbox
    // {} frame
    // [] color
    // (y-x,x,x,x,etc) pixels
    // ## frame time
    // && anim loop mode
    static bool ParseAnimationString(string animString, string type)
    {
        Stack <ParseAnimState> animStates = new Stack <ParseAnimState>();
        string currentString = "";

        // ANIMATION DATA
        string           name     = "";
        List <FrameData> frames   = new List <FrameData>();
        LoopMode         loopMode = LoopMode.Loops;

        // CURRENT FRAME DATA
        Color32          currentColor        = new Color32(0, 0, 0, 0);
        List <PixelData> currentPixels       = new List <PixelData>();
        List <PixelData> previousFramePixels = new List <PixelData>();
        PixelPoint       animSize            = new PixelPoint(0, 0);
        PixelRect        hitbox          = new PixelRect(0, 0, 0, 0);
        float            currentAnimTime = 0.0f;
        int currentPixelYPos             = 0;

        bool differencesMode = false;

        foreach (char c in animString)
        {
            if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.DifferencesMode)
            {
                if (c == '^')
                {
                    differencesMode = true;
                }
                else
                {
                    differencesMode = false;
                }

                animStates.Pop();
                animStates.Push(ParseAnimState.Frame);
            }
            else
            {
                if (c == '*')
                {
                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.Name)
                    {
                        name          = currentString;
                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Name);
                        currentString = "";
                    }
                }
                else if (c == '!')
                {
                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.Size)
                    {
                        // parse current string for animation rect and save it
                        string[] vals = currentString.Split(',');
                        if (vals.Length == 2)
                        {
                            int xSize = 0;
                            int ySize = 0;
                            if (!(int.TryParse(vals[0], out xSize) && int.TryParse(vals[1], out ySize)))
                            {
                                return(false);
                            }

                            animSize = new PixelPoint(xSize, ySize);
                        }
                        else
                        {
                            Debug.LogError(currentString + " is not properly formatted anim size data!");
                            return(false);
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Size);
                    }
                }
                else if (c == '<')
                {
                    animStates.Push(ParseAnimState.Hitbox);
                }
                else if (c == '>')
                {
                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.Hitbox)
                    {
                        // parse current string for hitbox info and save it
                        string[] vals = currentString.Split(',');
                        if (vals.Length == 4)
                        {
                            int left   = 0;
                            int bottom = 0;
                            int width  = 0;
                            int height = 0;
                            if (!(int.TryParse(vals[0], out left) &&
                                  int.TryParse(vals[1], out bottom) &&
                                  int.TryParse(vals[2], out width) &&
                                  int.TryParse(vals[3], out height)))
                            {
                                return(false);
                            }

                            hitbox = new PixelRect(left, bottom, width, height);
                        }
                        else
                        {
                            Debug.LogError(currentString + " is not properly formatted hitbox data!");
                            return(false);
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                }
                else if (c == '{')
                {
                    animStates.Push(ParseAnimState.DifferencesMode);
                }
                else if (c == '}')
                {
                    if (differencesMode)
                    {
                        // currentPixels holds pixels that are DIFFERENT than the previous frame
                        List <PixelData> pixels = new List <PixelData>();
                        foreach (PixelData prevPixelData in previousFramePixels)
                        {
                            // only add the previous frame pixels that AREN'T being overriden by the new frame data
                            bool allowPixel = true;
                            foreach (PixelData pixel in currentPixels)
                            {
                                if (pixel.position == prevPixelData.position)
                                {
                                    allowPixel = false;
                                    break;
                                }
                            }

                            if (allowPixel)
                            {
                                pixels.Add(new PixelData(prevPixelData.position, prevPixelData.color));
                            }
                        }

                        // add in the new, different pixels
                        foreach (PixelData newPixel in currentPixels)
                        {
                            if (newPixel.color.a > 0.0f)
                            {
                                pixels.Add(newPixel);
                            }
                        }

                        currentPixels.Clear();

                        frames.Add(new FrameData(pixels, currentAnimTime));

                        previousFramePixels.Clear();
                        previousFramePixels.AddRange(pixels);
                    }
                    else
                    {
                        // save current frame data
                        List <PixelData> pixels = new List <PixelData>();
                        pixels.AddRange(currentPixels);
                        currentPixels.Clear();

                        frames.Add(new FrameData(pixels, currentAnimTime));

                        previousFramePixels.Clear();
                        previousFramePixels.AddRange(pixels);
                    }

                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.Frame)
                    {
                        animStates.Pop();
                    }
                }
                else if (c == '[')
                {
                    animStates.Push(ParseAnimState.PixelColor);
                }
                else if (c == ']')
                {
                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelColor)
                    {
                        // parse current string for pixel color
                        if (currentString.Length == 0)
                        {
                            currentColor = new Color32(0, 0, 0, 0);
                        }
                        else
                        {
                            string[] vals = currentString.Split(',');
                            if (vals.Length == 1)
                            {
                                byte grey = 0;
                                if (!byte.TryParse(vals[0], out grey))
                                {
                                    return(false);
                                }
                                currentColor = new Color32(grey, grey, grey, 255);
                            }
                            else if (vals.Length == 2)
                            {
                                byte grey    = 0;
                                byte opacity = 0;
                                if (!(byte.TryParse(vals[0], out grey) && byte.TryParse(vals[1], out opacity)))
                                {
                                    return(false);
                                }
                                currentColor = new Color32(grey, grey, grey, opacity);
                            }
                            else if (vals.Length == 3)
                            {
                                byte red   = 0;
                                byte green = 0;
                                byte blue  = 0;
                                if (!(byte.TryParse(vals[0], out red) && byte.TryParse(vals[1], out green) && byte.TryParse(vals[2], out blue)))
                                {
                                    return(false);
                                }
                                currentColor = new Color32(red, green, blue, 255);
                            }
                            else if (vals.Length == 4)
                            {
                                byte red     = 0;
                                byte green   = 0;
                                byte blue    = 0;
                                byte opacity = 0;
                                if (!(byte.TryParse(vals[0], out red) && byte.TryParse(vals[1], out green) && byte.TryParse(vals[2], out blue) && byte.TryParse(vals[3], out opacity)))
                                {
                                    return(false);
                                }
                                currentColor = new Color32(red, green, blue, opacity);
                            }
                            else
                            {
                                Debug.LogError(currentString + " is not properly formatted color data!");
                                return(false);
                            }
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                }
                else if (c == '(')
                {
                    animStates.Push(ParseAnimState.PixelYPos);
                }
                else if (c == '-')
                {
                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelYPos)
                    {
                        if (!int.TryParse(currentString, out currentPixelYPos))
                        {
                            return(false);
                        }
                        currentString = "";
                        animStates.Pop();

                        animStates.Push(ParseAnimState.PixelXPos);
                    }
                }
                else if (c == ')')
                {
                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelXPos)
                    {
                        // parse current string for x pixel positions (for the current pixel y pos)
                        // add a pixel of current color to a list
                        string[] vals = currentString.Split(',');
                        for (int i = 0; i < vals.Length; i++)
                        {
                            int xPos = 0;
                            if (!int.TryParse(vals[i], out xPos))
                            {
                                return(false);
                            }

                            currentPixels.Add(new PixelData(new PixelPoint(xPos, currentPixelYPos), currentColor));
                        }

                        animStates.Pop();
                    }
                    currentString = "";
                }
                else if (c == '#')
                {
                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.AnimTime)
                    {
                        // parse current string for animation time and save it
                        if (!float.TryParse(currentString, out currentAnimTime))
                        {
                            return(false);
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.AnimTime);
                    }
                }
                else if (c == '&')
                {
                    if (animStates.Count > 0 && animStates.Peek() == ParseAnimState.Loops)
                    {
                        // parse current string for loop mode and save it
                        int loopModeInt = 0;
                        if (!int.TryParse(currentString, out loopModeInt))
                        {
                            return(false);
                        }

                        loopMode      = (LoopMode)loopModeInt;
                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Loops);
                    }
                }
                else
                {
                    currentString += c;
                }
            }
        }

        AnimationData animData = new AnimationData(name, frames, animSize, hitbox, loopMode);

        if (animations.ContainsKey(type))
        {
            animations[type].Add(animData);
        }
        else
        {
            animations.Add(type, new List <AnimationData>()
            {
                animData
            });
        }

        return(true);
    }
    public virtual void PlayAnimation(string animName)
    {
        if(currentAnimation != null && currentAnimation.name == animName)
            return;

        if(!SpriteManager.animations.ContainsKey(spriteName))
        {
            Debug.LogError("No entity type called <" + spriteName + ">!");
            return;
        }

        bool success = false;
        foreach(AnimationData animData in SpriteManager.animations[spriteName])
        {
            if(animData.name == animName)
            {
                currentAnimation = animData;
                _entity.hitbox = currentAnimation.hitbox;
                SetAnimationFrame(0);
                _currentFrameTime = 0.0f;
                _overrideLoopMode = false;
                success = true;
                _playOnceAnimFinished = false;
                break;
            }
        }

        if(!success)
            Debug.LogError("No animation called <" + animName + "> for <" + spriteName + ">!");
    }
Beispiel #36
0
        public void CycleTextures()
        {
            _textureType = AnimationData.CycleTextureType(_textureType);

            GameObject cubeletFaceUp, cubeletFaceDown, cubeletFaceFront, cubeletFaceBack, cubeletFaceLeft, cubeletFaceRight;
            Texture    textureUp, textureDown, textureFront, textureBack, textureLeft, textureRight;

            if (_textureType == TextureType.plain)
            {
                textureUp    = texturePlain;
                textureDown  = texturePlain;
                textureFront = texturePlain;
                textureBack  = texturePlain;
                textureLeft  = texturePlain;
                textureRight = texturePlain;
            }
            else // if (_textureType == TextureType.none)
            {
                textureUp    = null;
                textureDown  = null;
                textureFront = null;
                textureBack  = null;
                textureLeft  = null;
                textureRight = null;
            }

            for (int x = 0; x < 5; x++)
            {
                for (int y = 0; y < 5; y++)
                {
                    for (int z = 0; z < 5; z++)
                    {
                        if (IsOuterCubelet(x, y, z))
                        {
                            CubeletData cData = _cubeletData[x, y, z];

                            cubeletFaceUp    = cData.cubelet.transform.GetChild(0).gameObject;
                            cubeletFaceDown  = cData.cubelet.transform.GetChild(1).gameObject;
                            cubeletFaceFront = cData.cubelet.transform.GetChild(2).gameObject;
                            cubeletFaceBack  = cData.cubelet.transform.GetChild(3).gameObject;
                            cubeletFaceLeft  = cData.cubelet.transform.GetChild(4).gameObject;
                            cubeletFaceRight = cData.cubelet.transform.GetChild(5).gameObject;

                            if (_textureType == TextureType.number)
                            {
                                textureUp    = cData.textureNumberUp;
                                textureDown  = cData.textureNumberDown;
                                textureFront = cData.textureNumberFront;
                                textureBack  = cData.textureNumberBack;
                                textureLeft  = cData.textureNumberLeft;
                                textureRight = cData.textureNumberRight;
                            }

                            cubeletFaceUp.GetComponent <MeshRenderer>().materials[0].mainTexture    = textureUp;
                            cubeletFaceDown.GetComponent <MeshRenderer>().materials[0].mainTexture  = textureDown;
                            cubeletFaceFront.GetComponent <MeshRenderer>().materials[0].mainTexture = textureFront;
                            cubeletFaceBack.GetComponent <MeshRenderer>().materials[0].mainTexture  = textureBack;
                            cubeletFaceLeft.GetComponent <MeshRenderer>().materials[0].mainTexture  = textureLeft;
                            cubeletFaceRight.GetComponent <MeshRenderer>().materials[0].mainTexture = textureRight;
                        }
                    }
                }
            }
        }
Beispiel #37
0
    protected AnimationData CreateDataFromInfo(AnimationInfo info)
    {
        AnimationData lOut = new AnimationData();

        lOut.material = info.material;
        lOut.animationName = info.animationName;
        lOut.animationLength = info.animationLength;

        //动画中单幅图的像素信息
        //if(info.pixelVerticalNum)
        //	lOut.pixelVerticalNum=info.pixelVerticalNum;
        //else//use default
        lOut.pixelVerticalNum = defaultPixelVerticalNum;

        //if(info.pixelHorizonNum)
        //	lOut.pixelHorizonNum=info.pixelHorizonNum;
        //else
        lOut.pixelHorizonNum = defaultPixelHorizonNum;

        //开始的帧数,结束的帧数,数从0开始.将会播放从beginPicNum到endPicNum,共endPicNum-beginPicNum+1幅图
        lOut.beginPicNum = info.beginPicNum;
        lOut.endPicNum = info.endPicNum;

        lOut.loop = info.loop;

        /////////////////////////////////////////////////////////

        lOut.numOfHorizonPic = info.material.mainTexture.width / lOut.pixelHorizonNum;
        lOut.numOfVerticalPic = info.material.mainTexture.height / lOut.pixelVerticalNum;

        lOut.picRateInU = 1.0f / lOut.numOfHorizonPic;
        lOut.picRateInV = 1.0f / lOut.numOfVerticalPic;
        //numOfPic = numOfVerticaPic * numOfHorizonPic;
        lOut.numOfPic = lOut.endPicNum - lOut.beginPicNum + 1;
        //lOut.timeInOnePic = lOut.animationLength / lOut.numOfPic;

        return lOut;
    }
Beispiel #38
0
 public void AddAnimationData(AnimationData animationData)
 {
     m_animationDataList.Add(animationData);
 }
Beispiel #39
0
        private void ReadAnimationData()
        {
            m_AnimationData = new AnimationData[m_NumBones];

            for (int i = 0; i < m_NumBones; i++)
            {
                m_AnimationData[i] = new AnimationData(this, m_AnimationOffset + (uint)(i * 36), i);
            }
        }
Beispiel #40
0
 public ScalableSliceComponent(AnimationData image, string slice) : base(image, slice)
 {
 }
 private int GetCurrentIndex(AnimationData d)
 {
     return Mathf.FloorToInt(GetCurrentTime(d.startTime, d.stopTime) * d.frameRate);
 }
Beispiel #42
0
    public override IEnumerator CalculateActions(List <AIAction> validActions, BoardManager gm, Actor ai)
    {
        if (ai.CanAttack())
        {
            List <TileNode> movementNodes = GetTileNodeMovementRange(gm, ai);

            /// Store the actual position of the ai so that we can restore it later
            int originalX = ai.GetPosX();
            int originalY = ai.GetPosY();


            //Just going to get skills for now, expand to equipment and inventory
            //
            List <Skill> avaliableSkills = ai.actorData.JobDataState.GetAllSkillsOffCoolDown(ai);



            //stress test more skills
            // 7 * 3 = 21 skills to consider
            // a little inaccurate since coping this many skills would take more time than just processing them but ya know
            //
            Debug.Log("Skill count: " + avaliableSkills.Count);

            // So we're going to cycle through the possible movement options
            // use that as the source to find the range for each target type
            // use each node in that range for the target of each type

            //foreach tilenode                                   /pretend we moved there
            //foreach skill                                      /pretend we used that skill from there to find a rance
            //foreach tilenode in range                         /pretend we used the skill
            //record the combat data for that skill used

            int n = 0;

            //cycle through every place we can move
            foreach (TileNode movementOption in movementNodes)
            {
                // Basically we need to actually change the positional data of the ai to
                // accurately predict the best ability to use

                //We should also be checking if the unit is calculating from the area tha tit's starting from
                if (movementOption.data.posX == originalX && movementOption.data.posY == originalY)
                {
                    Debug.Log("Calculating from starting position");
                }


                ai.actorData.gridPosX = movementOption.data.posX;
                ai.actorData.gridPosY = movementOption.data.posY;

                //this might serve some purpose that i don't understand
                // yield return null;


                //cycle through every skill that can be used
                foreach (Skill skillOption in avaliableSkills)
                {
                    //find the range of the skill
                    // Get a list of tiles associated with that skill's range
                    //
                    List <TileNode> nodesInRange = gm.pathfinding.GetNodes(
                        gm.pathfinding.ValidBFS(skillOption, movementOption, ai
                                                ));

                    //gm.tileSelection.PopulateAttackRange(nodesInRange);

                    foreach (TileNode nodeInSkillrange in nodesInRange) //should be valid targets for the skill based on when it's being used from
                    {
                        /// So now we are cycling through a list of valid targets,
                        /// so we'll use the skill on this target and calculate the score
                        ///

                        //yield return null;
                        Combat testCombat = new Combat(ai);


                        AnimationData animationData = AnimationData.NewAntionData(skillOption, gm.pathfinding.GetTileNode(ai), nodeInSkillrange);
                        testCombat.animationDatas.Add(animationData);
                        testCombat.PoopulateCombat(animationData);

                        // So now we have a combat damage map we can use to determine the score and create an action



                        //check to make sure there is an actor here and that the actor is player controlled
                        // so we dont just randomaly blow up our own ppl
                        // further work: give negative score if allied units would be damaged?

                        AttackEnemyAction action = new AttackEnemyAction(nodeInSkillrange, movementOption, ai, skillOption);


                        CalculateDamageScore(testCombat, action);

                        CalcuateTileCost(movementOption, ai, action);
                        CalculateBuffScore(testCombat, action);
                        CacluateSummonScore(testCombat, action);

                        validActions.Add(action); //make this is like a heap or something later

                        /*
                         * if (score != 0)
                         * {
                         *  Debug.Log("Target Node: " + nodeInSkillrange.data.posX + ", " + nodeInSkillrange.data.posY +
                         *  ".  Skilled Used: " + skillOption.GetKey() +
                         *  ". Move Target: " + movementOption.data.posX + ", " + movementOption.data.posY +
                         *  "Score: " + action.GetScore());
                         * }*/
                    }
                }
            }

            //Debug.Log("Time compexity kinda: " + n);

            //POTENTIAL OPTIMIZATION: we theoretically know the ranges of skills and the aoe of there target
            //types so maybe we can just do math to cut out tiles where we know there wont be anything

            //Set the position back to where the actor ACTUALLY is
            ai.actorData.gridPosX = originalX;
            ai.actorData.gridPosY = originalY;

            //yield return null;
        }

        yield return(null);
    }
 public float GetSpeed(AnimationData animData)
 {
     return animData.speed;
 }
    void InitializeSkinningBuffers()
    {
        int numJoints = animation.jointNames.Count;

        AnimationData animData = hiero.MakeKeyFramesAndJointData(model);

        int kid = jointComputer.FindKernel("CalculateTransforms");

        hierarchyBuf = new ComputeBuffer(hiero.entries.Count, sizeof(int));
        hierarchyBuf.SetData(hiero.entries.ToArray());
        jointComputer.SetBuffer(kid, "hierarchyBuf", hierarchyBuf);

        jointDataBuf = new ComputeBuffer(numJoints, sizeof(int) * 21 + sizeof(float) * 32);
        jointDataBuf.SetData(animData.jointData);
        jointComputer.SetBuffer(kid, "jointBuf", jointDataBuf);

        tXBuf = new ComputeBuffer(animData.keyframes[0].Count, sizeof(float) * 2);
        tXBuf.SetData(animData.keyframes[0].ToArray());
        jointComputer.SetBuffer(kid, "tXBuf", tXBuf);

        tYBuf = new ComputeBuffer(animData.keyframes[1].Count, sizeof(float) * 2);
        tYBuf.SetData(animData.keyframes[1].ToArray());
        jointComputer.SetBuffer(kid, "tYBuf", tYBuf);

        tZBuf = new ComputeBuffer(animData.keyframes[2].Count, sizeof(float) * 2);
        tZBuf.SetData(animData.keyframes[2].ToArray());
        jointComputer.SetBuffer(kid, "tZBuf", tZBuf);

        rXBuf = new ComputeBuffer(animData.keyframes[3].Count, sizeof(float) * 2);
        rXBuf.SetData(animData.keyframes[3].ToArray());
        jointComputer.SetBuffer(kid, "rXBuf", rXBuf);

        rYBuf = new ComputeBuffer(animData.keyframes[4].Count, sizeof(float) * 2);
        rYBuf.SetData(animData.keyframes[4].ToArray());
        jointComputer.SetBuffer(kid, "rYBuf", rYBuf);

        rZBuf = new ComputeBuffer(animData.keyframes[5].Count, sizeof(float) * 2);
        rZBuf.SetData(animData.keyframes[5].ToArray());
        jointComputer.SetBuffer(kid, "rZBuf", rZBuf);

        rWBuf = new ComputeBuffer(animData.keyframes[6].Count, sizeof(float) * 2);
        rWBuf.SetData(animData.keyframes[6].ToArray());
        jointComputer.SetBuffer(kid, "rWBuf", rWBuf);

        sXBuf = new ComputeBuffer(animData.keyframes[7].Count, sizeof(float) * 2);
        sXBuf.SetData(animData.keyframes[7].ToArray());
        jointComputer.SetBuffer(kid, "sXBuf", sXBuf);

        sYBuf = new ComputeBuffer(animData.keyframes[8].Count, sizeof(float) * 2);
        sYBuf.SetData(animData.keyframes[8].ToArray());
        jointComputer.SetBuffer(kid, "sYBuf", sYBuf);

        sZBuf = new ComputeBuffer(animData.keyframes[9].Count, sizeof(float) * 2);
        sZBuf.SetData(animData.keyframes[9].ToArray());
        jointComputer.SetBuffer(kid, "sZBuf", sZBuf);

        jointXBuf = new ComputeBuffer(numJoints * AGENT_NUM, sizeof(float) * 16);
        jointComputer.SetBuffer(kid, "jointXforms", jointXBuf);

        float[] times = new float[AGENT_NUM];
        for (int i = 0; i < AGENT_NUM; i++)
        {
            times[i] = (Random.value * animation.length) % animation.length;
        }
        timeBuf = new ComputeBuffer(AGENT_NUM, sizeof(float));
        timeBuf.SetData(times);
        jointComputer.SetBuffer(kid, "times", timeBuf);

        jointComputer.SetFloat("animationLength", animation.length);

        jointComputer.SetInt("numJoints", numJoints);

        var wghts = model.boneWeights;

        Vector4[] boneIndices = new Vector4[wghts.Length];
        Vector4[] boneWeights = new Vector4[wghts.Length];
        for (int i = 0; i < wghts.Length; i++)
        {
            BoneWeight w = wghts[i];
            boneIndices[i] = new Vector4(w.boneIndex0, w.boneIndex1, w.boneIndex2, w.boneIndex3);
            boneWeights[i] = new Vector4(w.weight0, w.weight1, w.weight2, w.weight3);
        }
        boneIdxBuf    = new ComputeBuffer(wghts.Length, sizeof(float) * 4);
        boneWeightBuf = new ComputeBuffer(wghts.Length, sizeof(float) * 4);
        boneIdxBuf.SetData(boneIndices);
        boneWeightBuf.SetData(boneWeights);
        modelMat.SetBuffer("weights", boneWeightBuf);
        modelMat.SetBuffer("boneIndices", boneIdxBuf);
        modelMat.SetBuffer("xforms", jointXBuf);
        modelMat.SetBuffer("instanceXforms", instanceXBuf);
        modelMat.SetInt("numJoints", numJoints);
    }
    public bool IsPlaying(AnimationData animData, float weight)
    {
        if (animData == null) return false;
        if (currentAnimationData == null) return false;
        if (currentAnimationData == animData && animData.wrapMode == WrapMode.Once && animData.timesPlayed > 0) return false;
        if (currentAnimationData == animData && animData.wrapMode == WrapMode.ClampForever) return true;
        if (currentAnimationData == animData) return true;

        AnimatorClipInfo[] animationInfoArray = animator.GetCurrentAnimatorClipInfo(0);
        foreach (AnimatorClipInfo animationInfo in animationInfoArray){
            if (animData.clip == animationInfo.clip && animationInfo.weight >= weight) return true;
        }
        return false;
    }
Beispiel #46
0
 private int GetCurrentIndex(AnimationData d)
 {
     return(Mathf.FloorToInt(GetCurrentTime(d.startTime, d.stopTime) * d.frameRate));
 }
 public void Play(AnimationData animationData)
 {
     _playAnimation(animationData, animationData.transitionDuration, 0, currentMirror);
 }
Beispiel #48
0
 public virtual void OnDamageInflicted(Combat combat, AnimationData currentData)
 {
 }
 public void SetNormalizedSpeed(AnimationData animData, float normalizedSpeed)
 {
     animData.normalizedSpeed = normalizedSpeed;
     animData.speed = animData.originalSpeed * animData.normalizedSpeed;
     if (IsPlaying(animData)) SetSpeed(animData.speed);
 }
    public void AddClip(AnimationClip clip, string newName, float speed, WrapMode wrapMode)
    {
        if (GetAnimationData(newName) != null) Debug.LogWarning("An animation with the name '"+ newName +"' already exists.");
        AnimationData animData = new AnimationData();
        animData.clip = (AnimationClip) Instantiate(clip);
        if (wrapMode == WrapMode.Default) wrapMode = defaultWrapMode;
        animData.clip.wrapMode = wrapMode;
        animData.clip.name = newName;
        animData.clipName = newName;
        animData.speed = speed;
        animData.originalSpeed = speed;
        animData.length = clip.length;
        animData.wrapMode = wrapMode;

        List<AnimationData> animationDataList = new List<AnimationData>(animations);
        animationDataList.Add(animData);
        animations = animationDataList.ToArray();
    }
 public void SetWrapMode(AnimationData animationData, WrapMode wrapMode)
 {
     animationData.wrapMode = wrapMode;
     animationData.clip.wrapMode = wrapMode;
 }
 public void AddAnimation(AnimationData ad)
 {
     animations.Add(ad);
 }
    //The overrite machine. Creates an overrideController, replace its core animations and restate it back in
    private void _playAnimation(AnimationData targetAnimationData, float blendingTime, float normalizedTime, bool mirror)
    {
        if (targetAnimationData == null || targetAnimationData.clip == null) return;
        AnimatorOverrideController overrideController = new AnimatorOverrideController();

        float newAnimatorSpeed = Mathf.Abs(targetAnimationData.originalSpeed);
        float currentNormalizedTime = GetCurrentClipPosition();

        currentMirror = mirror;
        if (mirror){
            if (targetAnimationData.originalSpeed >= 0) {
                overrideController.runtimeAnimatorController = controller2;
            }else{
                overrideController.runtimeAnimatorController = controller4;
            }
        }else{
            if (targetAnimationData.originalSpeed >= 0) {
                overrideController.runtimeAnimatorController = controller1;
            }else{
                overrideController.runtimeAnimatorController = controller3;
            }
        }

        if (currentAnimationData != null) overrideController["State1"] = currentAnimationData.clip;
        overrideController["State2"] = targetAnimationData.clip;

        if (blendingTime == -1) blendingTime = currentAnimationData.transitionDuration;
        if (blendingTime == -1) blendingTime = defaultTransitionDuration;

        if (blendingTime <= 0 || currentAnimationData == null){
            animator.runtimeAnimatorController = overrideController;
            animator.Play("State2", 0, normalizedTime);

        }else {
            animator.runtimeAnimatorController = overrideController;
            currentAnimationData.stateName = "State1";
            SetCurrentClipPosition(currentNormalizedTime);

            animator.Update(0);
            animator.CrossFade("State2", blendingTime/newAnimatorSpeed, 0, normalizedTime);
        }

        targetAnimationData.secondsPlayed = (normalizedTime * targetAnimationData.clip.length) / newAnimatorSpeed;
        targetAnimationData.length = targetAnimationData.clip.length;
        targetAnimationData.normalizedTime = normalizedTime;

        if (overrideRootMotion) animator.applyRootMotion = targetAnimationData.applyRootMotion;
        SetSpeed(targetAnimationData.originalSpeed);

        if (currentAnimationData != null) {
            currentAnimationData.speed = currentAnimationData.originalSpeed;
            currentAnimationData.normalizedSpeed = 1;
            currentAnimationData.timesPlayed = 0;
        }

        currentAnimationData = targetAnimationData;
        currentAnimationData.stateName = "State2";

        if (MecanimControl.OnAnimationBegin != null) MecanimControl.OnAnimationBegin(currentAnimationData);
    }
Beispiel #54
0
        protected override void _StartAction(RPGCharacterController controller, SwitchWeaponContext context)
        {
            RPGCharacterWeaponController weaponController = controller.GetComponent <RPGCharacterWeaponController>();

            if (weaponController == null)
            {
                EndAction(controller);
                return;
            }

            context.LowercaseStrings();

            bool changeRight   = false;
            bool sheathRight   = false;
            bool unsheathRight = false;
            int  fromRight     = controller.rightWeapon;
            int  toRight       = context.rightWeapon;

            bool changeLeft   = false;
            bool sheathLeft   = false;
            bool unsheathLeft = false;
            int  fromLeft     = controller.leftWeapon;
            int  toLeft       = context.leftWeapon;

            bool dualWielding = AnimationData.Is1HandedWeapon(fromRight) && AnimationData.Is1HandedWeapon(fromLeft);
            bool dualUnsheath = context.side == "dual";
            bool dualSheath   = false;

            int toAnimatorWeapon = 0;

            // Filter which side is changing.
            switch (context.side)
            {
            case "none":
            case "right":
                changeRight = true;
                if (AnimationData.Is2HandedWeapon(toRight) && !AnimationData.IsNoWeapon(fromLeft))
                {
                    changeLeft = true;
                    toLeft     = (int)Weapon.Unarmed;
                    dualSheath = dualWielding;
                }
                break;

            case "left":
                changeLeft = true;
                if (AnimationData.Is2HandedWeapon(fromRight))
                {
                    changeRight = true;
                    toRight     = (int)Weapon.Unarmed;
                }
                break;

            case "dual":
                changeLeft  = true;
                changeRight = true;
                dualSheath  = dualWielding;
                break;

            case "both":
                changeLeft  = true;
                changeRight = true;
                break;
            }

            // Set sheath location.
            switch (context.sheathLocation)
            {
            case "back":
                controller.animator.SetInteger("SheathLocation", 0);
                break;

            case "hips":
                controller.animator.SetInteger("SheathLocation", 1);
                break;
            }

            // If relaxing, just use the Relax action.
            if (context.type == "relax")
            {
                controller.StartAction("Relax");
                return;
            }

            // Force unarmed if sheathing weapons.
            if (context.type == "sheath")
            {
                if (context.side == "left" || context.side == "dual" || context.side == "both")
                {
                    toLeft = (int)Weapon.Unarmed;
                }
                else
                {
                    toLeft = fromLeft;
                }
                if (context.side == "none" || context.side == "right" || context.side == "dual" || context.side == "both")
                {
                    toRight = (int)Weapon.Unarmed;
                }
                else
                {
                    toRight = fromRight;
                }
            }

            // Sheath weapons first if our starting weapon is different from our desired weapon and we're
            // not starting from an unarmed position.
            if (context.type == "sheath" || context.type == "switch")
            {
                sheathLeft       = changeLeft && fromLeft != toLeft && !AnimationData.IsNoWeapon(fromLeft);
                sheathRight      = changeRight && fromRight != toRight && !AnimationData.IsNoWeapon(fromRight);
                toAnimatorWeapon = AnimationData.ConvertToAnimatorWeapon(toLeft, toRight);
            }

            // Unsheath a weapon if our starting weapon is different from our desired weapon and we're
            // not ending on an unarmed position.
            if (context.type == "unsheath" || context.type == "switch")
            {
                unsheathLeft  = changeLeft && fromLeft != toLeft && !AnimationData.IsNoWeapon(toLeft);
                unsheathRight = changeRight && fromRight != toRight && !AnimationData.IsNoWeapon(toRight);

                // If you're switching from the relaxed state, you can "unsheath" your fists.
                if (controller.isRelaxed && (toLeft == (int)Weapon.Unarmed || toRight == (int)Weapon.Unarmed))
                {
                    fromLeft      = (int)Weapon.Relax;
                    fromRight     = (int)Weapon.Relax;
                    sheathLeft    = false;
                    sheathRight   = false;
                    unsheathLeft  = false;
                    unsheathRight = true;
                    dualSheath    = false;
                    dualUnsheath  = false;
                }
            }

            ///
            /// Actually make changes to the weapon controller.
            ///

            if (context.type == "instant")
            {
                if (changeLeft)
                {
                    weaponController.InstantWeaponSwitch(toLeft);
                }
                if (changeRight)
                {
                    weaponController.InstantWeaponSwitch(toRight);
                }
            }
            else
            {
                // Sheath weapons first if that's necessary.
                if (dualSheath && (sheathRight || sheathLeft))
                {
                    // Dual sheathing requires at most one call.
                    weaponController.SheathWeapon(fromRight, toAnimatorWeapon, dualSheath);
                }
                else
                {
                    if (sheathLeft)
                    {
                        // Debug.Log("Sheath Left: " + fromLeft + " > " + toLeft);
                        weaponController.SheathWeapon(fromLeft, toAnimatorWeapon, dualSheath);
                    }
                    if (sheathRight)
                    {
                        // Debug.Log("Sheath Right (dual: " + dualSheath + "): " + fromRight + " > " + toRight);
                        weaponController.SheathWeapon(fromRight, toAnimatorWeapon, dualSheath);
                    }
                }
                // Finally, unsheath the desired weapons!
                if (dualUnsheath && (unsheathRight || unsheathLeft))
                {
                    // Dual unsheathing requires at most one call.
                    weaponController.UnsheathWeapon(toRight, dualUnsheath);
                }
                else
                {
                    if (unsheathLeft)
                    {
                        // Debug.Log("Unsheath Left: " + toLeft);
                        weaponController.UnsheathWeapon(toLeft, dualUnsheath);
                    }
                    if (unsheathRight)
                    {
                        // Debug.Log("Unsheath Right (dual: " + dualUnsheath + "): " + toRight);
                        weaponController.UnsheathWeapon(toRight, dualUnsheath);
                    }
                }
            }

            // This callback will update the weapons in character controller after all other
            // coroutines finish.
            weaponController.AddCallback(() => {
                if (changeLeft)
                {
                    controller.leftWeapon = toLeft;
                }
                if (changeRight)
                {
                    controller.rightWeapon = toRight;
                }

                // Turn off the isWeaponSwitching flag and sync weapon object visibility.
                weaponController.SyncWeaponVisibility();
                controller.EndAction("Relax");
                EndAction(controller);
            });
        }
    AnimationData ParseAnimationString(string animString)
    {
        Stack<ParseAnimState> animStates = new Stack<ParseAnimState>();
        string currentString = "";

        // ANIMATION DATA
        string name = "";
        List<FrameData> frames = new List<FrameData>();
        LoopMode loopMode = LoopMode.Loops;

        // CURRENT FRAME DATA
        Color32 currentColor = new Color32(0, 0, 0, 0);
        List<PixelData> currentPixels = new List<PixelData>();
        List<PixelData> previousFramePixels = new List<PixelData>();
        PixelPoint animSize = new PixelPoint(0, 0);
        PixelRect hitbox = new PixelRect(0, 0, 0, 0);
        float currentAnimTime = 0.0f;
        int currentPixelYPos = 0;

        bool differencesMode = false;

        foreach(char c in animString)
        {
            if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.DifferencesMode)
            {
                if(c == '^')
                    differencesMode = true;
                else
                    differencesMode = false;

                animStates.Pop();
                animStates.Push(ParseAnimState.Frame);
            }
            else
            {
                if(c == '*')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Name)
                    {
                        name = currentString;
                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Name);
                        currentString = "";
                    }
                }
                else if(c == '!')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Size)
                    {
                        // parse current string for animation rect and save it
                        string[] vals = currentString.Split(',');
                        if(vals.Length == 2)
                        {
                            int xSize = 0;
                            int ySize = 0;
                            if(!(int.TryParse(vals[0], out xSize) && int.TryParse(vals[1], out ySize)))
                            {
                                ShowConsoleText(currentString + " is not properly formatted anim size data!");
                                return null;
                            }
                            animSize = new PixelPoint(xSize, ySize);
                        }
                        else
                        {
                            ShowConsoleText(currentString + " is not properly formatted anim size data!");
                            return null;
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Size);
                    }
                }
                else if(c == '<')
                {
                    animStates.Push(ParseAnimState.Hitbox);
                }
                else if(c == '>')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Hitbox)
                    {
                        // parse current string for hitbox info and save it
                        string[] vals = currentString.Split(',');
                        if(vals.Length == 4)
                        {
                            int left = 0;
                            int bottom = 0;
                            int width = 0;
                            int height = 0;

                            if(!(int.TryParse(vals[0], out left) &&
                                 int.TryParse(vals[1], out bottom) &&
                                 int.TryParse(vals[2], out width) &&
                                 int.TryParse(vals[3], out height)))
                            {
                                ShowConsoleText(currentString + " is not properly formatted hitbox data!");
                                return null;
                            }

                            hitbox = new PixelRect(left, bottom, width, height);
                        }
                        else
                        {
                            ShowConsoleText(currentString + " is not properly formatted hitbox data!");
                            return null;
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                }
                else if(c == '{')
                {
                    animStates.Push(ParseAnimState.DifferencesMode);
                }
                else if(c == '}')
                {
                    if(differencesMode)
                    {
                        // currentPixels holds pixels that are DIFFERENT than the previous frame
                        List<PixelData> pixels = new List<PixelData>();
                        foreach(PixelData prevPixelData in previousFramePixels)
                        {
                            // only add the previous frame pixels that AREN'T being overriden by the new frame data
                            bool allowPixel = true;
                            foreach(PixelData pixel in currentPixels)
                            {
                                if(pixel.position == prevPixelData.position)
                                {
                                    allowPixel = false;
                                    break;
                                }
                            }

                            if(allowPixel)
                                pixels.Add(new PixelData(prevPixelData.position, prevPixelData.color));
                        }

                        // add in the new, different pixels
                        foreach(PixelData newPixel in currentPixels)
                        {
                            pixels.Add(newPixel);
                        }

                        currentPixels.Clear();

                        frames.Add(new FrameData(pixels, currentAnimTime));

                        previousFramePixels.Clear();
                        previousFramePixels.AddRange(pixels);
                    }
                    else
                    {
                        // save current frame data
                        List<PixelData> pixels = new List<PixelData>();
                        pixels.AddRange(currentPixels);
                        currentPixels.Clear();

                        frames.Add(new FrameData(pixels, currentAnimTime));

                        previousFramePixels.Clear();
                        previousFramePixels.AddRange(pixels);
                    }

                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Frame)
                        animStates.Pop();
                }
                else if(c == '[')
                {
                    animStates.Push(ParseAnimState.PixelColor);
                }
                else if(c == ']')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelColor)
                    {
                        // parse current string for pixel color
                        if(currentString.Length == 0)
                        {
                            currentColor = new Color32(0, 0, 0, 0);
                        }
                        else
                        {
                            string[] vals = currentString.Split(',');
                            if(vals.Length == 1)
                            {
                                byte grey = 0;
                                if(!byte.TryParse(vals[0], out grey))
                                {
                                    ShowConsoleText(currentString + " is not properly formatted color data!");
                                    return null;
                                }
                                currentColor = new Color32(grey, grey, grey, 255);
                            }
                            else if(vals.Length == 2)
                            {
                                byte grey = 0;
                                byte opacity = 0;
                                if(!(byte.TryParse(vals[0], out grey) && byte.TryParse(vals[1], out opacity)))
                                {
                                    ShowConsoleText(currentString + " is not properly formatted color data!");
                                    return null;
                                }

                                currentColor = new Color32(grey, grey, grey, opacity);
                            }
                            else if(vals.Length == 3)
                            {
                                byte red = 0;
                                byte green = 0;
                                byte blue = 0;
                                if(!(byte.TryParse(vals[0], out red) && byte.TryParse(vals[1], out green) && byte.TryParse(vals[2], out blue)))
                                {
                                    ShowConsoleText(currentString + " is not properly formatted color data!");
                                    return null;
                                }

                                currentColor = new Color32(red, green, blue, 255);
                            }
                            else if(vals.Length == 4)
                            {
                                byte red = 0;
                                byte green = 0;
                                byte blue = 0;
                                byte opacity = 0;
                                if(!(byte.TryParse(vals[0], out red) && byte.TryParse(vals[1], out green) && byte.TryParse(vals[2], out blue) && byte.TryParse(vals[3], out opacity)))
                                {
                                    ShowConsoleText(currentString + " is not properly formatted color data!");
                                    return null;
                                }

                                currentColor = new Color32(red, green, blue, opacity);
                            }
                            else
                            {
                                ShowConsoleText(currentString + " is not properly formatted color data!");
                            }
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                }
                else if(c == '(')
                {
                    animStates.Push(ParseAnimState.PixelYPos);
                }
                else if(c == '-')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelYPos)
                    {
                        if(!int.TryParse(currentString, out currentPixelYPos))
                        {
                            ShowConsoleText(currentString + " is not a properly formatted y-position!");
                            return null;
                        }

                        currentString = "";
                        animStates.Pop();

                        animStates.Push(ParseAnimState.PixelXPos);
                    }
                }
                else if(c == ')')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.PixelXPos)
                    {
                        // parse current string for x pixel positions (for the current pixel y pos)
                        // add a pixel of current color to a list
                        string[] vals = currentString.Split(',');
                        for(int i = 0; i < vals.Length; i++)
                        {
                            int xPos = 0;
                            if(!int.TryParse(vals[i], out xPos))
                            {
                                ShowConsoleText(currentString + " is not a properly formatted x-position!");
                                return null;
                            }

                            currentPixels.Add(new PixelData(new PixelPoint(xPos, currentPixelYPos), currentColor));
                        }

                        animStates.Pop();
                    }
                    currentString = "";
                }
                else if(c == '#')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.AnimTime)
                    {
                        // parse current string for animation time and save it
                        if(!float.TryParse(currentString, out currentAnimTime))
                        {
                            ShowConsoleText(currentString + " is not a properly formatted frame time!");
                            return null;
                        }

                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.AnimTime);
                    }
                }
                else if(c == '&')
                {
                    if(animStates.Count > 0 && animStates.Peek() == ParseAnimState.Loops)
                    {
                        // parse current string for loop mode and save it
                        int loopModeInt = 0;
                        if(!int.TryParse(currentString, out loopModeInt))
                        {
                            ShowConsoleText(currentString + " is not a properly formatted loop mode!");
                            return null;
                        }

                        loopMode = (LoopMode)loopModeInt;

                        currentString = "";
                        animStates.Pop();
                    }
                    else
                    {
                        animStates.Push(ParseAnimState.Loops);
                    }
                }
                else
                {
                    currentString += c;
                }
            }
        }

        AnimationData animData = new AnimationData(name, frames, animSize, hitbox, loopMode);
        return animData;
    }
Beispiel #56
0
 public bool ConditionasMet(Combat c, AnimationData currentData)
 {
     return(ConditionsMet(c.source, currentData.DestNode, currentData.skillUsed as Skill));
 }
        /**
         * Move the playhead to that AnimationData
         * @param animationName The name of the AnimationData to play.
         * @param fadeInTime A fade time to apply (> 0)
         * @param duration The duration of that AnimationData.
         * @param loop Loop(0:loop forever, 1~+∞:loop times, -1~-∞:will fade animation after loop complete).
         * @param layer The layer of the animation.
         * @param group The group of the animation.
         * @param fadeOutMode Fade out mode.
         * @param displayControl Display control.
         * @param pauseFadeOut Pause other animation playing.
         * @param pauseFadeIn Pause this animation playing before fade in complete.
         * @see dragonBones.objects.AnimationData.
         * @see dragonBones.animation.AnimationState.
         */
        public AnimationState GotoAndPlay(
            string animationName,
            float fadeInTime    = -1f,
            float duration      = -1f,
            float loop          = float.NaN,
            uint layer          = 0,
            string group        = null,
            string fadeOutMode  = SAME_LAYER_AND_GROUP,
            bool displayControl = true,
            bool pauseFadeOut   = true,
            bool pauseFadeIn    = true
            )
        {
            if (_animationDataList == null)
            {
                return(null);
            }
            int           i = _animationDataList.Count;
            int           j;
            AnimationData animationData = null;

            while (i-- > 0)
            {
                if (_animationDataList[i].Name == animationName)
                {
                    animationData = _animationDataList[i];
                    break;
                }
            }
            if (animationData == null)
            {
                Debug.LogError(string.Format("Cannot find animation {0}", animationName));
                return(null);
            }

            _isPlaying = true;

            fadeInTime = fadeInTime < 0?(animationData.FadeInTime < 0?0.3f:animationData.FadeInTime):fadeInTime;

            float durationScale;

            if (duration < 0)
            {
                durationScale = animationData.Scale < 0?1:animationData.Scale;
            }
            else
            {
                durationScale = duration / animationData.Duration;
            }

            loop  = float.IsNaN(loop)?animationData.Loop:loop;
            layer = addLayer(layer);

            //autoSync = autoSync && !pauseFadeOut && !pauseFadeIn;
            AnimationState        animationState;
            List <AnimationState> animationStateList;

            switch (fadeOutMode)
            {
            case NONE:
                break;

            case SAME_LAYER:
                animationStateList = _animationLayer[(int)layer];
                i = animationStateList.Count;
                while (i-- > 0)
                {
                    animationState = animationStateList[i];
                    animationState.FadeOut(fadeInTime, pauseFadeOut);
                }
                break;

            case SAME_GROUP:
                j = _animationLayer.Count;
                while (j-- > 0)
                {
                    animationStateList = _animationLayer[j];
                    i = animationStateList.Count;
                    while (i-- > 0)
                    {
                        animationState = animationStateList[i];
                        if (animationState.Group == group)
                        {
                            animationState.FadeOut(fadeInTime, pauseFadeOut);
                        }
                    }
                }
                break;

            case ALL:
                j = _animationLayer.Count;
                while (j-- > 0)
                {
                    animationStateList = _animationLayer[j];
                    i = animationStateList.Count;
                    while (i-- > 0)
                    {
                        animationState = animationStateList[i];
                        animationState.FadeOut(fadeInTime, pauseFadeOut);
                    }
                }
                break;

            case SAME_LAYER_AND_GROUP:
            default:
                animationStateList = _animationLayer[(int)layer];
                i = animationStateList.Count;
                while (i-- > 0)
                {
                    animationState = animationStateList[i];
                    if (animationState.Group == group)
                    {
                        animationState.FadeOut(fadeInTime, pauseFadeOut);
                    }
                }

                break;
            }

            _lastAnimationState              = AnimationState.borrowObject();
            _lastAnimationState.Group        = group;
            _lastAnimationState.TweenEnabled = TweenEnabled;
            _lastAnimationState.fadeIn(_armature, animationData, fadeInTime, 1 / durationScale, (int)loop, layer, displayControl, pauseFadeIn);

            addState(_lastAnimationState);

            List <Slot> slotList = _armature._slotList;
            Slot        slot;

            i = slotList.Count;
            while (i-- > 0)
            {
                slot = slotList[i];
                if (slot.ChildArmature != null)
                {
                    slot.ChildArmature.Animation.GotoAndPlay(animationName, fadeInTime);
                }
            }

            _lastAnimationState.AdvanceTime(0);

            return(_lastAnimationState);
        }
Beispiel #58
0
        protected override void _StartAction(RPGCharacterController controller, AttackContext context)
        {
            int   attackSide   = 0;
            int   attackNumber = context.number;
            int   weaponNumber = controller.rightWeapon;
            float duration     = 0f;

            if (context.side == (int)AttackSide.Right && AnimationData.Is2HandedWeapon(weaponNumber))
            {
                context.side = (int)AttackSide.None;
            }

            switch (context.side)
            {
            case (int)AttackSide.None:
                attackSide   = 0;
                weaponNumber = controller.rightWeapon;
                break;

            case (int)AttackSide.Left:
                attackSide   = 1;
                weaponNumber = controller.leftWeapon;
                break;

            case (int)AttackSide.Right:
                attackSide   = 2;
                weaponNumber = controller.rightWeapon;
                break;

            case (int)AttackSide.Dual:
                attackSide   = 3;
                weaponNumber = controller.rightWeapon;
                break;
            }

            if (attackNumber == -1)
            {
                switch (context.type)
                {
                case "Attack":
                    attackNumber = AnimationData.RandomAttackNumber(attackSide, weaponNumber);
                    break;

                case "Kick":
                    attackNumber = AnimationData.RandomKickNumber(attackSide);
                    break;

                case "Special":
                    attackNumber = 1;
                    break;
                }
            }

            duration = AnimationData.AttackDuration(attackSide, weaponNumber, attackNumber);

            if (!controller.maintainingGround)
            {
                controller.AirAttack();
                EndAction(controller);
            }
            else if (controller.isMoving)
            {
                controller.RunningAttack(
                    attackSide,
                    controller.hasLeftWeapon,
                    controller.hasRightWeapon,
                    controller.hasDualWeapons,
                    controller.hasTwoHandedWeapon
                    );
                EndAction(controller);
            }
            else if (context.type == "Kick")
            {
                controller.AttackKick(attackNumber);
                EndAction(controller);
            }
            else if (context.type == "Attack")
            {
                controller.Attack(
                    attackNumber,
                    attackSide,
                    controller.leftWeapon,
                    controller.rightWeapon,
                    duration
                    );
                EndAction(controller);
            }
            else if (context.type == "Special")
            {
                controller.isSpecial = true;
                controller.StartSpecial(attackNumber);
            }
        }
Beispiel #59
0
 public virtual void OnTargeted(Combat combat, AnimationData currentData)
 {
 }
Beispiel #60
0
        public Player(Vector2 position)
            : base(position)
        {
            this.Tag((int)GameTags.Player);
            this.Collider = new Hitbox((float)32.0f, (float)32.0f, -16.0f, -6.0f);
            this.Visible  = true;

            sprite = new AnimationPlayer();

            playerTexture      = Engine.Instance.Content.Load <Texture2D>("Player/Idle");
            healthTexture      = Engine.Instance.Content.Load <Texture2D>("Player/Healthpoint");
            bulletPointTexture = Engine.Instance.Content.Load <Texture2D>("Player/bulletPoint");

            idleAnimation = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Idle"), 200, 96, true);
            runAnimation  = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Run"), 75, 96, true);
            jumpAnimation = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Jump"), 200, 96, true);
            fallAnimation = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Fall"), 200, 96, true);


            groundAttack1 = Engine.Instance.Content.Load <HitboxData>("Player/Combo1Box");
            groundAttack2 = Engine.Instance.Content.Load <HitboxData>("Player/Combo2Box");
            groundAttack3 = Engine.Instance.Content.Load <HitboxData>("Player/Combo3Box");
            parryBox      = Engine.Instance.Content.Load <HitboxData>("Player/ParryBox");

            attack1Animation = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Combo1"), 50, 96, false, groundAttack1);
            attack2Animation = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Combo2"), 50, 96, false, groundAttack2);
            attack3Animation = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Combo1"), 50, 96, false, groundAttack3);

            airAttackAnimation1 = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Combo1"), 50, 96, false, groundAttack1);
            airAttackAnimation2 = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Combo2"), 50, 96, false, groundAttack2);

            parryAnimation = new AnimationData(Engine.Instance.Content.Load <Texture2D>("Player/Parry"), 50, 96, false, parryBox);

            flip = SpriteEffects.None;
            sprite.PlayAnimation(idleAnimation);

            boxTexture        = Engine.Instance.Content.Load <Texture2D>("Tiles/Red");
            Camera.CameraTrap = new Rectangle((int)this.Right, (int)this.Bottom - 100, 50, 70);


            moves = new Move[]
            {
                new Move(attackName1, Buttons.X)
                {
                    IsSubMove = true, IsVertMove = true
                },
                new Move(attackName2, Buttons.X, Buttons.X)
                {
                    IsSubMove = true, IsVertMove = true
                },
                new Move(attackName3, Buttons.X, Buttons.X, Buttons.X)
                {
                    IsVertMove = true
                },

                new Move(attackName1, Buttons.X)
                {
                    IsSubMove = true
                },
                new Move(attackName2, Buttons.X, Buttons.X)
                {
                    IsSubMove = true
                },
                new Move(attackName3, Buttons.X, Buttons.X, Buttons.X),

                new Move(airAttackName1, Buttons.X)
                {
                    IsSubMove = true, IsAirMove = true
                },
                new Move(airAttackName1, Buttons.X)
                {
                    IsSubMove = true, IsAirMove = true, IsVertMove = true
                },

                new Move(airAttackName2, Buttons.X, Buttons.X)
                {
                    IsAirMove = true
                },
                new Move(airAttackName2, Buttons.X, Buttons.X)
                {
                    IsAirMove = true, IsVertMove = true
                }
            };

            moveList     = new MoveList(moves);
            comboManager = new ComboManager((PlayerIndex.One), moveList.LongestMoveLength);

            this.Add(counters);
        }