Exemplo n.º 1
0
    public override void OnInspectorGUI()
    {
        MB2_MeshBaker tb = (MB2_MeshBaker)target;

        if (GUILayout.Button(" MIGRATE COMPONENTS TO VERSION 3 "))
        {
            GameObject go = tb.gameObject;
            MB2_TextureBakerEditor.MigrateTestureBakerToVersion3Component(go);
            MB2_MultiMeshBakerEditor.MigrateMultiMeshBakerToVersion3Component(go);
            MigrateMeshBakerToVersion3Component(go);
        }
        mbe.OnInspectorGUI((MB2_MeshBakerCommon)target, typeof(MB_MeshBakerEditorWindow));
    }
    void createAndSetupBaker(List <_GameObjectAndWarning> gaws, string pthRoot)
    {
        if (gaws.Count < 1)
        {
            return;
        }

        int numVerts = 0;

        for (int i = 0; i < gaws.Count; i++)
        {
            numVerts = gaws[i].numVerts;
        }

        UnityEngine.GameObject newMeshBaker = null;
        if (numVerts >= 65535)
        {
            newMeshBaker = MB2_MultiMeshBakerEditor.CreateNewMeshBaker();
        }
        else
        {
            newMeshBaker = MB2_MeshBakerEditor.CreateNewMeshBaker();
        }

        newMeshBaker.name = ("MeshBaker-" + gaws[0].shader.name + "-LM" + gaws[0].lightmapIndex).ToString().Replace("/", "-");

        MB2_TextureBaker tb = newMeshBaker.GetComponent <MB2_TextureBaker>();
        //string pth = AssetDatabase.GenerateUniqueAssetPath(pthRoot);

        //create result material
        string pthMat = AssetDatabase.GenerateUniqueAssetPath(pthRoot + newMeshBaker.name + ".mat");

        AssetDatabase.CreateAsset(new Material(UnityEngine.Shader.Find("Diffuse")), pthMat);
        tb.resultMaterial = (Material)AssetDatabase.LoadAssetAtPath(pthMat, typeof(Material));

        //create the MB2_TextureBakeResults
        string pthAsset = AssetDatabase.GenerateUniqueAssetPath(pthRoot + newMeshBaker.name + ".asset");

        AssetDatabase.CreateAsset(ScriptableObject.CreateInstance <MB2_TextureBakeResults>(), pthAsset);
        tb.textureBakeResults = (MB2_TextureBakeResults)AssetDatabase.LoadAssetAtPath(pthAsset, typeof(MB2_TextureBakeResults));
        AssetDatabase.Refresh();

        tb.resultMaterial.shader = gaws[0].shader;
        tb.objsToMesh            = new List <UnityEngine.GameObject>();
        for (int i = 0; i < gaws.Count; i++)
        {
            tb.objsToMesh.Add(gaws[i].go);
        }
        MB2_MeshBakerCommon mb = newMeshBaker.GetComponent <MB2_MeshBakerCommon>();

        if (generate_LightmapOption == LightMapOption.ignore)
        {
            mb.lightmapOption = MB2_LightmapOptions.ignore_UV2;
        }
        else
        {
            if (gaws[0].lightmapIndex == -1 || gaws[0].lightmapIndex == -2)
            {
                mb.lightmapOption = MB2_LightmapOptions.ignore_UV2;
            }
            else
            {
                mb.lightmapOption = MB2_LightmapOptions.preserve_current_lightmapping;
            }
        }
    }