void OnGUI() { if (!destroyed) { PowerSystem ps = powerSys[seats[curSeat].powerSet]; GUI.color = Color.white; GUI.DrawTexture(new Rect((Screen.width * 0.1f), Screen.height / 2 - 256, 32, 512), barBG); GUI.DrawTexture(new Rect((Screen.width * 0.1f), Screen.height / 2 - 256 + 512, 32, 32), hullNote); if ((health * 1.0f) / maxHealth <= 0.5f) { GUI.DrawTexture(new Rect((Screen.width * 0.1f), Screen.height / 2 - 256 - 32, 32, 32), warningNote); } GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32, Screen.height / 2 - 256, 32, 512), barBG); GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32, Screen.height / 2 - 256 + 512, 32, 32), powerNote); if ((ps.energyStored * 1.0f) / ps.energyMax <= 0.5f) { GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32, Screen.height / 2 - 256 - 32, 32, 32), warningNote); } GUI.color = shipColorMain; int hbarH = (int)(510.0f * ((health * 1.0f) / maxHealth)); GUI.DrawTexture(new Rect((Screen.width * 0.1f) + 1, Screen.height / 2 - 256 + (510 - hbarH) + 1, 30, hbarH), barFG); GUI.color = Color.white; GUI.Label(new Rect((Screen.width * 0.1f) - 100, Screen.height / 2 - 10, 100, 20), ((int)health) + "/" + ((int)maxHealth), mainStyle); GUI.color = shipColorPower; int pbarH = (int)(510.0f * ((((int)ps.energyStored) * 1.0f) / ps.energyMax)); GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32 + 1, Screen.height / 2 - 256 + (510 - pbarH) + 1, 30, pbarH), barFG); GUI.color = Color.white; GUI.Label(new Rect((Screen.width * 0.9f), Screen.height / 2 - 10, 100, 20), ((int)ps.energyStored) + "/" + ((int)ps.energyMax), mainStyle); GUI.color = Color.white; GUI.DrawTexture(new Rect((Screen.width * 0.1f), Screen.height / 2 - 256, 32, 512), barOverlay); GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32, Screen.height / 2 - 256, 32, 512), barOverlay); WeaponPair thisWep = wp[seats[curSeat].weaponSet]; GUI.DrawTexture(new Rect((Screen.width * 0.1f) + 32, Screen.height / 2 - 64, 16, 128), wepBarBG); if ((thisWep.ammo1 * 1.0f) / thisWep.ammoMax1 <= 0.5f) { GUI.DrawTexture(new Rect((Screen.width * 0.1f) + 32, Screen.height / 2 - 64 - 16, 16, 16), wepBarWarning); } if (thisWep.reloading1) { GUI.DrawTexture(new Rect((Screen.width * 0.1f) + 32, Screen.height / 2 + 64, 16, 16), wepBarReload); } GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32 - 16, Screen.height / 2 - 64, 16, 128), wepBarBG); if ((thisWep.ammo2 * 1.0f) / thisWep.ammoMax2 <= 0.5f) { GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32 - 16, Screen.height / 2 - 64 - 16, 16, 16), wepBarWarning); } if (thisWep.reloading2) { GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32 - 16, Screen.height / 2 + 64, 16, 16), wepBarReload); } if (!thisWep.secondaryActive) { GUI.color = shipColorSpecial; } else { GUI.color = shipColorThrust; } int abar1H = (int)(126.0f * ((thisWep.ammo1 * 1.0f) / thisWep.ammoMax1)); if (thisWep.reloading1) { abar1H = (int)(126.0f * (thisWep.reload1 / thisWep.reloadSpeed1)); } float cm1 = 1; string t1 = "∞"; if (thisWep.ammoMax1 != 0) { cm1 = ((thisWep.ammo1 + (thisWep.ammoMax1 / 2)) / thisWep.ammoMax1); t1 = thisWep.ammo1 + "/" + thisWep.ammoMax1; } else { abar1H = 126; } GUI.DrawTexture(new Rect((Screen.width * 0.1f) + 32 + 1, Screen.height / 2 - 64 + 1 + (126 - abar1H), 14, abar1H), wepBarFG); GUI.color = Color.white; GUI.Label(new Rect((Screen.width * 0.1f) + 32 + 16, Screen.height / 2 - 5, 50, 10), t1, ammoStyle); if (thisWep.secondaryActive) { GUI.color = shipColorSpecial; } else { GUI.color = shipColorThrust; } int abar2H = (int)(126.0f * ((thisWep.ammo2 * 1.0f) / thisWep.ammoMax2)); if (thisWep.reloading2) { abar2H = (int)(126.0f * (thisWep.reload2 / thisWep.reloadSpeed2)); } float cm2 = 1; string t2 = "∞"; if (thisWep.ammoMax2 != 0) { cm2 = ((thisWep.ammo2 + (thisWep.ammoMax2 / 2)) / thisWep.ammoMax2); t2 = thisWep.ammo2 + "/" + thisWep.ammoMax2; } else { abar2H = 126; } GUI.DrawTexture(new Rect((Screen.width * 0.9f) - 32 - 16 + 1, Screen.height / 2 - 64 + 1 + (126 - abar2H), 14, abar2H), wepBarFG); GUI.color = Color.white; GUI.Label(new Rect((Screen.width * 0.9f) - 32 - 16 - 50, Screen.height / 2 - 5, 50, 10), t2, ammoStyle); crewmembers.Sort(); List <Crew> crewList = crewmembers; int width = crewList.Count * crewTex.width; for (int i = 0; i < crewList.Count; i++) { if (crewList[i].injured) { GUI.color = Color.white; GUI.DrawTexture(new Rect((Screen.width / 2) - (width / 2) + (crewTex.width * i), Screen.height * 0.1f, crewTex.width, crewTex.height), crewTexEmpty); } else { if (repairing) { GUI.color = shipColorPower; } else { GUI.color = shipColorMain; } GUI.DrawTexture(new Rect((Screen.width / 2) - (width / 2) + (crewTex.width * i), Screen.height * 0.1f, crewTex.width, crewTex.height), crewTex); } } int[] ms = seats[curSeat].moduleSlots; foreach (int i in ms) { GUI.color = Color.white; GUI.DrawTexture(new Rect((Screen.width / 2) - (abilityIcons[(int)slots[i].mtype].width * 2) + (abilityIcons[(int)slots[i].mtype].width * i), Screen.height * 0.9f, abilityIcons[(int)slots[i].mtype].width, abilityIcons[(int)slots[i].mtype].height), abilityIcons[(int)slots[i].mtype]); if (slots[i].cooldown > 0) { GUI.color = shipColorPower; int h1 = (int)(abilityIconOverlay.height * 1.0f * (1 - (slots[i].cooldown / (slots[i].modules[0].cooldown * slots[i].modCooldown)))); GUI.DrawTexture(new Rect((Screen.width / 2) - (abilityIcons[(int)slots[i].mtype].width * 2) + (abilityIcons[(int)slots[i].mtype].width * i) + 1, Screen.height * 0.9f + 1 + (abilityIconOverlay.height - h1), abilityIconOverlay.width, h1), abilityIconOverlay); } if (slots[i].runtime > 0) { GUI.color = shipColorSpecial; int h2 = (int)(abilityIconOverlay.height * 1.0f * (1 - (slots[i].runtime / (slots[i].modules[0].time * slots[i].modTime)))); GUI.DrawTexture(new Rect((Screen.width / 2) - (abilityIcons[(int)slots[i].mtype].width * 2) + (abilityIcons[(int)slots[i].mtype].width * i) + 1, Screen.height * 0.9f + 1 + h2, abilityIconOverlay.width, (abilityIconOverlay.height - h2)), abilityIconOverlay); } } if (Cursor.visible) { if (GUI.Button(new Rect(Screen.width / 2 - 256, 15, 512, 30), "SELF DESTRUCT")) { health = -maxHealth; } } } }
void Update() { if (!destroyed) { timeSinceDamage += Time.deltaTime; if (health < maxHealth && timeSinceDamage >= repairDelay) { repairing = true; } if (Input.GetButtonUp("WeaponSwap")) { wp[seats[curSeat].weaponSet].secondaryActive = !wp[seats[curSeat].weaponSet].secondaryActive; } if (Input.GetButtonUp("Module1")) { ModuleSlot mod = slots[seats[curSeat].moduleSlots[0]]; if (mod.cooldown <= 0) { mod.cooldown = mod.modules[0].cooldown * mod.modCooldown; mod.runtime = mod.modules[0].time * mod.modTime; } } if (Input.GetButtonUp("Module2")) { ModuleSlot mod = slots[seats[curSeat].moduleSlots[1]]; if (mod.cooldown <= 0) { mod.cooldown = mod.modules[0].cooldown * mod.modCooldown; mod.runtime = mod.modules[0].time * mod.modTime; } } if (Input.GetButtonUp("Module3")) { ModuleSlot mod = slots[seats[curSeat].moduleSlots[2]]; if (mod.cooldown <= 0) { mod.cooldown = mod.modules[0].cooldown * mod.modCooldown; mod.runtime = mod.modules[0].time * mod.modTime; } } if (Input.GetButtonUp("Module4")) { ModuleSlot mod = slots[seats[curSeat].moduleSlots[3]]; if (mod.cooldown <= 0) { mod.cooldown = mod.modules[0].cooldown * mod.modCooldown; mod.runtime = mod.modules[0].time * mod.modTime; } } foreach (ModuleSlot ms in slots) { ms.cooldown -= Time.deltaTime; if (ms.runtime > 0) { ms.runtime -= Time.deltaTime; if (ms.mtype == ModuleSlot.ModuleType.AutoRepair) { health += Time.deltaTime * ms.modules[0].power1 * ms.modPower; } else if (ms.mtype == ModuleSlot.ModuleType.JumpDrive) { if (ms.runtime <= 0) { transform.Translate(ms.modules[0].power1 * ms.modules[0].transform.forward, Space.World); } } else if (ms.mtype == ModuleSlot.ModuleType.Missile) { ms.runtime = -1; GameObject bullet = (GameObject)Instantiate(ms.modules[0].go, ms.modules[0].transform1.position, ms.modules[0].transform1.rotation); bullet.GetComponent <Rigidbody>().AddForce(bullet.transform.forward * ms.modules[0].time * ms.modTime); } } } int heals = injurySlots; foreach (Crew c in crewmembers) { if (c.j == Crew.Job.Engineer && c.injured == false && repairing) { health += repairSpeed * Time.deltaTime; } if (c.injured && heals > 0) { heals -= 1; c.recoveryTime += Time.deltaTime; if (c.recoveryTime > 30) { c.recoveryTime = 0; c.injured = false; } } } if (health < 0) { foreach (Block b in blocks) { b.OnShipDestroy(); b.transform.parent = null; b.transform.SetParent(null); } Cursor.lockState = CursorLockMode.None; Cursor.visible = true; destroyed = true; } if (health > maxHealth) { health = maxHealth; repairing = false; } foreach (PowerSystem ps in powerSys) { ps.energyStored += (ps.energyPerSec - ps.passive) * Time.deltaTime; if (ps.energyStored > ps.energyMax) { ps.energyStored = ps.energyMax; } if (ps.energyStored < 0) { ps.energyStored = 0; } } foreach (WeaponPair w in wp) { w.UpdateState(); } if (Input.GetButton("Fire1")) { wp[seats[curSeat].weaponSet].Fire(true); } if (Input.GetButtonUp("Fire1")) { wp[seats[curSeat].weaponSet].Fire(false); } if (Input.GetButtonUp("Reload")) { wp[seats[curSeat].weaponSet].Reload(); } if (Input.GetButton("Fire2")) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } if (Input.GetButtonUp("Pause")) { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } WeaponPair wpp = wp[seats[curSeat].weaponSet]; if (wpp.secondaryActive) { foreach (Weapon w in wpp.weapons2) { w.LookAt(seats[curSeat].weaponTarget); w.active = true; } foreach (Weapon w in wpp.weapons1) { w.active = false; } } else { foreach (Weapon w in wpp.weapons1) { w.LookAt(seats[curSeat].weaponTarget); w.active = true; } foreach (Weapon w in wpp.weapons2) { w.active = false; } } } if (destroyed) { lifetime -= Time.deltaTime; if (lifetime <= 0) { Destroy(this.gameObject); } } }
void SpawnShip(TextAsset file) { GameObject shipBase = (GameObject)Instantiate(shipCorePrefab, transform.position, transform.rotation); ShipScript ss = shipBase.GetComponent <ShipScript>(); myShip = ss; Transform targ = shipBase.transform.FindChild("CameraPos/CamObj/WeaponsTarget"); int offset = 0; //string[] sts = shipFilePlayer.text.Split('\n'); StreamReader sr = new StreamReader(Application.dataPath + "/" + shipPath); string[] sts = sr.ReadToEnd().Split('\n'); List <string> stringss = new List <string>(); foreach (string s in sts) { string result = Regex.Replace(s, @"\r\n?|\n", ""); stringss.Add(result); } string[] strings = stringss.ToArray(); string shipName = strings[offset]; print(strings[offset]); offset += 1; shipBase.name = shipName; string[] colorPrimary = strings[offset].Split(','); print(strings[offset]); offset += 1; Color cPrimary = new Color(float.Parse(colorPrimary[0]) / 255, float.Parse(colorPrimary[1]) / 255, float.Parse(colorPrimary[2]) / 255, 255); ss.shipColorMain = cPrimary; string[] colorPower = strings[offset].Split(','); print(strings[offset]); offset += 1; Color cPower = new Color(float.Parse(colorPower[0]) / 255, float.Parse(colorPower[1]) / 255, float.Parse(colorPower[2]) / 255, 255); ss.shipColorPower = cPower; string[] colorThrust = strings[offset].Split(','); print(strings[offset]); offset += 1; Color cThrust = new Color(float.Parse(colorThrust[0]) / 255, float.Parse(colorThrust[1]) / 255, float.Parse(colorThrust[2]) / 255, 255); ss.shipColorThrust = cThrust; string[] colorSpecial = strings[offset].Split(','); print(strings[offset]); offset += 1; Color cSpecial = new Color(float.Parse(colorSpecial[0]) / 255, float.Parse(colorSpecial[1]) / 255, float.Parse(colorSpecial[2]) / 255, 255); ss.shipColorSpecial = cSpecial; string[] posOff = strings[offset].Split(','); offset += 1; Vector3 poff = new Vector3(float.Parse(posOff[0]), float.Parse(posOff[1]), float.Parse(posOff[2])); int numSeats = int.Parse(strings[offset]); print(strings[offset]); offset += 1; ss.seats = new BridgeSeat[numSeats]; for (int i = 0; i < numSeats; i++) { ss.seats[i] = new BridgeSeat(); ss.seats[i].name = strings[offset]; ss.seats[i].weaponTarget = targ; print(strings[offset]); offset += 1; ss.seats[i].availableThrusts = new List <int>(); int numThrustsSeat = int.Parse(strings[offset]); print(strings[offset]); offset += 1; for (int n = 0; n < numThrustsSeat; n++) { ss.seats[i].availableThrusts.Add(int.Parse(strings[offset])); print(strings[offset]); offset += 1; } ss.seats[i].weaponSet = int.Parse(strings[offset]); print("WEAPON SET: " + strings[offset]); offset += 1; ss.seats[i].powerSet = int.Parse(strings[offset]); print("POWER SET: " + strings[offset]); offset += 1; int numSeatModules = int.Parse(strings[offset]); print("NUM SEAT MODULES: " + strings[offset]); offset += 1; ss.seats[i].moduleSlots = new int[numSeatModules]; for (int n = 0; n < numSeatModules; n++) { ss.seats[i].moduleSlots[n] = int.Parse(strings[offset]); print(strings[offset]); offset += 1; } } int numThrusts = int.Parse(strings[offset]); print(strings[offset]); offset += 1; ss.tgs = new List <ThrusterGroup>(); for (int i = 0; i < numThrusts; i++) { ThrusterGroup tg = new ThrusterGroup(); tg.name = strings[offset]; print(strings[offset]); offset += 1; tg.axis = strings[offset]; print(strings[offset]); offset += 1; tg.negThrust = new List <Thruster>(); tg.posThrust = new List <Thruster>(); ss.tgs.Add(tg); } int numWeps = int.Parse(strings[offset]); print(strings[offset]); offset += 1; ss.wp = new List <WeaponPair>(); for (int i = 0; i < numWeps; i++) { string wepSetName = strings[offset]; print(strings[offset]); offset += 1; string weaponPrimary = strings[offset]; print(strings[offset]); offset += 1; string weaponSecondary = strings[offset]; print(strings[offset]); offset += 1; WeaponPreset wep1 = weapons[weaponPrimary]; WeaponPreset wep2 = weapons[weaponSecondary]; WeaponPair wp = new WeaponPair(); wp.weapons1 = new List <Weapon>(); wp.weapons2 = new List <Weapon>(); wp.ammo1 = wep1.ammo; wp.ammoMax1 = wep1.ammo; wp.ammo2 = wep2.ammo; wp.ammoMax2 = wep2.ammo; wp.firerate1 = wep1.firerate; wp.reloadSpeed1 = wep1.reloadSpeed; wp.firerate2 = wep2.firerate; wp.reloadSpeed2 = wep2.reloadSpeed; wp.name = wepSetName; ss.wp.Add(wp); } int numPowerSys = int.Parse(strings[offset]); print(strings[offset]); offset += 1; ss.powerSys = new List <PowerSystem>(); for (int i = 0; i < numPowerSys; i++) { string powName = strings[offset]; print(strings[offset]); offset += 1; int numModules = int.Parse(strings[offset]); print(strings[offset]); offset += 1; PowerSystem ps = new PowerSystem(); ps.name = powName; ps.slots = new List <AuxPowerSlot>(); for (int n = 0; n < numModules; n++) { string modType = strings[offset]; print(strings[offset]); offset += 1; float mod = float.Parse(strings[offset]); print(strings[offset]); offset += 1; AuxPowerSlot aps = new AuxPowerSlot(); if (modType == "Shield") { aps.mtype = AuxPowerSlot.ModuleType.Shield; } else if (modType == "Thrust") { aps.mtype = AuxPowerSlot.ModuleType.Thrust; } else if (modType == "Weapon") { aps.mtype = AuxPowerSlot.ModuleType.Weapon; } aps.mod = mod; ps.slots.Add(aps); } ss.powerSys.Add(ps); } int numModulesReal = int.Parse(strings[offset]); print(strings[offset]); offset += 1; ss.slots = new List <ModuleSlot>(); for (int i = 0; i < numModulesReal; i++) { string modName = strings[offset]; print(strings[offset]); offset += 1; string modType = strings[offset]; print(strings[offset]); offset += 1; int powerPower = int.Parse(strings[offset]); print(strings[offset]); offset += 1; int timePower = int.Parse(strings[offset]); print(strings[offset]); offset += 1; int coolPower = int.Parse(strings[offset]); print(strings[offset]); offset += 1; float power = 1 + (powerPower - 20) * 0.05f; float time = 1 + (timePower - 10) * 0.1f; float cool = 1 + (coolPower - 20) * -0.025f; ModuleSlot ms = new ModuleSlot(); ms.name = modName; ms.modPower = power; ms.modTime = time; ms.modCooldown = cool; ms.mtype = modules[modType]; ms.modules = new List <Module>(); ss.slots.Add(ms); } float offsetX = float.Parse(strings[offset]); print(strings[offset]); offset += 1; float offsetY = float.Parse(strings[offset]); print(strings[offset]); offset += 1; float offsetZ = float.Parse(strings[offset]); print(strings[offset]); offset += 1; shipBase.transform.GetChild(0).localPosition = new Vector3(offsetX, offsetY, offsetZ); float camrange = float.Parse(strings[offset]); print(strings[offset]); offset += 1; shipBase.transform.FindChild("CameraPos/CamObj/Main Camera").localPosition = new Vector3(0, 0, -camrange); float range = float.Parse(strings[offset]); print(strings[offset]); offset += 1; targ.localPosition = new Vector3(0, 0, range); int numBlocks = int.Parse(strings[offset]); print(strings[offset]); offset += 1; ss.blocks = new List <Block>(); for (int i = 0; i < numBlocks; i++) { string[] bb = strings[offset].Split('/'); print(strings[offset]); offset += 1; string blockType = bb[0]; string[] position = bb[1].Split(','); string[] rotation = bb[2].Split(','); Vector3 pos = new Vector3(float.Parse(position[0]), float.Parse(position[1]), float.Parse(position[2])); Vector3 ea = new Vector3(float.Parse(rotation[0]), float.Parse(rotation[1]), float.Parse(rotation[2])); Quaternion rot = new Quaternion(); rot.eulerAngles = ea; GameObject blockObj = (GameObject)Instantiate(blocks[blockType], Vector3.zero, Quaternion.identity); blockObj.transform.parent = shipBase.transform; blockObj.transform.localPosition = pos + poff; blockObj.transform.localRotation = rot; Block b = blockObj.GetComponent <Block>(); b.powerSys = int.Parse(bb[3]); if (b is Weapon) { Weapon w = (Weapon)b; w.weaponGroupID = int.Parse(bb[4]); w.oneTwo = int.Parse(bb[5]) == 1; } if (b is Module) { Module m = (Module)b; m.moduleSlot = int.Parse(bb[4]); } if (b is AuxModule) { AuxModule am = (AuxModule)b; am.moduleSlot = int.Parse(bb[4]); } if (b is Thruster) { Thruster t = (Thruster)b; t.thrustGroup = int.Parse(bb[4]); t.posNeg = int.Parse(bb[5]) == 1; } } sr.Close(); }