public void SaveBot() { RemoveExtraNodes(); DNA savedDNA = new DNA(); foreach (GameObject node in nodes) { savedDNA.AddToPositions(node.transform.position); } foreach (BuilderTempInstruction bti in tempJoints) { savedDNA.AddToInstructions(new Instruction(nodes.IndexOf(bti.baseNode), nodes.IndexOf(bti.tailNode), Vector3.zero, 0)); } gd.editorDNA = savedDNA; /* * File.Delete("C:\\iterBot\\DNA.txt"); * File.Create("C:\\iterBot\\"); * File.Create("C:\\iterBot\\DNA.txt"); * StreamWriter writer = new StreamWriter("C:\\iterBot\\DNA.txt", true); * writer.WriteLine(savedDNA.toData()); * writer.Close(); */ }
private bool GetValidConnectionToNode(int a, int b) { GameObject newNode = nodes[a]; GameObject oldNode = nodes[b]; Vector3 vector = (newNode.transform.position - oldNode.transform.position); if (vector.magnitude < 3.1f) { return(false); } Physics.SyncTransforms(); Ray ray = new Ray(oldNode.transform.position + vector.normalized * 1.5f, vector.normalized); RaycastHit[] rch = Physics.SphereCastAll(ray, .5f, vector.magnitude - 3f); if (rch.Length > 0) { return(false); } GameObject newlyCreatedJoint = gd.lb.GetJoint(oldNode.transform.position + vector.normalized * .9f); joints.Add(newlyCreatedJoint); newlyCreatedJoint.transform.rotation = Quaternion.FromToRotation(Vector3.right, vector); JointScript js = newlyCreatedJoint.GetComponent <JointScript>(); js.SetBoneSize(vector.magnitude - 2.5f); js.ConnectBaseToNode(oldNode); js.ConnectEdgeToNode(newNode); js.SetSineFactors(GetRandomSineFactors()); myDNA.AddToInstructions(new Instruction(b, a, js.GetSineFactors(), GetRandomRotFactor())); return(true); }