mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
rename MakeDetail and move removeChildren and removeComponents into it.
This commit is contained in:
parent
65c1cdd505
commit
5f7eae91ab
@ -60,7 +60,7 @@ namespace NewHorizons.Builder.Body
|
|||||||
|
|
||||||
var prefab = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Geometry_HubDimension");
|
var prefab = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Geometry_HubDimension");
|
||||||
var detailInfo = new PropModule.DetailInfo();
|
var detailInfo = new PropModule.DetailInfo();
|
||||||
var geometry = DetailBuilder.MakeDetail(go, sector, prefab, detailInfo);
|
var geometry = DetailBuilder.Make(go, sector, prefab, detailInfo);
|
||||||
|
|
||||||
var exitWarps = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/OuterWarp_Hub").InstantiateInactive();
|
var exitWarps = SearchUtilities.Find("DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/OuterWarp_Hub").InstantiateInactive();
|
||||||
var repelVolume = SearchUtilities.Find("DB_HubDimension_Body/BrambleRepelVolume").InstantiateInactive();
|
var repelVolume = SearchUtilities.Find("DB_HubDimension_Body/BrambleRepelVolume").InstantiateInactive();
|
||||||
|
|||||||
@ -20,69 +20,25 @@ namespace NewHorizons.Builder.Props
|
|||||||
return detailInfoToCorrespondingSpawnedGameObject[detail];
|
return detailInfoToCorrespondingSpawnedGameObject[detail];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Make(GameObject go, Sector sector, IModBehaviour mod, PropModule.DetailInfo detail)
|
/// <summary>
|
||||||
|
/// Create a detail using an asset bundle.
|
||||||
|
/// </summary>
|
||||||
|
public static GameObject Make(GameObject go, Sector sector, IModBehaviour mod, PropModule.DetailInfo detail)
|
||||||
{
|
{
|
||||||
GameObject detailGO = null;
|
|
||||||
|
|
||||||
if (detail.assetBundle != null)
|
if (detail.assetBundle != null)
|
||||||
{
|
{
|
||||||
var prefab = AssetBundleUtilities.LoadPrefab(detail.assetBundle, detail.path, mod);
|
var prefab = AssetBundleUtilities.LoadPrefab(detail.assetBundle, detail.path, mod);
|
||||||
|
|
||||||
detailGO = MakeDetail(go, sector, prefab, detail);
|
return Make(go, sector, prefab, detail);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
return Make(go, sector, detail);
|
||||||
var prefab = SearchUtilities.Find(detail.path);
|
|
||||||
if (prefab == null) Logger.LogError($"Couldn't find detail {detail.path}");
|
|
||||||
else detailGO = MakeDetail(go, sector, prefab, detail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (detailGO == null) return;
|
/// <summary>
|
||||||
|
/// Create a detail using a path in the scene hierarchy of the item to copy.
|
||||||
if (detail.removeChildren != null)
|
/// </summary>
|
||||||
{
|
public static GameObject Make(GameObject planetGO, Sector sector, PropModule.DetailInfo info)
|
||||||
var detailPath = detailGO.transform.GetPath();
|
|
||||||
var transforms = detailGO.GetComponentsInChildren<Transform>(true);
|
|
||||||
foreach (var childPath in detail.removeChildren)
|
|
||||||
{
|
|
||||||
// Multiple children can have the same path so we delete all that match
|
|
||||||
var path = $"{detailPath}/{childPath}";
|
|
||||||
|
|
||||||
var flag = true;
|
|
||||||
foreach (var childObj in transforms.Where(x => x.GetPath() == path))
|
|
||||||
{
|
|
||||||
flag = false;
|
|
||||||
childObj.gameObject.SetActive(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detail.removeComponents)
|
|
||||||
{
|
|
||||||
// Just swap all the children to a new game object
|
|
||||||
var newDetailGO = new GameObject(detailGO.name);
|
|
||||||
newDetailGO.transform.position = detailGO.transform.position;
|
|
||||||
newDetailGO.transform.parent = detailGO.transform.parent;
|
|
||||||
// Can't modify parents while looping through children bc idk
|
|
||||||
var children = new List<Transform>();
|
|
||||||
foreach (Transform child in detailGO.transform)
|
|
||||||
{
|
|
||||||
children.Add(child);
|
|
||||||
}
|
|
||||||
foreach (var child in children)
|
|
||||||
{
|
|
||||||
child.parent = newDetailGO.transform;
|
|
||||||
}
|
|
||||||
GameObject.Destroy(detailGO);
|
|
||||||
detailGO = newDetailGO;
|
|
||||||
}
|
|
||||||
|
|
||||||
detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameObject MakeDetail(GameObject planetGO, Sector sector, PropModule.DetailInfo info)
|
|
||||||
{
|
{
|
||||||
var prefab = SearchUtilities.Find(info.path);
|
var prefab = SearchUtilities.Find(info.path);
|
||||||
if (prefab == null)
|
if (prefab == null)
|
||||||
@ -91,54 +47,13 @@ namespace NewHorizons.Builder.Props
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
return Make(planetGO, sector, prefab, info);
|
||||||
GameObject detailGO = MakeDetail(planetGO, sector, prefab, info);
|
|
||||||
|
|
||||||
if (info.removeChildren != null)
|
|
||||||
{
|
|
||||||
var detailPath = detailGO.transform.GetPath();
|
|
||||||
var transforms = detailGO.GetComponentsInChildren<Transform>(true);
|
|
||||||
foreach (var childPath in info.removeChildren)
|
|
||||||
{
|
|
||||||
// Multiple children can have the same path so we delete all that match
|
|
||||||
var path = $"{detailPath}/{childPath}";
|
|
||||||
|
|
||||||
var flag = true;
|
|
||||||
foreach (var childObj in transforms.Where(x => x.GetPath() == path))
|
|
||||||
{
|
|
||||||
flag = false;
|
|
||||||
childObj.gameObject.SetActive(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\".");
|
/// <summary>
|
||||||
}
|
/// Create a detail using a prefab.
|
||||||
}
|
/// </summary>
|
||||||
|
public static GameObject Make(GameObject planetGO, Sector sector, GameObject prefab, PropModule.DetailInfo info)
|
||||||
if (info.removeComponents)
|
|
||||||
{
|
|
||||||
// Just swap all the children to a new game object
|
|
||||||
var newDetailGO = new GameObject(detailGO.name);
|
|
||||||
newDetailGO.transform.position = detailGO.transform.position;
|
|
||||||
newDetailGO.transform.parent = detailGO.transform.parent;
|
|
||||||
// Can't modify parents while looping through children bc idk
|
|
||||||
var children = new List<Transform>();
|
|
||||||
foreach (Transform child in detailGO.transform)
|
|
||||||
{
|
|
||||||
children.Add(child);
|
|
||||||
}
|
|
||||||
foreach (var child in children)
|
|
||||||
{
|
|
||||||
child.parent = newDetailGO.transform;
|
|
||||||
}
|
|
||||||
GameObject.Destroy(detailGO);
|
|
||||||
detailGO = newDetailGO;
|
|
||||||
}
|
|
||||||
|
|
||||||
return detailGO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GameObject MakeDetail(GameObject planetGO, Sector sector, GameObject prefab, PropModule.DetailInfo info)
|
|
||||||
{
|
{
|
||||||
if (prefab == null) return null;
|
if (prefab == null) return null;
|
||||||
|
|
||||||
@ -193,8 +108,51 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
prop.transform.localScale = info.scale != 0 ? Vector3.one * info.scale : prefab.transform.localScale;
|
prop.transform.localScale = info.scale != 0 ? Vector3.one * info.scale : prefab.transform.localScale;
|
||||||
|
|
||||||
|
if (info.removeChildren != null)
|
||||||
|
{
|
||||||
|
var detailPath = prop.transform.GetPath();
|
||||||
|
var transforms = prop.GetComponentsInChildren<Transform>(true);
|
||||||
|
foreach (var childPath in info.removeChildren)
|
||||||
|
{
|
||||||
|
// Multiple children can have the same path so we delete all that match
|
||||||
|
var path = $"{detailPath}/{childPath}";
|
||||||
|
|
||||||
|
var flag = true;
|
||||||
|
foreach (var childObj in transforms.Where(x => x.GetPath() == path))
|
||||||
|
{
|
||||||
|
flag = false;
|
||||||
|
childObj.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag) Logger.LogWarning($"Couldn't find \"{childPath}\".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (info.removeComponents)
|
||||||
|
{
|
||||||
|
// Just swap all the children to a new game object
|
||||||
|
var newProp = new GameObject(prop.name);
|
||||||
|
newProp.transform.position = prop.transform.position;
|
||||||
|
newProp.transform.parent = prop.transform.parent;
|
||||||
|
newProp.SetActive(false);
|
||||||
|
// Can't modify parents while looping through children bc idk
|
||||||
|
var children = new List<Transform>();
|
||||||
|
foreach (Transform child in prop.transform)
|
||||||
|
{
|
||||||
|
children.Add(child);
|
||||||
|
}
|
||||||
|
foreach (var child in children)
|
||||||
|
{
|
||||||
|
child.parent = newProp.transform;
|
||||||
|
}
|
||||||
|
GameObject.Destroy(prop);
|
||||||
|
prop = newProp;
|
||||||
|
}
|
||||||
|
|
||||||
prop.SetActive(true);
|
prop.SetActive(true);
|
||||||
|
|
||||||
|
detailInfoToCorrespondingSpawnedGameObject[info] = prop;
|
||||||
|
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -280,7 +280,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
{
|
{
|
||||||
position = info.position
|
position = info.position
|
||||||
};
|
};
|
||||||
var computerObject = DetailBuilder.MakeDetail(planetGO, sector, _preCrashComputerPrefab, detailInfo);
|
var computerObject = DetailBuilder.Make(planetGO, sector, _preCrashComputerPrefab, detailInfo);
|
||||||
computerObject.SetActive(false);
|
computerObject.SetActive(false);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.rename))
|
if (!string.IsNullOrEmpty(info.rename))
|
||||||
@ -414,7 +414,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
rotation = info.rotation,
|
rotation = info.rotation,
|
||||||
position = info.position
|
position = info.position
|
||||||
};
|
};
|
||||||
var recorderObject = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo);
|
var recorderObject = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
|
||||||
recorderObject.SetActive(false);
|
recorderObject.SetActive(false);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.rename))
|
if (!string.IsNullOrEmpty(info.rename))
|
||||||
|
|||||||
@ -228,7 +228,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
position = info.position,
|
position = info.position,
|
||||||
scale = 2
|
scale = 2
|
||||||
};
|
};
|
||||||
var g = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo);
|
var g = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.parentPath))
|
if (!string.IsNullOrEmpty(info.parentPath))
|
||||||
{
|
{
|
||||||
@ -294,7 +294,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
position = info.position,
|
position = info.position,
|
||||||
rotation = info.rotation
|
rotation = info.rotation
|
||||||
};
|
};
|
||||||
var standingTorch = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo);
|
var standingTorch = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.parentPath))
|
if (!string.IsNullOrEmpty(info.parentPath))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -155,7 +155,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
position = info.position,
|
position = info.position,
|
||||||
rotation = info.rotation
|
rotation = info.rotation
|
||||||
};
|
};
|
||||||
var whiteboard = DetailBuilder.MakeDetail(go, sector, _whiteboardPrefab, detailInfo);
|
var whiteboard = DetailBuilder.Make(go, sector, _whiteboardPrefab, detailInfo);
|
||||||
whiteboard.SetActive(false);
|
whiteboard.SetActive(false);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.rename))
|
if (!string.IsNullOrEmpty(info.rename))
|
||||||
@ -218,7 +218,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
position = info.position,
|
position = info.position,
|
||||||
rotation = info.rotation
|
rotation = info.rotation
|
||||||
};
|
};
|
||||||
var platform = DetailBuilder.MakeDetail(go, sector, _remoteCameraPlatformPrefab, detailInfo);
|
var platform = DetailBuilder.Make(go, sector, _remoteCameraPlatformPrefab, detailInfo);
|
||||||
platform.SetActive(false);
|
platform.SetActive(false);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.rename))
|
if (!string.IsNullOrEmpty(info.rename))
|
||||||
|
|||||||
@ -98,7 +98,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
scale = propInfo.scale,
|
scale = propInfo.scale,
|
||||||
alignToNormal = true
|
alignToNormal = true
|
||||||
};
|
};
|
||||||
var prop = DetailBuilder.MakeDetail(go, sector, prefab, detailInfo);
|
var prop = DetailBuilder.Make(go, sector, prefab, detailInfo);
|
||||||
|
|
||||||
if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset);
|
if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset);
|
||||||
if (propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation);
|
if (propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation);
|
||||||
|
|||||||
@ -118,7 +118,7 @@ namespace NewHorizons
|
|||||||
scale = scale,
|
scale = scale,
|
||||||
alignToNormal = alignWithNormal
|
alignToNormal = alignWithNormal
|
||||||
};
|
};
|
||||||
return DetailBuilder.MakeDetail(planet, sector, prefab, detailInfo);
|
return DetailBuilder.Make(planet, sector, prefab, detailInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AudioSignal SpawnSignal(IModBehaviour mod, GameObject root, string audio, string name, string frequency,
|
public AudioSignal SpawnSignal(IModBehaviour mod, GameObject root, string audio, string name, string frequency,
|
||||||
|
|||||||
@ -120,7 +120,7 @@ namespace NewHorizons.Utility.DebugUtilities
|
|||||||
position = data.pos,
|
position = data.pos,
|
||||||
rotation = data.norm,
|
rotation = data.norm,
|
||||||
};
|
};
|
||||||
var prop = DetailBuilder.MakeDetail(planetGO, sector, prefab, detailInfo);
|
var prop = DetailBuilder.Make(planetGO, sector, prefab, detailInfo);
|
||||||
|
|
||||||
var body = data.hitBodyGameObject.GetComponent<AstroObject>();
|
var body = data.hitBodyGameObject.GetComponent<AstroObject>();
|
||||||
if (body != null) RegisterProp(body, prop);
|
if (body != null) RegisterProp(body, prop);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user