-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #374 from MSchmoecker/feat/clutter
Feat: custom clutter
- Loading branch information
Showing
10 changed files
with
450 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
using System; | ||
using Jotunn.Entities; | ||
using Jotunn.Managers; | ||
|
||
namespace Jotunn.Configs | ||
{ | ||
/// <summary> | ||
/// Configuration class for adding custom clutter.<br /> | ||
/// Use this in a constructor of <see cref="CustomClutter"/> | ||
/// </summary> | ||
public class ClutterConfig | ||
{ | ||
/// <summary> | ||
/// Whether this clutter gets spawned in the world. Defaults to <c>true</c>. | ||
/// </summary> | ||
public bool Enabled { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Biome to spawn in, multiple Biomes can be allowed with <see cref="ZoneManager.AnyBiomeOf"/>.<br /> | ||
/// Default to all biomes. | ||
/// </summary> | ||
public Heightmap.Biome Biome { get; set; } = (Heightmap.Biome)(-1); | ||
|
||
/// <summary> | ||
/// Whether this clutter has an <see cref="InstanceRenderer"/> attached that should be used. | ||
/// </summary> | ||
public bool Instanced { get; set; } | ||
|
||
/// <summary> | ||
/// The amount of displayed clutter prefabs per patch. | ||
/// For high values an <see cref="InstanceRenderer"/> should be used to lower the amount of overall prefabs. | ||
/// </summary> | ||
public int Amount { get; set; } = 10; | ||
|
||
/// <summary> | ||
/// Whether this clutter should be shown on unmodified ground. | ||
/// </summary> | ||
public bool OnUncleared { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Whether this clutter should be shown on modified ground. | ||
/// </summary> | ||
public bool OnCleared { get; set; } | ||
|
||
/// <summary> | ||
/// Minimum random size of the prefab, only active when <see cref="Instanced"/> is used. | ||
/// </summary> | ||
public float ScaleMin { get; set; } = 1f; | ||
|
||
/// <summary> | ||
/// Maximum random size of the prefab, only active when <see cref="Instanced"/> is used. | ||
/// </summary> | ||
public float ScaleMax { get; set; } = 1f; | ||
|
||
/// <summary> | ||
/// Maximum terrain tilt in degrees this clutter will be placed on. | ||
/// </summary> | ||
public float MaxTilt { get; set; } = 25f; | ||
|
||
/// <summary> | ||
/// Minimum terrain height this clutter will be placed on. | ||
/// </summary> | ||
public float MinAltitude { get; set; } | ||
|
||
/// <summary> | ||
/// Maximum terrain height this clutter will be placed on. | ||
/// </summary> | ||
public float MaxAltitude { get; set; } = 1000f; | ||
|
||
/// <summary> | ||
/// Whether the y position will always be at water level. | ||
/// Used before <see cref="RandomOffset"/> | ||
/// </summary> | ||
public bool SnapToWater { get; set; } | ||
|
||
/// <summary> | ||
/// Random y offset of every individual prefab. | ||
/// Calculated after <see cref="SnapToWater"/>. | ||
/// </summary> | ||
public float RandomOffset { get; set; } | ||
|
||
/// <summary> | ||
/// Whether this clutter will be rotated with the underlying terrain. | ||
/// Otherwise it will always point straight up. | ||
/// </summary> | ||
public bool TerrainTilt { get; set; } | ||
|
||
/// <summary> | ||
/// Whether the clutter should check for ocean height. | ||
/// </summary> | ||
public bool OceanDepthCheck { get; set; } | ||
|
||
/// <summary> | ||
/// Minimum ocean depth that is needed to place this clutter. | ||
/// Needs <see cref="OceanDepthCheck"/> to be <c>true</c>. | ||
/// </summary> | ||
public float MinOceanDepth { get; set; } | ||
|
||
/// <summary> | ||
/// Maximum ocean depth to place this clutter. | ||
/// Needs <see cref="OceanDepthCheck"/> to be <c>true</c>. | ||
/// </summary> | ||
public float MaxOceanDepth { get; set; } | ||
|
||
/// <summary> | ||
/// Whether the clutter should check for forest thresholds. | ||
/// </summary> | ||
public bool InForest { get; set; } | ||
|
||
/// <summary> | ||
/// Minimum value of the forest fractal:<br/> | ||
/// 0 - 1: inside the forest<br/> | ||
/// 1: forest edge<br/> | ||
/// 1 - infinity: outside the forest | ||
/// </summary> | ||
public float ForestThresholdMin { get; set; } | ||
|
||
/// <summary> | ||
/// Maximum value of the forest fractal:<br/> | ||
/// 0 - 1: inside the forest<br/> | ||
/// 1: forest edge<br/> | ||
/// 1 - infinity: outside the forest | ||
/// </summary> | ||
public float ForestThresholdMax { get; set; } = 1f; | ||
|
||
/// <summary> | ||
/// Size of a noise map used to determine if the clutter should be placed. | ||
/// Set to 0 to disable and place it everywhere. | ||
/// </summary> | ||
public float FractalScale { get; set; } | ||
|
||
/// <summary> | ||
/// Offset of the noise map. | ||
/// </summary> | ||
public float FractalOffset { get; set; } | ||
|
||
/// <summary> | ||
/// Minimum value of the noise map that is needed to place the clutter. | ||
/// </summary> | ||
public float FractalThresholdMin { get; set; } = 0.5f; | ||
|
||
/// <summary> | ||
/// Maximum value of the noise map to place the clutter. | ||
/// </summary> | ||
public float FractalThresholdMax { get; set; } = 1f; | ||
|
||
/// <summary> | ||
/// Create a new <see cref="ClutterConfig"/> | ||
/// </summary> | ||
public ClutterConfig() {} | ||
|
||
/// <summary> | ||
/// Create a copy of the <see cref="ClutterSystem.Clutter"/> | ||
/// </summary> | ||
/// <param name="clutter"></param> | ||
public ClutterConfig(ClutterSystem.Clutter clutter) | ||
{ | ||
Enabled = clutter.m_enabled; | ||
Biome = clutter.m_biome; | ||
Instanced = clutter.m_instanced; | ||
Amount = clutter.m_amount; | ||
OnUncleared = clutter.m_onUncleared; | ||
OnCleared = clutter.m_onCleared; | ||
ScaleMin = clutter.m_scaleMin; | ||
ScaleMax = clutter.m_scaleMax; | ||
MaxTilt = clutter.m_maxTilt; | ||
MinAltitude = clutter.m_minAlt; | ||
MaxAltitude = clutter.m_maxAlt; | ||
SnapToWater = clutter.m_snapToWater; | ||
RandomOffset = clutter.m_randomOffset; | ||
TerrainTilt = clutter.m_terrainTilt; | ||
OceanDepthCheck = Math.Abs(clutter.m_minOceanDepth - clutter.m_maxOceanDepth) > 0.001f; | ||
MinOceanDepth = clutter.m_minOceanDepth; | ||
MaxOceanDepth = clutter.m_maxOceanDepth; | ||
InForest = clutter.m_inForest; | ||
ForestThresholdMin = clutter.m_forestTresholdMin; | ||
ForestThresholdMax = clutter.m_forestTresholdMax; | ||
FractalScale = clutter.m_fractalScale; | ||
FractalOffset = clutter.m_fractalOffset; | ||
FractalThresholdMin = clutter.m_fractalTresholdMin; | ||
FractalThresholdMax = clutter.m_fractalTresholdMax; | ||
} | ||
|
||
internal ClutterSystem.Clutter ToClutter() | ||
{ | ||
return new ClutterSystem.Clutter() | ||
{ | ||
m_enabled = Enabled, | ||
m_biome = Biome, | ||
m_instanced = Instanced, | ||
m_amount = Amount, | ||
m_onUncleared = OnUncleared, | ||
m_onCleared = OnCleared, | ||
m_scaleMin = ScaleMin, | ||
m_scaleMax = ScaleMax, | ||
m_maxTilt = MaxTilt, | ||
m_minAlt = MinAltitude, | ||
m_maxAlt = MaxAltitude, | ||
m_snapToWater = SnapToWater, | ||
m_randomOffset = RandomOffset, | ||
m_terrainTilt = TerrainTilt, | ||
m_minOceanDepth = OceanDepthCheck ? MinOceanDepth : 0, | ||
m_maxOceanDepth = OceanDepthCheck ? MaxOceanDepth : 0, | ||
m_inForest = InForest, | ||
m_forestTresholdMin = ForestThresholdMin, | ||
m_forestTresholdMax = ForestThresholdMax, | ||
m_fractalScale = FractalScale, | ||
m_fractalOffset = FractalOffset, | ||
m_fractalTresholdMin = FractalThresholdMin, | ||
m_fractalTresholdMax = FractalThresholdMax, | ||
}; | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Jotunn.Configs; | ||
using Jotunn.Managers; | ||
using UnityEngine; | ||
|
||
namespace Jotunn.Entities | ||
{ | ||
/// <summary> | ||
/// Main interface for adding custom clutter to the game.<br /> | ||
/// Clutter are client side only objects scattered on the ground.<br /> | ||
/// All custom clutter have to be wrapped inside this class to add it to Jötunns <see cref="ZoneManager"/>. | ||
/// </summary> | ||
public class CustomClutter : CustomEntity | ||
{ | ||
/// <summary> | ||
/// The prefab for this custom clutter. | ||
/// </summary> | ||
public GameObject Prefab { get; } | ||
|
||
/// <summary> | ||
/// Associated <see cref="ClutterSystem.Clutter"/> class. | ||
/// </summary> | ||
public ClutterSystem.Clutter Clutter { get; } | ||
|
||
/// <summary> | ||
/// Name of this custom clutter. | ||
/// </summary> | ||
public string Name { get; } | ||
|
||
/// <summary> | ||
/// Indicator if references from <see cref="Entities.Mock{T}"/>s will be replaced at runtime. | ||
/// </summary> | ||
public bool FixReference { get; set; } | ||
|
||
/// <summary> | ||
/// Custom clutter from a prefab.<br /> | ||
/// Can fix references for mocks. | ||
/// </summary> | ||
/// <param name="prefab">The prefab for this custom clutter.</param> | ||
/// <param name="fixReference">If true references for <see cref="Entities.Mock{T}"/> objects get resolved at runtime by Jötunn.</param> | ||
/// <param name="config">The <see cref="ClutterConfig"/> for this custom vegation.</param> | ||
public CustomClutter(GameObject prefab, bool fixReference, ClutterConfig config) | ||
{ | ||
Prefab = prefab; | ||
Name = prefab.name; | ||
Clutter = config.ToClutter(); | ||
Clutter.m_prefab = prefab; | ||
FixReference = fixReference; | ||
} | ||
|
||
/// <summary> | ||
/// Custom clutter from a prefab loaded from an <see cref="AssetBundle"/>.<br /> | ||
/// Can fix references for mocks. | ||
/// </summary> | ||
/// <param name="assetBundle">A preloaded <see cref="AssetBundle"/></param> | ||
/// <param name="assetName">Name of the prefab in the bundle.</param> | ||
/// <param name="fixReference">If true references for <see cref="Entities.Mock{T}"/> objects get resolved at runtime by Jötunn.</param> | ||
/// <param name="config">The <see cref="ClutterConfig"/> for this custom clutter.</param> | ||
public CustomClutter(AssetBundle assetBundle, string assetName, bool fixReference, ClutterConfig config) | ||
{ | ||
var prefab = assetBundle.LoadAsset<GameObject>(assetName); | ||
if (prefab) | ||
{ | ||
Prefab = prefab; | ||
Name = prefab.name; | ||
Clutter = config.ToClutter(); | ||
Clutter.m_prefab = prefab; | ||
FixReference = fixReference; | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return Name; | ||
} | ||
} | ||
} |
Oops, something went wrong.