/// <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); }
private static GameObject CreateShape(Enums.Shape shape, Agent agent) { GameObject gameObject; switch (shape) { case Enums.Shape.Cylinder: gameObject = GameObject.CreatePrimitive(PrimitiveType.Capsule); break; case Enums.Shape.Sphere: gameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); break; case Enums.Shape.Cube: default: gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); break; } gameObject.layer = agent.id + 8; gameObject.transform.parent = agent.transform; return(gameObject); }