Esempio n. 1
0
    public static NamedAnimationClip[] Create4Dir(string baseClipPath, int frameRate, string spritePath, int[] idx, string controllerPath, string stateName, bool doFlip = true)
    {
        string[] dirs     = { "Down", "Right", "Up", "Left" };
        int[]    flipdirs = { 3 };

        int numdirs = dirs.Length;

        NamedAnimationClip[] result = new NamedAnimationClip[numdirs];

        if (idx.Length != (numdirs * 2))
        {
            Debug.LogError("Incorrect number of indices");
            return(result);
        }

        for (int i = 0; i < numdirs; i++)
        {
            string        clipPath = baseClipPath + dirs[i] + ".anim";
            AnimationClip clip     = CreateAnimationsUtility.CreateAnimationClip(frameRate);
            int           startIdx = idx[i * 2];
            int           endIdx   = idx[(i * 2) + 1];
            CreateAnimationsUtility.AddSprites(clip, spritePath, startIdx, endIdx, frameRate);
            if (doFlip && System.Array.IndexOf(flipdirs, i) >= 0)
            {
                CreateAnimationsUtility.FlipSprite(clip, (endIdx - startIdx) + 1);
            }
            NamedAnimationClip n = new NamedAnimationClip {
                clip     = clip,
                clipPath = clipPath
            };
            result[i] = n;
        }
        return(result);
    }
Esempio n. 2
0
    public static void AddCurve(AnimationClip clip, System.Type type, string path, string propertyName, SimpleKeyFrame[] keyFrames)
    {
        EditorCurveBinding binding = CreateAnimationsUtility.CreateEditorCurveBinding(type, path, propertyName);
        AnimationCurve     curve   = new AnimationCurve();

        foreach (SimpleKeyFrame keyFrame in keyFrames)
        {
            CreateAnimationsUtility.AddAnimationKey(clip.frameRate, curve, keyFrame.frame, keyFrame.value, keyFrame.left, keyFrame.right);
        }
        AnimationUtility.SetEditorCurve(clip, binding, curve);
    }
