コード例 #1
0
    //public Rect GetCurrentHitBox()
    //{
    //    return _activeHitBox;
    //}

    // Start is called before the first frame update
    public void Init()
    {
        //initialize all components necessary
        //_spriteController = this.GetComponent<Image>();
        _player = this.GetComponent <Player>();

        _defaultAnimation = fallBackAnimationName;
        _currentAnimation = _defaultAnimation;
        _currentOffset    = Vector2.zero;

        _mainLayer = _layerRenderers[0];

        _originalOffset = _mainLayer.rectTransform.anchoredPosition;

        _animations = new Dictionary <string, FGAnimation>();
        for (int i = 0; i < editorAnimationList.Length; i++)
        {
            string textureSetName = editorAnimationList[i].frames[0].sprite.texture.name;
            World.instance.LoadSprites(textureSetName);
            FGAnimation loadedAnim = Resources.Load <FGAnimation>("Animations\\" + editorAnimationList[i].name);
            if (loadedAnim == null)
            {
                loadedAnim = Resources.Load <FGAnimation>("Animations\\AttackAnimations\\" + editorAnimationList[i].name);
            }
            _animations.Add(editorAnimationList[i].animName, loadedAnim);
        }
    }
コード例 #2
0
    public FGAnimationKeyFrame LoopAnimationPlay(FGAnimation animation, double dt)
    {
        bool reset = animatorTimer >= animation.duration;

        if (reset)
        {
            animatorTimer -= animation.duration;
        }

        float adjustedTime = (float)animatorTimer;

        if (animation.type == FGAnimationType.REVERSE)
        {
            adjustedTime = animation.duration - adjustedTime;
        }

        currentFrame = AnimationPlayer.GetCurrentFrame(animation, adjustedTime);
        FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame);

        animatorTimer += dt;

        if (keyFrame != null)
        {
            ApplyFrame(keyFrame);
        }


        if (_currentKeyFrame != null)
        {
            return(_currentKeyFrame);
        }
        return(animation.frames[0]);
    }
コード例 #3
0
    void ShowAnimationPreview()
    {
        FGAnimation data = (FGAnimation)target;

        if (data.frames.Length > 0)
        {
            if (spriteToShow != null)
            {
                if (spriteToShow.type == FGAnimationStageType.ACTIVE)
                {
                    Texture2D sprite = GenerateTextureFromSprite(spriteToShow.sprite);
                    AddRectToTexture(ref sprite, spriteToShow.hitBox, Color.red);
                    GUILayout.Label(sprite);
                }
                else
                {
                    GUILayout.Label(GenerateTextureFromSprite(spriteToShow.sprite));
                }
            }
        }
        if (play)
        {
            if (GUILayout.Button("Stop"))
            {
                play = false;
                if (anim != null)
                {
                    anim.Reset();
                }
            }
        }
        else
        {
            if (GUILayout.Button("Play"))
            {
                play = true;
                if (anim != null)
                {
                    anim.Reset();
                }
            }

            if (GUILayout.Button("Move To Next Frame"))
            {
                anim.NextFrame((FGAnimation)target);
                spriteToShow = anim.GetCurrent();
            }
            if (GUILayout.Button("Back To Last Frame"))
            {
                anim.LastFrame((FGAnimation)target);
                spriteToShow = anim.GetCurrent();
            }
        }

        if (anim != null)
        {
            GUILayout.Label(new GUIContent("Frame number: " + anim.GetCurrentFrame().ToString()));
        }
    }
コード例 #4
0
    void OnEnable()
    {
        EditorAnimator anim = new EditorAnimator();
        FGAnimation    data = (FGAnimation)target;

        play  = false;
        _time = EditorApplication.timeSinceStartup;
        if (data.frames.Length > 0)
        {
            spriteToShow = data.frames[0];
        }
        EditorApplication.update += Update;
    }
