This commit is contained in:
Nick 2022-07-09 19:22:42 -04:00
commit baf4cff8d5
11 changed files with 50 additions and 42 deletions

View File

@ -2,7 +2,7 @@ using System.Collections.Generic;
using UnityEngine;
namespace NewHorizons.Builder.General
{
public static class MakeSector
public static class SectorBuilder
{
public static Sector Make(GameObject planetBody, OWRigidbody owRigidBody, float sphereOfInfluence)
{

View File

@ -187,8 +187,8 @@ namespace NewHorizons.Builder.Props
var path = config.isSeed ? brambleSeedPrefabPath : brambleNodePrefabPath;
var brambleNode = SearchUtilities.Find(path).InstantiateInactive();
OWAssetHandler.LoadObject(brambleNode);
sector.OnOccupantEnterSector += (sd) => OWAssetHandler.OnOccupantEnterSector(brambleNode, sd, sector);
StreamingHandler.HookStreaming(brambleNode);
sector.OnOccupantEnterSector += (sd) => StreamingHandler.OnOccupantEnterSector(brambleNode, sd, sector);
brambleNode.transform.parent = sector.transform;
brambleNode.transform.position = go.transform.TransformPoint(config.position);

View File

@ -109,8 +109,8 @@ namespace NewHorizons.Builder.Props
prop.transform.parent = sector?.transform ?? planetGO.transform;
prop.SetActive(false);
if (sector != null) sector.OnOccupantEnterSector += (SectorDetector sd) => OWAssetHandler.OnOccupantEnterSector(prop, sd, sector);
OWAssetHandler.LoadObject(prop);
if (sector != null) sector.OnOccupantEnterSector += (SectorDetector sd) => StreamingHandler.OnOccupantEnterSector(prop, sd, sector);
StreamingHandler.HookStreaming(prop);
foreach (var component in prop.GetComponents<Component>().Concat(prop.GetComponentsInChildren<Component>()))
{

View File

@ -201,8 +201,8 @@ namespace NewHorizons.Builder.Props
AddTranslation(xmlPath);
// Make sure the computer model is loaded
OWAssetHandler.LoadObject(computerObject);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(computerObject));
StreamingHandler.HookStreaming(computerObject);
sector.OnOccupantEnterSector.AddListener((x) => StreamingHandler.HookStreaming(computerObject));
computerObject.SetActive(true);
conversationInfoToCorrespondingSpawnedGameObject[info] = computerObject;
@ -249,8 +249,8 @@ namespace NewHorizons.Builder.Props
AddTranslation(xmlPath);
// Make sure the computer model is loaded
OWAssetHandler.LoadObject(cairnObject);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(cairnObject));
StreamingHandler.HookStreaming(cairnObject);
sector.OnOccupantEnterSector.AddListener((x) => StreamingHandler.HookStreaming(cairnObject));
conversationInfoToCorrespondingSpawnedGameObject[info] = cairnObject;
break;
}
@ -281,8 +281,8 @@ namespace NewHorizons.Builder.Props
AddTranslation(xmlPath);
// Make sure the recorder model is loaded
OWAssetHandler.LoadObject(recorderObject);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(recorderObject));
StreamingHandler.HookStreaming(recorderObject);
sector.OnOccupantEnterSector.AddListener((x) => StreamingHandler.HookStreaming(recorderObject));
recorderObject.SetActive(true);

View File

@ -129,8 +129,8 @@ namespace NewHorizons.Builder.Props
// Idk why but it wants reveals to be comma delimited not a list
if (info.reveals != null) slideCollectionContainer._shipLogOnComplete = string.Join(",", info.reveals);
OWAssetHandler.LoadObject(slideReelObj);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(slideReelObj));
StreamingHandler.HookStreaming(slideReelObj);
sector.OnOccupantEnterSector.AddListener((x) => StreamingHandler.HookStreaming(slideReelObj));
slideReelObj.SetActive(true);
}
@ -180,8 +180,8 @@ namespace NewHorizons.Builder.Props
slideCollectionContainer.slideCollection = slideCollection;
OWAssetHandler.LoadObject(projectorObj);
sector.OnOccupantEnterSector.AddListener((x) => OWAssetHandler.LoadObject(projectorObj));
StreamingHandler.HookStreaming(projectorObj);
sector.OnOccupantEnterSector.AddListener((x) => StreamingHandler.HookStreaming(projectorObj));
// Change the picture on the lens
var lens = projectorObj.transform.Find("Spotlight/Prop_IP_SingleSlideProjector/Projector_Lens").GetComponent<MeshRenderer>();

View File

@ -29,8 +29,8 @@ namespace NewHorizons.Builder.Props
raftObject.transform.position = planetGO.transform.TransformPoint(info.position);
raftObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.identity);
sector.OnOccupantEnterSector += (sd) => OWAssetHandler.OnOccupantEnterSector(raftObject, sd, sector);
OWAssetHandler.LoadObject(raftObject);
sector.OnOccupantEnterSector += (sd) => StreamingHandler.OnOccupantEnterSector(raftObject, sd, sector);
StreamingHandler.HookStreaming(raftObject);
var raftController = raftObject.GetComponent<RaftController>();
// Since awake already ran we have to unhook these events

