using QSB.Audio; using QSB.Player; using QSB.RoastingSync; using QSB.Tools; using QSB.Utility; using System.Linq; using UnityEngine; namespace QSB.PlayerBodySetup.Remote { public static class RemotePlayerCreation { public static Transform CreatePlayer( PlayerInfo player, out Transform visibleCameraRoot, out Transform visibleRoastingSystem, out Transform visibleStickPivot, out Transform visibleStickTip) { /* * CREATE PLAYER STRUCTURE */ // Variable naming convention is broken here to reflect OW unity project (with REMOTE_ prefixed) for readability var REMOTE_Player_Body = UnityEngine.Object.Instantiate(QSBCore.NetworkAssetBundle.LoadAsset("Assets/Prefabs/REMOTE_Player_Body.prefab")); REMOTE_Player_Body.transform.localPosition = Vector3.zero; REMOTE_Player_Body.transform.localScale = Vector3.one; REMOTE_Player_Body.transform.localRotation = Quaternion.identity; var REMOTE_PlayerCamera = REMOTE_Player_Body.transform.Find("REMOTE_PlayerCamera").gameObject; var REMOTE_RoastingSystem = REMOTE_Player_Body.transform.Find("REMOTE_RoastingSystem").gameObject; var REMOTE_Stick_Root = REMOTE_RoastingSystem.transform.Find("REMOTE_Stick_Root").gameObject; var REMOTE_Traveller_HEA_Player_v2 = REMOTE_Player_Body.transform.Find("REMOTE_Traveller_HEA_Player_v2").gameObject; /* * SET UP PLAYER BODY */ player.Body = REMOTE_Player_Body; FixMaterialsInAllChildren.ReplaceMaterials(REMOTE_Player_Body.transform); player.AnimationSync.InitRemote(REMOTE_Traveller_HEA_Player_v2.transform); player.InstrumentsManager.InitRemote(REMOTE_Player_Body.transform); REMOTE_Player_Body.GetComponent().Init(player); REMOTE_Player_Body.GetComponent().PlayerName = player.Name; player._ditheringAnimator = REMOTE_Player_Body.GetComponent(); // get inactive renderers too Delay.RunNextFrame(() => player._ditheringAnimator._renderers = player._ditheringAnimator .GetComponentsInChildren(true) .Select(x => x.gameObject.GetAddComponent()) .ToArray()); player.AudioController = PlayerAudioManager.InitRemote(REMOTE_Player_Body.transform); /* * SET UP PLAYER CAMERA */ REMOTE_PlayerCamera.GetComponent().enabled = false; var owcamera = REMOTE_PlayerCamera.GetComponent(); player.Camera = owcamera; player.CameraBody = REMOTE_PlayerCamera; visibleCameraRoot = REMOTE_PlayerCamera.transform; PlayerToolsManager.InitRemote(player); /* * SET UP ROASTING STICK */ var REMOTE_Stick_Pivot = REMOTE_Stick_Root.transform.GetChild(0); REMOTE_Stick_Pivot.gameObject.SetActive(false); var mallowRoot = REMOTE_Stick_Pivot.Find("REMOTE_Stick_Tip/Mallow_Root"); var newSystem = mallowRoot.Find("MallowSmoke").gameObject.GetComponent(); newSystem.Init(player); player.RoastingStick = REMOTE_Stick_Pivot.gameObject; var marshmallow = mallowRoot.GetComponent(); player.Marshmallow = marshmallow; marshmallow.enabled = true; visibleRoastingSystem = REMOTE_RoastingSystem.transform; visibleStickPivot = REMOTE_Stick_Pivot; visibleStickTip = REMOTE_Stick_Pivot.Find("REMOTE_Stick_Tip"); return REMOTE_Player_Body.transform; } } }