コード例 #5
0
    //!
    public void UpdateAnimator(float dt)
    {
        bool reset = _animatorTime >= _animations[_currentAnimation].duration;
        bool bounceAnimationReverse = false;

        //check what type of animation we're dealing with
        switch (_animations[_currentAnimation].type)
        {
        case FGAnimationType.BOUNCE:
        case FGAnimationType.LOOP:
            if (reset)
            {
                _animatorTime -= _animations[_currentAnimation].duration;
            }
            break;

        case FGAnimationType.REVERSE:
        case FGAnimationType.ONCE:
            if (reset)
            {
                if (_animations[_currentAnimation].nextAnimation != "")
                {
                    Play(_animations[_currentAnimation].nextAnimation);
                }
                else
                {
                    Play(_defaultAnimation);
                }
            }
            break;
        }

        FGAnimation current      = _animations[_currentAnimation];
        float       adjustedTime = _animatorTime;

        if (current.type == FGAnimationType.REVERSE)
        {
            adjustedTime = current.duration - adjustedTime;
        }

        int currFrame = AnimationPlayer.GetCurrentFrame(_animations[_currentAnimation], adjustedTime);
        FGAnimationKeyFrame keyFrame = _animations[_currentAnimation].GetKeyFrame(currFrame);

        if (_currentKeyFrame != keyFrame)
        {
            ApplyFrame(keyFrame);
        }

        //at end of update, update animator's time
        _animatorTime += dt;
    }
コード例 #6
0
    public void LastFrame(FGAnimation animation)
    {
        if ((currentFrame - 1) < 0)
        {
            currentFrame = animation.totalFrameCount - 1;
        }
        else
        {
            currentFrame--;
        }
        FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame);

        ApplyFrame(keyFrame);
    }
コード例 #7
0
    public void NextFrame(FGAnimation animation)
    {
        if (animation.totalFrameCount == (currentFrame + 1))
        {
            currentFrame = 0;
        }
        else
        {
            currentFrame++;
        }
        FGAnimationKeyFrame keyFrame = animation.GetKeyFrame(currentFrame);

        ApplyFrame(keyFrame);
    }
コード例 #8
0
    private void Awake()
    {
        if (anim == null)
        {
            anim = new EditorAnimator();
        }
        FGAnimation data = (FGAnimation)target;

        play  = false;
        _time = EditorApplication.timeSinceStartup;
        if (data.frames.Length > 0)
        {
            spriteToShow = data.frames[0];
        }
    }
コード例 #9
0
    /*void RenderGenerateToggle(ref FGAnimation animation)
     * {
     *  toggle = (bool)EditorGUILayout.BeginToggleGroup("Generate From Sheet", toggle);
     *  sheet = (Texture2D)EditorGUILayout.ObjectField(sheet, typeof(Texture2D), true);
     *  numRows = (int)EditorGUILayout.IntField("Number of Rows", numRows);
     *  numCols = (int)EditorGUILayout.IntField("Number of Columns", numCols);
     *  startIndex = (int)EditorGUILayout.IntField("Start Index", startIndex);
     *  endIndex = (int)EditorGUILayout.IntField("End Index", endIndex);
     *
     *  if (GUILayout.Button("Generate"))
     *  {
     *      if (numRows > 0 && numCols > 0 && endIndex >= startIndex)
     *      {
     *          Sprite[] createdSprites = GenerateFromSpriteSheet(sheet, numRows, numCols, startIndex, endIndex);
     *          for (int i = 0; i < createdSprites.Length; i++)
     *          {
     *              animation.AddFrame(new FGAnimationKeyFrame(createdSprites[i]));
     *          }
     *      }
     *  }
     *  EditorGUILayout.EndToggleGroup();
     * }*/

    void BuildAnimation(string spriteSheetName, int indexBegin, int indexEnd)
    {
        if (indexEnd < indexBegin || indexEnd < 0 || indexBegin < 0)
        {
            return;
        }

        Sprite[] allSprites = Resources.LoadAll <Sprite>(spriteSheetName);

        if (indexEnd >= allSprites.Length || indexBegin >= allSprites.Length)
        {
            return;
        }

        FGAnimation data = (FGAnimation)target;

        for (int i = indexBegin; i <= indexEnd; i++)
        {
            data.AddFrame(new FGAnimationKeyFrame(allSprites[i]));
        }
    }
コード例 #10
0
 public static int GetCurrentFrame(FGAnimation animation, float time)
 {
     return(animation.GetCurrentFrame(time / animation.duration));
 }
