Ejemplo n.º 1
0
 // Token: 0x06000097 RID: 151 RVA: 0x00007E60 File Offset: 0x00006060
 public static void SetProjectileSpriteRight(this Projectile proj, string name, int pixelWidth, int pixelHeight, bool lightened = true, tk2dBaseSprite.Anchor anchor = tk2dBaseSprite.Anchor.LowerLeft, int?overrideColliderPixelWidth = null, int?overrideColliderPixelHeight = null, int?overrideColliderOffsetX = null, int?overrideColliderOffsetY = null, Projectile overrideProjectileToCopyFrom = null)
 {
     try
     {
         ETGMod.GetAnySprite(proj).spriteId = ETGMod.Databases.Items.ProjectileCollection.inst.GetSpriteIdByName(name);
         tk2dSpriteDefinition tk2dSpriteDefinition = GunTools.SetupDefinitionForProjectileSprite(name, ETGMod.GetAnySprite(proj).spriteId, pixelWidth, pixelHeight, lightened, overrideColliderPixelWidth, overrideColliderPixelHeight, overrideColliderOffsetX, overrideColliderOffsetY, overrideProjectileToCopyFrom);
         tk2dSpriteDefinition.ConstructOffsetsFromAnchor(anchor, tk2dSpriteDefinition.position3);
     }
     catch (Exception ex)
     {
         ETGModConsole.Log("Ooops! Seems like something got very, Very, VERY wrong. Here's the exception:", false);
         ETGModConsole.Log(ex.ToString(), false);
     }
 }
Ejemplo n.º 2
0
        private static void SetupBeamPart(tk2dSpriteAnimation beamAnimation, List <string> animSpritePaths, string animationName, int fps, Vector2?colliderDimensions = null, Vector2?colliderOffsets = null, Vector3[] overrideVertices = null)
        {
            tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
            {
                name = animationName, frames = new tk2dSpriteAnimationFrame[0], fps = fps
            };
            List <string> spritePaths = animSpritePaths;

            List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();

            foreach (string path in spritePaths)
            {
                tk2dSpriteCollectionData collection = ETGMod.Databases.Items.ProjectileCollection;
                int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleCenter);
                if (overrideVertices != null)
                {
                    frameDef.colliderVertices = overrideVertices;
                }
                else
                {
                    if (colliderDimensions == null || colliderOffsets == null)
                    {
                        ETGModConsole.Log("<size=100><color=#ff0000ff>BEAM ERROR: colliderDimensions or colliderOffsets was null with no override vertices!</color></size>", false);
                    }
                    else
                    {
                        Vector2 actualDimensions = (Vector2)colliderDimensions;
                        Vector2 actualOffsets    = (Vector2)colliderDimensions;
                        frameDef.colliderVertices = new Vector3[] {
                            new Vector3(actualOffsets.x / 16, actualOffsets.y / 16, 0f),
                            new Vector3(actualDimensions.x / 16, actualDimensions.y / 16, 0f)
                        };
                    }
                }
                frames.Add(new tk2dSpriteAnimationFrame {
                    spriteId = frameSpriteId, spriteCollection = collection
                });
            }
            clip.frames         = frames.ToArray();
            beamAnimation.clips = beamAnimation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
        }
Ejemplo n.º 3
0
 public static void SetProjectileSpriteRight(this Projectile proj, string name, int pixelWidth, int pixelHeight, bool lightened = true, tk2dBaseSprite.Anchor anchor = tk2dBaseSprite.Anchor.LowerLeft, bool anchorChangesCollider = true,
                                             bool fixesScale = false, int?overrideColliderPixelWidth = null, int?overrideColliderPixelHeight = null, int?overrideColliderOffsetX = null, int?overrideColliderOffsetY = null, Projectile overrideProjectileToCopyFrom = null)
 {
     try
     {
         proj.GetAnySprite().spriteId = ETGMod.Databases.Items.ProjectileCollection.inst.GetSpriteIdByName(name);
         tk2dSpriteDefinition def     = SetupDefinitionForProjectileSprite(name, proj.GetAnySprite().spriteId, pixelWidth, pixelHeight, lightened, overrideColliderPixelWidth, overrideColliderPixelHeight, overrideColliderOffsetX,
                                                                           overrideColliderOffsetY, overrideProjectileToCopyFrom);
         def.ConstructOffsetsFromAnchor(anchor, def.position3, fixesScale, anchorChangesCollider);
         proj.GetAnySprite().scale = new Vector3(1f, 1f, 1f);
         proj.transform.localScale = new Vector3(1f, 1f, 1f);
         proj.GetAnySprite().transform.localScale = new Vector3(1f, 1f, 1f);
         proj.AdditionalScaleMultiplier = 1f;
     }
     catch (Exception ex)
     {
         ETGModConsole.Log("Ooops! Seems like something got very, Very, VERY wrong. Here's the exception:");
         ETGModConsole.Log(ex.ToString());
     }
 }
