//Generating FaceObj settings, what is important here that Components are const. defined in GridSettings
 private static void GenerateFaceObjSettings(GridCubeFaceID faceID, GameObject parent, out GameObject cubeFace, out MeshRenderer cubeFaceRenderer, out MeshFilter cubeFaceMeshFilter)
 {
     cubeFace = new GameObject(faceID.ToString(), GridMasterManager.GridSettings.GridCubeInitializingComponents);
     cubeFace.transform.parent = parent.transform;
     cubeFaceRenderer = cubeFace.GetComponent<MeshRenderer>();
     cubeFaceMeshFilter = cubeFace.GetComponent<MeshFilter>();
 }
    //Made for Optimisation reasons
    //This method combines each Face obj in GridCube to one obj ( so 6 cube faces as 1 child obj with combined MeshFilter)
    public static void CombineGridCubeFaceMeshes(GameObject gridParentObj , GridCubeFaceIDToObj cubeFaceToObj)
    {
        if (GridMasterManager.GridSettings.GridPreferences.SeperateState == GridSeperateState.PerCubeFace) return;

        GridCubeFaceID topFaceID = GridMasterManager.GridSettings.GridCubeFaceIDs[0];
        MeshFilter topMeshFilter = gridParentObj.GetComponent<MeshFilter>();

        List<CombineInstance> combineInstances = new List<CombineInstance>();

        for (int i = 0; i < GridMasterManager.GridSettings.GridCubeFaceIDs.Length; i++)
        {
            GridCubeFaceID faceID = GridMasterManager.GridSettings.GridCubeFaceIDs[i];

            CombineInstance combineInstance = new CombineInstance();
            combineInstance.mesh = cubeFaceToObj[faceID].GetComponent<MeshFilter>().mesh;
            combineInstance.transform = cubeFaceToObj[faceID].GetComponent<MeshFilter>().transform.localToWorldMatrix;

            combineInstances.Add(combineInstance);
            cubeFaceToObj[faceID].SetActive(false);
            GameObject.Destroy(cubeFaceToObj[faceID].gameObject);
        }

        topMeshFilter.mesh = new Mesh();
        topMeshFilter.mesh.CombineMeshes(combineInstances.ToArray());

    }
    //Generating gridCubeFace based on informations passed in paramethers
    //New Obj is instantiated, with default Cube Components
    //Approporiate FaceMesh is then applied to this obj
    public static GameObject GenerateGridCubeFace(GridCubeFaceID faceID , GameObject parent , GridCubeNoise cubeNoise)
    {
        GameObject cubeFace;
        MeshRenderer cubeFaceRenderer;
        MeshFilter cubeFaceMeshFilter;
        GenerateFaceObjSettings(faceID, parent, out cubeFace, out cubeFaceRenderer, out cubeFaceMeshFilter);
        Mesh faceMesh = new Mesh();

        if (faceID == GridCubeFaceID.DOWN)
        {
            faceMesh = GenerateGridCubeDownFace(cubeNoise);
            //cubeFace.transform.localRotation = Quaternion.LookRotation(Vector3.forward, Vector3.down);
        }
        else if (faceID == GridCubeFaceID.LEFT)
        {
            faceMesh = GenerateGridCubeLeftFace(cubeNoise);
        }
        else if (faceID == GridCubeFaceID.RIGHT)
        {
            faceMesh = GenerateGridCubeRightFace(cubeNoise);
        }
        else if (faceID == GridCubeFaceID.FORWARD)
        {
            faceMesh = GenerateGridCubeForwardFace(cubeNoise);
        }
        else if (faceID == GridCubeFaceID.BACKWARD)
        {
            faceMesh = GenerateGridCubeBackwardFace(cubeNoise);
        }
        
        else if(faceID == GridCubeFaceID.UP)
        {
            faceMesh = GenerateGridCubeTopFace(cubeNoise);
        }
        

        ApplyCubeFaceMeshSettings(faceID, cubeFaceRenderer, cubeFaceMeshFilter, faceMesh);

        cubeFace.isStatic = true;

        return cubeFace;
    }
 //Assigning FaceMesh to spawned Obj, and Material defined previously in Singleton
 private static void ApplyCubeFaceMeshSettings(GridCubeFaceID faceID, MeshRenderer cubeFaceRenderer, MeshFilter cubeFaceMeshFilter, Mesh faceMesh)
 {
     cubeFaceMeshFilter.sharedMesh = faceMesh;
     cubeFaceRenderer.sharedMaterial = GridMasterManager.GridSettings.GridCubeInitializeData.GridFaceIDMaterial[faceID];
 }
Ejemplo n.º 5
0
 public GridCubeFaceData(GridCubeFaceID faceID, Material material)
 {
     this.faceID   = faceID;
     this.material = material;
 }