コード例 #11
0
    public override void OnInspectorGUI()
    {
        //base.DrawDefaultInspector();
        GUILayout.BeginVertical();
        FGAnimation data = (FGAnimation)target;

        data.animName = EditorGUILayout.TextField("Animation name: ", data.animName) as string;
        data.type     = (FGAnimationType)EditorGUILayout.Popup("Animation play type: ", (int)data.type, new string[] { "Loop", "Once", "Bounce", "Reverse" });

        //data.positionOffset = (Vector2)EditorGUILayout.Vector2Field("Offset: ", data.positionOffset);

        data.imageOffset = (Vector2)EditorGUILayout.Vector2Field("Image Offset Position: ", data.imageOffset);
        data.imageSize   = (Vector2)EditorGUILayout.Vector2Field("Image Size: ", data.imageSize);

        if (data.type == FGAnimationType.ONCE)
        {
            data.nextAnimation = EditorGUILayout.TextField("Next animation to go to after this one completes: ", data.nextAnimation) as string;

            if (data.attackData == null)
            {
                data.attackData = new FGAttackData();
            }
            data.attackData.guard           = (Guard)EditorGUILayout.Popup("Guard Type: ", (int)data.attackData.guard, new string[] { "LOW", "MID", "HIGH" });
            data.attackData.frameAdvOnBlock = (int)EditorGUILayout.IntField("Frame adv on block: ", (int)data.attackData.frameAdvOnBlock);
            data.attackData.frameAdvOnHit   = (int)EditorGUILayout.IntField("Frame adv on hit: ", (int)data.attackData.frameAdvOnHit);
            data.attackData.damage          = (int)EditorGUILayout.IntField("Damage: ", (int)data.attackData.damage);
            data.attackData.attackVector    = (Vector2)EditorGUILayout.Vector2Field("Direction vector for attack pushback", data.attackData.attackVector);
        }

        //RenderGenerateToggle(ref data);

        //List<int> removeFrames = new List<int>();
        if (data.frames.Length <= 0)
        {
            GUILayout.Label("Create animation from sprite sheet?");
            spriteSheet = (Texture2D)EditorGUILayout.ObjectField(spriteSheet, typeof(Texture2D), true);

            indxBeg = (int)EditorGUILayout.IntField("Starting Index: ", indxBeg);
            indxEnd = (int)EditorGUILayout.IntField("Ending Index: ", indxEnd);

            if (GUILayout.Button("Generate"))
            {
                if (spriteSheet != null)
                {
                    BuildAnimation(spriteSheet.name, indxBeg, indxEnd);
                }
            }
        }
        else
        {
            for (int i = 0; i < data.frames.Length; i++)
            {
                GUILayout.BeginVertical();
                FGAnimationStageType stage = (FGAnimationStageType)EditorGUILayout.Popup("Stage in animation: ", (int)data.frames[i].type, new string[] { "Startup", "Active", "Recovery" });
                int    frameCount          = (int)EditorGUILayout.IntField("Frame count: ", data.frames[i].frameCount);
                Sprite sprite = (Sprite)EditorGUILayout.ObjectField(data.frames[i].sprite, typeof(Sprite), true);

                data.ModifyFrameAtIndex(i, sprite, frameCount, stage);

                if (stage == FGAnimationStageType.ACTIVE)
                {
                    if (data.frames[i].hitBox == null)
                    {
                        data.frames[i].hitBox = new Rect();
                    }

                    data.frames[i].hitBox = (Rect)EditorGUILayout.RectField(data.frames[i].hitBox);
                }


                GUILayout.EndVertical();

                /*GUILayout.BeginHorizontal();
                 * for (int j = 0; j < data.frames[i].frameCount; j++)
                 * {
                 *  if (sprite.texture)
                 *  {
                 *
                 *  }
                 * }
                 * GUILayout.EndHorizontal();*/
                if (GUILayout.Button("Remove Key"))
                {
                    data.RemoveFrame(i);
                    break;
                }
            }
        }

        if (GUILayout.Button("Add Key Frame"))
        {
            data.AddFrame(new FGAnimationKeyFrame());
        }

        ShowAnimationPreview();
        GUILayout.EndVertical();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            AssetDatabase.SaveAssets();
        }
    }