Ejemplo n.º 4
0
        public static void AddAnimationToObject(this GameObject target, tk2dSpriteCollectionData spriteCollection, string animationName, List <string> spritePaths, int fps, Vector2 colliderDimensions, Vector2 colliderOffsets, tk2dBaseSprite.Anchor anchor, tk2dSpriteAnimationClip.WrapMode wrapMode, bool isDefaultAnimation = false)
        {
            tk2dSpriteAnimator  animator  = target.GetOrAddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimation animation = target.GetOrAddComponent <tk2dSpriteAnimation>();

            animation.clips  = new tk2dSpriteAnimationClip[0];
            animator.Library = animation;

            tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
            {
                name = animationName, frames = new tk2dSpriteAnimationFrame[0], fps = fps
            };

            List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();

            foreach (string path in spritePaths)
            {
                tk2dSpriteCollectionData collection = spriteCollection;
                int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];

                frameDef.colliderVertices = new Vector3[] {
                    new Vector3(colliderOffsets.x / 16, colliderOffsets.y / 16, 0f),
                    new Vector3((colliderDimensions.x / 16), (colliderDimensions.y / 16), 0f)
                };

                frameDef.ConstructOffsetsFromAnchor(anchor);
                frames.Add(new tk2dSpriteAnimationFrame {
                    spriteId = frameSpriteId, spriteCollection = collection
                });
            }
            clip.frames     = frames.ToArray();
            clip.wrapMode   = wrapMode;
            animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();

            if (isDefaultAnimation)
            {
                animator.DefaultClipId     = animation.GetClipIdByName(animationName);
                animator.playAutomatically = true;
            }
        }