Esempio n. 3
0
    public static void CreatePlayerChargeAttack()
    {
        string baseClipPath   = "Assets/Animations/Player/PlayerChargeAttack";
        int    frameRate      = 12;
        string spritePath     = "Assets/Sprites/Player/spr_player_attack.png";
        string controllerPath = "Assets/Animations/Player/PlayerBase.controller";
        string stateName      = "ChargeAttack";

        int[] idx             = { 8, 15, 56, 63, 104, 111, 56, 63 };
        int[] subBlendTreeIdx = { 0, 0 };

        NamedAnimationClip[] clips = Create4Dir(baseClipPath, frameRate, spritePath, idx, controllerPath, stateName);
        for (int i = 0; i < clips.Length; i++)
        {
            AnimationClip clip      = clips[i].clip;
            string        clipPath  = clips[i].clipPath;
            int[]         keyFrames = { 0, 3, 6 };
            AddCurve(clip, typeof(BoxCollider2D), "Bullet", "m_Enabled", ParamsToKeyFrames(keyFrames, 0f, 1f, 0f));
            switch (i)
            {
            case 0:
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalPosition.y", ParamsToKeyFrames(keyFrames, 0f, -3f, 0f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalScale.x", ParamsToKeyFrames(keyFrames, 1f, 3f, 1f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalScale.y", ParamsToKeyFrames(keyFrames, 1f, 3.5f, 1f));
                break;

            case 1:
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalPosition.x", ParamsToKeyFrames(keyFrames, 0f, 2.5f, 0f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalPosition.y", ParamsToKeyFrames(keyFrames, 0f, -2f, 0f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalScale.x", ParamsToKeyFrames(keyFrames, 1f, 4f, 1f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalScale.y", ParamsToKeyFrames(keyFrames, 1f, 2.5f, 1f));
                break;

            case 2:
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalPosition.y", ParamsToKeyFrames(keyFrames, 0f, 1.5f, 0f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalScale.x", ParamsToKeyFrames(keyFrames, 1f, 3f, 1f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalScale.y", ParamsToKeyFrames(keyFrames, 1f, 3.5f, 1f));
                break;

            case 3:
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalPosition.x", MirrorKeyFrames(0, ParamsToKeyFrames(keyFrames, 0f, 2.5f, 0f)));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalPosition.y", ParamsToKeyFrames(keyFrames, 0f, -2f, 0f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalScale.x", ParamsToKeyFrames(keyFrames, 1f, 4f, 1f));
                AddCurve(clip, typeof(Transform), "Bullet", "m_LocalScale.y", ParamsToKeyFrames(keyFrames, 1f, 2.5f, 1f));
                break;
            }
            CreateAnimationsUtility.SaveAnimationClip(clip, clipPath);
            subBlendTreeIdx[subBlendTreeIdx.Length - 1] = i;
            CreateAnimationsUtility.SetClipToAnimatorControllerBlendTree(clip, controllerPath, 0, stateName, subBlendTreeIdx);
        }
    }
Esempio n. 4
0
    public static void CreatePlayerIdle()
    {
        string baseClipPath   = "Assets/Animations/Player/PlayerIdle";
        int    frameRate      = 1;
        string spritePath     = "Assets/Sprites/Player/spr_player_move.png";
        string controllerPath = "Assets/Animations/Player/PlayerBase.controller";
        string stateName      = "Idle";

        int[] idx             = { 40, 40, 42, 42, 44, 44, 42, 42 };
        int[] subBlendTreeIdx = { 0 };

        NamedAnimationClip[] clips = Create4Dir(baseClipPath, frameRate, spritePath, idx, controllerPath, stateName);
        for (int i = 0; i < clips.Length; i++)
        {
            CreateAnimationsUtility.SaveAnimationClip(clips[i].clip, clips[i].clipPath);
            subBlendTreeIdx[subBlendTreeIdx.Length - 1] = i;
            CreateAnimationsUtility.SetClipToAnimatorControllerBlendTree(clips[i].clip, controllerPath, 0, stateName, subBlendTreeIdx);
        }
    }
Esempio n. 5
0
    public static void CreateEnemyWalk()
    {
        string baseClipPath   = "Assets/Animations/Enemy/EnemyWalk";
        int    frameRate      = 12;
        string spritePath     = "Assets/Sprites/EnemyBase/spr_enemy_move.png";
        string controllerPath = "Assets/Animations/Enemy/EnemyBase.controller";
        string stateName      = "Walk";

        int[] idx             = { 0, 7, 16, 23, 32, 39, 16, 23 };
        int[] subBlendTreeIdx = { 0 };

        NamedAnimationClip[] clips = Create4Dir(baseClipPath, frameRate, spritePath, idx, controllerPath, stateName);
        for (int i = 0; i < clips.Length; i++)
        {
            CreateAnimationsUtility.SaveAnimationClip(clips[i].clip, clips[i].clipPath);
            subBlendTreeIdx[subBlendTreeIdx.Length - 1] = i;
            CreateAnimationsUtility.SetClipToAnimatorControllerBlendTree(clips[i].clip, controllerPath, 0, stateName, subBlendTreeIdx);
        }
    }
Esempio n. 6
0
    public static void CreatePlayerRoll()
    {
        string baseClipPath   = "Assets/Animations/Player/PlayerRoll";
        int    frameRate      = 4;
        string spritePath     = "Assets/Sprites/Player/spr_player_move.png";
        string controllerPath = "Assets/Animations/Player/PlayerBase.controller";
        string stateName      = "Roll";

        int[] idx             = { 40, 40, 42, 42, 44, 44, 42, 42 };
        int[] subBlendTreeIdx = { 0 };

        NamedAnimationClip[] clips = Create4Dir(baseClipPath, frameRate, spritePath, idx, controllerPath, stateName);
        for (int i = 0; i < clips.Length; i++)
        {
            AnimationClip clip      = clips[i].clip;
            string        clipPath  = clips[i].clipPath;
            int[]         keyFrames = { 0, 1 };
            AddCurve(clip, typeof(BoxCollider2D), "Hitbox", "m_Enabled", ParamsToKeyFrames(keyFrames, 0f, 1f));
            CreateAnimationsUtility.SaveAnimationClip(clip, clipPath);
            subBlendTreeIdx[subBlendTreeIdx.Length - 1] = i;
            CreateAnimationsUtility.SetClipToAnimatorControllerBlendTree(clip, controllerPath, 0, stateName, subBlendTreeIdx);
        }
    }
Esempio n. 7
0
    public static void CreateIdleReference()
    {
        int           frameRate      = 1;
        int           numFrames      = 1;
        int           lastFrame      = numFrames;
        string        spritePath     = "Assets/Sprites/Player/spr_player_move.png";
        string        controllerPath = "Assets/Animations/Player/PlayerBase.controller";
        string        stateName      = "Idle";
        string        clipPath;
        AnimationClip clip;

        clipPath = "Assets/Animations/Player/PlayerIdleDown.anim";
        clip     = CreateAnimationsUtility.CreateAnimationClip(frameRate);
        CreateAnimationsUtility.AddSprites(clip, spritePath, 40, 40, frameRate);
        CreateAnimationsUtility.SaveAnimationClip(clip, clipPath);
        CreateAnimationsUtility.SetClipToAnimatorControllerBlendTree(clip, controllerPath, 0, stateName, 0);

        clipPath = "Assets/Animations/Player/PlayerIdleRight.anim";
        clip     = CreateAnimationsUtility.CreateAnimationClip(frameRate);
        CreateAnimationsUtility.AddSprites(clip, spritePath, 42, 42, frameRate);
        CreateAnimationsUtility.SaveAnimationClip(clip, clipPath);
        CreateAnimationsUtility.SetClipToAnimatorControllerBlendTree(clip, controllerPath, 0, stateName, 1);

        clipPath = "Assets/Animations/Player/PlayerIdleUp.anim";
        clip     = CreateAnimationsUtility.CreateAnimationClip(frameRate);
        CreateAnimationsUtility.AddSprites(clip, spritePath, 44, 44, frameRate);
        CreateAnimationsUtility.SaveAnimationClip(clip, clipPath);
        CreateAnimationsUtility.SetClipToAnimatorControllerBlendTree(clip, controllerPath, 0, stateName, 2);

        clipPath = "Assets/Animations/Player/PlayerIdleLeft.anim";
        clip     = CreateAnimationsUtility.CreateAnimationClip(frameRate);
        CreateAnimationsUtility.AddSprites(clip, spritePath, 42, 42, frameRate);
        CreateAnimationsUtility.FlipSprite(clip, lastFrame);
        CreateAnimationsUtility.SaveAnimationClip(clip, clipPath);
        CreateAnimationsUtility.SetClipToAnimatorControllerBlendTree(clip, controllerPath, 0, stateName, 3);
    }