public void ResetHighlight() { foreach (ConstructBase ConstructBase in constructBase_list) { ConstructBase.ResetHighlight(); } }
public void FindGround() { foreach (ConstructBase ConstructBase in constructBase_list) { ConstructBase.FindGround(); } }
public void Placement() { foreach (ConstructBase ConstructBase in constructBase_list) { ConstructBase.constructSlot.aboveConstruct = this; ConstructBase.ResetHighlight(); } }
public void Spawn(int depth, int breadth, float height, GameObject nodeParent, GameObject mainBase) { // Setup our spawning angle. float angle = 0f; // Get our base for access to prefabs. ConstructBase baseComponenet = mainBase.GetComponent <ConstructBase>(); // Give the node it's parent. this.parentNode = nodeParent; // If we are spawned, we cannot be the master. masterNode = false; // Init our lists childNodes = new List <GameObject>(); cargoStorage = new List <GameObject>(); for (int i = 0; i < breadth; i++) { // Create a random angle that is additive from our previous angle. // We use our breadth to evenly distribute them around our circle. angle += Random.Range(180.0f / breadth, 360.0f / breadth); // Choose a random length for our connectors. float distanceToNode = Random.Range(0.0f, baseComponenet.baseConnectorsVariance) + distanceToNextNode; // Find our target position from our angle. float xx = Mathf.Sin(angle) * distanceToNode; float zz = Mathf.Cos(angle) * distanceToNode; Vector3 targetPosition = new Vector3(xx + transform.position.x, height, zz + transform.position.z); // Check if we haven't already created a node in this position; if (Physics.OverlapBox(targetPosition, new Vector3(3f, 3f, 3f)).Length == 0) { //Check if there is another node or connector between us. Vector3 direction = (targetPosition - transform.position).normalized; if (Physics.Raycast(transform.position, direction, distanceToNode) == false) { // Create our node. if (depth == 0 || Random.Range(0, 10) > 7) { // Build a landing pad if we are at the end of our depth or if we randomly determine it. GameObject newNode = Instantiate(baseComponenet.landingNode, targetPosition, Quaternion.identity); newNode.transform.parent = nodeParent.transform; newNode.GetComponent <Node>().InitLandingNode(gameObject); // Add it to our children childNodes.Add(newNode); } else { // Create another node. GameObject newNode = Instantiate(baseComponenet.node, targetPosition, Quaternion.identity); // Add it to our children childNodes.Add(newNode); } // Create our connector by finding the midpoint and rotating. Vector3 midPoint = (transform.position + targetPosition) / 2.0f; GameObject newConnector = Instantiate(baseComponenet.connector, midPoint, Quaternion.identity); Vector3 newScale = new Vector3(0.5f, 0.5f, distanceToNode); newConnector.transform.localScale = newScale; newConnector.transform.LookAt(targetPosition); newConnector.transform.parent = nodeParent.transform; } } } // Semi-Breadth first spawning system. // Will create all nodes before spawning next set on THIS path. // Does not account for the current depth of other nodes in the system. for (int i = 0; i < childNodes.Count; i++) { // Check for landingPad if (childNodes[i].tag == "LandingNode") { continue; } // Call the recusive spawn function on our node. GameObject newNode = childNodes[i]; newNode.GetComponent <Node>().Spawn(depth - 1, breadth, height, gameObject, mainBase); newNode.transform.parent = nodeParent.transform; } // Create our own drone and link it to this node. nodeDrone = Instantiate(baseComponenet.drone, transform.position, Quaternion.identity); nodeDrone.GetComponent <Drone>().InitDrone(this, childNodes.Count); nodeDrone.transform.parent = nodeParent.transform; }