Empty game object (#654)

<!-- A new module or something else important -->
## Major features
-

<!-- A new parameter added to a module, or API feature -->
## Minor features
-

<!-- Some improvement that requires no action on the part of add-on
creators i.e., improved star graphics -->
## Improvements
-

<!-- Be sure to reference the existing issue if it exists -->
## Bug fixes
-
This commit is contained in:
Nick 2023-07-19 23:24:12 -04:00 committed by GitHub
commit 65b0010d3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -20,6 +20,7 @@ namespace NewHorizons.Builder.Props
{ {
private static readonly Dictionary<DetailInfo, GameObject> _detailInfoToCorrespondingSpawnedGameObject = new(); private static readonly Dictionary<DetailInfo, GameObject> _detailInfoToCorrespondingSpawnedGameObject = new();
private static readonly Dictionary<(Sector, string), (GameObject prefab, bool isItem)> _fixedPrefabCache = new(); private static readonly Dictionary<(Sector, string), (GameObject prefab, bool isItem)> _fixedPrefabCache = new();
private static GameObject _emptyPrefab;
static DetailBuilder() static DetailBuilder()
{ {
@ -69,14 +70,20 @@ namespace NewHorizons.Builder.Props
/// </summary> /// </summary>
public static GameObject Make(GameObject planetGO, Sector sector, DetailInfo info) public static GameObject Make(GameObject planetGO, Sector sector, DetailInfo info)
{ {
var prefab = SearchUtilities.Find(info.path); _emptyPrefab ??= new GameObject("Empty");
// Allow for empty game objects so you can set up conditional activation on them and parent other props to them
var prefab = string.IsNullOrEmpty(info.path) ? _emptyPrefab : SearchUtilities.Find(info.path);
if (prefab == null) if (prefab == null)
{ {
NHLogger.LogError($"Couldn't find detail {info.path}"); NHLogger.LogError($"Couldn't find detail {info.path}");
return null; return null;
} }
else else
{
return Make(planetGO, sector, prefab, info); return Make(planetGO, sector, prefab, info);
}
} }
/// <summary> /// <summary>

View File

@ -21,7 +21,8 @@ namespace NewHorizons.External.Modules.Props
public string assetBundle; public string assetBundle;
/// <summary> /// <summary>
/// Either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle /// Either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle.
/// If empty, will make an empty game object. This can be useful for adding other props to it as its children.
/// </summary> /// </summary>
public string path; public string path;

View File

@ -1278,7 +1278,7 @@
}, },
"path": { "path": {
"type": "string", "type": "string",
"description": "Either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle" "description": "Either the path in the scene hierarchy of the item to copy or the path to the object in the supplied asset bundle. \nIf empty, will make an empty game object. This can be useful for adding other props to it as its children."
}, },
"removeChildren": { "removeChildren": {
"type": "array", "type": "array",