private bool activateJetsIfRequested() { bool activated = false; HullPrefabInfo hullPrefabInfo = PartPrefabManager.Instance.GetHullPrefabInfoViaName(Schematic.Name); Vector2[] curDirs = new Vector2[] { owner.GetForwardVec(), owner.GetBackwardVec(), owner.GetForwardVec().Rotate(90f), owner.GetForwardVec().Rotate(-90f) }; string[] curDirJetOffsetNames = new string[] { "bot", "top", "right", "left" }; foreach (Vector2 jetDir in jetUsageDirs) { if (EnergyAvailableForUsage(Schematic.JetEnergyUsage)) { float minAngle = 9999f; Vector2 minDir = new Vector2(); string dirJetOffsetName = ""; for (int i = 0; i < curDirs.Length; ++i) { Vector2 curDir = curDirs[i]; float angle = Vector2.Angle(curDir, jetDir); if (minAngle > angle) { minDir = curDir; minAngle = angle; dirJetOffsetName = curDirJetOffsetNames[i]; } } owner.Body.AddForce(minDir.normalized * Schematic.JetImpulse, ForceMode2D.Impulse); Vector2 jetOffset = hullPrefabInfo.JetOffsets[dirJetOffsetName]; float jetAngle = Vector2.SignedAngle(owner.GetForwardVec(), minDir); CombatAnimationHandler.Instance.InstantiatePrefab("jet_cloud", jetOffset, jetAngle, owner.JetRoot, true); ModEnergy(-Schematic.JetEnergyUsage); activated = true; } } jetUsageDirs.Clear(); return(activated); }
public void Init(TankSchematic tankSchematic) { HullPrefabInfo hullPrefabInfo = PartPrefabManager.Instance.GetHullPrefabInfoViaName(tankSchematic.HullSchematic.Name); LeftWheelGO = Instantiate(hullPrefabInfo.WheelPrefab, this.transform, false); RightWheelGO = Instantiate(hullPrefabInfo.WheelPrefab, this.transform, false); LeftWheelGO.transform.localPosition = new Vector3(-hullPrefabInfo.WheelXOffset, 0); RightWheelGO.transform.localPosition = new Vector3(hullPrefabInfo.WheelXOffset, 0); HullGO = Instantiate(hullPrefabInfo.HullPrefab, this.transform, false); Transform weaponRoot = HullGO.transform.Find("Turret"); JetRoot = HullGO.transform.Find("Jets"); weaponGOs = new List <GameObject>(); int count = 0; foreach (WeaponPartSchematic weaponSchematic in tankSchematic.WeaponSchematics) { if (weaponSchematic != null) { // First initialize GO GameObject instance = Instantiate(PartPrefabManager.Instance.GetPrefabViaName(weaponSchematic.Name), weaponRoot, false); RectTransform rect = instance.GetComponent <RectTransform>(); rect.pivot = new Vector2(0.5f, 0); rect.transform.localPosition = tankSchematic.HullSchematic.OrigWeaponPos[count]; Vector2 dir = tankSchematic.HullSchematic.OrigWeaponDirs[count]; float angle = Vector2.Angle(new Vector2(0, 1), dir); rect.transform.Rotate(new Vector3(0, 0, angle)); weaponGOs.Add(instance); } count += 1; } initialized = true; }