Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
    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();
    }
Exemplo n.º 3
0
    /// <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);
    }
Exemplo n.º 4
0
    /// <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);
    }
Exemplo n.º 5
0
    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);
    }
Exemplo n.º 6
0
 public static AtomDetails Deserialize(string json)
 {
     return(AtomDetails.Deserialize(json));
 }
Exemplo n.º 7
0
    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));
            }
        }
    }