using NewHorizons.External.VariableSize; using NewHorizons.Utility; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Body { public static class FunnelBuilder { private enum FunnelType { SAND, WATER, LAVA, STAR } public static void Make(GameObject go, ConstantForceDetector detector, InitialMotion initialMotion, FunnelModule module) { var funnelType = FunnelType.SAND; if (module.Type.ToUpper().Equals("WATER")) funnelType = FunnelType.WATER; else if (module.Type.ToUpper().Equals("LAVA")) funnelType = FunnelType.LAVA; else if (module.Type.ToUpper().Equals("STAR")) funnelType = FunnelType.STAR; var funnelGO = new GameObject($"{go.name.Replace("_Body", "")}Funnel_Body"); funnelGO.SetActive(false); var owrb = funnelGO.AddComponent(); var alignment = funnelGO.AddComponent(); Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => alignment.SetTargetBody(AstroObjectLocator.GetAstroObject(module.Target)?.GetAttachedOWRigidbody())); var im = funnelGO.AddComponent(); var velocity = initialMotion.GetInitVelocity(); im._initLinearDirection = initialMotion._initLinearDirection; im._initLinearSpeed = initialMotion._initLinearSpeed; funnelGO.AddComponent(); funnelGO.AddComponent(); funnelGO.AddComponent(); var detectorGO = new GameObject("Detector_Funnel"); detectorGO.transform.parent = funnelGO.transform; var funnelDetector = detectorGO.AddComponent(); funnelDetector._inheritDetector = detector; funnelDetector._detectableFields = new ForceVolume[0]; detectorGO.AddComponent(); var scaleRoot = new GameObject("ScaleRoot"); scaleRoot.transform.parent = funnelGO.transform; var proxyGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Proxy_SandFunnel"), scaleRoot.transform); proxyGO.name = "Proxy_Funnel"; var geoGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Geo_SandFunnel"), scaleRoot.transform); geoGO.name = "Geo_Funnel"; var volumesGO = GameObject.Instantiate(GameObject.Find("SandFunnel_Body/ScaleRoot/Volumes_SandFunnel"), scaleRoot.transform); volumesGO.name = "Volumes_Funnel"; var sfv = volumesGO.GetComponentInChildren(); switch(funnelType) { case FunnelType.SAND: sfv._fluidType = FluidVolume.Type.SAND; break; case FunnelType.WATER: sfv._fluidType = FluidVolume.Type.WATER; break; case FunnelType.LAVA: sfv._fluidType = FluidVolume.Type.PLASMA; break; case FunnelType.STAR: sfv._fluidType = FluidVolume.Type.PLASMA; break; } funnelGO.transform.position = go.transform.position; funnelGO.SetActive(true); } } }