예제 #1
0
 public void updateTreeInstanceSettings(TerrainGenerator myTarget)
 {
     myTarget.TreeInstanceSettings = updateSettingsOnTarget(
         settings: myTarget.TreeInstanceSettings,
         source: myTarget?.TemplateTerrain?.terrainData?.treePrototypes,
         settingsName: "Terrain Tree Instance Settings",
         sourceName: "Template TreePrototypes",
         comparator: (settings, prototype) => prototype.Equals(settings?.Prototype),
         creator: source =>
     {
         TreeInstanceSettings output = (TreeInstanceSettings)CreateInstance(typeof(TreeInstanceSettings));
         output.Prototype            = source;
         //output.name = $"DetailMapSettings {source.ToString()}";
         return(output);
     },
         sequenceComparator: (settings, sources) => settings.Select(x => x?.Prototype).SequenceEqual(sources)
         );
 }
예제 #2
0
 public void updateTextureSplatSettingsOnTarget(TerrainGenerator myTarget)
 {
     TextureSplatSettings[] splatSettings = myTarget.TextureSplatSettings;
     myTarget.TextureSplatSettings = updateSettingsOnTarget(
         settings: splatSettings,
         source: myTarget?.TemplateTerrain?.terrainData?.terrainLayers,
         settingsName: "Texture Splat Settings",
         sourceName: "Template TerrainLayers",
         comparator: (settings, terrainLayer) => settings?.Prototype == terrainLayer,
         creator: templateTerrainLayer =>
     {
         TextureSplatSettings output = (TextureSplatSettings)CreateInstance(typeof(TextureSplatSettings));
         output.Prototype            = templateTerrainLayer;
         output.name = $"{templateTerrainLayer.name} Splat Settings";
         return(output);
     },
         sequenceComparator: (settings, terrainLayers) => settings.Select(x => x?.Prototype).SequenceEqual(terrainLayers)
         );
 }
예제 #3
0
        public override void OnInspectorGUI()
        {
            TerrainGenerator terrainGenerator = (TerrainGenerator)target;

            // update target
            updateTextureSplatSettingsOnTarget(terrainGenerator);
            updateDetailMapSettings(terrainGenerator);
            updateTreeInstanceSettings(terrainGenerator);
            // pull updated texture splat settings from target into SerializedObject
            serializedObject.Update();
            GameObject prefab = PrefabUtility.GetOutermostPrefabInstanceRoot(target);

            if (prefab != null)
            {
                EditorGUILayout.HelpBox(
                    $"Terrain texture splat settings do not persist on prefabs." +
                    $" You must unpack the prefab \"{prefab.name}\" for texure splat settings to work.",
                    MessageType.Warning);
            }
            // now draw the inspector
            DrawDefaultInspector();
            // post changes to SerializedObject back
            serializedObject.ApplyModifiedProperties();
        }