WIP development branch, first commit.

This commit is contained in:
Droog71 2020-08-04 21:33:47 -04:00
parent 20dcb5143e
commit 67fa58161e
22 changed files with 1903 additions and 2017 deletions

View File

@ -14,6 +14,7 @@ public class AirLock : MonoBehaviour
void Start()
{
// Disable particle effects when using lower video quality settings
if (QualitySettings.GetQualityLevel() < 3)
{
effects.SetActive(false);
@ -25,12 +26,13 @@ public class AirLock : MonoBehaviour
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
//Debug.Log(ID + " Physics update tick: " + address * 0.1f);
// Block physics update
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
}
}
// Toggle the open or closed state of the hatchway
public void ToggleOpen()
{
if (open == false)

View File

@ -46,14 +46,238 @@ public class AlloySmelter : MonoBehaviour
builtObjects = GameObject.Find("Built_Objects");
}
bool IsValidObject(GameObject obj)
{
if (obj != null)
{
return obj.transform.parent != builtObjects.transform && obj.activeInHierarchy;
}
return false;
}
bool IsValidOutputObject(GameObject obj)
{
return outputObject == null && inputObject1 != null && inputObject2 != null && obj != inputObject1 && obj != inputObject2 && obj != gameObject;
}
private void GetInputConduits()
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (IsValidObject(obj))
{
if (obj.GetComponent<UniversalConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < 20)
{
if (obj.GetComponent<UniversalConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<UniversalConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
private void SmeltAlloy()
{
if (inputObject1.GetComponent<UniversalConduit>() != null && inputObject2.GetComponent<UniversalConduit>() != null)
{
if (amount < 1)
{
inputType1 = inputObject1.GetComponent<UniversalConduit>().type;
}
if (amount2 < 1)
{
inputType2 = inputObject2.GetComponent<UniversalConduit>().type;
}
//Debug.Log(ID + " receiving: " + inputObject1.GetComponent<UniversalConduit>().type + " and " + inputObject2.GetComponent<UniversalConduit>().type);
if (inputObject1.GetComponent<UniversalConduit>().type.Equals("Copper Ingot") && inputObject2.GetComponent<UniversalConduit>().type.Equals("Tin Ingot"))
{
outputType = "Bronze Ingot";
if (amount >= speed && amount2 >= speed)
{
if (powerON == true && connectionFailed == false && speed > 0)
{
outputAmount += speed - heat;
amount -= speed - heat;
amount2 -= speed - heat;
fireObject.SetActive(true);
GetComponent<AudioSource>().enabled = true;
}
else
{
fireObject.SetActive(false);
GetComponent<AudioSource>().enabled = false;
}
//Debug.Log(ID + " output: " + outputType);
}
}
else if (inputObject1.GetComponent<UniversalConduit>().type.Equals("Tin Ingot") && inputObject2.GetComponent<UniversalConduit>().type.Equals("Copper Ingot"))
{
outputType = "Bronze Ingot";
if (amount >= speed && amount2 >= speed)
{
if (powerON == true && connectionFailed == false && speed > 0)
{
outputAmount += speed - heat;
amount -= speed - heat;
amount2 -= speed - heat;
fireObject.SetActive(true);
GetComponent<AudioSource>().enabled = true;
}
else
{
fireObject.SetActive(false);
GetComponent<AudioSource>().enabled = false;
}
//Debug.Log(ID + " output: " + outputType);
}
}
else if (inputObject1.GetComponent<UniversalConduit>().type.Equals("Iron Ingot") && inputObject2.GetComponent<UniversalConduit>().type.Equals("Coal"))
{
outputType = "Steel Ingot";
if (amount >= speed && amount2 >= speed)
{
if (powerON == true && connectionFailed == false && speed > 0)
{
outputAmount += speed - heat;
amount -= speed - heat;
amount2 -= speed - heat;
fireObject.SetActive(true);
GetComponent<AudioSource>().enabled = true;
}
else
{
fireObject.SetActive(false);
GetComponent<AudioSource>().enabled = false;
}
//Debug.Log(ID + " output: " + outputType);
}
}
else if (inputObject1.GetComponent<UniversalConduit>().type.Equals("Coal") && inputObject2.GetComponent<UniversalConduit>().type.Equals("Iron Ingot"))
{
outputType = "Steel Ingot";
if (amount >= speed && amount2 >= speed)
{
if (powerON == true && connectionFailed == false && speed > 0)
{
outputAmount += speed - heat;
amount -= speed - heat;
amount2 -= speed - heat;
fireObject.SetActive(true);
GetComponent<AudioSource>().enabled = true;
}
else
{
fireObject.SetActive(false);
GetComponent<AudioSource>().enabled = false;
}
//Debug.Log(ID + " output: " + outputType);
}
}
if (inputObject1.GetComponent<UniversalConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
if (inputObject2.GetComponent<UniversalConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
}
}
private void OutputToConduit()
{
if (outputObject != null)
{
if (outputObject.GetComponent<UniversalConduit>() != null)
{
outputObject.GetComponent<UniversalConduit>().inputID = ID;
outputObject.GetComponent<UniversalConduit>().type = outputType;
outputObject.GetComponent<UniversalConduit>().speed = speed;
//Debug.Log("Setting " + ID + " output conduit type to: " + outputType);
outputID = outputObject.GetComponent<UniversalConduit>().ID;
if (outputAmount >= speed)
{
if (outputType.Equals(outputObject.GetComponent<UniversalConduit>().type))
{
if (powerON == true && connectionFailed == false && inputObject1 != null && inputObject2 != null && speed > 0)
{
conduitItem.GetComponent<ConduitItem>().active = true;
if (GetComponent<AudioSource>().isPlaying == false)
{
GetComponent<AudioSource>().Play();
fireObject.SetActive(true);
}
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
outputObject.GetComponent<UniversalConduit>().amount += speed - heat;
outputAmount -= speed;
machineTimer = 0;
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
machineTimer = 0;
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
connectionLine.enabled = false;
if (connectionFailed == true)
{
if (creationMethod.Equals("spawned"))
{
creationMethod = "built";
}
}
}
}
void Update()
{
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
//Debug.Log(ID + " Machine update tick: " + address * 0.1f);
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
if (speed > 1)
{
heat = speed - 1 - cooling;
@ -62,14 +286,17 @@ public class AlloySmelter : MonoBehaviour
{
heat = 0;
}
if (heat < 0)
{
heat = 0;
}
if (GetComponent<AudioSource>().isPlaying == false)
{
fireObject.SetActive(false);
}
if (inputObject1 == null || inputObject2 == null || outputObject == null)
{
connectionAttempts += 1;
@ -91,233 +318,21 @@ public class AlloySmelter : MonoBehaviour
}
if (connectionFailed == false)
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (obj != null)
{
if (obj.transform.parent != builtObjects.transform)
{
if (obj.activeInHierarchy)
{
if (obj.GetComponent<UniversalConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
if (outputObject == null)
{
if (inputObject1 != null && inputObject2 != null)
{
if (obj != inputObject1 && obj != inputObject2 && obj != this.gameObject)
{
if (obj.GetComponent<UniversalConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<UniversalConduit>().ID + " vs " + outputID);
if (obj.GetComponent<UniversalConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
//Debug.Log("Setting " + ID + " output conduit type to: " + outputType);
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
}
}
}
}
GetInputConduits();
}
}
if (inputObject1 != null && inputObject2 != null)
{
if (inputObject1.GetComponent<UniversalConduit>() != null && inputObject2.GetComponent<UniversalConduit>() != null)
{
if (amount < 1)
{
inputType1 = inputObject1.GetComponent<UniversalConduit>().type;
}
if (amount2 < 1)
{
inputType2 = inputObject2.GetComponent<UniversalConduit>().type;
}
//Debug.Log(ID + " receiving: " + inputObject1.GetComponent<UniversalConduit>().type + " and " + inputObject2.GetComponent<UniversalConduit>().type);
if (inputObject1.GetComponent<UniversalConduit>().type.Equals("Copper Ingot") && inputObject2.GetComponent<UniversalConduit>().type.Equals("Tin Ingot"))
{
outputType = "Bronze Ingot";
if (amount >= speed && amount2 >= speed)
{
if (powerON == true && connectionFailed == false && speed > 0)
{
outputAmount += speed - heat;
amount -= speed - heat;
amount2 -= speed - heat;
fireObject.SetActive(true);
GetComponent<AudioSource>().enabled = true;
}
else
{
fireObject.SetActive(false);
GetComponent<AudioSource>().enabled = false;
}
//Debug.Log(ID + " output: " + outputType);
}
}
else if (inputObject1.GetComponent<UniversalConduit>().type.Equals("Tin Ingot") && inputObject2.GetComponent<UniversalConduit>().type.Equals("Copper Ingot"))
{
outputType = "Bronze Ingot";
if (amount >= speed && amount2 >= speed)
{
if (powerON == true && connectionFailed == false && speed > 0)
{
outputAmount += speed - heat;
amount -= speed - heat;
amount2 -= speed - heat;
fireObject.SetActive(true);
GetComponent<AudioSource>().enabled = true;
}
else
{
fireObject.SetActive(false);
GetComponent<AudioSource>().enabled = false;
}
//Debug.Log(ID + " output: " + outputType);
}
}
else if (inputObject1.GetComponent<UniversalConduit>().type.Equals("Iron Ingot") && inputObject2.GetComponent<UniversalConduit>().type.Equals("Coal"))
{
outputType = "Steel Ingot";
if (amount >= speed && amount2 >= speed)
{
if (powerON == true && connectionFailed == false && speed > 0)
{
outputAmount += speed - heat;
amount -= speed - heat;
amount2 -= speed - heat;
fireObject.SetActive(true);
GetComponent<AudioSource>().enabled = true;
}
else
{
fireObject.SetActive(false);
GetComponent<AudioSource>().enabled = false;
}
//Debug.Log(ID + " output: " + outputType);
}
}
else if (inputObject1.GetComponent<UniversalConduit>().type.Equals("Coal") && inputObject2.GetComponent<UniversalConduit>().type.Equals("Iron Ingot"))
{
outputType = "Steel Ingot";
if (amount >= speed && amount2 >= speed)
{
if (powerON == true && connectionFailed == false && speed > 0)
{
outputAmount += speed - heat;
amount -= speed - heat;
amount2 -= speed - heat;
fireObject.SetActive(true);
GetComponent<AudioSource>().enabled = true;
}
else
{
fireObject.SetActive(false);
GetComponent<AudioSource>().enabled = false;
}
//Debug.Log(ID + " output: " + outputType);
}
}
if (inputObject1.GetComponent<UniversalConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
if (inputObject2.GetComponent<UniversalConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
}
SmeltAlloy();
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
if (outputObject != null)
{
if (outputObject.GetComponent<UniversalConduit>() != null)
{
outputObject.GetComponent<UniversalConduit>().inputID = ID;
outputObject.GetComponent<UniversalConduit>().type = outputType;
outputObject.GetComponent<UniversalConduit>().speed = speed;
//Debug.Log("Setting " + ID + " output conduit type to: " + outputType);
outputID = outputObject.GetComponent<UniversalConduit>().ID;
if (outputAmount >= speed)
{
if (outputType.Equals(outputObject.GetComponent<UniversalConduit>().type))
{
if (powerON == true && connectionFailed == false && inputObject1 != null && inputObject2 != null && speed > 0)
{
conduitItem.GetComponent<ConduitItem>().active = true;
if (GetComponent<AudioSource>().isPlaying == false)
{
GetComponent<AudioSource>().Play();
fireObject.SetActive(true);
}
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
outputObject.GetComponent<UniversalConduit>().amount += speed - heat;
outputAmount -= speed;
machineTimer = 0;
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
machineTimer = 0;
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
connectionLine.enabled = false;
if (connectionFailed == true)
{
if (creationMethod.Equals("spawned"))
{
creationMethod = "built";
}
}
}
OutputToConduit();
if (inputObject1 != null && inputObject2 != null && outputObject != null)
{
connectionAttempts = 0;

View File

@ -31,11 +31,6 @@ public class Auger : MonoBehaviour
connectionLine.enabled = false;
}
void OnDestroy()
{
}
void Update()
{
updateTick += 1 * Time.deltaTime;

View File

@ -5,12 +5,6 @@ using UnityEngine;
public class AugerBlade : MonoBehaviour
{
public GameObject auger;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()

View File

@ -16,11 +16,12 @@ public class AutoCrafter : MonoBehaviour
public GameObject powerObject;
public GameObject conduitItem;
public Material lineMat;
LineRenderer connectionLine;
private LineRenderer connectionLine;
private float updateTick;
public int address;
public bool hasHeatExchanger;
private MachineCrafting machineCrafting;
private CraftingDictionary craftingDictionary;
private ComputerCrafting computerCrafting;
private int machineTimer;
public int connectionAttempts;
@ -32,6 +33,7 @@ public class AutoCrafter : MonoBehaviour
{
machineCrafting = GetComponent<MachineCrafting>();
computerCrafting = GetComponent<ComputerCrafting>();
craftingDictionary = new CraftingDictionary(machineCrafting, computerCrafting);
connectionLine = gameObject.AddComponent<LineRenderer>();
connectionLine.startWidth = 0.2f;
connectionLine.endWidth = 0.2f;
@ -46,7 +48,6 @@ public class AutoCrafter : MonoBehaviour
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
//Debug.Log(ID + " Machine update tick: " + address * 0.1f);
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
if (speed > 1)
@ -61,6 +62,7 @@ public class AutoCrafter : MonoBehaviour
{
heat = 0;
}
GetComponent<InventoryManager>().ID = ID;
bool foundType = false;
foreach (InventorySlot slot in GetComponent<InventoryManager>().inventory)
@ -99,472 +101,23 @@ public class AutoCrafter : MonoBehaviour
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (obj != null)
if (IsValidObject(obj))
{
if (obj.transform.parent != builtObjects.transform)
{
if (obj.activeInHierarchy)
{
if (obj.GetComponent<InventoryManager>() != null && !obj.GetComponent<InventoryManager>().ID.Equals("player") && obj.GetComponent<Retriever>() == null && obj.GetComponent<Rocket>() == null && obj.GetComponent<AutoCrafter>() == null && obj != this.gameObject)
{
if (inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<InventoryManager>().ID + " vs " + outputID);
if (obj.GetComponent<InventoryManager>().ID.Equals(inputID))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20 || obj.GetComponent<RailCart>() != null)
{
inputObject = obj;
if (obj.GetComponent<RailCart>() != null)
{
inputID = obj.GetComponent<RailCart>().ID;
}
else
{
inputID = obj.GetComponent<InventoryManager>().ID;
}
machineCrafting.inventoryManager = obj.GetComponent<InventoryManager>();
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
}
else if (creationMethod.Equals("built"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
inputObject = obj;
inputID = obj.GetComponent<InventoryManager>().ID;
machineCrafting.inventoryManager = obj.GetComponent<InventoryManager>();
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<StorageComputer>() != null)
{
if (inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<InventoryManager>().ID + " vs " + outputID);
if (obj.GetComponent<StorageComputer>().ID.Equals(inputID))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
inputObject = obj;
inputID = obj.GetComponent<StorageComputer>().ID;
computerCrafting.computerManager = obj.GetComponent<StorageComputer>().computerContainers;
computerCrafting.conduitItem = inputObject.GetComponent<StorageComputer>().conduitItem.GetComponent<ConduitItem>();
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
}
else if (creationMethod.Equals("built"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
inputObject = obj;
inputID = obj.GetComponent<StorageComputer>().ID;
computerCrafting.computerManager = obj.GetComponent<StorageComputer>().computerContainers;
computerCrafting.conduitItem = inputObject.GetComponent<StorageComputer>().conduitItem.GetComponent<ConduitItem>();
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
ConnectToObject(obj);
}
}
}
}
if (connectionFailed == false)
if (connectionFailed == false && inputObject != null)
{
if (inputObject != null)
{
float distance = Vector3.Distance(transform.position, inputObject.transform.position);
if (distance < 20)
{
if (powerON == true && speed > 0 && type != "" && type != "nothing")
{
if (inputObject.GetComponent<InventoryManager>() != null)
{
if (inputObject.GetComponent<RailCart>() != null)
{
inputID = inputObject.GetComponent<RailCart>().ID;
}
else
{
inputID = inputObject.GetComponent<InventoryManager>().ID;
}
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
if (GetComponent<AudioSource>().isPlaying == false)
{
GetComponent<AudioSource>().Play();
}
connectionLine.enabled = true;
connectionLine.SetPosition(1, inputObject.transform.position);
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
for (int count = 0; count < speed; count++)
{
if (type.Equals("Iron Block"))
{
machineCrafting.CraftIronBlock();
}
if (type.Equals("Iron Ramp"))
{
machineCrafting.CraftIronRamp();
}
if (type.Equals("Steel Block"))
{
machineCrafting.CraftSteelBlock();
}
if (type.Equals("Steel Ramp"))
{
machineCrafting.CraftSteelRamp();
}
if (type.Equals("Circuit Board"))
{
machineCrafting.CraftCircuitBoard();
}
if (type.Equals("Electric Motor"))
{
machineCrafting.CraftMotor();
}
if (type.Equals("Quantum Hatchway"))
{
machineCrafting.CraftQuantumHatchway();
}
if (type.Equals("Electric Light"))
{
machineCrafting.CraftElectricLight();
}
if (type.Equals("Auger"))
{
machineCrafting.CraftAuger();
}
if (type.Equals("Storage Container"))
{
machineCrafting.CraftStorageContainer();
}
if (type.Equals("Storage Computer"))
{
machineCrafting.CraftStorageComputer();
}
if (type.Equals("Extruder"))
{
machineCrafting.CraftExtruder();
}
if (type.Equals("Press"))
{
machineCrafting.CraftPress();
}
if (type.Equals("Universal Extractor"))
{
machineCrafting.CraftUniversalExtractor();
}
if (type.Equals("Universal Conduit"))
{
machineCrafting.CraftUniversalConduit();
}
if (type.Equals("Retriever"))
{
machineCrafting.CraftRetriever();
}
if (type.Equals("Solar Panel"))
{
machineCrafting.CraftSolarPanel();
}
if (type.Equals("Generator"))
{
machineCrafting.CraftGenerator();
}
if (type.Equals("Power Conduit"))
{
machineCrafting.CraftPowerConduit();
}
if (type.Equals("Nuclear Reactor"))
{
machineCrafting.CraftNuclearReactor();
}
if (type.Equals("Reactor Turbine"))
{
machineCrafting.CraftReactorTurbine();
}
if (type.Equals("Heat Exchanger"))
{
machineCrafting.CraftHeatExchanger();
}
if (type.Equals("Smelter"))
{
machineCrafting.CraftSmelter();
}
if (type.Equals("Gear Cutter"))
{
machineCrafting.CraftGearCutter();
}
if (type.Equals("Alloy Smelter"))
{
machineCrafting.CraftAlloySmelter();
}
if (type.Equals("Turret"))
{
machineCrafting.CraftTurret();
}
if (type.Equals("DM Collector"))
{
machineCrafting.CraftDarkMatterCollector();
}
if (type.Equals("DM Conduit"))
{
machineCrafting.CraftDarkMatterConduit();
}
if (type.Equals("Auto Crafter"))
{
machineCrafting.CraftAutoCrafter();
}
if (type.Equals("Rail Cart Hub"))
{
machineCrafting.CraftRailCartHub();
}
if (type.Equals("Rail Cart"))
{
machineCrafting.CraftRailCart();
}
}
machineTimer = 0;
}
}
if (inputObject.GetComponent<StorageComputer>() != null)
{
inputID = inputObject.GetComponent<StorageComputer>().ID;
if (inputObject.GetComponent<StorageComputer>().initialized == true)
{
computerCrafting.computerManager = inputObject.GetComponent<StorageComputer>().computerContainers;
if (computerCrafting.conduitItem == null)
{
GameObject storageComputerItemObject = Instantiate(storageComputerConduitItemObject, inputObject.transform.position, inputObject.transform.rotation);
storageComputerItemObject.transform.parent = inputObject.transform;
computerCrafting.conduitItem = storageComputerItemObject.GetComponent<ConduitItem>();
}
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
if (GetComponent<AudioSource>().isPlaying == false)
{
GetComponent<AudioSource>().Play();
}
connectionLine.enabled = true;
connectionLine.SetPosition(1, inputObject.transform.position);
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
for (int count = 0; count < speed; count++)
{
if (type.Equals("Iron Block"))
{
computerCrafting.CraftIronBlock();
}
if (type.Equals("Iron Ramp"))
{
computerCrafting.CraftIronRamp();
}
if (type.Equals("Steel Block"))
{
computerCrafting.CraftSteelBlock();
}
if (type.Equals("Steel Ramp"))
{
computerCrafting.CraftSteelRamp();
}
if (type.Equals("Circuit Board"))
{
computerCrafting.CraftCircuitBoard();
}
if (type.Equals("Electric Motor"))
{
computerCrafting.CraftMotor();
}
if (type.Equals("Quantum Hatchway"))
{
computerCrafting.CraftQuantumHatchway();
}
if (type.Equals("Electric Light"))
{
computerCrafting.CraftElectricLight();
}
if (type.Equals("Auger"))
{
computerCrafting.CraftAuger();
}
if (type.Equals("Storage Container"))
{
computerCrafting.CraftStorageContainer();
}
if (type.Equals("Storage Computer"))
{
computerCrafting.CraftStorageComputer();
}
if (type.Equals("Extruder"))
{
computerCrafting.CraftExtruder();
}
if (type.Equals("Press"))
{
computerCrafting.CraftPress();
}
if (type.Equals("Universal Extractor"))
{
computerCrafting.CraftUniversalExtractor();
}
if (type.Equals("Universal Conduit"))
{
computerCrafting.CraftUniversalConduit();
}
if (type.Equals("Retriever"))
{
computerCrafting.CraftRetriever();
}
if (type.Equals("Solar Panel"))
{
computerCrafting.CraftSolarPanel();
}
if (type.Equals("Generator"))
{
computerCrafting.CraftGenerator();
}
if (type.Equals("Power Conduit"))
{
computerCrafting.CraftPowerConduit();
}
if (type.Equals("Nuclear Reactor"))
{
computerCrafting.CraftNuclearReactor();
}
if (type.Equals("Reactor Turbine"))
{
computerCrafting.CraftReactorTurbine();
}
if (type.Equals("Heat Exchanger"))
{
computerCrafting.CraftHeatExchanger();
}
if (type.Equals("Smelter"))
{
computerCrafting.CraftSmelter();
}
if (type.Equals("Gear Cutter"))
{
computerCrafting.CraftGearCutter();
}
if (type.Equals("Alloy Smelter"))
{
computerCrafting.CraftAlloySmelter();
}
if (type.Equals("Turret"))
{
computerCrafting.CraftTurret();
}
if (type.Equals("DM Collector"))
{
computerCrafting.CraftDarkMatterCollector();
}
if (type.Equals("DM Conduit"))
{
computerCrafting.CraftDarkMatterConduit();
}
if (type.Equals("Auto Crafter"))
{
computerCrafting.CraftAutoCrafter();
}
if (type.Equals("Rail Cart Hub"))
{
computerCrafting.CraftRailCartHub();
}
if (type.Equals("Rail Cart"))
{
computerCrafting.CraftRailCart();
}
}
machineTimer = 0;
}
}
else
{
if (computerCrafting.conduitItem != null)
{
computerCrafting.conduitItem.active = false;
}
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().Stop();
}
}
}
else
{
if (computerCrafting.conduitItem != null)
{
computerCrafting.conduitItem.active = false;
}
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().Stop();
}
}
else
{
if (computerCrafting.conduitItem != null)
{
computerCrafting.conduitItem.active = false;
}
connectionLine.enabled = false;
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().Stop();
}
}
else
{
if (computerCrafting.conduitItem != null)
{
computerCrafting.conduitItem.active = false;
}
connectionLine.enabled = false;
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().Stop();
}
DoWork();
}
else
{
if (computerCrafting.conduitItem != null)
{
computerCrafting.conduitItem.active = false;
}
connectionLine.enabled = false;
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().Stop();
ShutDown(true);
}
if (inputObject == null)
{
connectionLine.enabled = false;
@ -578,4 +131,200 @@ public class AutoCrafter : MonoBehaviour
}
}
}
bool IsValidObject(GameObject obj)
{
if (obj != null)
{
return obj.transform.parent != builtObjects.transform && obj.activeInHierarchy;
}
return false;
}
private void ConnectToObject(GameObject obj)
{
if (obj.GetComponent<InventoryManager>() != null && !obj.GetComponent<InventoryManager>().ID.Equals("player") && obj.GetComponent<Retriever>() == null && obj.GetComponent<Rocket>() == null && obj.GetComponent<AutoCrafter>() == null && obj != gameObject)
{
if (inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<InventoryManager>().ID.Equals(inputID))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20 || obj.GetComponent<RailCart>() != null)
{
inputObject = obj;
if (obj.GetComponent<RailCart>() != null)
{
inputID = obj.GetComponent<RailCart>().ID;
}
else
{
inputID = obj.GetComponent<InventoryManager>().ID;
}
machineCrafting.inventoryManager = obj.GetComponent<InventoryManager>();
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
inputObject = obj;
inputID = obj.GetComponent<InventoryManager>().ID;
machineCrafting.inventoryManager = obj.GetComponent<InventoryManager>();
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<StorageComputer>() != null)
{
if (inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<InventoryManager>().ID + " vs " + outputID);
if (obj.GetComponent<StorageComputer>().ID.Equals(inputID))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
inputObject = obj;
inputID = obj.GetComponent<StorageComputer>().ID;
computerCrafting.computerManager = obj.GetComponent<StorageComputer>().computerContainers;
computerCrafting.conduitItem = inputObject.GetComponent<StorageComputer>().conduitItem.GetComponent<ConduitItem>();
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
}
else if (creationMethod.Equals("built"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
inputObject = obj;
inputID = obj.GetComponent<StorageComputer>().ID;
computerCrafting.computerManager = obj.GetComponent<StorageComputer>().computerContainers;
computerCrafting.conduitItem = inputObject.GetComponent<StorageComputer>().conduitItem.GetComponent<ConduitItem>();
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
private void MachineCraftItem()
{
for (int count = 0; count < speed; count++)
{
bool craft = craftingDictionary.machineCraftingDictionary[type];
}
}
private void ComputerCraftItem()
{
for (int count = 0; count < speed; count++)
{
bool craft = craftingDictionary.computerCraftingDictionary[type];
}
}
private void DoWork()
{
float distance = Vector3.Distance(transform.position, inputObject.transform.position);
if (distance < 20)
{
if (powerON == true && speed > 0 && type != "" && type != "nothing")
{
if (inputObject.GetComponent<InventoryManager>() != null)
{
if (inputObject.GetComponent<RailCart>() != null)
{
inputID = inputObject.GetComponent<RailCart>().ID;
}
else
{
inputID = inputObject.GetComponent<InventoryManager>().ID;
}
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
if (GetComponent<AudioSource>().isPlaying == false)
{
GetComponent<AudioSource>().Play();
}
connectionLine.enabled = true;
connectionLine.SetPosition(1, inputObject.transform.position);
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
MachineCraftItem();
machineTimer = 0;
}
}
if (inputObject.GetComponent<StorageComputer>() != null)
{
inputID = inputObject.GetComponent<StorageComputer>().ID;
if (inputObject.GetComponent<StorageComputer>().initialized == true)
{
computerCrafting.computerManager = inputObject.GetComponent<StorageComputer>().computerContainers;
if (computerCrafting.conduitItem == null)
{
GameObject storageComputerItemObject = Instantiate(storageComputerConduitItemObject, inputObject.transform.position, inputObject.transform.rotation);
storageComputerItemObject.transform.parent = inputObject.transform;
computerCrafting.conduitItem = storageComputerItemObject.GetComponent<ConduitItem>();
}
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
if (GetComponent<AudioSource>().isPlaying == false)
{
GetComponent<AudioSource>().Play();
}
connectionLine.enabled = true;
connectionLine.SetPosition(1, inputObject.transform.position);
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
ComputerCraftItem();
machineTimer = 0;
}
}
else
{
ShutDown(false);
}
}
}
else
{
ShutDown(false);
}
}
else
{
ShutDown(true);
}
}
private void ShutDown(bool disconnect)
{
if (computerCrafting.conduitItem != null)
{
computerCrafting.conduitItem.active = false;
}
connectionLine.enabled &= !disconnect;
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().Stop();
}
}

View File

@ -4,17 +4,19 @@ using UnityEngine;
public class BlockDummy : MonoBehaviour
{
// This class is attached to placeholder objects identified through Unity's GetComponent method.
public string type;
// Start is called before the first frame update
void Start()
{
//NOOP
}
// Update is called once per frame
void Update()
{
//NOOP
}
}

View File

@ -16,7 +16,7 @@ public class ComputerCrafting : MonoBehaviour
}
}
public void CraftIronBlock()
public bool CraftIronBlock()
{
InventorySlot ironPlateSlot = null;
bool foundItems = false;
@ -74,9 +74,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftIronRamp()
public bool CraftIronRamp()
{
InventorySlot ironPlateSlot = null;
bool foundItems = false;
@ -134,9 +135,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftSteelBlock()
public bool CraftSteelBlock()
{
InventorySlot steelPlateSlot = null;
bool foundItems = false;
@ -194,9 +196,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftSteelRamp()
public bool CraftSteelRamp()
{
InventorySlot steelPlateSlot = null;
bool foundItems = false;
@ -254,9 +257,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftStorageContainer()
public bool CraftStorageContainer()
{
InventorySlot ironPlateSlot = null;
bool foundItems = false;
@ -314,9 +318,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftQuantumHatchway()
public bool CraftQuantumHatchway()
{
InventoryManager tinManager = null;
InventoryManager darkMatterManager = null;
@ -393,9 +398,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftElectricLight()
public bool CraftElectricLight()
{
InventoryManager glassBlockManager = null;
InventoryManager tinPlateManager = null;
@ -486,9 +492,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftAuger()
public bool CraftAuger()
{
InventoryManager ironIngotManager = null;
InventoryManager copperIngotManager = null;
@ -565,9 +572,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftStorageComputer()
public bool CraftStorageComputer()
{
InventoryManager retrieverManager = null;
InventoryManager universalConduitManager = null;
@ -717,9 +725,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftExtruder()
public bool CraftExtruder()
{
InventoryManager ironIngotManager = null;
InventoryManager copperIngotManager = null;
@ -797,9 +806,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftPress()
public bool CraftPress()
{
InventoryManager ironIngotManager = null;
InventoryManager ironPipeManager = null;
@ -887,9 +897,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftUniversalExtractor()
public bool CraftUniversalExtractor()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -1000,9 +1011,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftUniversalConduit()
public bool CraftUniversalConduit()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -1113,9 +1125,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftRetriever()
public bool CraftRetriever()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -1244,9 +1257,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftGenerator()
public bool CraftGenerator()
{
InventoryManager smelterManager = null;
InventoryManager ironPipeManager = null;
@ -1392,9 +1406,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftReactorTurbine()
public bool CraftReactorTurbine()
{
InventoryManager generatorManager = null;
InventoryManager steelPipeManager = null;
@ -1540,9 +1555,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftAutoCrafter()
public bool CraftAutoCrafter()
{
InventoryManager bronzeGearManager = null;
InventoryManager steelPlateManager = null;
@ -1671,9 +1687,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftRailCartHub()
public bool CraftRailCartHub()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -1763,9 +1780,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftRailCart()
public bool CraftRailCart()
{
InventoryManager electricMotorManager = null;
InventoryManager copperWireManager = null;
@ -1906,9 +1924,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftSolarPanel()
public bool CraftSolarPanel()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -2032,9 +2051,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftPowerConduit()
public bool CraftPowerConduit()
{
InventoryManager aluminumPlateManager = null;
InventoryManager glassBlockManager = null;
@ -2128,9 +2148,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftNuclearReactor()
public bool CraftNuclearReactor()
{
InventoryManager steelPlateManager = null;
InventoryManager steelPipeManager = null;
@ -2275,9 +2296,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftHeatExchanger()
public bool CraftHeatExchanger()
{
InventoryManager steelPlateManager = null;
InventoryManager steelPipeManager = null;
@ -2354,9 +2376,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftSmelter()
public bool CraftSmelter()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -2450,9 +2473,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftGearCutter()
public bool CraftGearCutter()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -2571,9 +2595,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftCircuitBoard()
public bool CraftCircuitBoard()
{
InventoryManager tinManager = null;
InventoryManager glassManager = null;
@ -2684,9 +2709,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftMotor()
public bool CraftMotor()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -2793,9 +2819,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftAlloySmelter()
public bool CraftAlloySmelter()
{
InventoryManager ironPlateManager = null;
InventoryManager ironPipeManager = null;
@ -2928,9 +2955,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftTurret()
public bool CraftTurret()
{
InventoryManager steelPlateManager = null;
InventoryManager steelPipeManager = null;
@ -3094,9 +3122,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftDarkMatterCollector()
public bool CraftDarkMatterCollector()
{
InventoryManager steelPlateManager = null;
InventoryManager steelPipeManager = null;
@ -3257,9 +3286,10 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftDarkMatterConduit()
public bool CraftDarkMatterConduit()
{
InventoryManager steelPlateManager = null;
InventoryManager steelPipeManager = null;
@ -3420,5 +3450,6 @@ public class ComputerCrafting : MonoBehaviour
}
}
}
return true;
}
}

91
CraftingDictionary.cs Normal file
View File

@ -0,0 +1,91 @@
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CraftingDictionary : MonoBehaviour
{
public Dictionary<string, bool> machineCraftingDictionary;
public Dictionary<string, bool> computerCraftingDictionary;
private MachineCrafting machineCrafting;
private ComputerCrafting computerCrafting;
public CraftingDictionary(MachineCrafting machineCrafting, ComputerCrafting computerCrafting)
{
this.machineCrafting = machineCrafting;
this.computerCrafting = computerCrafting;
}
void Start()
{
machineCraftingDictionary = new Dictionary<string, bool>
{
{ "CraftIronBlock", machineCrafting.CraftIronBlock() },
{ "CraftIronRamp", machineCrafting.CraftIronRamp() },
{ "CraftSteelBlock", machineCrafting.CraftSteelBlock() },
{ "CraftSteelRamp", machineCrafting.CraftSteelRamp() },
{ "CraftQuantumHatchway", machineCrafting.CraftQuantumHatchway() },
{ "CraftElectricLight", machineCrafting.CraftElectricLight() },
{ "CraftAuger", machineCrafting.CraftAuger() },
{ "CraftStorageContainer", machineCrafting.CraftStorageContainer() },
{ "CraftExtruder", machineCrafting.CraftExtruder() },
{ "CraftPress", machineCrafting.CraftPress() },
{ "CraftUniversalExtractor", machineCrafting.CraftUniversalExtractor() },
{ "CraftUniversalConduit", machineCrafting.CraftUniversalConduit() },
{ "CraftRetriever", machineCrafting.CraftRetriever() },
{ "CraftGenerator", machineCrafting.CraftGenerator() },
{ "CraftReactorTurbine", machineCrafting.CraftReactorTurbine() },
{ "CraftRailCartHub", machineCrafting.CraftRailCartHub() },
{ "CraftRailCart", machineCrafting.CraftRailCart() },
{ "CraftCircuitBoard", machineCrafting.CraftCircuitBoard() },
{ "CraftMotor", machineCrafting.CraftMotor() },
{ "CraftAutoCrafter", machineCrafting.CraftAutoCrafter() },
{ "CraftSolarPanel", machineCrafting.CraftSolarPanel() },
{ "CraftPowerConduit", machineCrafting.CraftPowerConduit() },
{ "CraftNuclearReactor", machineCrafting.CraftNuclearReactor() },
{ "CraftHeatExchanger", machineCrafting.CraftHeatExchanger() },
{ "CraftSmelter", machineCrafting.CraftSmelter() },
{ "CraftGearCutter", machineCrafting.CraftGearCutter() },
{ "CraftStorageComputer", machineCrafting.CraftStorageComputer() },
{ "CraftAlloySmelter", machineCrafting.CraftAlloySmelter() },
{ "CraftTurret", machineCrafting.CraftTurret() },
{ "CraftDarkMatterCollector", machineCrafting.CraftDarkMatterCollector() },
{ "CraftDarkMatterConduit", machineCrafting.CraftDarkMatterConduit() },
};
computerCraftingDictionary = new Dictionary<string, bool>
{
{ "CraftIronBlock", computerCrafting.CraftIronBlock() },
{ "CraftIronRamp", computerCrafting.CraftIronRamp() },
{ "CraftSteelBlock", computerCrafting.CraftSteelBlock() },
{ "CraftSteelRamp", computerCrafting.CraftSteelRamp() },
{ "CraftQuantumHatchway", computerCrafting.CraftQuantumHatchway() },
{ "CraftElectricLight", computerCrafting.CraftElectricLight() },
{ "CraftAuger", computerCrafting.CraftAuger() },
{ "CraftStorageContainer", computerCrafting.CraftStorageContainer() },
{ "CraftExtruder", computerCrafting.CraftExtruder() },
{ "CraftPress", computerCrafting.CraftPress() },
{ "CraftUniversalExtractor", computerCrafting.CraftUniversalExtractor() },
{ "CraftUniversalConduit", computerCrafting.CraftUniversalConduit() },
{ "CraftRetriever", computerCrafting.CraftRetriever() },
{ "CraftGenerator", computerCrafting.CraftGenerator() },
{ "CraftReactorTurbine", computerCrafting.CraftReactorTurbine() },
{ "CraftRailCartHub", computerCrafting.CraftRailCartHub() },
{ "CraftRailCart", computerCrafting.CraftRailCart() },
{ "CraftCircuitBoard", computerCrafting.CraftCircuitBoard() },
{ "CraftMotor", computerCrafting.CraftMotor() },
{ "CraftAutoCrafter", computerCrafting.CraftAutoCrafter() },
{ "CraftSolarPanel", computerCrafting.CraftSolarPanel() },
{ "CraftPowerConduit", computerCrafting.CraftPowerConduit() },
{ "CraftNuclearReactor", computerCrafting.CraftNuclearReactor() },
{ "CraftHeatExchanger", computerCrafting.CraftHeatExchanger() },
{ "CraftSmelter", computerCrafting.CraftSmelter() },
{ "CraftGearCutter", computerCrafting.CraftGearCutter() },
{ "CraftStorageComputer", computerCrafting.CraftStorageComputer() },
{ "CraftAlloySmelter", computerCrafting.CraftAlloySmelter() },
{ "CraftTurret", computerCrafting.CraftTurret() },
{ "CraftDarkMatterCollector", computerCrafting.CraftDarkMatterCollector() },
{ "CraftDarkMatterConduit", computerCrafting.CraftDarkMatterConduit() },
};
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 000bef17e9da612059c4e1600458b8e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -45,14 +45,56 @@ public class DarkMatterCollector : MonoBehaviour
}
}
bool IsValidObject(GameObject obj)
{
if (obj != null)
{
return obj.transform.parent != builtObjects.transform && obj.activeInHierarchy;
}
return false;
}
private void FindDarkMatter()
{
DarkMatter[] allDarkMatter = FindObjectsOfType<DarkMatter>();
foreach (DarkMatter d in allDarkMatter)
{
GameObject obj = d.gameObject;
if (IsValidObject(obj))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (obj.GetComponent<DarkMatter>() != null && distance < 20)
{
if (obj.GetComponent<DarkMatter>().collector == null)
{
obj.GetComponent<DarkMatter>().collector = gameObject;
}
if (obj.GetComponent<DarkMatter>().collector == gameObject)
{
if (inputLine == null && obj.GetComponent<LineRenderer>() == null)
{
inputLine = obj.AddComponent<LineRenderer>();
inputLine.startWidth = 0.2f;
inputLine.endWidth = 0.2f;
inputLine.material = lineMat;
inputLine.SetPosition(0, transform.position);
inputLine.SetPosition(1, obj.transform.position);
}
foundDarkMatter = true;
}
}
}
}
}
void Update()
{
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
//Debug.Log(ID + " Machine update tick: " + address * 0.1f);
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
if (speed > 1)
{
heat = speed - 1 - cooling;
@ -61,10 +103,12 @@ public class DarkMatterCollector : MonoBehaviour
{
heat = 0;
}
if (heat < 0)
{
heat = 0;
}
if (outputObject != null)
{
connectionLine.SetPosition(0, transform.position);
@ -75,6 +119,7 @@ public class DarkMatterCollector : MonoBehaviour
{
connectionLine.enabled = false;
}
if (foundDarkMatter == true)
{
if (powerON == true && connectionFailed == false && speed > 0)
@ -116,46 +161,10 @@ public class DarkMatterCollector : MonoBehaviour
connectionFailed = true;
}
}
if (connectionFailed == false)
{
DarkMatter[] allDarkMatter = FindObjectsOfType<DarkMatter>();
foreach (DarkMatter d in allDarkMatter)
{
GameObject obj = d.gameObject;
if (obj != null)
{
if (obj.transform.parent != builtObjects.transform)
{
if (obj.activeInHierarchy)
{
if (obj.GetComponent<DarkMatter>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
if (obj.GetComponent<DarkMatter>().collector == null)
{
obj.GetComponent<DarkMatter>().collector = this.gameObject;
}
if (obj.GetComponent<DarkMatter>().collector == this.gameObject)
{
if (inputLine == null && obj.GetComponent<LineRenderer>() == null)
{
inputLine = obj.AddComponent<LineRenderer>();
inputLine.startWidth = 0.2f;
inputLine.endWidth = 0.2f;
inputLine.material = lineMat;
inputLine.SetPosition(0, transform.position);
inputLine.SetPosition(1, obj.transform.position);
}
foundDarkMatter = true;
}
}
}
}
}
}
}
FindDarkMatter();
}
}
}

View File

@ -43,12 +43,319 @@ public class DarkMatterConduit : MonoBehaviour
}
}
bool IsValidObject(GameObject obj)
{
if (obj != null)
{
return obj.transform.parent != builtObjects.transform && obj.activeInHierarchy;
}
return false;
}
bool IsValidOutputObject(GameObject obj)
{
return outputObject == null && inputObject != null && obj != inputObject && obj != gameObject;
}
private void FindConnections()
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (IsValidObject(obj))
{
if (obj.GetComponent<DarkMatterCollector>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
if (inputObject == null && obj.GetComponent<DarkMatterCollector>().outputObject == null)
{
if (creationMethod.Equals("spawned"))
{
if (obj.GetComponent<DarkMatterCollector>().ID.Equals(inputID))
{
inputObject = obj;
obj.GetComponent<DarkMatterCollector>().outputObject = this.gameObject;
}
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
inputObject = obj;
obj.GetComponent<DarkMatterCollector>().outputObject = this.gameObject;
}
}
}
}
if (obj.GetComponent<InventoryManager>() != null && obj.GetComponent<Retriever>() == null && obj.GetComponent<AutoCrafter>() == null && !obj.GetComponent<InventoryManager>().ID.Equals("player"))
{
if (IsValidOutputObject(obj))
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<InventoryManager>().ID + " vs " + outputID);
if (obj.GetComponent<InventoryManager>().ID.Equals(outputID))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range || obj.GetComponent<RailCart>() != null)
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
}
else if (creationMethod.Equals("built"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<StorageComputer>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<StorageComputer>().ID.Equals(outputID))
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
if (obj.GetComponent<DarkMatterConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<DarkMatterConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
if (obj.GetComponent<DarkMatterConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<DarkMatterConduit>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<DarkMatterConduit>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
private void HandleIO()
{
if (inputObject != null)
{
if (inputObject.GetComponent<DarkMatterCollector>() != null)
{
inputID = inputObject.GetComponent<DarkMatterCollector>().ID;
speed = inputObject.GetComponent<DarkMatterCollector>().speed;
if (inputObject.GetComponent<DarkMatterCollector>().powerON == true && inputObject.GetComponent<DarkMatterCollector>().foundDarkMatter == true && inputObject.GetComponent<DarkMatterCollector>().speed > 0)
{
if (inputObject.GetComponent<DarkMatterCollector>().darkMatterAmount >= speed && connectionFailed == false)
{
inputObject.GetComponent<DarkMatterCollector>().darkMatterAmount -= speed;
darkMatterAmount += speed;
}
}
else
{
if (storageComputerConduitItem != null)
{
storageComputerConduitItem.active = false;
}
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
if (inputObject.GetComponent<DarkMatterConduit>() != null)
{
if (inputObject.GetComponent<DarkMatterConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
{
if (storageComputerConduitItem != null)
{
storageComputerConduitItem.active = false;
}
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
HandleOutput();
}
private void HandleOutput()
{
if (outputObject != null)
{
if (outputObject.GetComponent<DarkMatterConduit>() != null)
{
outputObject.GetComponent<DarkMatterConduit>().inputID = ID;
outputID = outputObject.GetComponent<DarkMatterConduit>().ID;
outputObject.GetComponent<DarkMatterConduit>().speed = speed;
if (darkMatterAmount >= speed && connectionFailed == false && speed > 0)
{
outputObject.GetComponent<DarkMatterConduit>().darkMatterAmount += speed;
darkMatterAmount -= speed;
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
}
}
else if (outputObject.GetComponent<StorageComputer>() != null)
{
outputID = outputObject.GetComponent<StorageComputer>().ID;
if (outputObject.GetComponent<StorageComputer>().initialized == true)
{
if (storageComputerConduitItem == null)
{
GameObject storageComputerItemObject = Instantiate(storageComputerConduitItemObject, outputObject.transform.position, outputObject.transform.rotation);
storageComputerItemObject.transform.parent = outputObject.transform;
storageComputerConduitItem = storageComputerItemObject.GetComponent<ConduitItem>();
}
if (darkMatterAmount >= speed && connectionFailed == false && speed > 0)
{
connectionLine.enabled = true;
connectionLine.SetPosition(1, outputObject.transform.position);
bool itemAdded = false;
foreach (InventoryManager manager in outputObject.GetComponent<StorageComputer>().computerContainers)
{
if (itemAdded == false)
{
manager.AddItem("Dark Matter", speed);
if (manager.itemAdded == true)
{
itemAdded = true;
darkMatterAmount -= speed;
if (storageComputerConduitItem != null)
{
if (storageComputerConduitItem.textureDictionary != null)
{
storageComputerConduitItem.billboard.GetComponent<Renderer>().material.mainTexture = storageComputerConduitItem.textureDictionary.dictionary["Dark Matter"];
}
storageComputerConduitItem.target = manager.gameObject;
}
}
}
}
if (storageComputerConduitItem != null)
{
storageComputerConduitItem.active = true;
}
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
connectionLine.enabled = true;
}
}
else
{
if (storageComputerConduitItem != null)
{
storageComputerConduitItem.active = false;
}
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
else if (outputObject.GetComponent<InventoryManager>() != null)
{
if (outputObject.GetComponent<RailCart>() != null)
{
outputID = outputObject.GetComponent<RailCart>().ID;
}
else
{
outputID = outputObject.GetComponent<InventoryManager>().ID;
}
if (Vector3.Distance(transform.position, outputObject.transform.position) <= range)
{
if (darkMatterAmount >= speed && connectionFailed == false && speed > 0)
{
connectionLine.enabled = true;
connectionLine.SetPosition(1, outputObject.transform.position);
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
connectionLine.enabled = true;
outputObject.GetComponent<InventoryManager>().AddItem("Dark Matter", speed);
if (outputObject.GetComponent<InventoryManager>().itemAdded == true)
{
darkMatterAmount -= speed;
}
}
}
else
{
connectionLine.enabled = false;
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
}
else
{
connectionLine.enabled = false;
if (connectionFailed == true)
{
if (creationMethod.Equals("spawned"))
{
creationMethod = "built";
}
}
}
}
void Update()
{
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
//Debug.Log(ID + " Machine update tick: " + address * 0.1f);
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
if (inputObject == null || outputObject == null)
@ -70,322 +377,15 @@ public class DarkMatterConduit : MonoBehaviour
connectionFailed = true;
}
}
if (connectionFailed == false)
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (obj != null)
{
if (obj.transform.parent != builtObjects.transform)
{
if (obj.activeInHierarchy)
{
if (obj.GetComponent<DarkMatterCollector>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
if (inputObject == null && obj.GetComponent<DarkMatterCollector>().outputObject == null)
{
if (creationMethod.Equals("spawned"))
{
if (obj.GetComponent<DarkMatterCollector>().ID.Equals(inputID))
{
inputObject = obj;
obj.GetComponent<DarkMatterCollector>().outputObject = this.gameObject;
}
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
inputObject = obj;
obj.GetComponent<DarkMatterCollector>().outputObject = this.gameObject;
}
}
}
}
if (obj.GetComponent<InventoryManager>() != null && obj.GetComponent<Retriever>() == null && obj.GetComponent<AutoCrafter>() == null && !obj.GetComponent<InventoryManager>().ID.Equals("player"))
{
if (outputObject == null)
{
if (inputObject != null)
{
if (obj != inputObject && obj != this.gameObject)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<InventoryManager>().ID + " vs " + outputID);
if (obj.GetComponent<InventoryManager>().ID.Equals(outputID))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range || obj.GetComponent<RailCart>() != null)
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
}
else if (creationMethod.Equals("built"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
if (obj.GetComponent<StorageComputer>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
if (outputObject == null)
{
if (inputObject != null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<InventoryManager>().ID + " vs " + outputID);
if (obj.GetComponent<StorageComputer>().ID.Equals(outputID))
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
if (obj.GetComponent<DarkMatterConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
if (outputObject == null)
{
if (inputObject != null)
{
if (obj != inputObject && obj != this.gameObject)
{
if (obj.GetComponent<DarkMatterConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<DarkMatterConduit>().ID + " vs " + outputID);
if (obj.GetComponent<DarkMatterConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<DarkMatterConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<DarkMatterConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
}
}
}
}
}
}
if (inputObject != null)
{
if (inputObject.GetComponent<DarkMatterCollector>() != null)
{
inputID = inputObject.GetComponent<DarkMatterCollector>().ID;
speed = inputObject.GetComponent<DarkMatterCollector>().speed;
if (inputObject.GetComponent<DarkMatterCollector>().powerON == true && inputObject.GetComponent<DarkMatterCollector>().foundDarkMatter == true && inputObject.GetComponent<DarkMatterCollector>().speed > 0)
{
if (inputObject.GetComponent<DarkMatterCollector>().darkMatterAmount >= speed && connectionFailed == false)
{
inputObject.GetComponent<DarkMatterCollector>().darkMatterAmount -= speed;
darkMatterAmount += speed;
}
}
else
{
if (storageComputerConduitItem != null)
{
storageComputerConduitItem.active = false;
}
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
if (inputObject.GetComponent<DarkMatterConduit>() != null)
{
if (inputObject.GetComponent<DarkMatterConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
{
if (storageComputerConduitItem != null)
{
storageComputerConduitItem.active = false;
}
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
if (outputObject != null)
{
if (outputObject.GetComponent<DarkMatterConduit>() != null)
{
outputObject.GetComponent<DarkMatterConduit>().inputID = ID;
outputID = outputObject.GetComponent<DarkMatterConduit>().ID;
outputObject.GetComponent<DarkMatterConduit>().speed = speed;
if (darkMatterAmount >= speed && connectionFailed == false && speed > 0)
{
outputObject.GetComponent<DarkMatterConduit>().darkMatterAmount += speed;
darkMatterAmount -= speed;
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
}
}
else if (outputObject.GetComponent<StorageComputer>() != null)
{
outputID = outputObject.GetComponent<StorageComputer>().ID;
if (outputObject.GetComponent<StorageComputer>().initialized == true)
{
if (storageComputerConduitItem == null)
{
GameObject storageComputerItemObject = Instantiate(storageComputerConduitItemObject, outputObject.transform.position, outputObject.transform.rotation);
storageComputerItemObject.transform.parent = outputObject.transform;
storageComputerConduitItem = storageComputerItemObject.GetComponent<ConduitItem>();
}
if (darkMatterAmount >= speed && connectionFailed == false && speed > 0)
{
connectionLine.enabled = true;
connectionLine.SetPosition(1, outputObject.transform.position);
bool itemAdded = false;
foreach (InventoryManager manager in outputObject.GetComponent<StorageComputer>().computerContainers)
{
if (itemAdded == false)
{
manager.AddItem("Dark Matter", speed);
if (manager.itemAdded == true)
{
itemAdded = true;
darkMatterAmount -= speed;
if (storageComputerConduitItem != null)
{
if (storageComputerConduitItem.textureDictionary != null)
{
storageComputerConduitItem.billboard.GetComponent<Renderer>().material.mainTexture = storageComputerConduitItem.textureDictionary.dictionary["Dark Matter"];
}
storageComputerConduitItem.target = manager.gameObject;
}
}
}
}
if (storageComputerConduitItem != null)
{
storageComputerConduitItem.active = true;
}
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
connectionLine.enabled = true;
}
}
else
{
if (storageComputerConduitItem != null)
{
storageComputerConduitItem.active = false;
}
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
else if (outputObject.GetComponent<InventoryManager>() != null)
{
if (outputObject.GetComponent<RailCart>() != null)
{
outputID = outputObject.GetComponent<RailCart>().ID;
}
else
{
outputID = outputObject.GetComponent<InventoryManager>().ID;
}
if (Vector3.Distance(transform.position, outputObject.transform.position) <= range)
{
if (darkMatterAmount >= speed && connectionFailed == false && speed > 0)
{
connectionLine.enabled = true;
connectionLine.SetPosition(1, outputObject.transform.position);
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
connectionLine.enabled = true;
outputObject.GetComponent<InventoryManager>().AddItem("Dark Matter", speed);
if (outputObject.GetComponent<InventoryManager>().itemAdded == true)
{
darkMatterAmount -= speed;
}
}
}
else
{
connectionLine.enabled = false;
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
}
else
{
connectionLine.enabled = false;
if (connectionFailed == true)
{
if (creationMethod.Equals("spawned"))
{
creationMethod = "built";
}
FindConnections();
}
}
HandleIO();
if (inputObject != null && outputObject != null)
{
connectionAttempts = 0;

View File

@ -25,7 +25,6 @@ public class ElectricLight : MonoBehaviour
updateTick += 1 * Time.deltaTime;
if (updateTick > 1 + (address * 0.001f))
{
//Debug.Log(ID + " Machine update tick: " + address * 0.1f);
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
if (powerON == true)

View File

@ -5,6 +5,7 @@ using UnityEngine;
public class Explosion : MonoBehaviour
{
private float timer;
// Start is called before the first frame update
void Start()
{

View File

@ -40,12 +40,135 @@ public class Extruder : MonoBehaviour
builtObjects = GameObject.Find("Built_Objects");
}
bool IsValidObject(GameObject obj)
{
if (obj != null)
{
return obj.transform.parent != builtObjects.transform && obj.activeInHierarchy;
}
return false;
}
bool IsValidOutputObject(GameObject obj)
{
return outputObject == null && inputObject != null && obj != inputObject && obj != gameObject;
}
private void ConnectToOutput()
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (IsValidObject(obj))
{
if (obj.GetComponent<UniversalConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < 20)
{
if (obj.GetComponent<UniversalConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<UniversalConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
private void SetOutputType()
{
inputType = inputObject.GetComponent<UniversalConduit>().type;
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Copper Ingot"))
{
outputType = "Copper Wire";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Aluminum Ingot"))
{
outputType = "Aluminum Wire";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Steel Ingot"))
{
outputType = "Steel Pipe";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Iron Ingot"))
{
outputType = "Iron Pipe";
}
}
private void HandleOutput()
{
if (outputObject != null)
{
if (outputObject.GetComponent<UniversalConduit>() != null)
{
outputObject.GetComponent<UniversalConduit>().inputID = ID;
outputObject.GetComponent<UniversalConduit>().type = outputType;
outputObject.GetComponent<UniversalConduit>().speed = speed;
outputID = outputObject.GetComponent<UniversalConduit>().ID;
if (amount >= speed)
{
if (outputType.Equals(outputObject.GetComponent<UniversalConduit>().type))
{
if (powerON == true && connectionFailed == false && inputObject != null && speed > 0)
{
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
outputObject.GetComponent<UniversalConduit>().amount += speed - heat;
amount -= speed - heat;
machineTimer = 0;
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
}
}
}
}
}
else
{
// Reset the output connection, allow new connections to be made
connectionLine.enabled = false;
if (connectionFailed == true)
{
if (creationMethod.Equals("spawned"))
{
creationMethod = "built";
}
}
}
}
void Update()
{
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
//Debug.Log(ID + " Machine update tick: " + address * 0.1f);
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
if (speed > 1)
@ -81,88 +204,20 @@ public class Extruder : MonoBehaviour
}
if (connectionFailed == false)
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (obj != null)
{
if (obj.transform.parent != builtObjects.transform)
{
if (obj.activeInHierarchy)
{
if (obj.GetComponent<UniversalConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
if (outputObject == null)
{
if (inputObject != null)
{
if (obj != inputObject && obj != this.gameObject)
{
if (obj.GetComponent<UniversalConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<UniversalConduit>().ID + " vs " + outputID);
if (obj.GetComponent<UniversalConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
//Debug.Log("Setting " + ID + " output conduit type to: " + outputType);
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
}
}
}
}
ConnectToOutput();
}
}
if (inputObject != null)
{
if (inputObject.GetComponent<UniversalConduit>() != null)
{
// Determine the item to be processed before it enters the inventory
if (amount < 1)
{
inputType = inputObject.GetComponent<UniversalConduit>().type;
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Copper Ingot"))
{
outputType = "Copper Wire";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Aluminum Ingot"))
{
outputType = "Aluminum Wire";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Steel Ingot"))
{
outputType = "Steel Pipe";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Iron Ingot"))
{
outputType = "Iron Pipe";
}
SetOutputType();
}
// Disable effects when there is no input to this machine
if (inputObject.GetComponent<UniversalConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
{
conduitItem.GetComponent<ConduitItem>().active = false;
@ -172,54 +227,13 @@ public class Extruder : MonoBehaviour
}
else
{
// With no input object, this machine is inactive
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
}
if (outputObject != null)
{
if (outputObject.GetComponent<UniversalConduit>() != null)
{
outputObject.GetComponent<UniversalConduit>().inputID = ID;
outputObject.GetComponent<UniversalConduit>().type = outputType;
outputObject.GetComponent<UniversalConduit>().speed = speed;
//Debug.Log("Setting " + ID + " output conduit type to: " + outputType);
outputID = outputObject.GetComponent<UniversalConduit>().ID;
if (amount >= speed)
{
if (outputType.Equals(outputObject.GetComponent<UniversalConduit>().type))
{
if (powerON == true && connectionFailed == false && inputObject != null && speed > 0)
{
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
outputObject.GetComponent<UniversalConduit>().amount += speed - heat;
amount -= speed - heat;
machineTimer = 0;
}
}
else
{
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
}
}
}
}
}
else
{
connectionLine.enabled = false;
if (connectionFailed == true)
{
if (creationMethod.Equals("spawned"))
{
creationMethod = "built";
}
}
}
HandleOutput();
if (inputObject != null && outputObject != null)
{
connectionAttempts = 0;

View File

@ -41,12 +41,151 @@ public class GearCutter : MonoBehaviour
builtObjects = GameObject.Find("Built_Objects");
}
bool IsValidObject(GameObject obj)
{
if (obj != null)
{
return obj.transform.parent != builtObjects.transform && obj.activeInHierarchy;
}
return false;
}
bool IsValidOutputObject(GameObject obj)
{
return outputObject == null && inputObject != null && obj != inputObject && obj != gameObject;
}
private void ConnectToOutput()
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (IsValidObject(obj))
{
if (obj.GetComponent<UniversalConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < 20)
{
if (obj.GetComponent<UniversalConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
if (obj.GetComponent<UniversalConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
private void SetOutputType()
{
inputType = inputObject.GetComponent<UniversalConduit>().type;
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Copper Plate"))
{
outputType = "Copper Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Iron Plate"))
{
outputType = "Iron Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Tin Plate"))
{
outputType = "Tin Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Bronze Plate"))
{
outputType = "Bronze Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Steel Plate"))
{
outputType = "Steel Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Aluminum Plate"))
{
outputType = "Aluminum Gear";
}
}
private void HandleOutput()
{
if (outputObject != null)
{
if (outputObject.GetComponent<UniversalConduit>() != null)
{
outputObject.GetComponent<UniversalConduit>().inputID = ID;
outputObject.GetComponent<UniversalConduit>().type = outputType;
outputObject.GetComponent<UniversalConduit>().speed = speed;
outputID = outputObject.GetComponent<UniversalConduit>().ID;
if (amount >= speed)
{
if (outputType.Equals(outputObject.GetComponent<UniversalConduit>().type))
{
if (powerON == true && connectionFailed == false && inputObject != null && speed > 0)
{
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
laserCutter.SetActive(true);
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
outputObject.GetComponent<UniversalConduit>().amount += speed - heat;
amount -= speed - heat;
machineTimer = 0;
}
}
else
{
machineTimer = 0;
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
laserCutter.SetActive(false);
}
}
}
}
}
else
{
// Reset the output connection, allow new connections to be made
connectionLine.enabled = false;
if (connectionFailed == true)
{
if (creationMethod.Equals("spawned"))
{
creationMethod = "built";
}
}
}
}
void Update()
{
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
//Debug.Log(ID + " Machine update tick: " + address * 0.1f);
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
if (speed > 1)
@ -82,96 +221,20 @@ public class GearCutter : MonoBehaviour
}
if (connectionFailed == false)
{
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (obj != null)
{
if (obj.transform.parent != builtObjects.transform)
{
if (obj.activeInHierarchy)
{
if (obj.GetComponent<UniversalConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
if (outputObject == null)
{
if (inputObject != null)
{
if (obj != inputObject && obj != this.gameObject)
{
if (obj.GetComponent<UniversalConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<UniversalConduit>().ID + " vs " + outputID);
if (obj.GetComponent<UniversalConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
//Debug.Log("Setting " + ID + " output conduit type to: " + outputType);
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = outputType;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
}
}
}
}
ConnectToOutput();
}
}
if (inputObject != null)
{
if (inputObject.GetComponent<UniversalConduit>() != null)
{
// Determine the item to be processed before it enters the inventory
if (amount < 1)
{
inputType = inputObject.GetComponent<UniversalConduit>().type;
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Copper Plate"))
{
outputType = "Copper Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Iron Plate"))
{
outputType = "Iron Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Tin Plate"))
{
outputType = "Tin Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Bronze Plate"))
{
outputType = "Bronze Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Steel Plate"))
{
outputType = "Steel Gear";
}
if (inputObject.GetComponent<UniversalConduit>().type.Equals("Aluminum Plate"))
{
outputType = "Aluminum Gear";
}
SetOutputType();
}
// Disable effects when there is no input to this machine
if (inputObject.GetComponent<UniversalConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
{
conduitItem.GetComponent<ConduitItem>().active = false;
@ -183,61 +246,15 @@ public class GearCutter : MonoBehaviour
}
else
{
// With no input object, this machine is inactive
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
laserCutter.SetActive(false);
}
if (outputObject != null)
{
if (outputObject.GetComponent<UniversalConduit>() != null)
{
outputObject.GetComponent<UniversalConduit>().inputID = ID;
outputObject.GetComponent<UniversalConduit>().type = outputType;
outputObject.GetComponent<UniversalConduit>().speed = speed;
//Debug.Log("Setting " + ID + " output conduit type to: " + outputType);
outputID = outputObject.GetComponent<UniversalConduit>().ID;
if (amount >= speed)
{
if (outputType.Equals(outputObject.GetComponent<UniversalConduit>().type))
{
if (powerON == true && connectionFailed == false && inputObject != null && speed > 0)
{
conduitItem.GetComponent<ConduitItem>().active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
laserCutter.SetActive(true);
machineTimer += 1;
if (machineTimer > 5 - (address * 0.01f))
{
outputObject.GetComponent<UniversalConduit>().amount += speed - heat;
amount -= speed - heat;
machineTimer = 0;
}
}
else
{
machineTimer = 0;
conduitItem.GetComponent<ConduitItem>().active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
laserCutter.SetActive(false);
}
}
}
}
}
else
{
connectionLine.enabled = false;
if (connectionFailed == true)
{
if (creationMethod.Equals("spawned"))
{
creationMethod = "built";
}
}
}
HandleOutput();
if (inputObject != null && outputObject != null)
{
connectionAttempts = 0;

View File

@ -19,7 +19,6 @@ public class Glass : MonoBehaviour
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
//Debug.Log(ID + " Physics update tick: " + address * 0.1f);
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
}

View File

@ -578,67 +578,67 @@ public class InventoryGUI : MonoBehaviour
GUI.DrawTexture(GetComponent<GuiCoordinates>().craftingBackgroundRect, GetComponent<TextureDictionary>().dictionary["Interface Background"]);
if (GUI.Button(GetComponent<GuiCoordinates>().button1Rect, "Storage Container"))
{
playerCrafting.CraftStorageContainer();
playerCrafting.CraftItem(new string[] { "Iron Plate" },new int[] { 6 }, "Storage Container", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button2Rect, "Auger"))
{
playerCrafting.CraftAuger();
playerCrafting.CraftItem(new string[] { "Iron Ingot", "Copper Ingot" }, new int[] { 10, 10 }, "Auger", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button3Rect, "Extruder"))
{
playerCrafting.CraftExtruder();
playerCrafting.CraftItem(new string[] { "Iron Ingot", "Copper Ingot" }, new int[] { 10, 10 }, "Extruder", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button4Rect, "Press"))
{
playerCrafting.CraftPress();
playerCrafting.CraftItem(new string[] { "Iron Ingot", "Iron Pipe", "Copper Wire" }, new int[] { 10, 10, 10 }, "Press", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button5Rect, "Gear Cutter"))
{
playerCrafting.CraftGearCutter();
playerCrafting.CraftItem(new string[] { "Iron Plate", "Tin Plate", "Iron Pipe", "Aluminum Wire", "Copper Wire" }, new int[] { 5, 5, 5, 10, 10 }, "Gear Cutter", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button6Rect, "Universal Extractor"))
{
playerCrafting.CraftUniversalExtractor();
playerCrafting.CraftItem(new string[] { "Iron Plate", "Iron Pipe", "Copper Wire", "Dark Matter" }, new int[] { 10, 10, 10, 10 }, "Universal Extractor", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button7Rect, "Universal Conduit"))
{
playerCrafting.CraftUniversalConduit();
playerCrafting.CraftItem(new string[] { "Iron Plate", "Iron Pipe", "Copper Wire", "Dark Matter" }, new int[] { 5, 5, 5, 5 }, "Universal Conduit", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button9Rect, "Retriever"))
{
playerCrafting.CraftRetriever();
playerCrafting.CraftItem(new string[] { "Iron Plate", "Iron Pipe", "Copper Wire", "Electric Motor", "Circuit Board" }, new int[] { 4 , 2, 4, 2, 2 }, "Retriever", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button10Rect, "Solar Panel"))
{
playerCrafting.CraftSolarPanel();
playerCrafting.CraftItem(new string[] { "Iron Plate", "Iron Pipe", "Copper Wire", "Copper Plate", "Glass Block" }, new int[] { 4, 4, 4, 4, 4 }, "Solar Panel", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button11Rect, "Generator"))
{
playerCrafting.CraftGenerator();
playerCrafting.CraftItem(new string[] { "Iron Plate", "Iron Pipe", "Copper Wire", "Copper Plate", "Glass Block" }, new int[] { 4, 4, 4, 4, 4 }, "Solar Panel", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button12Rect, "Nuclear Reactor"))
{
playerCrafting.CraftNuclearReactor();
playerCrafting.CraftItem(new string[] { "Steel Plate", "Steel Pipe", "Copper Wire", "Copper Plate", "Glass Block", "Dark Matter" }, new int[] { 10, 10, 10, 10, 10, 10 }, "Nuclear Reactor", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button13Rect, "Reactor Turbine"))
{
playerCrafting.CraftReactorTurbine();
playerCrafting.CraftItem(new string[] { "Generator", "Glass Block", "Steel Pipe", "Steel Gear", "Copper Wire", "Steel Plate" }, new int[] { 1, 1, 2, 2, 4, 4 }, "Reactor Turbine", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button14Rect, "Power Conduit"))
{
playerCrafting.CraftPowerConduit();
playerCrafting.CraftItem(new string[] { "Aluminum Plate", "Copper Wire", "Glass Block" }, new int[] { 4, 4, 4 }, "Power Conduit", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button15Rect, "Heat Exchanger"))
{
playerCrafting.CraftHeatExchanger();
playerCrafting.CraftItem(new string[] { "Steel Plate", "Steel Pipe" }, new int[] { 10, 10 }, "Heat Exchanger", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button17Rect, "Smelter"))
{
playerCrafting.CraftSmelter();
playerCrafting.CraftItem(new string[] { "Iron Pipe", "Iron Plate", "Copper Wire" }, new int[] { 5, 10, 10 }, "Smelter", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button18Rect, "Alloy Smelter"))
{
playerCrafting.CraftAlloySmelter();
playerCrafting.CraftItem(new string[] { "Iron Plate", "Tin Plate", "Iron Pipe", "Iron Gear", "Aluminum Wire", "Copper Wire" }, new int[] { 20, 20, 20, 20, 40, 40 }, "Alloy Smelter", 1);
}
if (GUI.Button(GetComponent<GuiCoordinates>().button19Rect, "DM Collector"))
{

View File

@ -7,7 +7,54 @@ public class MachineCrafting : MonoBehaviour
public InventoryManager inventoryManager;
public bool missingItem;
public void CraftIronBlock()
public void CraftItem(string[] ingredients, int[] amounts, string output, int outputAmount)
{
int[] slots = new int[ingredients.Length];
bool[] found = new bool[ingredients.Length];
for (int i = 0; i < ingredients.Length; i++)
{
int currentSlot = 0;
foreach (InventorySlot slot in inventoryManager.inventory)
{
if (slot.amountInSlot >= amounts[i])
{
if (slot.typeInSlot.Equals(ingredients[i]))
{
found[i] = true;
slots[i] = currentSlot;
}
}
currentSlot++;
}
}
foreach (bool b in found)
{
if (!missingItem)
{
missingItem |= !b;
}
}
if (!missingItem)
{
inventoryManager.AddItem(output, outputAmount);
if (inventoryManager.itemAdded)
{
for (int i = 0; i < ingredients.Length; i++)
{
inventoryManager.inventory[slots[i]].amountInSlot -= amounts[i];
if (inventoryManager.inventory[slots[i]].amountInSlot <= 0)
{
inventoryManager.inventory[slots[i]].typeInSlot = "nothing";
}
}
}
}
}
public bool CraftIronBlock()
{
bool foundItems = false;
foreach (InventorySlot slot in inventoryManager.inventory)
@ -36,9 +83,10 @@ public class MachineCrafting : MonoBehaviour
{
missingItem = true;
}
return true;
}
public void CraftIronRamp()
public bool CraftIronRamp()
{
bool foundItems = false;
foreach (InventorySlot slot in inventoryManager.inventory)
@ -67,9 +115,10 @@ public class MachineCrafting : MonoBehaviour
{
missingItem = true;
}
return true;
}
public void CraftSteelBlock()
public bool CraftSteelBlock()
{
bool foundItems = false;
foreach (InventorySlot slot in inventoryManager.inventory)
@ -98,9 +147,10 @@ public class MachineCrafting : MonoBehaviour
{
missingItem = true;
}
return true;
}
public void CraftSteelRamp()
public bool CraftSteelRamp()
{
bool foundItems = false;
foreach (InventorySlot slot in inventoryManager.inventory)
@ -129,9 +179,10 @@ public class MachineCrafting : MonoBehaviour
{
missingItem = true;
}
return true;
}
public void CraftQuantumHatchway()
public bool CraftQuantumHatchway()
{
bool foundTin = false;
bool foundDarkMatter = false;
@ -179,9 +230,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftElectricLight()
public bool CraftElectricLight()
{
bool foundGlass = false;
bool foundCopperWire = false;
@ -241,9 +293,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftAuger()
public bool CraftAuger()
{
bool foundIron = false;
bool foundCopper = false;
@ -291,9 +344,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftStorageContainer()
public bool CraftStorageContainer()
{
bool foundItems = false;
foreach (InventorySlot slot in inventoryManager.inventory)
@ -322,9 +376,10 @@ public class MachineCrafting : MonoBehaviour
{
missingItem = true;
}
return true;
}
public void CraftExtruder()
public bool CraftExtruder()
{
bool foundIron = false;
bool foundCopper = false;
@ -372,9 +427,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftPress()
public bool CraftPress()
{
bool foundIronIngot = false;
bool foundIronPipe = false;
@ -431,9 +487,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftUniversalExtractor()
public bool CraftUniversalExtractor()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -511,9 +568,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftUniversalConduit()
public bool CraftUniversalConduit()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -591,9 +649,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftRetriever()
public bool CraftRetriever()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -686,9 +745,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftGenerator()
public bool CraftGenerator()
{
bool foundSmelter = false;
bool foundIronPipe = false;
@ -796,9 +856,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftReactorTurbine()
public bool CraftReactorTurbine()
{
bool foundGenerator = false;
bool foundCopperWire = false;
@ -906,9 +967,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftRailCartHub()
public bool CraftRailCartHub()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -971,9 +1033,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftRailCart()
public bool CraftRailCart()
{
bool foundElectricMotor = false;
bool foundCopperWire = false;
@ -1081,9 +1144,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftCircuitBoard()
public bool CraftCircuitBoard()
{
bool foundTinPlate = false;
bool foundGlassBlock = false;
@ -1161,9 +1225,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftMotor()
public bool CraftMotor()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -1241,9 +1306,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftAutoCrafter()
public bool CraftAutoCrafter()
{
bool foundBronzeGear = false;
bool foundSteelPlate = false;
@ -1336,9 +1402,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftSolarPanel()
public bool CraftSolarPanel()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -1427,9 +1494,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftPowerConduit()
public bool CraftPowerConduit()
{
bool foundAluminumPlate = false;
bool foundGlassBlock = false;
@ -1492,9 +1560,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftNuclearReactor()
public bool CraftNuclearReactor()
{
bool foundSteelPlate = false;
bool foundSteelPipe = false;
@ -1598,9 +1667,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftHeatExchanger()
public bool CraftHeatExchanger()
{
bool foundPlates = false;
bool foundPipe = false;
@ -1648,9 +1718,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftSmelter()
public bool CraftSmelter()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -1713,9 +1784,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftGearCutter()
public bool CraftGearCutter()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -1799,9 +1871,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftStorageComputer()
public bool CraftStorageComputer()
{
bool foundRetriever = false;
bool foundUniversalConduit = false;
@ -1912,9 +1985,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftAlloySmelter()
public bool CraftAlloySmelter()
{
bool foundIronPlate = false;
bool foundIronPipe = false;
@ -2010,9 +2084,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftTurret()
public bool CraftTurret()
{
bool foundSteelPlate = false;
bool foundSteelPipe = false;
@ -2135,9 +2210,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftDarkMatterCollector()
public bool CraftDarkMatterCollector()
{
bool foundSteelPlate = false;
bool foundSteelPipe = false;
@ -2257,9 +2333,10 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
public void CraftDarkMatterConduit()
public bool CraftDarkMatterConduit()
{
bool foundSteelPlate = false;
bool foundSteelPipe = false;
@ -2379,6 +2456,7 @@ public class MachineCrafting : MonoBehaviour
}
}
}
return true;
}
}

View File

@ -14,6 +14,67 @@ public class PlayerCrafting : MonoBehaviour
playerInventory = GetComponent<InventoryManager>();
}
public void CraftItem(string[] ingredients, int[] amounts, string output, int outputAmount)
{
if (Input.GetKey(KeyCode.LeftShift))
{
for (int i = 0; i < amounts.Length; i++)
{
amounts[i] *= 10;
}
outputAmount *= 10;
}
int[] slots = new int[ingredients.Length];
bool[] found = new bool[ingredients.Length];
for (int i = 0; i < ingredients.Length; i++)
{
int currentSlot = 0;
foreach (InventorySlot slot in playerInventory.inventory)
{
if (slot.amountInSlot >= amounts[i])
{
if (slot.typeInSlot.Equals(ingredients[i]))
{
found[i] = true;
slots[i] = currentSlot;
}
}
currentSlot++;
}
}
foreach (bool b in found)
{
if (!missingItem)
{
missingItem |= !b;
}
}
if (!missingItem)
{
playerInventory.AddItem(output, outputAmount);
if (playerInventory.itemAdded)
{
for (int i = 0; i < ingredients.Length; i++)
{
playerInventory.inventory[slots[i]].amountInSlot -= amounts[i];
if (playerInventory.inventory[slots[i]].amountInSlot <= 0)
{
playerInventory.inventory[slots[i]].typeInSlot = "nothing";
}
}
playerController.playCraftingSound();
}
}
else
{
playerController.playMissingItemsSound();
}
}
public void CraftIronBlock()
{
if (Input.GetKey(KeyCode.LeftShift))

View File

@ -8,83 +8,85 @@ public class TextureDictionary : MonoBehaviour
void Start()
{
dictionary = new Dictionary<string, Texture2D>();
dictionary.Add("Tablet", Resources.Load("Tablet") as Texture2D);
dictionary.Add("Menu Background", Resources.Load("MenuBackground") as Texture2D);
dictionary.Add("Interface Background", Resources.Load("InterfaceBackground") as Texture2D);
dictionary.Add("Container Background", Resources.Load("ContainerBackground") as Texture2D);
dictionary.Add("Crafting Background", Resources.Load("CraftingBackground") as Texture2D);
dictionary.Add("Selection Box", Resources.Load("SelectionBox") as Texture2D);
dictionary.Add("Bronze Schematic", Resources.Load("BronzeSchematic") as Texture2D);
dictionary.Add("Dark Matter Schematic", Resources.Load("DarkMatterSchematic") as Texture2D);
dictionary.Add("Gear Schematic", Resources.Load("GearSchematic") as Texture2D);
dictionary.Add("Heat Exchanger Schematic", Resources.Load("HeatExchangerSchematic") as Texture2D);
dictionary.Add("Plate Schematic", Resources.Load("PlateSchematic") as Texture2D);
dictionary.Add("Steel Schematic", Resources.Load("SteelSchematic") as Texture2D);
dictionary.Add("Wire Schematic", Resources.Load("WireSchematic") as Texture2D);
dictionary.Add("Crosshair", Resources.Load("Crosshair") as Texture2D);
dictionary.Add("Dark Matter", Resources.Load("DarkMatter") as Texture2D);
dictionary.Add("Iron Ingot", Resources.Load("IronIngot") as Texture2D);
dictionary.Add("Tin Ingot", Resources.Load("TinIngot") as Texture2D);
dictionary.Add("Aluminum Ingot", Resources.Load("AluminumIngot") as Texture2D);
dictionary.Add("Copper Ingot", Resources.Load("CopperIngot") as Texture2D);
dictionary.Add("Bronze Ingot", Resources.Load("BronzeIngot") as Texture2D);
dictionary.Add("Steel Ingot", Resources.Load("IronIngot") as Texture2D);
dictionary.Add("Iron Block", Resources.Load("IronBlock") as Texture2D);
dictionary.Add("Iron Ramp", Resources.Load("IronRamp") as Texture2D);
dictionary.Add("Steel Block", Resources.Load("SteelBlock") as Texture2D);
dictionary.Add("Steel Ramp", Resources.Load("SteelRamp") as Texture2D);
dictionary.Add("Glass Block", Resources.Load("Glass") as Texture2D);
dictionary.Add("Brick", Resources.Load("Brick") as Texture2D);
dictionary.Add("Electric Light", Resources.Load("Light") as Texture2D);
dictionary.Add("Dark Matter Collector", Resources.Load("DarkMatterCollector") as Texture2D);
dictionary.Add("Dark Matter Conduit", Resources.Load("DarkMatterConduit") as Texture2D);
dictionary.Add("Universal Conduit", Resources.Load("UniversalConduit") as Texture2D);
dictionary.Add("Universal Extractor", Resources.Load("UniversalExtractor") as Texture2D);
dictionary.Add("Auger", Resources.Load("Auger") as Texture2D);
dictionary.Add("Quantum Hatchway", Resources.Load("Hatch") as Texture2D);
dictionary.Add("Storage Container", Resources.Load("StorageContainer") as Texture2D);
dictionary.Add("Copper Ore", Resources.Load("CopperOre") as Texture2D);
dictionary.Add("Iron Ore", Resources.Load("IronOre") as Texture2D);
dictionary.Add("Tin Ore", Resources.Load("TinOre") as Texture2D);
dictionary.Add("Aluminum Ore", Resources.Load("AluminumOre") as Texture2D);
dictionary.Add("Copper Plate", Resources.Load("CopperPlate") as Texture2D);
dictionary.Add("Iron Plate", Resources.Load("IronPlate") as Texture2D);
dictionary.Add("Tin Plate", Resources.Load("TinPlate") as Texture2D);
dictionary.Add("Bronze Plate", Resources.Load("BronzePlate") as Texture2D);
dictionary.Add("Steel Plate", Resources.Load("IronPlate") as Texture2D);
dictionary.Add("Aluminum Plate", Resources.Load("AluminumPlate") as Texture2D);
dictionary.Add("Copper Gear", Resources.Load("CopperGear") as Texture2D);
dictionary.Add("Iron Gear", Resources.Load("IronGear") as Texture2D);
dictionary.Add("Tin Gear", Resources.Load("TinGear") as Texture2D);
dictionary.Add("Bronze Gear", Resources.Load("BronzeGear") as Texture2D);
dictionary.Add("Steel Gear", Resources.Load("IronGear") as Texture2D);
dictionary.Add("Aluminum Gear", Resources.Load("AluminumGear") as Texture2D);
dictionary.Add("Smelter", Resources.Load("Smelter") as Texture2D);
dictionary.Add("Turret", Resources.Load("Turret") as Texture2D);
dictionary.Add("Solar Panel", Resources.Load("SolarPanel") as Texture2D);
dictionary.Add("Generator", Resources.Load("Generator") as Texture2D);
dictionary.Add("Power Conduit", Resources.Load("PowerConduit") as Texture2D);
dictionary.Add("Nuclear Reactor", Resources.Load("NuclearReactor") as Texture2D);
dictionary.Add("Reactor Turbine", Resources.Load("ReactorTurbine") as Texture2D);
dictionary.Add("Alloy Smelter", Resources.Load("AlloySmelter") as Texture2D);
dictionary.Add("Press", Resources.Load("Press") as Texture2D);
dictionary.Add("Extruder", Resources.Load("Extruder") as Texture2D);
dictionary.Add("Retriever", Resources.Load("Retriever") as Texture2D);
dictionary.Add("Heat Exchanger", Resources.Load("HeatExchanger") as Texture2D);
dictionary.Add("Gear Cutter", Resources.Load("GearCutter") as Texture2D);
dictionary.Add("Copper Wire", Resources.Load("CopperWire") as Texture2D);
dictionary.Add("Aluminum Wire", Resources.Load("AluminumWire") as Texture2D);
dictionary.Add("Iron Pipe", Resources.Load("IronPipe") as Texture2D);
dictionary.Add("Steel Pipe", Resources.Load("SteelPipe") as Texture2D);
dictionary.Add("Coal", Resources.Load("CoalOre") as Texture2D);
dictionary.Add("Ice", Resources.Load("Ice") as Texture2D);
dictionary.Add("Regolith", Resources.Load("Regolith") as Texture2D);
dictionary.Add("Auto Crafter", Resources.Load("AutoCrafter") as Texture2D);
dictionary.Add("Rail Cart", Resources.Load("RailCart") as Texture2D);
dictionary.Add("Rail Cart Hub", Resources.Load("RailCartHub") as Texture2D);
dictionary.Add("Storage Computer", Resources.Load("StorageComputer") as Texture2D);
dictionary.Add("Circuit Board", Resources.Load("CircuitBoard") as Texture2D);
dictionary.Add("Electric Motor", Resources.Load("Motor") as Texture2D);
dictionary = new Dictionary<string, Texture2D>
{
{ "Tablet", Resources.Load("Tablet") as Texture2D },
{ "Menu Background", Resources.Load("MenuBackground") as Texture2D },
{ "Interface Background", Resources.Load("InterfaceBackground") as Texture2D },
{ "Container Background", Resources.Load("ContainerBackground") as Texture2D },
{ "Crafting Background", Resources.Load("CraftingBackground") as Texture2D },
{ "Selection Box", Resources.Load("SelectionBox") as Texture2D },
{ "Bronze Schematic", Resources.Load("BronzeSchematic") as Texture2D },
{ "Dark Matter Schematic", Resources.Load("DarkMatterSchematic") as Texture2D },
{ "Gear Schematic", Resources.Load("GearSchematic") as Texture2D },
{ "Heat Exchanger Schematic", Resources.Load("HeatExchangerSchematic") as Texture2D },
{ "Plate Schematic", Resources.Load("PlateSchematic") as Texture2D },
{ "Steel Schematic", Resources.Load("SteelSchematic") as Texture2D },
{ "Wire Schematic", Resources.Load("WireSchematic") as Texture2D },
{ "Crosshair", Resources.Load("Crosshair") as Texture2D },
{ "Dark Matter", Resources.Load("DarkMatter") as Texture2D },
{ "Iron Ingot", Resources.Load("IronIngot") as Texture2D },
{ "Tin Ingot", Resources.Load("TinIngot") as Texture2D },
{ "Aluminum Ingot", Resources.Load("AluminumIngot") as Texture2D },
{ "Copper Ingot", Resources.Load("CopperIngot") as Texture2D },
{ "Bronze Ingot", Resources.Load("BronzeIngot") as Texture2D },
{ "Steel Ingot", Resources.Load("IronIngot") as Texture2D },
{ "Iron Block", Resources.Load("IronBlock") as Texture2D },
{ "Iron Ramp", Resources.Load("IronRamp") as Texture2D },
{ "Steel Block", Resources.Load("SteelBlock") as Texture2D },
{ "Steel Ramp", Resources.Load("SteelRamp") as Texture2D },
{ "Glass Block", Resources.Load("Glass") as Texture2D },
{ "Brick", Resources.Load("Brick") as Texture2D },
{ "Electric Light", Resources.Load("Light") as Texture2D },
{ "Dark Matter Collector", Resources.Load("DarkMatterCollector") as Texture2D },
{ "Dark Matter Conduit", Resources.Load("DarkMatterConduit") as Texture2D },
{ "Universal Conduit", Resources.Load("UniversalConduit") as Texture2D },
{ "Universal Extractor", Resources.Load("UniversalExtractor") as Texture2D },
{ "Auger", Resources.Load("Auger") as Texture2D },
{ "Quantum Hatchway", Resources.Load("Hatch") as Texture2D },
{ "Storage Container", Resources.Load("StorageContainer") as Texture2D },
{ "Copper Ore", Resources.Load("CopperOre") as Texture2D },
{ "Iron Ore", Resources.Load("IronOre") as Texture2D },
{ "Tin Ore", Resources.Load("TinOre") as Texture2D },
{ "Aluminum Ore", Resources.Load("AluminumOre") as Texture2D },
{ "Copper Plate", Resources.Load("CopperPlate") as Texture2D },
{ "Iron Plate", Resources.Load("IronPlate") as Texture2D },
{ "Tin Plate", Resources.Load("TinPlate") as Texture2D },
{ "Bronze Plate", Resources.Load("BronzePlate") as Texture2D },
{ "Steel Plate", Resources.Load("IronPlate") as Texture2D },
{ "Aluminum Plate", Resources.Load("AluminumPlate") as Texture2D },
{ "Copper Gear", Resources.Load("CopperGear") as Texture2D },
{ "Iron Gear", Resources.Load("IronGear") as Texture2D },
{ "Tin Gear", Resources.Load("TinGear") as Texture2D },
{ "Bronze Gear", Resources.Load("BronzeGear") as Texture2D },
{ "Steel Gear", Resources.Load("IronGear") as Texture2D },
{ "Aluminum Gear", Resources.Load("AluminumGear") as Texture2D },
{ "Smelter", Resources.Load("Smelter") as Texture2D },
{ "Turret", Resources.Load("Turret") as Texture2D },
{ "Solar Panel", Resources.Load("SolarPanel") as Texture2D },
{ "Generator", Resources.Load("Generator") as Texture2D },
{ "Power Conduit", Resources.Load("PowerConduit") as Texture2D },
{ "Nuclear Reactor", Resources.Load("NuclearReactor") as Texture2D },
{ "Reactor Turbine", Resources.Load("ReactorTurbine") as Texture2D },
{ "Alloy Smelter", Resources.Load("AlloySmelter") as Texture2D },
{ "Press", Resources.Load("Press") as Texture2D },
{ "Extruder", Resources.Load("Extruder") as Texture2D },
{ "Retriever", Resources.Load("Retriever") as Texture2D },
{ "Heat Exchanger", Resources.Load("HeatExchanger") as Texture2D },
{ "Gear Cutter", Resources.Load("GearCutter") as Texture2D },
{ "Copper Wire", Resources.Load("CopperWire") as Texture2D },
{ "Aluminum Wire", Resources.Load("AluminumWire") as Texture2D },
{ "Iron Pipe", Resources.Load("IronPipe") as Texture2D },
{ "Steel Pipe", Resources.Load("SteelPipe") as Texture2D },
{ "Coal", Resources.Load("CoalOre") as Texture2D },
{ "Ice", Resources.Load("Ice") as Texture2D },
{ "Regolith", Resources.Load("Regolith") as Texture2D },
{ "Auto Crafter", Resources.Load("AutoCrafter") as Texture2D },
{ "Rail Cart", Resources.Load("RailCart") as Texture2D },
{ "Rail Cart Hub", Resources.Load("RailCartHub") as Texture2D },
{ "Storage Computer", Resources.Load("StorageComputer") as Texture2D },
{ "Circuit Board", Resources.Load("CircuitBoard") as Texture2D },
{ "Electric Motor", Resources.Load("Motor") as Texture2D }
};
}
}

View File

@ -45,6 +45,353 @@ public class UniversalConduit : MonoBehaviour
}
}
bool IsValidObject(GameObject obj)
{
if (obj != null)
{
return obj.transform.parent != builtObjects.transform && obj.activeInHierarchy;
}
return false;
}
bool IsValidOutputObject(GameObject obj)
{
return outputObject == null && inputObject != null && obj != inputObject && obj != gameObject;
}
void ConnectToObject(GameObject obj)
{
if (obj.GetComponent<Auger>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range && inputObject == null && obj.GetComponent<Auger>().outputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<Auger>().ID.Equals(inputID))
{
inputObject = obj;
type = "Regolith";
obj.GetComponent<Auger>().outputObject = gameObject;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
inputObject = obj;
type = "Regolith";
obj.GetComponent<Auger>().outputObject = gameObject;
}
}
}
if (obj.GetComponent<UniversalExtractor>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range && inputObject == null && obj.GetComponent<UniversalExtractor>().outputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<UniversalExtractor>().ID.Equals(inputID))
{
inputObject = obj;
obj.GetComponent<UniversalExtractor>().outputObject = gameObject;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
inputObject = obj;
obj.GetComponent<UniversalExtractor>().outputObject = gameObject;
}
}
}
if (obj.GetComponent<UniversalConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<UniversalConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<UniversalConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = type;
obj.GetComponent<UniversalConduit>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = type;
obj.GetComponent<UniversalConduit>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<InventoryManager>() != null && !obj.GetComponent<InventoryManager>().ID.Equals("player") && obj.GetComponent<Retriever>() == null && obj.GetComponent<AutoCrafter>() == null)
{
if (IsValidOutputObject(obj))
{
if (creationMethod.Equals("spawned") && obj.GetComponent<InventoryManager>().ID.Equals(outputID))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range || obj.GetComponent<RailCart>() != null)
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<StorageComputer>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range && outputObject == null && inputObject != null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<StorageComputer>().ID.Equals(outputID))
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
if (obj.GetComponent<AlloySmelter>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<AlloySmelter>().inputObject1 == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<AlloySmelter>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<AlloySmelter>().inputObject1 = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<AlloySmelter>().inputObject1 = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
else if (obj.GetComponent<AlloySmelter>().inputObject2 == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<AlloySmelter>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<AlloySmelter>().inputObject2 = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<AlloySmelter>().inputObject2 = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<Smelter>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<Smelter>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<Smelter>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<Smelter>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<Smelter>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<PowerSource>() != null)
{
if (obj.GetComponent<PowerSource>().type.Equals("Generator"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<PowerSource>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<PowerSource>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<PowerSource>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<PowerSource>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
if (obj.GetComponent<Extruder>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<Extruder>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<Extruder>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<Extruder>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<Extruder>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<HeatExchanger>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<HeatExchanger>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<HeatExchanger>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<HeatExchanger>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<HeatExchanger>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<GearCutter>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<GearCutter>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<GearCutter>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<GearCutter>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<GearCutter>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
if (obj.GetComponent<Press>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (IsValidOutputObject(obj) && distance < range)
{
if (obj.GetComponent<Press>().inputObject == null)
{
if (creationMethod.Equals("spawned") && obj.GetComponent<Press>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<Press>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<Press>().inputObject = gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
void Update()
{
updateTick += 1 * Time.deltaTime;
@ -77,536 +424,9 @@ public class UniversalConduit : MonoBehaviour
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
foreach (GameObject obj in allObjects)
{
if (obj != null)
if (IsValidObject(obj))
{
if (obj.transform.parent != builtObjects.transform)
{
if (obj.activeInHierarchy)
{
if (obj.GetComponent<Auger>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
if (inputObject == null && obj.GetComponent<Auger>().outputObject == null)
{
if (creationMethod.Equals("spawned"))
{
if (obj.GetComponent<Auger>().ID.Equals(inputID))
{
inputObject = obj;
type = "Regolith";
obj.GetComponent<Auger>().outputObject = this.gameObject;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
inputObject = obj;
type = "Regolith";
obj.GetComponent<Auger>().outputObject = this.gameObject;
}
}
}
}
if (obj.GetComponent<UniversalExtractor>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
if (inputObject == null && obj.GetComponent<UniversalExtractor>().outputObject == null)
{
if (creationMethod.Equals("spawned"))
{
if (obj.GetComponent<UniversalExtractor>().ID.Equals(inputID))
{
inputObject = obj;
obj.GetComponent<UniversalExtractor>().outputObject = this.gameObject;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
inputObject = obj;
obj.GetComponent<UniversalExtractor>().outputObject = this.gameObject;
}
}
}
}
if (obj.GetComponent<UniversalConduit>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
if (outputObject == null)
{
if (inputObject != null)
{
if (obj != inputObject && obj != this.gameObject)
{
if (obj.GetComponent<UniversalConduit>().inputObject == null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<UniversalConduit>().ID + " vs " + outputID);
if (obj.GetComponent<UniversalConduit>().ID.Equals(outputID))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = type;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
obj.GetComponent<UniversalConduit>().type = type;
obj.GetComponent<UniversalConduit>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
if (obj.GetComponent<InventoryManager>() != null && !obj.GetComponent<InventoryManager>().ID.Equals("player") && obj.GetComponent<Retriever>() == null && obj.GetComponent<AutoCrafter>() == null)
{
if (outputObject == null)
{
if (inputObject != null)
{
if (obj != inputObject && obj != this.gameObject)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<InventoryManager>().ID + " vs " + outputID);
if (obj.GetComponent<InventoryManager>().ID.Equals(outputID))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range || obj.GetComponent<RailCart>() != null)
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
}
else if (creationMethod.Equals("built"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
if (obj.GetComponent<StorageComputer>() != null)
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
if (outputObject == null)
{
if (inputObject != null)
{
if (creationMethod.Equals("spawned"))
{
//Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<InventoryManager>().ID + " vs " + outputID);
if (obj.GetComponent<StorageComputer>().ID.Equals(outputID))
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
else if (creationMethod.Equals("built"))
{
outputObject = obj;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
if (obj.GetComponent<AlloySmelter>() != null)
{
////Debug.Log("CONDUIT ALLOY FOUND SMELTER");
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
////Debug.Log("CONDUIT FOUND ALLOY SMELTER IN RANGE");
if (outputObject == null)
{
if (inputObject != null)
{
////Debug.Log("CONDUIT HAS INPUT");
if (obj != inputObject && obj != this.gameObject)
{
////Debug.Log("INPUT is VALID");
if (obj.GetComponent<AlloySmelter>().inputObject1 == null)
{
////Debug.Log("ALLOY SMELTER INPUT PORT IS EMPTY");
if (creationMethod.Equals("spawned"))
{
////Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<AlloySmelter>().ID + " vs " + outputID);
if (obj.GetComponent<AlloySmelter>().ID.Equals(outputID))
{
////Debug.Log("PRE-EXISTING CONNECTION ESTABLISHING");
outputObject = obj;
obj.GetComponent<AlloySmelter>().inputObject1 = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
////Debug.Log("NEW ALLOY SMELTER");
outputObject = obj;
obj.GetComponent<AlloySmelter>().inputObject1 = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
////Debug.Log("INPUT is VALID");
else if (obj.GetComponent<AlloySmelter>().inputObject2 == null)
{
////Debug.Log("ALLOY SMELTER INPUT PORT IS EMPTY");
if (creationMethod.Equals("spawned"))
{
////Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<AlloySmelter>().ID + " vs " + outputID);
if (obj.GetComponent<AlloySmelter>().ID.Equals(outputID))
{
////Debug.Log("PRE-EXISTING CONNECTION ESTABLISHING");
outputObject = obj;
obj.GetComponent<AlloySmelter>().inputObject2 = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
////Debug.Log("NEW ALLOY SMELTER");
outputObject = obj;
obj.GetComponent<AlloySmelter>().inputObject2 = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
if (obj.GetComponent<Smelter>() != null)
{
////Debug.Log("CONDUIT FOUND SMELTER");
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
////Debug.Log("CONDUIT FOUND SMELTER IN RANGE");
if (outputObject == null)
{
if (inputObject != null)
{
////Debug.Log("CONDUIT HAS INPUT");
if (obj != inputObject && obj != this.gameObject)
{
////Debug.Log("INPUT is VALID");
if (obj.GetComponent<Smelter>().inputObject == null)
{
////Debug.Log("SMELTER INPUT PORT IS EMPTY");
if (creationMethod.Equals("spawned"))
{
////Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<Smelter>().ID + " vs " + outputID);
if (obj.GetComponent<Smelter>().ID.Equals(outputID))
{
////Debug.Log("PRE-EXISTING CONNECTION ESTABLISHING");
outputObject = obj;
obj.GetComponent<Smelter>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
////Debug.Log("NEW SMELTER");
outputObject = obj;
obj.GetComponent<Smelter>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
if (obj.GetComponent<PowerSource>() != null)
{
if (obj.GetComponent<PowerSource>().type.Equals("Generator"))
{
////Debug.Log("CONDUIT FOUND GENERATOR");
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
////Debug.Log("CONDUIT FOUND GENERATOR IN RANGE");
if (outputObject == null)
{
if (inputObject != null)
{
////Debug.Log("CONDUIT HAS INPUT");
if (obj != inputObject && obj != this.gameObject)
{
////Debug.Log("INPUT is VALID");
if (obj.GetComponent<PowerSource>().inputObject == null)
{
////Debug.Log("GENERATOR INPUT PORT IS EMPTY");
if (creationMethod.Equals("spawned"))
{
////Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<Smelter>().ID + " vs " + outputID);
if (obj.GetComponent<PowerSource>().ID.Equals(outputID))
{
////Debug.Log("PRE-EXISTING CONNECTION ESTABLISHING");
outputObject = obj;
obj.GetComponent<PowerSource>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
////Debug.Log("NEW GENERATOR");
outputObject = obj;
obj.GetComponent<PowerSource>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
}
if (obj.GetComponent<Extruder>() != null)
{
////Debug.Log("CONDUIT FOUND Extruder");
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
////Debug.Log("CONDUIT FOUND Extruder IN RANGE");
if (outputObject == null)
{
if (inputObject != null)
{
////Debug.Log("CONDUIT HAS INPUT");
if (obj != inputObject && obj != this.gameObject)
{
////Debug.Log("INPUT is VALID");
if (obj.GetComponent<Extruder>().inputObject == null)
{
////Debug.Log("Extruder INPUT PORT IS EMPTY");
if (creationMethod.Equals("spawned"))
{
////Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<Extruder>().ID + " vs " + outputID);
if (obj.GetComponent<Extruder>().ID.Equals(outputID))
{
////Debug.Log("PRE-EXISTING CONNECTION ESTABLISHING");
outputObject = obj;
obj.GetComponent<Extruder>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
////Debug.Log("NEW Extruder");
outputObject = obj;
obj.GetComponent<Extruder>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
if (obj.GetComponent<HeatExchanger>() != null)
{
////Debug.Log("CONDUIT FOUND GearCutter");
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
////Debug.Log("CONDUIT FOUND GearCutter IN RANGE");
if (outputObject == null)
{
if (inputObject != null)
{
////Debug.Log("CONDUIT HAS INPUT");
if (obj != inputObject && obj != this.gameObject)
{
////Debug.Log("INPUT is VALID");
if (obj.GetComponent<HeatExchanger>().inputObject == null)
{
////Debug.Log("GearCutter INPUT PORT IS EMPTY");
if (creationMethod.Equals("spawned"))
{
////Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<GearCutter>().ID + " vs " + outputID);
if (obj.GetComponent<HeatExchanger>().ID.Equals(outputID))
{
////Debug.Log("PRE-EXISTING CONNECTION ESTABLISHING");
outputObject = obj;
obj.GetComponent<HeatExchanger>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
////Debug.Log("NEW GearCutter");
outputObject = obj;
obj.GetComponent<HeatExchanger>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
if (obj.GetComponent<GearCutter>() != null)
{
////Debug.Log("CONDUIT FOUND GearCutter");
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
////Debug.Log("CONDUIT FOUND GearCutter IN RANGE");
if (outputObject == null)
{
if (inputObject != null)
{
////Debug.Log("CONDUIT HAS INPUT");
if (obj != inputObject && obj != this.gameObject)
{
////Debug.Log("INPUT is VALID");
if (obj.GetComponent<GearCutter>().inputObject == null)
{
////Debug.Log("GearCutter INPUT PORT IS EMPTY");
if (creationMethod.Equals("spawned"))
{
////Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<GearCutter>().ID + " vs " + outputID);
if (obj.GetComponent<GearCutter>().ID.Equals(outputID))
{
////Debug.Log("PRE-EXISTING CONNECTION ESTABLISHING");
outputObject = obj;
obj.GetComponent<GearCutter>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
////Debug.Log("NEW GearCutter");
outputObject = obj;
obj.GetComponent<GearCutter>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
if (obj.GetComponent<Press>() != null)
{
////Debug.Log("CONDUIT FOUND Press");
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < range)
{
////Debug.Log("CONDUIT FOUND Press IN RANGE");
if (outputObject == null)
{
if (inputObject != null)
{
////Debug.Log("CONDUIT HAS INPUT");
if (obj != inputObject && obj != this.gameObject)
{
////Debug.Log("INPUT is VALID");
if (obj.GetComponent<Press>().inputObject == null)
{
////Debug.Log("Press INPUT PORT IS EMPTY");
if (creationMethod.Equals("spawned"))
{
////Debug.Log("trying to connect " + ID + " to " + obj.GetComponent<Press>().ID + " vs " + outputID);
if (obj.GetComponent<Press>().ID.Equals(outputID))
{
////Debug.Log("PRE-EXISTING CONNECTION ESTABLISHING");
outputObject = obj;
obj.GetComponent<Press>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
creationMethod = "built";
}
}
else if (creationMethod.Equals("built"))
{
////Debug.Log("NEW Press");
outputObject = obj;
obj.GetComponent<Press>().inputObject = this.gameObject;
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, obj.transform.position);
connectionLine.enabled = true;
}
}
}
}
}
}
}
}
}
ConnectToObject(obj);
}
}
}
@ -904,7 +724,7 @@ public class UniversalConduit : MonoBehaviour
if (outputObject.GetComponent<AlloySmelter>() != null)
{
outputID = outputObject.GetComponent<AlloySmelter>().ID;
if (outputObject.GetComponent<AlloySmelter>().inputObject1 == this.gameObject)
if (outputObject.GetComponent<AlloySmelter>().inputObject1 == gameObject)
{
outputObject.GetComponent<AlloySmelter>().inputID1 = ID;
//Debug.Log("CONDUIT OUTPUT SET TO: " + outputObject.GetComponent<AlloySmelter>().ID);
@ -926,7 +746,7 @@ public class UniversalConduit : MonoBehaviour
}
}
}
else if (outputObject.GetComponent<AlloySmelter>().inputObject2 == this.gameObject)
else if (outputObject.GetComponent<AlloySmelter>().inputObject2 == gameObject)
{
outputObject.GetComponent<AlloySmelter>().inputID2 = ID;
////Debug.Log("CONDUIT OUTPUT SET TO: " + outputObject.GetComponent<AlloySmelter>().ID);

View File

@ -48,6 +48,11 @@ public class UniversalExtractor : MonoBehaviour
}
}
bool IsValidResource(GameObject obj)
{
return obj != null && obj.transform.parent != builtObjects.transform && obj.activeInHierarchy && obj.GetComponent<UniversalResource>() != null;
}
void Update()
{
updateTick += 1 * Time.deltaTime;
@ -117,45 +122,36 @@ public class UniversalExtractor : MonoBehaviour
foreach (UniversalResource r in allResources)
{
GameObject obj = r.gameObject;
if (obj != null)
if (IsValidResource(obj))
{
if (obj.transform.parent != builtObjects.transform)
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
if (obj.activeInHierarchy)
if (obj.GetComponent<UniversalResource>().extractor == null)
{
if (obj.GetComponent<UniversalResource>() != null)
obj.GetComponent<UniversalResource>().extractor = gameObject;
}
if (obj.GetComponent<UniversalResource>().extractor == gameObject)
{
if (obj.GetComponent<UniversalResource>().type.Equals("Ice"))
{
float distance = Vector3.Distance(transform.position, obj.transform.position);
if (distance < 20)
{
if (obj.GetComponent<UniversalResource>().extractor == null)
{
obj.GetComponent<UniversalResource>().extractor = this.gameObject;
}
if (obj.GetComponent<UniversalResource>().extractor == this.gameObject)
{
if (obj.GetComponent<UniversalResource>().type.Equals("Ice"))
{
extractingIce = true;
}
else
{
extractingIce = false;
}
if (inputLine == null && obj.GetComponent<LineRenderer>() == null)
{
inputLine = obj.AddComponent<LineRenderer>();
inputLine.startWidth = 0.2f;
inputLine.endWidth = 0.2f;
inputLine.material = lineMat;
inputLine.SetPosition(0, transform.position);
inputLine.SetPosition(1, obj.transform.position);
}
inputObject = obj;
hasResource = true;
}
}
extractingIce = true;
}
else
{
extractingIce = false;
}
if (inputLine == null && obj.GetComponent<LineRenderer>() == null)
{
inputLine = obj.AddComponent<LineRenderer>();
inputLine.startWidth = 0.2f;
inputLine.endWidth = 0.2f;
inputLine.material = lineMat;
inputLine.SetPosition(0, transform.position);
inputLine.SetPosition(1, obj.transform.position);
}
inputObject = obj;
hasResource = true;
}
}
}