public static void CreateBuildingHLOD()
    {
        if (PrefabStageUtility.GetCurrentPrefabStage() == null ||
            PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot == null)
        {
            Debug.LogWarning("Setup HLOD can only be used while prefab editing.");
            return;
        }

        var parent = PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot.transform;

        if (parent.GetComponent <LODGroup>() != null || parent.GetComponent <HLOD>() != null)
        {
            Debug.LogWarning("HLOD is already setup on this hierarchy");
            return;
        }

        EditorSceneManager.MarkSceneDirty(parent.gameObject.scene);

        var lowLOD = CreateLowLod();


        var highLOD = new GameObject("High LOD").transform;

        while (parent.childCount != 0)
        {
            parent.GetChild(0).SetParent(highLOD, false);
        }

        lowLOD.SetParent(parent, false);
        highLOD.SetParent(parent, false);

        parent.gameObject.AddComponent(typeof(HLOD));
        var hlod = parent.GetComponent <HLOD>();

        Transform[] transforms = { highLOD, lowLOD };
        hlod.LODParentTransforms = transforms;


        var lodgroup = parent.GetComponent <LODGroup>();

        var lods = lodgroup.GetLODs();

        lods[0].screenRelativeTransitionHeight = 0.3F;
        lods[1].screenRelativeTransitionHeight = 0.02F;
        ArrayUtility.RemoveAt(ref lods, 2);
        lodgroup.SetLODs(lods);

        UpdateBounds(hlod);
        var generatedMeshes = new List <Mesh>();

        GenerateCombinedMesh(hlod, highLOD, lowLOD, 1, generatedMeshes);
        WriteMeshAsset(generatedMeshes);

        HLOD.InvalidateHLODCache();
    }
    public static void GenerateCombinedMesh()
    {
        if (PrefabStageUtility.GetCurrentPrefabStage() == null ||
            PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot == null)
        {
            Debug.LogWarning("UpdateCombinedMesh can only be used while prefab editing.");
            return;
        }

        var root = PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot;
        var hlod = root.GetComponent <HLOD>();

        if (hlod == null)
        {
            Debug.LogWarning("UpdateCombinedMesh requires a correctly configured HLOD setup");
            return;
        }

        EditorSceneManager.MarkSceneDirty(root.gameObject.scene);

        var hlodTransforms = hlod.LODParentTransforms;

        var lodCount = hlod.GetComponent <LODGroup>().lodCount;

        while (lodCount < hlodTransforms.Length)
        {
            if (hlodTransforms[hlodTransforms.Length - 1])
            {
                Object.DestroyImmediate(hlodTransforms[hlodTransforms.Length - 1].gameObject);
            }
            ArrayUtility.RemoveAt(ref hlodTransforms, hlodTransforms.Length - 1);
        }

        System.Array.Resize(ref hlodTransforms, lodCount);
        var generatedMeshes = new List <Mesh>();

        for (int i = 1; i < lodCount; i++)
        {
            if (hlodTransforms[i] == null)
            {
                hlodTransforms[i] = CreateLowLod();
                hlodTransforms[i].SetParent(root.transform, false);
            }

            GenerateCombinedMesh(hlod, hlod.LODParentTransforms[0], hlodTransforms[i], i, generatedMeshes);
        }

        hlod.LODParentTransforms = hlodTransforms;

        WriteMeshAsset(generatedMeshes);

        HLOD.InvalidateHLODCache();
    }