// Use this for initialization void Start() { if (viewCamera == null) { // Find a camera parent Transform node = transform; while (node && node.camera == null) { node = node.parent; } if (node && node.camera != null) { viewCamera = node.camera; } // See if a tk2dCamera exists if (viewCamera == null && tk2dCamera.inst) { viewCamera = tk2dCamera.inst.mainCamera; } // ...otherwise, use the main camera if (viewCamera == null) { viewCamera = Camera.main; } } sprite = GetComponent <tk2dBaseSprite>(); // Further tests for sprite not being null aren't necessary, as the IDs will default to -1 in that case. Testing them will be sufficient if (sprite) { // Change this to use animated sprites if necessary // Same concept here, lookup Ids and call Play(xxx) instead of .spriteId = xxx if (buttonDownSprite.Length > 0) { buttonDownSpriteId = sprite.GetSpriteIdByName(buttonDownSprite); } if (buttonUpSprite.Length > 0) { buttonUpSpriteId = sprite.GetSpriteIdByName(buttonUpSprite); } if (buttonPressedSprite.Length > 0) { buttonPressedSpriteId = sprite.GetSpriteIdByName(buttonPressedSprite); } } if (collider == null) { BoxCollider newCollider = gameObject.AddComponent <BoxCollider>(); Vector3 colliderExtents = newCollider.extents; colliderExtents.z = 0.2f; newCollider.extents = colliderExtents; } }
void DoSetSpriteID() { if (_sprite == null) { LogWarning("Missing tk2dBaseSprite component: " + _sprite.gameObject.name); return; } int id = spriteID.Value; if (ORSpriteName.Value != "") { id = _sprite.GetSpriteIdByName(ORSpriteName.Value); } if (id != _sprite.spriteId) { _sprite.spriteId = id; } }
/// <summary> /// Call this when the sprite names have changed /// </summary> public void UpdateSpriteIds() { buttonDownSpriteId = (buttonDownSprite.Length > 0)?sprite.GetSpriteIdByName(buttonDownSprite):-1; buttonUpSpriteId = (buttonUpSprite.Length > 0)?sprite.GetSpriteIdByName(buttonUpSprite):-1; buttonPressedSpriteId = (buttonPressedSprite.Length > 0)?sprite.GetSpriteIdByName(buttonPressedSprite):-1; }
// Use this for initialization void Start() { if (viewCamera == null) { // Find a camera parent Transform node = transform; while (node && node.camera == null) { node = node.parent; } if (node && node.camera != null) { viewCamera = node.camera; } // See if a tk2dCamera exists if (viewCamera == null && tk2dCamera.inst) { viewCamera = tk2dCamera.inst.mainCamera; } // ...otherwise, use the main camera if (viewCamera == null) { viewCamera = Camera.main; } } sprite = GetComponent<tk2dBaseSprite>(); // Further tests for sprite not being null aren't necessary, as the IDs will default to -1 in that case. Testing them will be sufficient if (sprite) { // Change this to use animated sprites if necessary // Same concept here, lookup Ids and call Play(xxx) instead of .spriteId = xxx if (buttonDownSprite.Length > 0) buttonDownSpriteId = sprite.GetSpriteIdByName(buttonDownSprite); if (buttonUpSprite.Length > 0) buttonUpSpriteId = sprite.GetSpriteIdByName(buttonUpSprite); if (buttonPressedSprite.Length > 0) buttonPressedSpriteId = sprite.GetSpriteIdByName(buttonPressedSprite); } if (collider == null) { BoxCollider newCollider = gameObject.AddComponent<BoxCollider>(); Vector3 colliderExtents = newCollider.extents; colliderExtents.z = 0.2f; newCollider.extents = colliderExtents; } }
public static void Build() { GameObject reaper = UnityEngine.Object.Instantiate(PrefabDatabase.Instance.SuperReaper); reaper.SetActive(false); FakePrefab.MarkAsFakePrefab(reaper); UnityEngine.Object.DontDestroyOnLoad(reaper); SuperReaperController controller = reaper.GetComponent <SuperReaperController>(); CustomSuperReaperController customController = reaper.AddComponent <CustomSuperReaperController>(); customController.PreventShooting = false; customController.BulletScript = controller.BulletScript; customController.ShootPoint = controller.ShootPoint; customController.ShootTimer = controller.ShootTimer; customController.MinSpeed = controller.MinSpeed; customController.MaxSpeed = controller.MaxSpeed; customController.MinSpeedDistance = controller.MinSpeedDistance; customController.MaxSpeedDistance = controller.MaxSpeedDistance; customController.knockbackComponent = controller.knockbackComponent; Destroy(controller); List <AIBulletBank.Entry> entries = new List <AIBulletBank.Entry>(); foreach (AIBulletBank.Entry bullet in customController.bulletBank.Bullets) { AIBulletBank.Entry entry = bullet.Clone(true, true, false, false); entries.Add(entry); } customController.bulletBank.Bullets.Clear(); foreach (AIBulletBank.Entry bullet in entries) { customController.bulletBank.Bullets.Add(bullet); } customController.bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().BulletScriptSettings.preventPooling = true; customController.bulletBank.Bullets[0].ProjectileData.damage = 10f; customController.bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().GetAnySprite().SetSprite(ETGMod.Databases.Items.ProjectileCollection, ETGMod.Databases.Items.ProjectileCollection.GetSpriteIdByName("10x10_player_projectile_dark_002")); ETGMod.Databases.Items.ProjectileCollection.spriteDefinitions[customController.bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().GetAnySprite().spriteId] = PrefabDatabase.Instance.SuperReaper.GetComponent <SuperReaperController>().bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().GetAnySprite().GetCurrentSpriteDef().CopyDefinitionFrom(); Material material = Toolbox.GetGunById(38).DefaultModule.projectiles[0].GetAnySprite().GetCurrentSpriteDef().material; ETGMod.Databases.Items.ProjectileCollection.spriteDefinitions[customController.bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().GetAnySprite().spriteId].material = material; ETGMod.Databases.Items.ProjectileCollection.spriteDefinitions[customController.bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().GetAnySprite().spriteId].materialInst = material; ETGMod.Databases.Items.ProjectileCollection.spriteDefinitions[customController.bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().GetAnySprite().spriteId].name = "10x10_player_projectile_dark_002"; tk2dBaseSprite sprite = PrefabDatabase.Instance.SuperReaper.GetComponent <SuperReaperController>().bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().GetAnySprite(); PixelCollider pcollider = PrefabDatabase.Instance.SuperReaper.GetComponent <SuperReaperController>().bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().specRigidbody.PrimaryPixelCollider; tk2dSpriteDefinition tk2dSpriteDefinition; if (pcollider.BagleUseFirstFrameOnly && !string.IsNullOrEmpty(pcollider.SpecifyBagelFrame)) { tk2dSpriteDefinition = sprite.Collection.GetSpriteDefinition(pcollider.SpecifyBagelFrame); } else { tk2dSpriteDefinition = sprite.GetTrueCurrentSpriteDef(); } int num = (tk2dSpriteDefinition != null) ? sprite.GetSpriteIdByName(tk2dSpriteDefinition.name) : -1; BagelColliderData data = Toolbox.GetBagelColliders(num, sprite.Collection); ETGMod.Databases.Items.ProjectileCollection.SpriteIDsWithBagelColliders.Add(customController.bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().GetAnySprite().spriteId); ETGMod.Databases.Items.ProjectileCollection.SpriteDefinedBagelColliders.Add(data); customController.bulletBank.Bullets[0].BulletObject.GetComponent <Projectile>().specRigidbody.PrimaryPixelCollider.SpecifyBagelFrame = ""; CustomSuperReaperController.friendlyReaperPrefab = reaper; }