Exemplo n.º 1
0
    /// <summary>
    /// creates the mesh of the cube that is generated
    /// </summary>
    private Mesh MakeCube()
    {
        Mesh         mesh   = MeshTools.MakeTaperCube(.2f);
        List <Color> colors = new List <Color>();

        for (int i = 0; i < mesh.vertexCount; i++)
        {
            Color color = Color.HSVToRGB(Random.Range(0, 2), 1, Random.Range(0, 2));

            colors.Add(color);
        }

        mesh.SetColors(colors);
        return(mesh);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Grow is called to create all the mesh data to add to the spawner's mesh filter.
    /// </summary>
    /// <param name="meshes">A collection of meshes to push to the object.</param>
    /// <param name="pos">The x,y,z position of the object.</param>
    /// <param name="rot">The rotation of the object.</param>
    void Grow(List <CombineInstance> meshes, Vector3 pos, Quaternion rot)
    {
        //Set randomized values:
        numberOfArms = Random.Range(minArms, maxArms);
        float tempRandomScaling = Random.Range(minRandomScaling, maxRandomScaling);

        //Set random values to adjust arm width/height:
        float tempRandomArmScaleX = Random.Range(minRandomScaling, maxRandomScaling);
        float tempRandomArmScaleZ = Random.Range(minRandomScaling, maxRandomScaling);

        //Create temporary scaling for center and arms:
        Vector3 tempCenterScale = (centerScale * tempRandomScaling) * objectScaling;
        Vector3 tempArmScale    = (armScale * tempRandomScaling) * objectScaling;

        //Add arm length & width
        tempArmScale.x += Random.Range(minArmWidth, maxArmWidth);
        tempArmScale.z += Random.Range(minArmLength, maxArmLength);

        //Add randomness to arm width/height:
        tempArmScale.x *= tempRandomArmScaleX;
        tempArmScale.z *= tempRandomArmScaleZ;

        //Make center of the sea star:
        CombineInstance center = new CombineInstance();

        center.mesh = MeshTools.MakeCylinder(8);
        AddColorToVertices(center.mesh);

        //Adjust center values:
        Quaternion adjustRot = Quaternion.Euler(0, 15, 0) * rot;
        Vector3    adjustPos = pos;

        adjustPos.y += centerRiseAmount;

        //Set center transform:
        center.transform = Matrix4x4.TRS(adjustPos, adjustRot, tempCenterScale);
        meshes.Add(center);

        //Make arms of sea star:
        for (int i = 0; i < numberOfArms; i++)
        {
            CombineInstance arm = new CombineInstance();
            arm.mesh = MeshTools.MakeTaperCube(taperAmount);
            AddColorToVertices(arm.mesh);
            float rotDegrees = (360 / numberOfArms) * i;
            float rotRadians = rotDegrees * (Mathf.PI / 180.0f);

            //Build out arm in that direction:
            float armX = Mathf.Sin(rotRadians) * 1f;
            float armZ = Mathf.Cos(rotRadians) * 1f;

            Vector3    armPos = pos + new Vector3(armX, 0.5f, armZ);
            Quaternion armRot = Quaternion.Euler(0, rotDegrees, 0) * rot;

            // TODO: adjust arm position by scale


            arm.transform = Matrix4x4.TRS(armPos, armRot, tempArmScale);
            meshes.Add(arm);
        }
    }