public void DrawSetupGUI()
        {
            string label = "Setup";
            string id    = "ms-integration-setup";

            GEditorCommon.Foldout(label, true, id, () =>
            {
                GMicroSplatIntegrationSettings settings = GMicroSplatIntegrationSettings.Instance;
                string dir = settings.DataDirectory;
                GEditorCommon.BrowseFolder("Directory", ref dir);
                settings.DataDirectory      = dir;
                settings.ShaderNamePrefix   = EditorGUILayout.TextField("Shader Name", settings.ShaderNamePrefix);
                settings.InitTextureEntries = EditorGUILayout.Toggle("Init Texture Entries", settings.InitTextureEntries);
                if (targets == null)
                {
                    targets = new HashSet <GStylizedTerrain>();
                }
                EditorGUILayout.LabelField("Target(s)", targets.Count.ToString());

                EditorGUI.indentLevel += 1;
                IEnumerator <GStylizedTerrain> iTargets = targets.GetEnumerator();
                while (iTargets.MoveNext())
                {
                    GStylizedTerrain t = iTargets.Current;
                    if (t == null)
                    {
                        continue;
                    }
                    EditorGUILayout.LabelField(" ", t.name, GEditorCommon.ItalicLabel);
                }
                EditorGUI.indentLevel -= 1;

                Rect r       = EditorGUILayout.GetControlRect(GUILayout.Height(GEditorCommon.objectSelectorDragDropHeight));
                GameObject g = GEditorCommon.ObjectSelectorDragDrop <GameObject>(r, "Drop a Game Object here", "t:GStylizedTerrain", true);
                if (g != null)
                {
                    GStylizedTerrain[] terrains = g.GetComponentsInChildren <GStylizedTerrain>();
                    for (int i = 0; i < terrains.Length; ++i)
                    {
                        targets.Add(terrains[i]);
                    }
                }

                if (GUILayout.Button("Setup"))
                {
                    GMicroSplatSetup.Setup(targets);
                }

                EditorUtility.SetDirty(settings);
            });
        }
Exemple #2
0
        public static void Setup(GStylizedTerrain t)
        {
            if (t.TerrainData == null)
            {
                return;
            }

            t.TerrainData.Shading.ShadingSystem = GShadingSystem.MicroSplat;
            GMicroSplatIntegrationSettings settings = GMicroSplatIntegrationSettings.Instance;
            MicroSplatPolarisMesh          pm       = t.gameObject.GetComponent <MicroSplatPolarisMesh>();

            if (pm != null)
            {
                GUtilities.DestroyObject(pm);
            }

            MeshRenderer[]      renderers    = t.GetOrCreateChunkRoot().GetComponentsInChildren <MeshRenderer>();
            List <MeshRenderer> rendererList = new List <MeshRenderer>();

            rendererList.AddRange(renderers);

            MicroSplatPolarisMeshEditor.PolarisData data = new MicroSplatPolarisMeshEditor.PolarisData();
            data.basePath           = settings.DataDirectory;
            data.name               = settings.ShaderNamePrefix;
            data.additionalKeywords = new string[0];
            data.rootObject         = t.gameObject;
            data.renderers          = rendererList;
            MicroSplatPolarisMeshEditor.Setup(data);

            pm = t.gameObject.GetComponent <MicroSplatPolarisMesh>();
            t.TerrainData.Shading.CustomMaterial = pm.templateMaterial;

            string             materialPath = AssetDatabase.GetAssetPath(pm.templateMaterial);
            string             directory    = Path.GetDirectoryName(materialPath);
            string             configPath   = string.Format("{0}/MicroSplatConfig.asset", directory);
            TextureArrayConfig config       = AssetDatabase.LoadAssetAtPath <TextureArrayConfig>(configPath);

            t.TerrainData.Shading.MicroSplatTextureArrayConfig = config;

            currentTAConfig = config;
        }