2020-07-19 21:36:57 -04:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
public class UniversalConduit : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float amount;
|
|
|
|
|
public int speed = 1;
|
|
|
|
|
public int power;
|
|
|
|
|
public string type;
|
|
|
|
|
public string ID = "unassigned";
|
|
|
|
|
public string inputID;
|
|
|
|
|
public string outputID;
|
2020-08-27 05:06:16 -04:00
|
|
|
|
public string creationMethod = "built";
|
2020-07-19 21:36:57 -04:00
|
|
|
|
public GameObject inputObject;
|
|
|
|
|
public GameObject outputObject;
|
|
|
|
|
public GameObject conduitItem;
|
|
|
|
|
public Material lineMat;
|
|
|
|
|
public bool inputMachineDisabled;
|
|
|
|
|
public int address;
|
|
|
|
|
public int range = 6;
|
|
|
|
|
public int connectionAttempts;
|
|
|
|
|
public bool connectionFailed;
|
|
|
|
|
public GameObject storageComputerConduitItemObject;
|
|
|
|
|
public ConduitItem storageComputerConduitItem;
|
|
|
|
|
private GameObject builtObjects;
|
2020-09-03 03:09:26 -04:00
|
|
|
|
private LineRenderer connectionLine;
|
|
|
|
|
private float updateTick;
|
2020-07-19 21:36:57 -04:00
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Called by unity engine on start up to initialize variables
|
|
|
|
|
public void Start()
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
connectionLine = gameObject.AddComponent<LineRenderer>();
|
|
|
|
|
connectionLine.startWidth = 0.2f;
|
|
|
|
|
connectionLine.endWidth = 0.2f;
|
|
|
|
|
connectionLine.material = lineMat;
|
|
|
|
|
connectionLine.loop = true;
|
|
|
|
|
connectionLine.enabled = false;
|
|
|
|
|
builtObjects = GameObject.Find("Built_Objects");
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-03 03:09:26 -04:00
|
|
|
|
// Called once per frame by unity engine
|
|
|
|
|
public void Update()
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
updateTick += 1 * Time.deltaTime;
|
|
|
|
|
if (updateTick > 0.5f + (address * 0.001f))
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
GetComponent<PhysicsHandler>().UpdatePhysics();
|
|
|
|
|
updateTick = 0;
|
|
|
|
|
if (inputObject == null || outputObject == null)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
connectionAttempts += 1;
|
|
|
|
|
if (creationMethod.Equals("spawned"))
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (connectionAttempts >= 30)
|
|
|
|
|
{
|
|
|
|
|
connectionAttempts = 0;
|
|
|
|
|
connectionFailed = true;
|
|
|
|
|
}
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
else
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (connectionAttempts >= 120)
|
|
|
|
|
{
|
|
|
|
|
connectionAttempts = 0;
|
|
|
|
|
connectionFailed = true;
|
|
|
|
|
}
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (connectionFailed == false)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Built");
|
|
|
|
|
foreach (GameObject obj in allObjects)
|
|
|
|
|
{
|
|
|
|
|
if (IsValidObject(obj))
|
|
|
|
|
{
|
|
|
|
|
ConnectToObject(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject != null)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<AlloySmelter>() != null)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<AlloySmelter>().conduitItem.GetComponent<ConduitItem>().active == false)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
else
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
inputMachineDisabled = false;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<Auger>() != null)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
inputID = inputObject.GetComponent<Auger>().ID;
|
|
|
|
|
speed = inputObject.GetComponent<Auger>().speed;
|
|
|
|
|
if (inputObject.GetComponent<Auger>().powerON == true && inputObject.GetComponent<Auger>().speed > 0)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<Auger>().amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
inputObject.GetComponent<Auger>().amount -= speed;
|
|
|
|
|
amount += speed;
|
|
|
|
|
}
|
|
|
|
|
inputMachineDisabled = false;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
else
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<AutoCrafter>() != null)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<AutoCrafter>().conduitItem.GetComponent<ConduitItem>().active == false)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
else
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
inputMachineDisabled = false;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<Extruder>() != null)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<Extruder>().conduitItem.GetComponent<ConduitItem>().active == false)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
else
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
inputMachineDisabled = false;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<GearCutter>() != null)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<GearCutter>().conduitItem.GetComponent<ConduitItem>().active == false)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
else
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
inputMachineDisabled = false;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<Press>() != null)
|
2020-08-04 21:33:47 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (inputObject.GetComponent<Press>().conduitItem.GetComponent<ConduitItem>().active == false)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inputMachineDisabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (inputObject.GetComponent<Retriever>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (inputObject.GetComponent<Retriever>().conduitItem.GetComponent<ConduitItem>().active == false)
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inputMachineDisabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (inputObject.GetComponent<Smelter>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (inputObject.GetComponent<Smelter>().conduitItem.GetComponent<ConduitItem>().active == false)
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inputMachineDisabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (inputObject.GetComponent<UniversalConduit>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (inputObject.GetComponent<UniversalConduit>().conduitItem.GetComponent<ConduitItem>().active == false)
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inputMachineDisabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (inputObject.GetComponent<UniversalExtractor>() != null)
|
|
|
|
|
{
|
|
|
|
|
inputID = inputObject.GetComponent<UniversalExtractor>().ID;
|
|
|
|
|
speed = inputObject.GetComponent<UniversalExtractor>().speed;
|
|
|
|
|
if (inputObject.GetComponent<UniversalExtractor>().type != "" && inputObject.GetComponent<UniversalExtractor>().type != "nothing")
|
|
|
|
|
{
|
|
|
|
|
type = inputObject.GetComponent<UniversalExtractor>().type;
|
|
|
|
|
if (inputObject.GetComponent<UniversalExtractor>().powerON == true && inputObject.GetComponent<UniversalExtractor>().speed > 0)
|
|
|
|
|
{
|
|
|
|
|
if (inputObject.GetComponent<UniversalExtractor>().amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
inputObject.GetComponent<UniversalExtractor>().amount -= speed;
|
|
|
|
|
amount += speed;
|
|
|
|
|
}
|
|
|
|
|
inputMachineDisabled = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
inputMachineDisabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
if (outputObject != null && connectionFailed == false)
|
|
|
|
|
{
|
|
|
|
|
connectionLine.SetPosition(0, transform.position);
|
|
|
|
|
connectionLine.SetPosition(1, outputObject.transform.position);
|
|
|
|
|
connectionLine.enabled = true;
|
|
|
|
|
if (speed > 0)
|
|
|
|
|
{
|
|
|
|
|
if (outputObject.GetComponent<UniversalConduit>() != null)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<UniversalConduit>().inputID = ID;
|
|
|
|
|
outputID = outputObject.GetComponent<UniversalConduit>().ID;
|
|
|
|
|
if (type.Equals("Brick") && inputObject.GetComponent<Press>() != null)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<UniversalConduit>().speed = speed * 10;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<UniversalConduit>().speed = speed;
|
|
|
|
|
}
|
|
|
|
|
if (type != "" && type != "nothing")
|
|
|
|
|
{
|
|
|
|
|
if (outputObject.GetComponent<UniversalConduit>().amount < 1)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<UniversalConduit>().type = type;
|
|
|
|
|
}
|
|
|
|
|
if (amount >= speed && outputObject.GetComponent<UniversalConduit>().type.Equals(type))
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals("Brick") && inputObject.GetComponent<Press>() != null)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<UniversalConduit>().amount += speed * 10;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<UniversalConduit>().amount += speed;
|
|
|
|
|
}
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<PowerSource>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals("Coal"))
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<PowerSource>().fuelType = type;
|
|
|
|
|
outputObject.GetComponent<PowerSource>().inputID = ID;
|
|
|
|
|
outputID = outputObject.GetComponent<PowerSource>().ID;
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
if (outputObject.GetComponent<PowerSource>().fuelAmount < 1000)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<PowerSource>().fuelAmount += speed;
|
|
|
|
|
}
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<Smelter>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals(outputObject.GetComponent<Smelter>().inputType))
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<Smelter>().inputID = ID;
|
|
|
|
|
outputID = outputObject.GetComponent<Smelter>().ID;
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<Smelter>().amount += speed;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<HeatExchanger>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals(outputObject.GetComponent<HeatExchanger>().inputType))
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<HeatExchanger>().inputID = ID;
|
|
|
|
|
outputID = outputObject.GetComponent<HeatExchanger>().ID;
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<HeatExchanger>().amount += speed;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<AlloySmelter>() != null)
|
|
|
|
|
{
|
|
|
|
|
outputID = outputObject.GetComponent<AlloySmelter>().ID;
|
2020-08-04 21:33:47 -04:00
|
|
|
|
if (outputObject.GetComponent<AlloySmelter>().inputObject1 == gameObject)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<AlloySmelter>().inputID1 = ID;
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals(outputObject.GetComponent<AlloySmelter>().inputType1))
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<AlloySmelter>().amount += speed;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-04 21:33:47 -04:00
|
|
|
|
else if (outputObject.GetComponent<AlloySmelter>().inputObject2 == gameObject)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<AlloySmelter>().inputID2 = ID;
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals(outputObject.GetComponent<AlloySmelter>().inputType2))
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<AlloySmelter>().amount2 += speed;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<Press>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals(outputObject.GetComponent<Press>().inputType))
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<Press>().inputID = ID;
|
|
|
|
|
outputID = outputObject.GetComponent<Press>().ID;
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<Press>().amount += speed;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<Extruder>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals(outputObject.GetComponent<Extruder>().inputType))
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<Extruder>().inputID = ID;
|
|
|
|
|
outputID = outputObject.GetComponent<Extruder>().ID;
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<Extruder>().amount += speed;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<GearCutter>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals(outputObject.GetComponent<GearCutter>().inputType))
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<GearCutter>().inputID = ID;
|
|
|
|
|
outputID = outputObject.GetComponent<GearCutter>().ID;
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<GearCutter>().amount += speed;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<InventoryManager>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (Vector3.Distance(transform.position, outputObject.transform.position) <= range)
|
|
|
|
|
{
|
|
|
|
|
if (type != "" && type != "nothing")
|
|
|
|
|
{
|
|
|
|
|
if (inputObject != null)
|
|
|
|
|
{
|
|
|
|
|
if (inputMachineDisabled == false && inputObject.GetComponent<UniversalConduit>() == null)
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
}
|
|
|
|
|
else if (inputObject.GetComponent<UniversalConduit>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (inputObject.GetComponent<UniversalConduit>().inputMachineDisabled == false)
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
connectionLine.enabled = true;
|
|
|
|
|
connectionLine.SetPosition(1, outputObject.transform.position);
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
if (outputObject.GetComponent<RailCart>() != null)
|
|
|
|
|
{
|
|
|
|
|
outputID = outputObject.GetComponent<RailCart>().ID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
outputID = outputObject.GetComponent<InventoryManager>().ID;
|
|
|
|
|
}
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
if (type.Equals("Brick") && inputObject.GetComponent<Press>() != null)
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<InventoryManager>().AddItem(type, speed * 10);
|
|
|
|
|
if (outputObject.GetComponent<InventoryManager>().itemAdded == true)
|
|
|
|
|
{
|
|
|
|
|
amount -= speed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
outputObject.GetComponent<InventoryManager>().AddItem(type, speed);
|
|
|
|
|
if (outputObject.GetComponent<InventoryManager>().itemAdded == true)
|
|
|
|
|
{
|
|
|
|
|
amount -= speed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
connectionLine.enabled = false;
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputObject.GetComponent<StorageComputer>() != null)
|
|
|
|
|
{
|
|
|
|
|
outputID = outputObject.GetComponent<StorageComputer>().ID;
|
|
|
|
|
if (outputObject.GetComponent<StorageComputer>().initialized == true && type != "" && type != "nothing")
|
|
|
|
|
{
|
|
|
|
|
if (storageComputerConduitItem == null)
|
|
|
|
|
{
|
|
|
|
|
GameObject storageComputerItemObject = Instantiate(storageComputerConduitItemObject, outputObject.transform.position, outputObject.transform.rotation);
|
|
|
|
|
storageComputerItemObject.transform.parent = outputObject.transform;
|
2020-09-03 03:09:26 -04:00
|
|
|
|
storageComputerConduitItem = storageComputerItemObject.GetComponent<ConduitItem>();
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (inputMachineDisabled == true && inputObject.GetComponent<UniversalConduit>() == null)
|
|
|
|
|
{
|
|
|
|
|
storageComputerConduitItem.active = false;
|
|
|
|
|
}
|
|
|
|
|
else if (inputObject.GetComponent<UniversalConduit>() != null)
|
|
|
|
|
{
|
|
|
|
|
if (inputObject.GetComponent<UniversalConduit>().inputMachineDisabled == true)
|
|
|
|
|
{
|
|
|
|
|
storageComputerConduitItem.active = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (amount >= speed)
|
|
|
|
|
{
|
|
|
|
|
connectionLine.enabled = true;
|
|
|
|
|
connectionLine.SetPosition(1, outputObject.transform.position);
|
|
|
|
|
if (type.Equals("Brick") && inputObject.GetComponent<Press>() != null)
|
|
|
|
|
{
|
|
|
|
|
bool itemAdded = false;
|
|
|
|
|
foreach (InventoryManager manager in outputObject.GetComponent<StorageComputer>().computerContainers)
|
|
|
|
|
{
|
|
|
|
|
if (itemAdded == false)
|
|
|
|
|
{
|
|
|
|
|
manager.AddItem(type, speed * 10);
|
|
|
|
|
if (manager.itemAdded == true)
|
|
|
|
|
{
|
|
|
|
|
itemAdded = true;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
if (storageComputerConduitItem != null)
|
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (storageComputerConduitItem.td != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
storageComputerConduitItem.billboard.GetComponent<Renderer>().material.mainTexture = storageComputerConduitItem.td[type];
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
storageComputerConduitItem.target = manager.gameObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bool itemAdded = false;
|
|
|
|
|
foreach (InventoryManager manager in outputObject.GetComponent<StorageComputer>().computerContainers)
|
|
|
|
|
{
|
|
|
|
|
if (itemAdded == false)
|
|
|
|
|
{
|
|
|
|
|
manager.AddItem(type, speed);
|
|
|
|
|
if (manager.itemAdded == true)
|
|
|
|
|
{
|
|
|
|
|
itemAdded = true;
|
|
|
|
|
amount -= speed;
|
|
|
|
|
if (storageComputerConduitItem != null)
|
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
if (storageComputerConduitItem.td != null)
|
2020-07-19 21:36:57 -04:00
|
|
|
|
{
|
2020-09-03 03:09:26 -04:00
|
|
|
|
storageComputerConduitItem.billboard.GetComponent<Renderer>().material.mainTexture = storageComputerConduitItem.td[type];
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
storageComputerConduitItem.target = manager.gameObject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (storageComputerConduitItem != null)
|
|
|
|
|
{
|
|
|
|
|
storageComputerConduitItem.active = true;
|
|
|
|
|
}
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = true;
|
|
|
|
|
GetComponent<Light>().enabled = true;
|
|
|
|
|
GetComponent<AudioSource>().enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (storageComputerConduitItem != null)
|
|
|
|
|
{
|
|
|
|
|
storageComputerConduitItem.active = false;
|
|
|
|
|
}
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (connectionFailed == true)
|
|
|
|
|
{
|
|
|
|
|
if (creationMethod.Equals("spawned"))
|
|
|
|
|
{
|
|
|
|
|
creationMethod = "built";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
conduitItem.GetComponent<ConduitItem>().active = false;
|
|
|
|
|
GetComponent<Light>().enabled = false;
|
|
|
|
|
GetComponent<AudioSource>().enabled = false;
|
|
|
|
|
connectionLine.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
if (inputObject != null && outputObject != null)
|
|
|
|
|
{
|
|
|
|
|
connectionAttempts = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-03 03:09:26 -04:00
|
|
|
|
|
|
|
|
|
// The object exists, is active and is not a standard building block
|
|
|
|
|
private bool IsValidObject(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj != null)
|
|
|
|
|
{
|
|
|
|
|
return obj.transform.parent != builtObjects.transform && obj.activeInHierarchy;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The object is a potential output connection
|
|
|
|
|
private bool IsValidOutputObject(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
return outputObject == null && inputObject != null && obj != inputObject && obj != gameObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns true if the object in question is a storage container
|
|
|
|
|
private bool IsStorageContainer(GameObject obj)
|
|
|
|
|
{
|
|
|
|
|
if (obj.GetComponent<InventoryManager>() != null)
|
|
|
|
|
{
|
|
|
|
|
return !obj.GetComponent<InventoryManager>().ID.Equals("player") && obj.GetComponent<Retriever>() == null && obj.GetComponent<AutoCrafter>() == null;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Makes input and output connections
|
|
|
|
|
private 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 (IsStorageContainer(obj))
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Used to remove conduit item from storage computer if connected to one
|
|
|
|
|
public void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
if (storageComputerConduitItem != null)
|
|
|
|
|
{
|
|
|
|
|
storageComputerConduitItem.active = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-19 21:36:57 -04:00
|
|
|
|
}
|