public static GameObject CreateCustomShellCasing(string spriteName, int pixelWidth, int pixelHeight) { GameObject casing = UnityEngine.Object.Instantiate((PickupObjectDatabase.GetById(202) as Gun).shellCasing); casing.gameObject.SetActive(false); FakePrefab.MarkAsFakePrefab(casing.gameObject); UnityEngine.Object.DontDestroyOnLoad(casing); casing.GetComponent <tk2dBaseSprite>().spriteId = VFXCollection.inst.GetSpriteIdByName(spriteName); VFXToolbox.SetupDefinitionForShellSprite(spriteName, casing.GetComponent <tk2dBaseSprite>().spriteId, pixelWidth, pixelHeight); return(casing); }
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 = VFXToolbox.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.materialInst.shader = ShaderCache.Acquire("Brave/LitTk2dCustomFalloffTintableTiltedCutoutEmissive"); def.materialInst.SetFloat("_EmissiveColorPower", emissivePower); def.materialInst.SetColor("_EmissiveColor", emissiveColor); 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]); 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); }