static void DoCreateSlicedSpriteObject() { tk2dSpriteGuiUtility.GetSpriteCollectionAndCreate((sprColl) => { GameObject go = tk2dEditorUtility.CreateGameObjectInScene("Tiled Sprite"); tk2dTiledSprite sprite = go.AddComponent <tk2dTiledSprite>(); sprite.SetSprite(sprColl, sprColl.FirstValidDefinitionIndex); sprite.Build(); Selection.activeGameObject = go; Undo.RegisterCreatedObjectUndo(go, "Create Tiled Sprite"); }); }
static void DoCreateSlicedSpriteObject() { tk2dSpriteCollectionData sprColl = null; if (sprColl == null) { // try to inherit from other Sprites in scene tk2dSprite spr = GameObject.FindObjectOfType(typeof(tk2dSprite)) as tk2dSprite; if (spr) { sprColl = spr.Collection; } } if (sprColl == null) { tk2dSpriteCollectionIndex[] spriteCollections = tk2dEditorUtility.GetOrCreateIndex().GetSpriteCollectionIndex(); foreach (var v in spriteCollections) { GameObject scgo = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(v.spriteCollectionDataGUID), typeof(GameObject)) as GameObject; var sc = scgo.GetComponent <tk2dSpriteCollectionData>(); if (sc != null && sc.spriteDefinitions != null && sc.spriteDefinitions.Length > 0) { sprColl = sc; break; } } if (sprColl == null) { EditorUtility.DisplayDialog("Create Tiled Sprite", "Unable to create tiled sprite as no SpriteCollections have been found.", "Ok"); return; } } GameObject go = tk2dEditorUtility.CreateGameObjectInScene("Tiled Sprite"); tk2dTiledSprite sprite = go.AddComponent <tk2dTiledSprite>(); sprite.SetSprite(sprColl, sprColl.FirstValidDefinitionIndex); sprite.Build(); Selection.activeGameObject = go; Undo.RegisterCreatedObjectUndo(go, "Create Tiled Sprite"); }
/// <summary> /// 设置血量类型 /// </summary> /// <param name="type"></param> internal void SetLifeType(Global.LIFE_TYPE type) { hpBar.SetSprite(type.ToString().ToLower()); switch (type) { case Global.LIFE_TYPE.LV1: hp = hpMax = 10; break; case Global.LIFE_TYPE.LV2: hp = hpMax = 13; break; case Global.LIFE_TYPE.LV3: hp = hpMax = 16; break; case Global.LIFE_TYPE.LV4: hp = hpMax = 20; break; } }
public void BuildPatch() { if (m_stripPrefab == null) { m_stripPrefab = (GameObject)BraveResources.Load("Global Prefabs/TallGrassStrip", ".prefab"); } HashSet <IntVector2> hashSet = new HashSet <IntVector2>(); for (int j = 0; j < cells.Count; j++) { IntVector2 intVector = cells[j]; if (!hashSet.Contains(intVector)) { hashSet.Add(intVector); int num = 1; var targetIndexForPosition = GetTargetIndexForPosition(intVector); IntVector2 intVector2 = intVector; while (true) { intVector2 += IntVector2.Right; if (hashSet.Contains(intVector2)) { break; } if (!cells.Contains(intVector2)) { break; } if (targetIndexForPosition != GetTargetIndexForPosition(intVector2)) { break; } num++; hashSet.Add(intVector2); } GameObject grassObject = SpawnManager.SpawnVFX(m_stripPrefab, false); tk2dTiledSprite tiledSprite = grassObject.GetComponent <tk2dTiledSprite>(); tiledSprite.SetSprite(GameManager.Instance.Dungeon.tileIndices.dungeonCollection, (int)targetIndexForPosition); tiledSprite.dimensions = new Vector2((16 * num), 16f); grassObject.transform.position = new Vector3(intVector.x, intVector.y, intVector.y); m_tiledSpritePool.Add(intVector, tiledSprite); switch (targetIndexForPosition) { case IndexPosition.BOTTOM: tiledSprite.HeightOffGround = -2f; tiledSprite.IsPerpendicular = true; tiledSprite.transform.position += new Vector3(0f, 0.6875f, 0f); break; case IndexPosition.TOP: tiledSprite.IsPerpendicular = true; break; default: tiledSprite.IsPerpendicular = false; break; } tiledSprite.UpdateZDepth(); } } if (!ExpandStaticReferenceManager.AllGrasses.Contains(this)) { ExpandStaticReferenceManager.AllGrasses.Add(this); } InitializeParticleSystem(); }
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); } }
/// <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()); } }