public static Atom Create(Vector3 pos, Agent agent, Enums.Direction parent, AtomDetails details) { GameObject gameObject = CreateShape(details.shape, agent); Atom atom = gameObject.AddComponent <Atom>(); Rigidbody rb = gameObject.AddComponent <Rigidbody>(); atom.Create(agent, rb, pos, parent, details); return(atom); }
private void Create(Agent agent, Rigidbody rb, Vector3 pos, Enums.Direction parent, AtomDetails details) { this.agent = agent; this.rb = rb; this.details = details; this.pos = pos; this.parent = parent; transform.localPosition = pos; Resize(); MakeJoint(); }
/// <summary> /// Create the base atom with no motion /// </summary> /// <param name="pos">index in the atoms array of where to spawn the atom</param> /// <returns>The newly generated atom attached to a gameobject</returns> public static Atom Create(Vector3 pos, Agent agent) { Enums.Shape shape = Enums.Shape.Cube; GameObject gameObject = CreateShape(shape, agent); Atom atom = gameObject.AddComponent <Atom>(); Rigidbody rb = gameObject.AddComponent <Rigidbody>(); rb.useGravity = false; AtomDetails details = new AtomDetails(shape, Enums.Motion.None); atom.Create(agent, rb, pos, Enums.Direction.None, details); return(atom); }
/// <summary> /// Create a new atom with random properties. /// </summary> /// <param name="pos">index in the atoms array of where to spawn the atom</param> /// <returns>The newly generated atom attached to a gameobject</returns> public static Atom CreateRandom(Vector3 pos, Agent agent, Enums.Direction parent) { Enums.Shape shape = Enums.GetRandomShape(); GameObject gameObject = CreateShape(shape, agent); Enums.Motion motion = Enums.GetRandomMotion(); Atom atom = gameObject.AddComponent <Atom>(); Rigidbody rb = gameObject.AddComponent <Rigidbody>(); //rb.useGravity = false; AtomDetails details = new AtomDetails(shape, motion); atom.Create(agent, rb, pos, parent, details); return(atom); }
public static AtomDetails[,,] ToDetails(string f) { string[] pieces = f.Split(';'); AtomDetails[,,] details = new AtomDetails[AgentSize, AgentSize, AgentSize]; int total = 0; for (int i = 0; i < AgentSize; i++) { for (int k = 0; k < AgentSize; k++) { for (int j = 0; j < AgentSize; j++) { if (pieces[total] != "") { details[i, j, k] = Atom.Deserialize(pieces[total]); } total++; } } } return(details); }
public static AtomDetails Deserialize(string json) { return(AtomDetails.Deserialize(json)); }
private void MutateAtom(Vector3 p) { if (Random.value < PointMutationRate) { details[(int)p.x, (int)p.y, (int)p.z].Mutate(); } if (Random.value < ExpansionRate) { Enums.Direction direction = (Enums.Direction)Random.Range(0, 6) + 1; //add one to skip direction.none Vector3 childLoc = Enums.InDirection(p, direction); if (details[(int)childLoc.x, (int)childLoc.y, (int)childLoc.z] == null) //only create the child if there's space { details[(int)childLoc.x, (int)childLoc.y, (int)childLoc.z] = AtomDetails.CreateRandom(); details[(int)p.x, (int)p.y, (int)p.z].children[((int)direction - 1)] = true; } } //Mutate by traversing over children depth first. for (int i = 0; i < details[(int)p.x, (int)p.y, (int)p.z].children.Length; i++) { Enums.Direction childDir = (Enums.Direction)(i + 1); if (details[(int)p.x, (int)p.y, (int)p.z].children[i]) { MutateAtom(Enums.InDirection(p, childDir)); } } }