mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Merge branch 'dev' into no-more-eye-ship
This commit is contained in:
commit
40a038fb05
@ -1,5 +1,4 @@
|
|||||||
using NewHorizons.Builder.General;
|
using NewHorizons.Builder.General;
|
||||||
using NewHorizons.External.Configs;
|
|
||||||
using NewHorizons.External.Modules;
|
using NewHorizons.External.Modules;
|
||||||
using NewHorizons.Handlers;
|
using NewHorizons.Handlers;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
@ -8,22 +7,37 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.SceneManagement;
|
||||||
using Logger = NewHorizons.Utility.Logger;
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
|
|
||||||
namespace NewHorizons.Builder.Props
|
namespace NewHorizons.Builder.Props
|
||||||
{
|
{
|
||||||
public static class DetailBuilder
|
public static class DetailBuilder
|
||||||
{
|
{
|
||||||
private static Dictionary<PropModule.DetailInfo, GameObject> detailInfoToCorrespondingSpawnedGameObject = new Dictionary<PropModule.DetailInfo, GameObject>();
|
private static readonly Dictionary<PropModule.DetailInfo, GameObject> _detailInfoToCorrespondingSpawnedGameObject = new();
|
||||||
|
private static readonly Dictionary<string, (GameObject prefab, bool isItem)> _fixedPrefabCache = new();
|
||||||
|
|
||||||
|
static DetailBuilder()
|
||||||
|
{
|
||||||
|
SceneManager.sceneUnloaded += SceneManager_sceneUnloaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SceneManager_sceneUnloaded(Scene scene)
|
||||||
|
{
|
||||||
|
_fixedPrefabCache.Clear();
|
||||||
|
_detailInfoToCorrespondingSpawnedGameObject.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
public static GameObject GetSpawnedGameObjectByDetailInfo(PropModule.DetailInfo detail)
|
public static GameObject GetSpawnedGameObjectByDetailInfo(PropModule.DetailInfo detail)
|
||||||
{
|
{
|
||||||
if (!detailInfoToCorrespondingSpawnedGameObject.ContainsKey(detail)) return null;
|
if (!_detailInfoToCorrespondingSpawnedGameObject.ContainsKey(detail))
|
||||||
return detailInfoToCorrespondingSpawnedGameObject[detail];
|
{
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
public static void RegisterDetailInfo(PropModule.DetailInfo detail, GameObject detailGO)
|
else
|
||||||
{
|
{
|
||||||
detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO;
|
return _detailInfoToCorrespondingSpawnedGameObject[detail];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -64,28 +78,47 @@ namespace NewHorizons.Builder.Props
|
|||||||
{
|
{
|
||||||
if (prefab == null) return null;
|
if (prefab == null) return null;
|
||||||
|
|
||||||
GameObject prop = prefab.InstantiateInactive();
|
GameObject prop;
|
||||||
prop.name = prefab.name;
|
bool isItem;
|
||||||
prop.transform.parent = sector?.transform ?? go.transform;
|
|
||||||
|
|
||||||
StreamingHandler.SetUpStreaming(prop, sector);
|
// We save copies with all their components fixed, good if the user is placing the same detail more than once
|
||||||
|
if (detail?.path != null && _fixedPrefabCache.TryGetValue(detail.path, out var storedPrefab))
|
||||||
// Could check this in the for loop but I'm not sure what order we need to know about this in
|
|
||||||
var isTorch = prop.GetComponent<VisionTorchItem>() != null;
|
|
||||||
var isItem = false;
|
|
||||||
|
|
||||||
foreach (var component in prop.GetComponentsInChildren<Component>(true))
|
|
||||||
{
|
{
|
||||||
if (component.gameObject == prop && component is OWItem) isItem = true;
|
prop = storedPrefab.prefab.InstantiateInactive();
|
||||||
|
prop.name = prefab.name;
|
||||||
if (sector == null)
|
isItem = storedPrefab.isItem;
|
||||||
{
|
|
||||||
if (FixUnsectoredComponent(component)) continue;
|
|
||||||
}
|
|
||||||
else FixSectoredComponent(component, sector, isTorch);
|
|
||||||
|
|
||||||
FixComponent(component, go);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
prop = prefab.InstantiateInactive();
|
||||||
|
prop.name = prefab.name;
|
||||||
|
|
||||||
|
StreamingHandler.SetUpStreaming(prop, sector);
|
||||||
|
|
||||||
|
// Could check this in the for loop but I'm not sure what order we need to know about this in
|
||||||
|
var isTorch = prop.GetComponent<VisionTorchItem>() != null;
|
||||||
|
isItem = false;
|
||||||
|
|
||||||
|
foreach (var component in prop.GetComponentsInChildren<Component>(true))
|
||||||
|
{
|
||||||
|
if (component.gameObject == prop && component is OWItem) isItem = true;
|
||||||
|
|
||||||
|
if (sector == null)
|
||||||
|
{
|
||||||
|
if (FixUnsectoredComponent(component)) continue;
|
||||||
|
}
|
||||||
|
else FixSectoredComponent(component, sector, isTorch);
|
||||||
|
|
||||||
|
FixComponent(component, go);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detail.path != null)
|
||||||
|
{
|
||||||
|
_fixedPrefabCache.Add(detail.path, (prop.InstantiateInactive(), isItem));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prop.transform.parent = sector?.transform ?? go.transform;
|
||||||
|
|
||||||
// Items shouldn't use these else they get weird
|
// Items shouldn't use these else they get weird
|
||||||
if (isItem) detail.keepLoaded = true;
|
if (isItem) detail.keepLoaded = true;
|
||||||
@ -173,6 +206,8 @@ namespace NewHorizons.Builder.Props
|
|||||||
if (!detail.keepLoaded) GroupsBuilder.Make(prop, sector);
|
if (!detail.keepLoaded) GroupsBuilder.Make(prop, sector);
|
||||||
prop.SetActive(true);
|
prop.SetActive(true);
|
||||||
|
|
||||||
|
_detailInfoToCorrespondingSpawnedGameObject[detail] = prop;
|
||||||
|
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,7 +354,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
[RequireComponent(typeof(AnglerfishAnimController))]
|
[RequireComponent(typeof(AnglerfishAnimController))]
|
||||||
private class AnglerAnimFixer : MonoBehaviour
|
private class AnglerAnimFixer : MonoBehaviour
|
||||||
{
|
{
|
||||||
private void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
var angler = GetComponent<AnglerfishAnimController>();
|
var angler = GetComponent<AnglerfishAnimController>();
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,6 @@ namespace NewHorizons.Builder.Props
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var detailGO = DetailBuilder.Make(go, sector, mod, detail);
|
var detailGO = DetailBuilder.Make(go, sector, mod, detail);
|
||||||
DetailBuilder.RegisterDetailInfo(detail, detailGO);
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user