View File

@ -136,8 +136,8 @@ namespace NewHorizons.Builder.Props
controller._midBone.localPosition = controller._midStartPos;
controller._topBone.localPosition = controller._topStartPos;
OWAssetHandler.LoadObject(tornadoGO);
sector.OnOccupantEnterSector += (sd) => OWAssetHandler.LoadObject(tornadoGO);
StreamingHandler.HookStreaming(tornadoGO);
sector.OnOccupantEnterSector += (sd) => StreamingHandler.HookStreaming(tornadoGO);
tornadoGO.GetComponentInChildren<CapsuleShape>().enabled = true;

View File

@ -195,7 +195,7 @@ namespace NewHorizons.Handlers
var rb = existingPlanet.GetComponent<OWRigidbody>();
var sector = MakeSector.Make(existingPlanet, rb, GetSphereOfInfluence(body));
var sector = SectorBuilder.Make(existingPlanet, rb, GetSphereOfInfluence(body));
sector.name = $"Sector-{existingPlanet.GetComponentsInChildren<Sector>().Count()}";
SharedGenerateBody(body, existingPlanet, sector, rb);
@ -310,7 +310,7 @@ namespace NewHorizons.Handlers
var owRigidBody = RigidBodyBuilder.Make(go, body.Config);
var ao = AstroObjectBuilder.Make(go, null, body.Config);
var sector = MakeSector.Make(go, owRigidBody, 2000f);
var sector = SectorBuilder.Make(go, owRigidBody, 2000f);
ao._rootSector = sector;
ao._type = AstroObject.Type.None;
@ -365,7 +365,7 @@ namespace NewHorizons.Handlers
var sphereOfInfluence = GetSphereOfInfluence(body);
var sector = MakeSector.Make(go, owRigidBody, sphereOfInfluence * 2f);
var sector = SectorBuilder.Make(go, owRigidBody, sphereOfInfluence * 2f);
ao._rootSector = sector;
if (body.Config.Base.surfaceGravity != 0)

View File

@ -6,7 +6,7 @@ namespace NewHorizons.Handlers
/// <summary>
/// handles streaming meshes so they stay loaded
/// </summary>
public static class OWAssetHandler
public static class StreamingHandler
{
private static Dictionary<Material, string> _materialCache;
private static Dictionary<GameObject, List<string>> _objectCache;
@ -19,7 +19,7 @@ namespace NewHorizons.Handlers
public static void OnOccupantEnterSector(GameObject obj, SectorDetector sd, Sector sector)
{
LoadObject(obj);
HookStreaming(obj);
// If its too laggy put this back idk
/*
@ -30,7 +30,10 @@ namespace NewHorizons.Handlers
*/
}
public static void LoadObject(GameObject obj)
/// <summary>
/// makes it so that this object's streaming stuff will be connected to the given sector
/// </summary>
public static void HookStreaming(GameObject obj, Sector sector = null)
{
var assetBundles = new List<string>();

View File

@ -272,7 +272,7 @@ namespace NewHorizons
BrambleDimensionBuilder.Init();
BrambleNodeBuilder.Init();
AstroObjectLocator.Init();
OWAssetHandler.Init();
StreamingHandler.Init();
PlanetCreationHandler.Init(BodyDict[CurrentStarSystem]);
VesselWarpHandler.LoadVessel();
SystemCreationHandler.LoadSystem(SystemDict[CurrentStarSystem]);

View File

@ -88,29 +88,34 @@ namespace NewHorizons.Utility
public static GameObject FindChild(this GameObject g, string childPath) =>
g.transform.Find(childPath)?.gameObject;
/// <summary>
/// finds active or inactive object by path,
/// or recursively finds an active object by name
/// </summary>
public static GameObject Find(string path, bool warn = true)
{
if (CachedGameObjects.TryGetValue(path, out var go)) return go;
go = GameObject.Find(path);
if (go != null) return go;
var names = path.Split('/');
var rootName = names[0];
var root = SceneManager.GetActiveScene().GetRootGameObjects().FirstOrDefault(x => x.name == rootName);
if (root == null)
{
if (warn) Logger.LogWarning($"Couldn't find root object in path ({path})");
return null;
}
var childPath = names.Skip(1).Join(delimiter: "/");
go = root.FindChild(childPath);
if (go == null)
{
var name = names.Last();
if (warn) Logger.LogWarning($"Couldn't find object in path ({path}), will look for potential matches for name {name}");
go = FindObjectOfTypeAndName<GameObject>(name);
// find inactive use root + transform.find
var names = path.Split('/');
var rootName = names[0];
var root = SceneManager.GetActiveScene().GetRootGameObjects().FirstOrDefault(x => x.name == rootName);
if (root == null)
{
if (warn) Logger.LogWarning($"Couldn't find root object in path ({path})");
return null;
}
var childPath = names.Skip(1).Join(delimiter: "/");
go = root.FindChild(childPath);
if (go == null)
{
if (warn) Logger.LogWarning($"Couldn't find child object in path ({path})");
return null;
}
}
CachedGameObjects.Add(path, go);