Ejemplo n.º 5
0
        public static void AnimateProjectile(this Projectile proj, List <string> names, int fps, bool loops, List <IntVector2> pixelSizes, List <bool> lighteneds, List <tk2dBaseSprite.Anchor> anchors, List <bool> anchorsChangeColliders,
                                             List <bool> fixesScales, List <Vector3?> manualOffsets, List <IntVector2?> overrideColliderPixelSizes, List <IntVector2?> overrideColliderOffsets, List <Projectile> overrideProjectilesToCopyFrom)
        {
            tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip();

            clip.name = "idle";
            clip.fps  = fps;
            List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();

            for (int i = 0; i < names.Count; i++)
            {
                string     name      = names[i];
                IntVector2 pixelSize = pixelSizes[i];
                IntVector2?overrideColliderPixelSize = overrideColliderPixelSizes[i];
                IntVector2?overrideColliderOffset    = overrideColliderOffsets[i];
                Vector3?   manualOffset          = manualOffsets[i];
                bool       anchorChangesCollider = anchorsChangeColliders[i];
                bool       fixesScale            = fixesScales[i];
                if (!manualOffset.HasValue)
                {
                    manualOffset = new Vector2?(Vector2.zero);
                }
                tk2dBaseSprite.Anchor anchor            = anchors[i];
                bool       lightened                    = lighteneds[i];
                Projectile overrideProjectileToCopyFrom = overrideProjectilesToCopyFrom[i];
                tk2dSpriteAnimationFrame frame          = new tk2dSpriteAnimationFrame();
                frame.spriteId         = ETGMod.Databases.Items.ProjectileCollection.inst.GetSpriteIdByName(name);
                frame.spriteCollection = ETGMod.Databases.Items.ProjectileCollection;
                frames.Add(frame);
                int?overrideColliderPixelWidth  = null;
                int?overrideColliderPixelHeight = null;
                if (overrideColliderPixelSize.HasValue)
                {
                    overrideColliderPixelWidth  = overrideColliderPixelSize.Value.x;
                    overrideColliderPixelHeight = overrideColliderPixelSize.Value.y;
                }
                int?overrideColliderOffsetX = null;
                int?overrideColliderOffsetY = null;
                if (overrideColliderOffset.HasValue)
                {
                    overrideColliderOffsetX = overrideColliderOffset.Value.x;
                    overrideColliderOffsetY = overrideColliderOffset.Value.y;
                }
                tk2dSpriteDefinition def = GunTools.SetupDefinitionForProjectileSprite(name, frame.spriteId, pixelSize.x, pixelSize.y, lightened, overrideColliderPixelWidth, overrideColliderPixelHeight, overrideColliderOffsetX, overrideColliderOffsetY,
                                                                                       overrideProjectileToCopyFrom);
                def.ConstructOffsetsFromAnchor(anchor, def.position3, fixesScale, anchorChangesCollider);
                def.position0 += manualOffset.Value;
                def.position1 += manualOffset.Value;
                def.position2 += manualOffset.Value;
                def.position3 += manualOffset.Value;
                if (i == 0)
                {
                    proj.GetAnySprite().SetSprite(frame.spriteCollection, frame.spriteId);
                }
            }
            clip.wrapMode = loops ? tk2dSpriteAnimationClip.WrapMode.Loop : tk2dSpriteAnimationClip.WrapMode.Once;
            clip.frames   = frames.ToArray();
            if (proj.sprite.spriteAnimator == null)
            {
                proj.sprite.spriteAnimator = proj.sprite.gameObject.AddComponent <tk2dSpriteAnimator>();
            }
            proj.sprite.spriteAnimator.playAutomatically = true;
            bool flag = proj.sprite.spriteAnimator.Library == null;

            if (flag)
            {
                proj.sprite.spriteAnimator.Library         = proj.sprite.spriteAnimator.gameObject.AddComponent <tk2dSpriteAnimation>();
                proj.sprite.spriteAnimator.Library.clips   = new tk2dSpriteAnimationClip[0];
                proj.sprite.spriteAnimator.Library.enabled = true;
            }
            proj.sprite.spriteAnimator.Library.clips      = proj.sprite.spriteAnimator.Library.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
            proj.sprite.spriteAnimator.DefaultClipId      = proj.sprite.spriteAnimator.Library.GetClipIdByName("idle");
            proj.sprite.spriteAnimator.deferNextStartClip = false;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Used to create new VFX. Place sprites inside of Mods/YourModFolder/sprites/VFX Collection, inside the EtG directory. Each parameter that is a list must have an entry for each sprite of the animation
        /// </summary>
        /// <param name="name">The name of the VFX</param>
        /// <param name="spriteNames">The name of the sprites for the VFX, like VFX_001, VFX_002, etc.</param>
        /// <param name="fps">The frame rate the animation will play at</param>
        /// <param name="spriteSizes">The size of each sprite in the animation. Must have an IntVector2 entry for each sprite in the animation</param>
        /// <param name="anchors">I don't know what exactly this does</param>
        /// <param name="manualOffsets">I don't know what exactly this does</param>
        /// <param name="orphaned">I don't know what exactly this does</param>
        /// <param name="attached">I don't know what exactly this does</param>
        /// <param name="persistsOnDeath">Best left false</param>
        /// <param name="usesZHeight">Change if needed</param>
        /// <param name="zHeight">Change if needed, but usually left at 0</param>
        /// <param name="alignment">Leave at Fixed</param>
        /// <param name="destructible">Always set to true</param>
        /// <param name="emissivePowers">Doesn't seem to work, set all entries at 0. Might cause bugs if tinkered with</param>
        /// <param name="emissiveColors">Does't seem to work, set all entries to VFXLibrary.emptyColor. Might cause bugs if tinkered with</param>
        /// <returns></returns>
        public static VFXPool CreateMuzzleflash(string name, List <string> spriteNames, int fps, List <IntVector2> spriteSizes, List <tk2dBaseSprite.Anchor> anchors, List <Vector2> manualOffsets, bool orphaned, bool attached, bool persistsOnDeath,
                                                bool usesZHeight, float zHeight, VFXAlignment alignment, bool destructible, List <float> emissivePowers, List <Color> emissiveColors)
        {
            VFXPool pool = new VFXPool();

            pool.type = VFXPoolType.All;
            VFXComplex complex = new VFXComplex();
            VFXObject  vfObj   = new VFXObject();
            GameObject obj     = new GameObject(name);

            obj.SetActive(false);
            FakePrefab.MarkAsFakePrefab(obj);
            UnityEngine.Object.DontDestroyOnLoad(obj);
            tk2dSprite              sprite   = obj.AddComponent <tk2dSprite>();
            tk2dSpriteAnimator      animator = obj.AddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimationClip clip     = new tk2dSpriteAnimationClip();

            clip.fps    = fps;
            clip.frames = new tk2dSpriteAnimationFrame[0];
            for (int i = 0; i < spriteNames.Count; i++)
            {
                string                spriteName   = spriteNames[i];
                IntVector2            spriteSize   = spriteSizes[i];
                tk2dBaseSprite.Anchor anchor       = anchors[i];
                Vector2               manualOffset = manualOffsets[i];
                float emissivePower            = emissivePowers[i];
                Color emissiveColor            = emissiveColors[i];
                tk2dSpriteAnimationFrame frame = new tk2dSpriteAnimationFrame();
                frame.spriteId = VFXCollection.GetSpriteIdByName(spriteName);
                tk2dSpriteDefinition def = SetupDefinitionForShellSprite(spriteName, frame.spriteId, spriteSize.x, spriteSize.y);
                def.ConstructOffsetsFromAnchor(anchor, def.position3);
                def.MakeOffset(manualOffset);
                def.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                def.material.SetFloat("_EmissiveColorPower", emissivePower);
                def.material.SetColor("_EmissiveColor", emissiveColor);
                def.material.SetTexture("_MainTex", def.material.GetTexture("_MainTex"));
                def.materialInst.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                def.materialInst.SetFloat("_EmissiveColorPower", emissivePower);
                def.materialInst.SetColor("_EmissiveColor", emissiveColor);
                def.materialInst.SetTexture("_MainTex", def.materialInst.GetTexture("_MainTex"));
                frame.spriteCollection = VFXCollection;
                clip.frames            = clip.frames.Concat(new tk2dSpriteAnimationFrame[] { frame }).ToArray();
            }
            sprite.renderer.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
            sprite.renderer.material.SetFloat("_EmissiveColorPower", emissivePowers[0]);
            sprite.renderer.material.SetColor("_EmissiveColor", emissiveColors[0]);
            sprite.renderer.material.SetTexture("_MainTex", sprite.renderer.material.GetTexture("_MainTex"));
            clip.wrapMode = tk2dSpriteAnimationClip.WrapMode.Once;
            clip.name     = "start";
            animator.spriteAnimator.Library         = animator.gameObject.AddComponent <tk2dSpriteAnimation>();
            animator.spriteAnimator.Library.clips   = new tk2dSpriteAnimationClip[] { clip };
            animator.spriteAnimator.Library.enabled = true;
            SpriteAnimatorKiller kill = animator.gameObject.AddComponent <SpriteAnimatorKiller>();

            kill.fadeTime             = -1f;
            kill.animator             = animator;
            kill.delayDestructionTime = -1f;
            vfObj.orphaned            = orphaned;
            vfObj.attached            = attached;
            vfObj.persistsOnDeath     = persistsOnDeath;
            vfObj.usesZHeight         = usesZHeight;
            vfObj.zHeight             = zHeight;
            vfObj.alignment           = alignment;
            vfObj.destructible        = destructible;
            vfObj.effect               = obj;
            complex.effects            = new VFXObject[] { vfObj };
            pool.effects               = new VFXComplex[] { complex };
            animator.playAutomatically = true;
            animator.DefaultClipId     = animator.GetClipIdByName("start");
            return(pool);
        }
Ejemplo n.º 7
0
        public static VFXPool CreateVFXPool(string name, List <string> spritePaths, int fps, IntVector2 Dimensions, tk2dBaseSprite.Anchor anchor, bool usesZHeight, float zHeightOffset, bool persist = false, VFXAlignment alignment = VFXAlignment.NormalAligned, float emissivePower = -1, Color?emissiveColour = null)
        {
            GameObject Obj  = new GameObject(name);
            VFXPool    pool = new VFXPool();

            pool.type = VFXPoolType.All;
            VFXComplex complex = new VFXComplex();
            VFXObject  vfObj   = new VFXObject();

            Obj.SetActive(false);
            FakePrefab.MarkAsFakePrefab(Obj);
            UnityEngine.Object.DontDestroyOnLoad(Obj);

            tk2dSpriteCollectionData VFXSpriteCollection = SpriteBuilder.ConstructCollection(Obj, (name + "_Collection"));
            int spriteID = SpriteBuilder.AddSpriteToCollection(spritePaths[0], VFXSpriteCollection);

            tk2dSprite sprite = Obj.GetOrAddComponent <tk2dSprite>();

            sprite.SetSprite(VFXSpriteCollection, spriteID);
            tk2dSpriteDefinition defaultDef = sprite.GetCurrentSpriteDef();

            defaultDef.colliderVertices = new Vector3[] {
                new Vector3(0f, 0f, 0f),
                new Vector3((Dimensions.x / 16), (Dimensions.y / 16), 0f)
            };

            tk2dSpriteAnimator  animator  = Obj.GetOrAddComponent <tk2dSpriteAnimator>();
            tk2dSpriteAnimation animation = Obj.GetOrAddComponent <tk2dSpriteAnimation>();

            animation.clips  = new tk2dSpriteAnimationClip[0];
            animator.Library = animation;
            tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
            {
                name = "start", frames = new tk2dSpriteAnimationFrame[0], fps = fps
            };
            List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();

            for (int i = 0; i < spritePaths.Count; i++)
            {
                tk2dSpriteCollectionData collection = VFXSpriteCollection;
                int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(spritePaths[i], collection);
                tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                frameDef.ConstructOffsetsFromAnchor(anchor);
                frameDef.colliderVertices = defaultDef.colliderVertices;
                if (emissivePower > 0)
                {
                    frameDef.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                }
                if (emissivePower > 0)
                {
                    frameDef.material.SetFloat("_EmissiveColorPower", emissivePower);
                }
                if (emissiveColour != null)
                {
                    frameDef.material.SetColor("_EmissiveColor", (Color)emissiveColour);
                }
                if (emissivePower > 0)
                {
                    frameDef.materialInst.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
                }
                if (emissivePower > 0)
                {
                    frameDef.materialInst.SetFloat("_EmissiveColorPower", emissivePower);
                }
                if (emissiveColour != null)
                {
                    frameDef.materialInst.SetColor("_EmissiveColor", (Color)emissiveColour);
                }
                frames.Add(new tk2dSpriteAnimationFrame {
                    spriteId = frameSpriteId, spriteCollection = collection
                });
            }
            if (emissivePower > 0)
            {
                sprite.renderer.material.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive");
            }
            if (emissivePower > 0)
            {
                sprite.renderer.material.SetFloat("_EmissiveColorPower", emissivePower);
            }
            if (emissiveColour != null)
            {
                sprite.renderer.material.SetColor("_EmissiveColor", (Color)emissiveColour);
            }
            clip.frames     = frames.ToArray();
            clip.wrapMode   = tk2dSpriteAnimationClip.WrapMode.Once;
            animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
            if (!persist)
            {
                SpriteAnimatorKiller kill = animator.gameObject.AddComponent <SpriteAnimatorKiller>();
                kill.fadeTime             = -1f;
                kill.animator             = animator;
                kill.delayDestructionTime = -1f;
            }
            animator.playAutomatically = true;
            animator.DefaultClipId     = animator.GetClipIdByName("start");
            vfObj.attached             = true;
            vfObj.persistsOnDeath      = persist;
            vfObj.usesZHeight          = usesZHeight;
            vfObj.zHeight      = zHeightOffset;
            vfObj.alignment    = alignment;
            vfObj.destructible = false;
            vfObj.effect       = Obj;
            complex.effects    = new VFXObject[] { vfObj };
            pool.effects       = new VFXComplex[] { complex };
            return(pool);
        }
Ejemplo n.º 8
0
        public static BasicBeamController GenerateBeamPrefab(this Projectile projectile, string spritePath, Vector2 colliderDimensions, Vector2 colliderOffsets, List <string> beamAnimationPaths = null, int beamFPS = -1, List <string> impactVFXAnimationPaths = null, int beamImpactFPS = -1, Vector2?impactVFXColliderDimensions = null, Vector2?impactVFXColliderOffsets = null, List <string> endVFXAnimationPaths = null, int beamEndFPS = -1, Vector2?endVFXColliderDimensions = null, Vector2?endVFXColliderOffsets = null, List <string> muzzleVFXAnimationPaths = null, int beamMuzzleFPS = -1, Vector2?muzzleVFXColliderDimensions = null, Vector2?muzzleVFXColliderOffsets = null)
        {
            try
            {
                float convertedColliderX = colliderDimensions.x / 16f;
                float convertedColliderY = colliderDimensions.y / 16f;
                float convertedOffsetX   = colliderOffsets.x / 16f;
                float convertedOffsetY   = colliderOffsets.y / 16f;

                int             spriteID    = SpriteBuilder.AddSpriteToCollection(spritePath, ETGMod.Databases.Items.ProjectileCollection);
                tk2dTiledSprite tiledSprite = projectile.gameObject.GetOrAddComponent <tk2dTiledSprite>();



                tiledSprite.SetSprite(ETGMod.Databases.Items.ProjectileCollection, spriteID);
                tk2dSpriteDefinition def = tiledSprite.GetCurrentSpriteDef();
                def.colliderVertices = new Vector3[] {
                    new Vector3(convertedOffsetX, convertedOffsetY, 0f),
                    new Vector3(convertedColliderX, convertedColliderY, 0f)
                };

                def.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleLeft);

                //tiledSprite.anchor = tk2dBaseSprite.Anchor.MiddleCenter;
                tk2dSpriteAnimator  animator  = projectile.gameObject.GetOrAddComponent <tk2dSpriteAnimator>();
                tk2dSpriteAnimation animation = projectile.gameObject.GetOrAddComponent <tk2dSpriteAnimation>();
                animation.clips  = new tk2dSpriteAnimationClip[0];
                animator.Library = animation;
                UnityEngine.Object.Destroy(projectile.GetComponentInChildren <tk2dSprite>());
                BasicBeamController beamController = projectile.gameObject.GetOrAddComponent <BasicBeamController>();

                //---------------- Sets up the animation for the main part of the beam
                if (beamAnimationPaths != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "beam_idle", frames = new tk2dSpriteAnimationFrame[0], fps = beamFPS
                    };
                    List <string> spritePaths = beamAnimationPaths;

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in spritePaths)
                    {
                        tk2dSpriteCollectionData collection = ETGMod.Databases.Items.ProjectileCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleLeft);
                        frameDef.colliderVertices = def.colliderVertices;
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                    beamController.beamAnimation = "beam_idle";
                }

                //------------- Sets up the animation for the part of the beam that touches the wall
                if (endVFXAnimationPaths != null && endVFXColliderDimensions != null && endVFXColliderOffsets != null)
                {
                    SetupBeamPart(animation, endVFXAnimationPaths, "beam_end", beamEndFPS, (Vector2)endVFXColliderDimensions, (Vector2)endVFXColliderOffsets);
                    beamController.beamEndAnimation = "beam_end";
                }
                else
                {
                    SetupBeamPart(animation, beamAnimationPaths, "beam_end", beamFPS, null, null, def.colliderVertices);
                    beamController.beamEndAnimation = "beam_end";
                }

                //---------------Sets up the animaton for the VFX that plays over top of the end of the beam where it hits stuff
                if (impactVFXAnimationPaths != null && impactVFXColliderDimensions != null && impactVFXColliderOffsets != null)
                {
                    SetupBeamPart(animation, impactVFXAnimationPaths, "beam_impact", beamImpactFPS, (Vector2)impactVFXColliderDimensions, (Vector2)impactVFXColliderOffsets);
                    beamController.impactAnimation = "beam_impact";
                }

                //--------------Sets up the animation for the very start of the beam
                if (muzzleVFXAnimationPaths != null && muzzleVFXColliderDimensions != null && muzzleVFXColliderOffsets != null)
                {
                    SetupBeamPart(animation, muzzleVFXAnimationPaths, "beam_start", beamMuzzleFPS, (Vector2)muzzleVFXColliderDimensions, (Vector2)muzzleVFXColliderOffsets);
                    beamController.beamStartAnimation = "beam_start";
                }
                else
                {
                    SetupBeamPart(animation, beamAnimationPaths, "beam_start", beamFPS, null, null, def.colliderVertices);
                    beamController.beamStartAnimation = "beam_start";
                }

                return(beamController);
            }
            catch (Exception e)
            {
                ETGModConsole.Log(e.ToString());
                return(null);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Adds a tiled trail to the Projectile
        /// </summary>
        /// <param name="timeTillAnimStart">How long after spawning until the trail will begin to play it's animation, if it has one.</param>
        public static void AddTrailToProjectile(this Projectile target, string spritePath, Vector2 colliderDimensions, Vector2 colliderOffsets, List <string> animPaths = null, int animFPS = -1, List <string> startAnimPaths = null, int startAnimFPS = -1, float timeTillAnimStart = -1, float cascadeTimer = -1, float softMaxLength = -1, bool destroyOnEmpty = false)
        {
            try
            {
                GameObject newTrailObject = new GameObject();
                newTrailObject.InstantiateAndFakeprefab();
                newTrailObject.transform.parent = target.transform;

                float convertedColliderX = colliderDimensions.x / 16f;
                float convertedColliderY = colliderDimensions.y / 16f;
                float convertedOffsetX   = colliderOffsets.x / 16f;
                float convertedOffsetY   = colliderOffsets.y / 16f;

                int             spriteID    = SpriteBuilder.AddSpriteToCollection(spritePath, ETGMod.Databases.Items.ProjectileCollection);
                tk2dTiledSprite tiledSprite = newTrailObject.GetOrAddComponent <tk2dTiledSprite>();

                tiledSprite.SetSprite(ETGMod.Databases.Items.ProjectileCollection, spriteID);
                tk2dSpriteDefinition def = tiledSprite.GetCurrentSpriteDef();
                def.colliderVertices = new Vector3[] {
                    new Vector3(convertedOffsetX, convertedOffsetY, 0f),
                    new Vector3(convertedColliderX, convertedColliderY, 0f)
                };

                def.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.MiddleLeft);

                tk2dSpriteAnimator  animator  = newTrailObject.GetOrAddComponent <tk2dSpriteAnimator>();
                tk2dSpriteAnimation animation = newTrailObject.GetOrAddComponent <tk2dSpriteAnimation>();
                animation.clips  = new tk2dSpriteAnimationClip[0];
                animator.Library = animation;

                TrailController trail = newTrailObject.AddComponent <TrailController>();

                //---------------- Sets up the animation for the main part of the trail
                if (animPaths != null)
                {
                    BeamToolbox.SetupBeamPart(animation, animPaths, "trail_mid", animFPS, null, null, def.colliderVertices);
                    trail.animation     = "trail_mid";
                    trail.usesAnimation = true;
                }
                else
                {
                    trail.usesAnimation = false;
                }

                if (startAnimPaths != null)
                {
                    BeamToolbox.SetupBeamPart(animation, startAnimPaths, "trail_start", startAnimFPS, null, null, def.colliderVertices);
                    trail.startAnimation     = "trail_start";
                    trail.usesStartAnimation = true;
                }
                else
                {
                    trail.usesStartAnimation = false;
                }

                //Trail Variables
                if (softMaxLength > 0)
                {
                    trail.usesSoftMaxLength = true; trail.softMaxLength = softMaxLength;
                }
                if (cascadeTimer > 0)
                {
                    trail.usesCascadeTimer = true; trail.cascadeTimer = cascadeTimer;
                }
                if (timeTillAnimStart > 0)
                {
                    trail.usesGlobalTimer = true; trail.globalTimer = timeTillAnimStart;
                }
                trail.destroyOnEmpty = destroyOnEmpty;
            }
            catch (Exception e)
            {
                ETGModConsole.Log(e.ToString());
            }
        }
        public static void SetupHatSprites(List <string> spritePaths, GameObject hatObj, int fps, Vector2 hatSize)
        {
            Hat hatness = hatObj.GetComponent <Hat>();

            if (hatness)
            {
                string collectionName = hatness.hatName;
                collectionName = collectionName.Replace(" ", "_");
                tk2dSpriteCollectionData HatSpriteCollection = SpriteBuilder.ConstructCollection(hatObj, (collectionName + "_Collection"));

                int        spriteID      = SpriteBuilder.AddSpriteToCollection(spritePaths[0], HatSpriteCollection);
                tk2dSprite hatBaseSprite = hatObj.GetOrAddComponent <tk2dSprite>();
                hatBaseSprite.SetSprite(HatSpriteCollection, spriteID);
                tk2dSpriteDefinition def = hatBaseSprite.GetCurrentSpriteDef();
                def.colliderVertices = new Vector3[] {
                    new Vector3(0f, 0f, 0f),
                    new Vector3((hatSize.x / 16), (hatSize.y / 16), 0f)
                };
                hatBaseSprite.PlaceAtPositionByAnchor(hatObj.transform.position, tk2dBaseSprite.Anchor.LowerCenter);
                hatBaseSprite.depthUsesTrimmedBounds = true;
                hatBaseSprite.IsPerpendicular        = true;
                hatBaseSprite.UpdateZDepth();
                hatBaseSprite.HeightOffGround = 0.2f;

                List <string> SouthAnimation     = new List <string>();
                List <string> NorthAnimation     = new List <string>();
                List <string> EastAnimation      = new List <string>();
                List <string> WestAnimation      = new List <string>();
                List <string> NorthWestAnimation = new List <string>();
                List <string> NorthEastAnimation = new List <string>();
                List <string> SouthEastAnimation = new List <string>();
                List <string> SouthWestAnimation = new List <string>();

                switch (hatness.hatDirectionality)
                {
                case Hat.HatDirectionality.EIGHTWAY:
                    foreach (string path in spritePaths)
                    {
                        if (path.ToLower().Contains("_north_"))
                        {
                            NorthAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_south_"))
                        {
                            SouthAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_west_"))
                        {
                            WestAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_east_"))
                        {
                            EastAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_northwest_"))
                        {
                            NorthWestAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_northeast_"))
                        {
                            NorthEastAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_southwest_"))
                        {
                            SouthWestAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_southeast_"))
                        {
                            SouthEastAnimation.Add(path);
                        }
                    }
                    break;

                case Hat.HatDirectionality.SIXWAY:
                    foreach (string path in spritePaths)
                    {
                        if (path.ToLower().Contains("_north_"))
                        {
                            NorthAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_south_"))
                        {
                            SouthAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_west_"))
                        {
                            WestAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_east_"))
                        {
                            EastAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_northwest_"))
                        {
                            NorthWestAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_northeast_"))
                        {
                            NorthEastAnimation.Add(path);
                        }
                    }
                    break;

                case Hat.HatDirectionality.FOURWAY:
                    foreach (string path in spritePaths)
                    {
                        if (path.ToLower().Contains("_west_"))
                        {
                            WestAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_east_"))
                        {
                            EastAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_north_"))
                        {
                            NorthAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_south_"))
                        {
                            SouthAnimation.Add(path);
                        }
                    }
                    break;

                case Hat.HatDirectionality.TWOWAYHORIZONTAL:
                    foreach (string path in spritePaths)
                    {
                        if (path.ToLower().Contains("_west_"))
                        {
                            WestAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_east_"))
                        {
                            EastAnimation.Add(path);
                        }
                    }
                    break;

                case Hat.HatDirectionality.TWOWAYVERTICAL:
                    foreach (string path in spritePaths)
                    {
                        if (path.ToLower().Contains("_north_"))
                        {
                            NorthAnimation.Add(path);
                        }
                        if (path.ToLower().Contains("_south_"))
                        {
                            SouthAnimation.Add(path);
                        }
                    }
                    break;

                case Hat.HatDirectionality.NONE:
                    foreach (string path in spritePaths)
                    {
                        if (path.ToLower().Contains("_south_"))
                        {
                            SouthAnimation.Add(path);
                        }
                    }
                    break;
                }

                //SET UP THE ANIMATOR AND THE ANIMATION
                tk2dSpriteAnimator  animator  = hatObj.GetOrAddComponent <tk2dSpriteAnimator>();
                tk2dSpriteAnimation animation = hatObj.GetOrAddComponent <tk2dSpriteAnimation>();
                animation.clips  = new tk2dSpriteAnimationClip[0];
                animator.Library = animation;

                //SOUTH ANIMATION
                if (SouthAnimation != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "hat_south", frames = new tk2dSpriteAnimationFrame[0], fps = fps
                    };

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in SouthAnimation)
                    {
                        tk2dSpriteCollectionData collection = HatSpriteCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.colliderVertices = def.colliderVertices;
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.LowerCenter);
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                }
                //NORTH ANIMATIONS
                if (NorthAnimation != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "hat_north", frames = new tk2dSpriteAnimationFrame[0], fps = fps
                    };

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in NorthAnimation)
                    {
                        tk2dSpriteCollectionData collection = HatSpriteCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.colliderVertices = def.colliderVertices;
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.LowerCenter);
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                }
                //WEST ANIMATIONS
                if (WestAnimation != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "hat_west", frames = new tk2dSpriteAnimationFrame[0], fps = fps
                    };

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in WestAnimation)
                    {
                        tk2dSpriteCollectionData collection = HatSpriteCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.colliderVertices = def.colliderVertices;
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.LowerCenter);
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                }
                //EAST ANIMATIONS
                if (EastAnimation != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "hat_east", frames = new tk2dSpriteAnimationFrame[0], fps = fps
                    };

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in EastAnimation)
                    {
                        tk2dSpriteCollectionData collection = HatSpriteCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.colliderVertices = def.colliderVertices;
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.LowerCenter);
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                }
                //NORTHEAST
                if (NorthEastAnimation != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "hat_northeast", frames = new tk2dSpriteAnimationFrame[0], fps = fps
                    };

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in NorthEastAnimation)
                    {
                        tk2dSpriteCollectionData collection = HatSpriteCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.colliderVertices = def.colliderVertices;
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.LowerCenter);
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                }
                //NORTHWEST ANIMATION
                if (NorthWestAnimation != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "hat_northwest", frames = new tk2dSpriteAnimationFrame[0], fps = fps
                    };

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in NorthWestAnimation)
                    {
                        tk2dSpriteCollectionData collection = HatSpriteCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.colliderVertices = def.colliderVertices;
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.LowerCenter);
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                }
                //SOUTHWEST ANIMATION
                if (SouthWestAnimation != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "hat_southwest", frames = new tk2dSpriteAnimationFrame[0], fps = fps
                    };

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in SouthWestAnimation)
                    {
                        tk2dSpriteCollectionData collection = HatSpriteCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.colliderVertices = def.colliderVertices;
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.LowerCenter);
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                }
                //SOUTHEAST ANIMATION
                if (SouthEastAnimation != null)
                {
                    tk2dSpriteAnimationClip clip = new tk2dSpriteAnimationClip()
                    {
                        name = "hat_southeast", frames = new tk2dSpriteAnimationFrame[0], fps = fps
                    };

                    List <tk2dSpriteAnimationFrame> frames = new List <tk2dSpriteAnimationFrame>();
                    foreach (string path in SouthEastAnimation)
                    {
                        tk2dSpriteCollectionData collection = HatSpriteCollection;
                        int frameSpriteId             = SpriteBuilder.AddSpriteToCollection(path, collection);
                        tk2dSpriteDefinition frameDef = collection.spriteDefinitions[frameSpriteId];
                        frameDef.colliderVertices = def.colliderVertices;
                        frameDef.ConstructOffsetsFromAnchor(tk2dBaseSprite.Anchor.LowerCenter);
                        frames.Add(new tk2dSpriteAnimationFrame {
                            spriteId = frameSpriteId, spriteCollection = collection
                        });
                    }
                    clip.frames     = frames.ToArray();
                    animation.clips = animation.clips.Concat(new tk2dSpriteAnimationClip[] { clip }).ToArray();
                }
            }
        }