cleanup of main proj

This commit is contained in:
Aleksander Waage 2020-12-14 21:41:56 +01:00
parent 36bf53b3c3
commit a8181605ab
56 changed files with 651 additions and 716 deletions

View File

@ -29,9 +29,9 @@ namespace QSB.Animation
private RuntimeAnimatorController _riebeckController;
public AnimatorMirror Mirror { get; private set; }
public AnimationType CurrentType;
public AnimationType CurrentType { get; set; }
protected override void Awake()
protected override void Awake()
{
base.Awake();
_anim = gameObject.AddComponent<Animator>();
@ -39,10 +39,10 @@ namespace QSB.Animation
_netAnim.enabled = false;
_netAnim.animator = _anim;
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => LoadControllers();
QSBSceneManager.OnUniverseSceneLoaded += OnUniverseSceneLoaded;
}
protected override void OnDestroy()
protected override void OnDestroy()
{
base.OnDestroy();
if (_playerController == null)
@ -53,10 +53,12 @@ namespace QSB.Animation
_playerController.OnBecomeGrounded -= OnBecomeGrounded;
_playerController.OnBecomeUngrounded -= OnBecomeUngrounded;
QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => LoadControllers();
}
QSBSceneManager.OnUniverseSceneLoaded -= OnUniverseSceneLoaded;
}
private void LoadControllers()
private void OnUniverseSceneLoaded(OWScene obj) => LoadControllers();
private void LoadControllers()
{
var bundle = QSBCore.InstrumentAssetBundle;
_chertController = bundle.LoadAsset("assets/Chert/Traveller_Chert.controller") as RuntimeAnimatorController;

View File

@ -2,12 +2,12 @@
{
public enum AnimationType
{
Chert,
Esker,
Feldspar,
Gabbro,
PlayerSuited,
PlayerUnsuited,
Riebeck
Chert = 0,
Esker = 1,
Feldspar = 2,
Gabbro = 3,
PlayerSuited = 4,
PlayerUnsuited = 5,
Riebeck = 6
}
}

View File

@ -1,5 +1,4 @@
using OWML.Common;
using QSB.Player;
using QSB.Utility;
using System.Collections.Generic;
using System.Linq;
@ -36,12 +35,7 @@ namespace QSB.Animation
}
}
private PlayerInfo GetPlayer()
{
return QSBPlayerManager.GetSyncObjects<AnimationSync>().First(x => x.Mirror == this).Player;
}
private void Update()
public void Update()
{
if (_to == null || _from == null)
{

View File

@ -27,7 +27,7 @@ namespace QSB.Animation
_bodyAnim = bodyAnim;
}
private void Update()
public void Update()
{
if (IsLocalPlayer)
{

View File

@ -11,133 +11,126 @@ using UnityEngine.UI;
namespace QSB.ConversationSync
{
public class ConversationManager : MonoBehaviour
{
public static ConversationManager Instance { get; private set; }
public AssetBundle ConversationAssetBundle { get; private set; }
private GameObject BoxPrefab;
public Dictionary<CharacterDialogueTree, GameObject> BoxMappings = new Dictionary<CharacterDialogueTree, GameObject>();
public class ConversationManager : MonoBehaviour
{
public static ConversationManager Instance { get; private set; }
public AssetBundle ConversationAssetBundle { get; private set; }
public Dictionary<CharacterDialogueTree, GameObject> BoxMappings { get; } = new Dictionary<CharacterDialogueTree, GameObject>();
private void Start()
{
Instance = this;
private GameObject _boxPrefab;
ConversationAssetBundle = QSBCore.Helper.Assets.LoadBundle("assets/conversation");
public void Start()
{
Instance = this;
BoxPrefab = ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
// TODO : make dynamic so it can be different sizes!
var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold");
if (font == null)
{
DebugLog.ToConsole("Error - Font is null!", MessageType.Error);
}
BoxPrefab.GetComponent<Text>().font = font;
BoxPrefab.GetComponent<Text>().color = Color.white;
}
ConversationAssetBundle = QSBCore.Helper.Assets.LoadBundle("assets/conversation");
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
{
var treeIndex = QSBWorldSync.OldDialogueTrees.IndexOf(tree);
if (!QSBPlayerManager.PlayerList.Any(x => x.CurrentDialogueID == treeIndex))
{
return uint.MaxValue;
}
return QSBPlayerManager.PlayerList.First(x => x.CurrentDialogueID == treeIndex).PlayerId;
}
_boxPrefab = ConversationAssetBundle.LoadAsset<GameObject>("assets/dialoguebubble.prefab");
// TODO : make dynamic so it can be different sizes!
var font = (Font)Resources.Load(@"fonts\english - latin\spacemono-bold");
if (font == null)
{
DebugLog.ToConsole("Error - Font is null!", MessageType.Error);
}
_boxPrefab.GetComponent<Text>().font = font;
_boxPrefab.GetComponent<Text>().color = Color.white;
}
public void SendPlayerOption(string text)
{
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, text, ConversationType.Player);
}
public uint GetPlayerTalkingToTree(CharacterDialogueTree tree)
{
var treeIndex = QSBWorldSync.OldDialogueTrees.IndexOf(tree);
return QSBPlayerManager.PlayerList.All(x => x.CurrentDialogueID != treeIndex)
? uint.MaxValue
: QSBPlayerManager.PlayerList.First(x => x.CurrentDialogueID == treeIndex).PlayerId;
}
public void SendCharacterDialogue(int id, string text)
{
if (id == -1)
{
DebugLog.ToConsole("Warning - Tried to send conv. event with char id -1.", MessageType.Warning);
return;
}
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, (uint)id, text, ConversationType.Character);
}
public void SendPlayerOption(string text) =>
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, text, ConversationType.Player);
public void CloseBoxPlayer()
{
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, "", ConversationType.ClosePlayer);
}
public void SendCharacterDialogue(int id, string text)
{
if (id == -1)
{
DebugLog.ToConsole("Warning - Tried to send conv. event with char id -1.", MessageType.Warning);
return;
}
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, (uint)id, text, ConversationType.Character);
}
public void CloseBoxCharacter(int id)
{
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, (uint)id, "", ConversationType.CloseCharacter);
}
public void CloseBoxPlayer() =>
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, QSBPlayerManager.LocalPlayerId, "", ConversationType.ClosePlayer);
public void SendConvState(int charId, bool state)
{
if (charId == -1)
{
DebugLog.ToConsole("Warning - Tried to send conv. start/end event with char id -1.", MessageType.Warning);
return;
}
GlobalMessenger<int, uint, bool>
.FireEvent(EventNames.QSBConversationStartEnd, charId, QSBPlayerManager.LocalPlayerId, state);
}
public void CloseBoxCharacter(int id) =>
GlobalMessenger<uint, string, ConversationType>
.FireEvent(EventNames.QSBConversation, (uint)id, "", ConversationType.CloseCharacter);
public void DisplayPlayerConversationBox(uint playerId, string text)
{
if (playerId == QSBPlayerManager.LocalPlayerId)
{
DebugLog.ToConsole("Error - Cannot display conversation box for local player!", MessageType.Error);
return;
}
public void SendConvState(int charId, bool state)
{
if (charId == -1)
{
DebugLog.ToConsole("Warning - Tried to send conv. start/end event with char id -1.", MessageType.Warning);
return;
}
GlobalMessenger<int, uint, bool>
.FireEvent(EventNames.QSBConversationStartEnd, charId, QSBPlayerManager.LocalPlayerId, state);
}
var player = QSBPlayerManager.GetPlayer(playerId);
public void DisplayPlayerConversationBox(uint playerId, string text)
{
if (playerId == QSBPlayerManager.LocalPlayerId)
{
DebugLog.ToConsole("Error - Cannot display conversation box for local player!", MessageType.Error);
return;
}
// Destroy old box if it exists
var playerBox = player.CurrentDialogueBox;
if (playerBox != null)
{
Destroy(playerBox);
}
var player = QSBPlayerManager.GetPlayer(playerId);
QSBPlayerManager.GetPlayer(playerId).CurrentDialogueBox = CreateBox(player.Body.transform, 25, text);
}
// Destroy old box if it exists
var playerBox = player.CurrentDialogueBox;
if (playerBox != null)
{
Destroy(playerBox);
}
public void DisplayCharacterConversationBox(int index, string text)
{
if (QSBWorldSync.OldDialogueTrees.ElementAtOrDefault(index) == null)
{
DebugLog.ToConsole($"Error - Tried to display character conversation box for id {index}! (Doesn't exist!)", MessageType.Error);
return;
}
QSBPlayerManager.GetPlayer(playerId).CurrentDialogueBox = CreateBox(player.Body.transform, 25, text);
}
// Remove old box if it exists
var oldDialogueTree = QSBWorldSync.OldDialogueTrees[index];
if (BoxMappings.ContainsKey(oldDialogueTree))
{
Destroy(BoxMappings[oldDialogueTree]);
BoxMappings.Remove(oldDialogueTree);
}
public void DisplayCharacterConversationBox(int index, string text)
{
if (QSBWorldSync.OldDialogueTrees.ElementAtOrDefault(index) == null)
{
DebugLog.ToConsole($"Error - Tried to display character conversation box for id {index}! (Doesn't exist!)", MessageType.Error);
return;
}
BoxMappings.Add(oldDialogueTree, CreateBox(oldDialogueTree.gameObject.transform, 2, text));
}
// Remove old box if it exists
var oldDialogueTree = QSBWorldSync.OldDialogueTrees[index];
if (BoxMappings.ContainsKey(oldDialogueTree))
{
Destroy(BoxMappings[oldDialogueTree]);
BoxMappings.Remove(oldDialogueTree);
}
private GameObject CreateBox(Transform parent, float vertOffset, string text)
{
var newBox = Instantiate(BoxPrefab);
newBox.SetActive(false);
newBox.transform.parent = parent;
newBox.transform.localPosition = new Vector3(0, vertOffset, 0);
newBox.transform.rotation = parent.rotation;
var lookAt = newBox.AddComponent<FaceActiveCamera>();
lookAt.SetValue("_useLookAt", false);
lookAt.SetValue("_localFacingVector", Vector3.back);
lookAt.SetValue("_localRotationAxis", Vector3.up);
newBox.GetComponent<Text>().text = text;
newBox.SetActive(true);
return newBox;
}
}
BoxMappings.Add(oldDialogueTree, CreateBox(oldDialogueTree.gameObject.transform, 2, text));
}
private GameObject CreateBox(Transform parent, float vertOffset, string text)
{
var newBox = Instantiate(_boxPrefab);
newBox.SetActive(false);
newBox.transform.parent = parent;
newBox.transform.localPosition = new Vector3(0, vertOffset, 0);
newBox.transform.rotation = parent.rotation;
var lookAt = newBox.AddComponent<FaceActiveCamera>();
lookAt.SetValue("_useLookAt", false);
lookAt.SetValue("_localFacingVector", Vector3.back);
lookAt.SetValue("_localRotationAxis", Vector3.up);
newBox.GetComponent<Text>().text = text;
newBox.SetActive(true);
return newBox;
}
}
}

View File

@ -74,17 +74,12 @@ namespace QSB.ConversationSync
CharacterDialogueTree ____dialogueTree)
{
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
Vector3 position;
if (playerId == uint.MaxValue)
{
// TODO : Find closest player and track to that camera.
position = Locator.GetActiveCamera().transform.position;
}
else
{
position = QSBPlayerManager.GetPlayer(playerId).Camera.transform.position;
}
var b = ___headTrackingWeight * Mathf.Min(1, (!___lookOnlyWhenTalking) ? ((!____playerInHeadZone) ? 0 : 1) : ((!____inConversation || !____playerInHeadZone) ? 0 : 1));
var position = playerId == uint.MaxValue
? Locator.GetActiveCamera().transform.position
: QSBPlayerManager.GetPlayer(playerId).Camera.transform.position;
var b = ___headTrackingWeight * Mathf.Min(1, !___lookOnlyWhenTalking
? !____playerInHeadZone ? 0 : 1
: !____inConversation || !____playerInHeadZone ? 0 : 1);
____currentLookWeight = Mathf.Lerp(____currentLookWeight, b, Time.deltaTime * 2f);
____currentLookTarget = ___lookSpring.Update(____currentLookTarget, position, Time.deltaTime);
____animator.SetLookAtPosition(____currentLookTarget);
@ -95,12 +90,8 @@ namespace QSB.ConversationSync
public static bool OnZoneExit(CharacterDialogueTree ____dialogueTree)
{
var playerId = ConversationManager.Instance.GetPlayerTalkingToTree(____dialogueTree);
if (playerId == uint.MaxValue)
{
return true;
}
return false;
}
return playerId == uint.MaxValue;
}
public override void DoPatches()
{

View File

@ -2,9 +2,9 @@
{
public enum ConversationType
{
Character,
Player,
CloseCharacter,
ClosePlayer
Character = 0,
Player = 1,
CloseCharacter = 2,
ClosePlayer = 3
}
}

View File

@ -95,9 +95,7 @@ namespace QSB.DeathSync
} }
};
public static string GetPhrase(DeathType deathType)
{
return DeathDictionary[deathType].OrderBy(x => Guid.NewGuid()).First();
}
}
public static string GetPhrase(DeathType deathType) =>
DeathDictionary[deathType].OrderBy(x => Guid.NewGuid()).First();
}
}

View File

@ -8,7 +8,7 @@ namespace QSB.DeathSync
{
public class PreventShipDestruction : MonoBehaviour
{
private void Awake()
public void Awake()
{
QSBCore.Helper.HarmonyHelper.Transpile<ShipDetachableLeg>("Detach", typeof(Patch), nameof(Patch.ReturnNull));
QSBCore.Helper.HarmonyHelper.Transpile<ShipDetachableModule>("Detach", typeof(Patch), nameof(Patch.ReturnNull));

View File

@ -28,7 +28,7 @@ namespace QSB.DeathSync
private ShipCockpitController _cockpitController;
private PlayerSpacesuit _spaceSuit;
private void Awake()
public void Awake()
{
Instance = this;
@ -126,11 +126,9 @@ namespace QSB.DeathSync
_spaceSuit.RemoveSuit(true);
}
private SpawnPoint GetSpawnPoint(bool isShip = false)
{
return _playerSpawner
.GetValue<SpawnPoint[]>("_spawnList")
.FirstOrDefault(spawnPoint => spawnPoint.GetSpawnLocation() == SpawnLocation.TimberHearth && spawnPoint.IsShipSpawn() == isShip);
}
}
private SpawnPoint GetSpawnPoint(bool isShip = false) =>
_playerSpawner
.GetValue<SpawnPoint[]>("_spawnList")
.FirstOrDefault(spawnPoint => spawnPoint.GetSpawnLocation() == SpawnLocation.TimberHearth && spawnPoint.IsShipSpawn() == isShip);
}
}

View File

@ -11,18 +11,15 @@ namespace QSB.ElevatorSync
private List<Elevator> _elevators;
private void Awake()
public void Awake()
{
Instance = this;
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
}
public void OnDestroy() => QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
{
_elevators = Resources.FindObjectsOfTypeAll<Elevator>().ToList();
for (var id = 0; id < _elevators.Count; id++)

View File

@ -25,8 +25,6 @@
public static string QSBSectorChange = "QSBSectorChange";
public static string QSBPlayerStatesRequest = "QSBPlayerStatesRequest";
public static string QSBServerTime = "QSBServerTime";
public static string QSBOnProbeAnchor = "QSBOnProbeAnchor";
public static string QSBOnProbeWarp = "QSBOnProbeWarp";
public static string QSBStartLift = "QSBStartLift";
public static string QSBGeyserState = "QSBGeyserState";
public static string QSBCrouch = "QSBAnimTrigger";

View File

@ -8,14 +8,15 @@ namespace QSB.Events
public abstract class QSBEvent<T> : IQSBEvent where T : PlayerMessage, new()
{
public abstract EventType Type { get; }
public uint LocalPlayerId => QSBPlayerManager.LocalPlayerId;
public uint LocalPlayerId => QSBPlayerManager.LocalPlayerId;
private readonly MessageHandler<T> _eventHandler;
protected QSBEvent()
{
_eventHandler = new MessageHandler<T>(Type);
_eventHandler.OnClientReceiveMessage += (T message) => OnReceive(false, message);
_eventHandler.OnServerReceiveMessage += (T message) => OnReceive(true, message);
_eventHandler.OnClientReceiveMessage += message => OnReceive(false, message);
_eventHandler.OnServerReceiveMessage += message => OnReceive(true, message);
}
public abstract void SetupListener();

View File

@ -1,5 +1,4 @@
using OWML.Common;
using QSB.Animation;
using QSB.Animation.Events;
using QSB.ConversationSync.Events;
using QSB.DeathSync.Events;

View File

@ -6,13 +6,13 @@ namespace QSB.GeyserSync
{
public class GeyserManager : MonoBehaviour
{
private void Awake()
public void Awake()
{
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
QSBPatchManager.OnPatchType += OnPatchType;
}
private void OnDestroy()
public void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
QSBPatchManager.OnPatchType -= OnPatchType;

View File

@ -10,13 +10,13 @@ namespace QSB.Instruments
{
public class InstrumentsManager : PlayerSyncObject
{
private Transform rootObj;
private Transform _rootObj;
private AnimationType _savedType;
private GameObject ChertDrum;
private GameObject _chertDrum;
public void InitLocal(Transform root)
{
rootObj = root;
_rootObj = root;
gameObject.AddComponent<CameraManager>();
QSBInputManager.ChertTaunt += () => StartInstrument(AnimationType.Chert);
@ -24,14 +24,14 @@ namespace QSB.Instruments
QSBInputManager.FeldsparTaunt += () => StartInstrument(AnimationType.Feldspar);
QSBInputManager.GabbroTaunt += () => StartInstrument(AnimationType.Gabbro);
QSBInputManager.RiebeckTaunt += () => StartInstrument(AnimationType.Riebeck);
QSBInputManager.ExitTaunt += () => ReturnToPlayer();
QSBInputManager.ExitTaunt += ReturnToPlayer;
QSBCore.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments);
}
public void InitRemote(Transform root)
{
rootObj = root;
_rootObj = root;
QSBCore.Helper.Events.Unity.RunWhen(() => Locator.GetPlayerBody() != null, SetupInstruments);
}
@ -42,18 +42,24 @@ namespace QSB.Instruments
{
return;
}
QSBInputManager.ChertTaunt -= () => StartInstrument(AnimationType.Chert);
QSBInputManager.EskerTaunt -= () => StartInstrument(AnimationType.Esker);
QSBInputManager.FeldsparTaunt -= () => StartInstrument(AnimationType.Feldspar);
QSBInputManager.GabbroTaunt -= () => StartInstrument(AnimationType.Gabbro);
QSBInputManager.RiebeckTaunt -= () => StartInstrument(AnimationType.Riebeck);
QSBInputManager.ExitTaunt -= () => ReturnToPlayer();
QSBInputManager.ChertTaunt -= OnChertTaunt;
QSBInputManager.EskerTaunt -= OnEskerTaunt;
QSBInputManager.FeldsparTaunt -= OnFeldsparTaunt;
QSBInputManager.GabbroTaunt -= OnGabbroTaunt;
QSBInputManager.RiebeckTaunt -= OnRiebeckTaunt;
QSBInputManager.ExitTaunt -= ReturnToPlayer;
}
private void OnChertTaunt() => StartInstrument(AnimationType.Chert);
private void OnEskerTaunt() => StartInstrument(AnimationType.Esker);
private void OnFeldsparTaunt() => StartInstrument(AnimationType.Feldspar);
private void OnGabbroTaunt() => StartInstrument(AnimationType.Gabbro);
private void OnRiebeckTaunt() => StartInstrument(AnimationType.Riebeck);
private void SetupInstruments()
private void SetupInstruments()
{
var bundle = QSBCore.InstrumentAssetBundle;
ChertDrum = MakeChertDrum(bundle);
_chertDrum = MakeChertDrum(bundle);
}
private GameObject MakeChertDrum(AssetBundle bundle)
@ -72,8 +78,8 @@ namespace QSB.Instruments
// TODO : fix for instrument release
mr.sharedMaterial = null;
}
drum.transform.parent = rootObj;
drum.transform.rotation = rootObj.rotation;
drum.transform.parent = _rootObj;
drum.transform.rotation = _rootObj.rotation;
drum.transform.localPosition = Vector3.zero;
drum.transform.localScale = new Vector3(16.0f, 16.5f, 16.0f);
drum.SetActive(false);
@ -120,12 +126,12 @@ namespace QSB.Instruments
switch (type)
{
case AnimationType.Chert:
ChertDrum.SetActive(true);
_chertDrum.SetActive(true);
break;
case AnimationType.PlayerSuited:
case AnimationType.PlayerUnsuited:
ChertDrum.SetActive(false);
_chertDrum.SetActive(false);
break;
}
}

View File

@ -3,8 +3,10 @@
namespace QSB.Instruments.QSBCamera
{
internal class CameraController : MonoBehaviour
{
private float _degreesX;
{
public GameObject CameraObject { get; set; }
private float _degreesX;
private float _degreesY;
private Quaternion _rotationX;
private Quaternion _rotationY;
@ -15,9 +17,7 @@ namespace QSB.Instruments.QSBCamera
// Maximum distance for camera clipping
private const float RayLength = 5f;
public GameObject CameraObject;
private void FixedUpdate()
public void FixedUpdate()
{
if (CameraManager.Instance.Mode != CameraMode.ThirdPerson)
{
@ -41,27 +41,19 @@ namespace QSB.Instruments.QSBCamera
else
{
// Raycast didn't hit collider, get target from camera direction
localTargetPoint = localDirection * RayLength * PercentToMove;
localTargetPoint = RayLength * PercentToMove * localDirection;
}
var targetDistance = Vector3.Distance(origin, transform.TransformPoint(localTargetPoint));
var currentDistance = Vector3.Distance(origin, CameraObject.transform.position);
Vector3 movement;
if (targetDistance < currentDistance)
{
// Snap to target to avoid clipping
movement = localTargetPoint;
}
else
{
// Move camera out slowly
movement = Vector3.MoveTowards(CameraObject.transform.localPosition, localTargetPoint, Time.fixedDeltaTime * 2f);
}
var movement = targetDistance < currentDistance
? localTargetPoint
: Vector3.MoveTowards(CameraObject.transform.localPosition, localTargetPoint, Time.fixedDeltaTime * 2f);
CameraObject.transform.localPosition = movement;
}
private void UpdateInput()
{
var input = OWInput.GetValue(InputLibrary.look, false, InputMode.All);
var input = OWInput.GetValue(InputLibrary.look, false);
_degreesX += input.x * 180f * Time.fixedDeltaTime;
_degreesY += input.y * 180f * Time.fixedDeltaTime;
}

View File

@ -8,14 +8,17 @@ namespace QSB.Instruments.QSBCamera
public class CameraManager : MonoBehaviour
{
public static CameraManager Instance;
private GameObject CameraBase;
private GameObject CameraObj;
private Camera Camera;
private OWCamera OWCamera;
public bool IsSetUp { get; private set; }
public CameraMode Mode { get; private set; }
public void Start()
private GameObject _cameraBase;
private GameObject _cameraObj;
private Camera _camera;
private OWCamera _owCamera;
public void Start()
{
Instance = this;
SetupCamera();
@ -23,38 +26,38 @@ namespace QSB.Instruments.QSBCamera
private void SetupCamera()
{
CameraBase = new GameObject();
CameraBase.SetActive(false);
CameraBase.AddComponent<Transform>();
CameraBase.transform.parent = Locator.GetPlayerTransform();
CameraBase.transform.localPosition = Vector3.zero;
CameraBase.transform.localRotation = Quaternion.Euler(0, 0, 0);
_cameraBase = new GameObject();
_cameraBase.SetActive(false);
_cameraBase.AddComponent<Transform>();
_cameraBase.transform.parent = Locator.GetPlayerTransform();
_cameraBase.transform.localPosition = Vector3.zero;
_cameraBase.transform.localRotation = Quaternion.Euler(0, 0, 0);
CameraObj = new GameObject();
CameraObj.transform.parent = CameraBase.transform;
CameraObj.transform.localPosition = new Vector3(0, 0, -5f);
CameraObj.transform.localRotation = Quaternion.Euler(0, 0, 0);
Camera = CameraObj.AddComponent<Camera>();
Camera.cullingMask = Locator.GetPlayerCamera().mainCamera.cullingMask & ~(1 << 27) | (1 << 22);
Camera.clearFlags = CameraClearFlags.Color;
Camera.backgroundColor = Color.black;
Camera.fieldOfView = 90f;
Camera.nearClipPlane = 0.1f;
Camera.farClipPlane = 40000f;
Camera.depth = 0f;
Camera.enabled = false;
OWCamera = CameraObj.AddComponent<OWCamera>();
OWCamera.renderSkybox = true;
_cameraObj = new GameObject();
_cameraObj.transform.parent = _cameraBase.transform;
_cameraObj.transform.localPosition = new Vector3(0, 0, -5f);
_cameraObj.transform.localRotation = Quaternion.Euler(0, 0, 0);
_camera = _cameraObj.AddComponent<Camera>();
_camera.cullingMask = Locator.GetPlayerCamera().mainCamera.cullingMask & ~(1 << 27) | (1 << 22);
_camera.clearFlags = CameraClearFlags.Color;
_camera.backgroundColor = Color.black;
_camera.fieldOfView = 90f;
_camera.nearClipPlane = 0.1f;
_camera.farClipPlane = 40000f;
_camera.depth = 0f;
_camera.enabled = false;
_owCamera = _cameraObj.AddComponent<OWCamera>();
_owCamera.renderSkybox = true;
CameraBase.AddComponent<CameraController>().CameraObject = CameraObj;
_cameraBase.AddComponent<CameraController>().CameraObject = _cameraObj;
var screenGrab = CameraObj.AddComponent<FlashbackScreenGrabImageEffect>();
var screenGrab = _cameraObj.AddComponent<FlashbackScreenGrabImageEffect>();
screenGrab._downsampleShader = Locator.GetPlayerCamera().gameObject.GetComponent<FlashbackScreenGrabImageEffect>()._downsampleShader;
var fogImage = CameraObj.AddComponent<PlanetaryFogImageEffect>();
var fogImage = _cameraObj.AddComponent<PlanetaryFogImageEffect>();
fogImage.fogShader = Locator.GetPlayerCamera().gameObject.GetComponent<PlanetaryFogImageEffect>().fogShader;
CameraBase.SetActive(true);
_cameraBase.SetActive(true);
IsSetUp = true;
}
@ -79,14 +82,14 @@ namespace QSB.Instruments.QSBCamera
return;
}
OWInput.ChangeInputMode(InputMode.None);
GlobalMessenger<OWCamera>.FireEvent("SwitchActiveCamera", OWCamera);
GlobalMessenger<OWCamera>.FireEvent("SwitchActiveCamera", _owCamera);
Locator.GetPlayerCamera().mainCamera.enabled = false;
if (CameraObj.GetComponent<PostProcessingBehaviour>() == null)
if (_cameraObj.GetComponent<PostProcessingBehaviour>() == null)
{
var postProcessing = CameraObj.AddComponent<PostProcessingBehaviour>();
var postProcessing = _cameraObj.AddComponent<PostProcessingBehaviour>();
postProcessing.profile = Locator.GetPlayerCamera().gameObject.GetComponent<PostProcessingBehaviour>().profile;
}
Camera.enabled = true;
_camera.enabled = true;
Mode = CameraMode.ThirdPerson;
}
@ -107,7 +110,7 @@ namespace QSB.Instruments.QSBCamera
OWInput.ChangeInputMode(InputMode.Character);
GlobalMessenger<OWCamera>.FireEvent("SwitchActiveCamera", Locator.GetPlayerCamera());
Locator.GetActiveCamera().mainCamera.enabled = true;
Camera.enabled = false;
_camera.enabled = false;
Mode = CameraMode.FirstPerson;
}
}

View File

@ -2,7 +2,7 @@
{
public enum CameraMode
{
FirstPerson,
ThirdPerson
FirstPerson = 0,
ThirdPerson = 1
}
}

View File

@ -13,7 +13,6 @@ namespace QSB.Messaging
public event Action<T> OnServerReceiveMessage;
private readonly short _eventType;
public EventType BaseEventType => (EventType)(_eventType - 1 - QSBMsgType.Highest);
public MessageHandler(EventType eventType)
{

View File

@ -25,49 +25,62 @@ namespace QSB.OrbSync.Events
};
public override void OnReceiveRemote(bool server, WorldObjectMessage message)
{
if (!server)
{
if (QSBWorldSync.OrbSyncList.Count < message.ObjectId)
{
DebugLog.DebugWrite($"Error - Orb id {message.ObjectId} out of range of orb sync list {QSBWorldSync.OrbSyncList.Count}.", MessageType.Error);
return;
}
var orb = QSBWorldSync.OrbSyncList
.First(x => x.AttachedOrb == QSBWorldSync.OldOrbList[message.ObjectId]);
orb.enabled = true;
return;
}
{
if (server)
{
HandleServer(message);
}
else
{
HandleClient(message);
}
}
var fromPlayer = QSBNetworkServer.connections.First(x => x.GetPlayer().PlayerId == message.FromId);
if (QSBWorldSync.OrbSyncList.Count == 0)
{
DebugLog.ToConsole($"Error - OrbSyncList is empty. (ID {message.ObjectId})", MessageType.Error);
return;
}
if (fromPlayer == null)
{
DebugLog.DebugWrite("Error - FromPlayer is null!", MessageType.Error);
}
var orbSync = QSBWorldSync.OrbSyncList
.First(x => x.AttachedOrb == QSBWorldSync.OldOrbList[message.ObjectId]);
if (orbSync == null)
{
DebugLog.ToConsole($"Error - No orb found for user event. (ID {message.ObjectId})", MessageType.Error);
return;
}
var orbIdentity = orbSync.GetComponent<QSBNetworkIdentity>();
if (orbIdentity == null)
{
DebugLog.ToConsole($"Error - Orb identity is null. (ID {message.ObjectId})", MessageType.Error);
return;
}
if (orbIdentity.ClientAuthorityOwner != null && orbIdentity.ClientAuthorityOwner != fromPlayer)
{
orbIdentity.RemoveClientAuthority(orbIdentity.ClientAuthorityOwner);
}
orbIdentity.AssignClientAuthority(fromPlayer);
orbSync.enabled = true;
}
}
private static void HandleServer(WorldObjectMessage message)
{
var fromPlayer = QSBNetworkServer.connections.First(x => x.GetPlayer().PlayerId == message.FromId);
if (QSBWorldSync.OrbSyncList.Count == 0)
{
DebugLog.ToConsole($"Error - OrbSyncList is empty. (ID {message.ObjectId})", MessageType.Error);
return;
}
if (fromPlayer == null)
{
DebugLog.DebugWrite("Error - FromPlayer is null!", MessageType.Error);
}
var orbSync = QSBWorldSync.OrbSyncList
.First(x => x.AttachedOrb == QSBWorldSync.OldOrbList[message.ObjectId]);
if (orbSync == null)
{
DebugLog.ToConsole($"Error - No orb found for user event. (ID {message.ObjectId})", MessageType.Error);
return;
}
var orbIdentity = orbSync.GetComponent<QSBNetworkIdentity>();
if (orbIdentity == null)
{
DebugLog.ToConsole($"Error - Orb identity is null. (ID {message.ObjectId})", MessageType.Error);
return;
}
if (orbIdentity.ClientAuthorityOwner != null && orbIdentity.ClientAuthorityOwner != fromPlayer)
{
orbIdentity.RemoveClientAuthority(orbIdentity.ClientAuthorityOwner);
}
orbIdentity.AssignClientAuthority(fromPlayer);
orbSync.enabled = true;
}
private static void HandleClient(WorldObjectMessage message)
{
if (QSBWorldSync.OrbSyncList.Count < message.ObjectId)
{
DebugLog.DebugWrite(
$"Error - Orb id {message.ObjectId} out of range of orb sync list {QSBWorldSync.OrbSyncList.Count}.",
MessageType.Error);
return;
}
var orb = QSBWorldSync.OrbSyncList
.First(x => x.AttachedOrb == QSBWorldSync.OldOrbList[message.ObjectId]);
orb.enabled = true;
}
}
}

View File

@ -15,11 +15,11 @@ namespace QSB.Patches
public static class QSBPatchManager
{
public static List<QSBPatch> _patchList = new List<QSBPatch>();
public static event PatchEvent OnPatchType;
public static void Init()
private static List<QSBPatch> _patchList = new List<QSBPatch>();
public static void Init()
{
_patchList = new List<QSBPatch>
{

View File

@ -2,8 +2,8 @@
{
public enum QSBPatchTypes
{
OnModStart,
OnClientConnect,
OnNonServerClientConnect
OnModStart = 0,
OnClientConnect = 1,
OnNonServerClientConnect = 2
}
}

View File

@ -23,25 +23,39 @@ namespace QSB.Player.Events
};
public override void OnReceiveRemote(bool server, ToggleMessage message)
{
if (!server)
{
DebugLog.DebugWrite($"Get ready event from {message.FromId}", MessageType.Success);
if (!QSBPlayerManager.PlayerExists(message.FromId))
{
DebugLog.ToConsole("Error - Got ready event for non-existent player! Did we not send a PlayerStatesRequestEvent? Or was it not handled?", MessageType.Error);
return;
}
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
{
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
}
return;
}
DebugLog.DebugWrite($"Get ready event from {message.FromId}", MessageType.Success);
QSBPlayerManager.GetPlayer(message.AboutId).IsReady = message.ToggleValue;
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
}
}
{
if (server)
{
HandleServer(message);
}
else
{
HandleClient(message);
}
}
private static void HandleServer(ToggleMessage message)
{
DebugLog.DebugWrite($"Get ready event from {message.FromId}", MessageType.Success);
QSBPlayerManager.GetPlayer(message.AboutId).IsReady = message.ToggleValue;
GlobalMessenger.FireEvent(EventNames.QSBServerSendPlayerStates);
}
private void HandleClient(ToggleMessage message)
{
DebugLog.DebugWrite($"Get ready event from {message.FromId}", MessageType.Success);
if (!QSBPlayerManager.PlayerExists(message.FromId))
{
DebugLog.ToConsole(
"Error - Got ready event for non-existent player! Did we not send a PlayerStatesRequestEvent? Or was it not handled?",
MessageType.Error);
return;
}
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null && x.PlayerId == LocalPlayerId))
{
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
}
}
}
}

View File

@ -7,67 +7,65 @@ using System.Linq;
namespace QSB.Player
{
public static class QSBPlayerManager
{
public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.NetIdentity?.NetId.Value ?? uint.MaxValue;
public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId);
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();
public static List<PlayerSyncObject> PlayerSyncObjects { get; } = new List<PlayerSyncObject>();
public static class QSBPlayerManager
{
public static uint LocalPlayerId => PlayerTransformSync.LocalInstance.NetIdentity?.NetId.Value ?? uint.MaxValue;
public static PlayerInfo LocalPlayer => GetPlayer(LocalPlayerId);
public static List<PlayerInfo> PlayerList { get; } = new List<PlayerInfo>();
public static List<PlayerSyncObject> PlayerSyncObjects { get; } = new List<PlayerSyncObject>();
public static PlayerInfo GetPlayer(uint id)
{
if (id == uint.MaxValue || id == 0U)
{
return default;
}
var player = PlayerList.FirstOrDefault(x => x.PlayerId == id);
if (player != null)
{
return player;
}
DebugLog.DebugWrite($"Creating player id {id}", MessageType.Info);
player = new PlayerInfo(id);
PlayerList.Add(player);
return player;
}
public static PlayerInfo GetPlayer(uint id)
{
if (id == uint.MaxValue || id == 0U)
{
return default;
}
var player = PlayerList.FirstOrDefault(x => x.PlayerId == id);
if (player != null)
{
return player;
}
DebugLog.DebugWrite($"Creating player id {id}", MessageType.Info);
player = new PlayerInfo(id);
PlayerList.Add(player);
return player;
}
public static void RemovePlayer(uint id)
{
DebugLog.DebugWrite($"Removing player {GetPlayer(id).Name} id {id}", MessageType.Info);
PlayerList.Remove(GetPlayer(id));
}
public static void RemovePlayer(uint id)
{
DebugLog.DebugWrite($"Removing player {GetPlayer(id).Name} id {id}", MessageType.Info);
PlayerList.Remove(GetPlayer(id));
}
public static void RemoveAllPlayers()
{
DebugLog.DebugWrite($"Removing all players.", MessageType.Info);
PlayerList.Clear();
}
public static void RemoveAllPlayers()
{
DebugLog.DebugWrite($"Removing all players.", MessageType.Info);
PlayerList.Clear();
}
public static bool PlayerExists(uint id)
=> id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
public static bool PlayerExists(uint id) =>
id != uint.MaxValue && PlayerList.Any(x => x.PlayerId == id);
public static void HandleFullStateMessage(PlayerStateMessage message)
{
var player = GetPlayer(message.AboutId);
player.Name = message.PlayerName;
player.IsReady = message.PlayerReady;
player.State = message.PlayerState;
if (LocalPlayer.IsReady)
{
player.UpdateStateObjects();
}
}
public static void HandleFullStateMessage(PlayerStateMessage message)
{
var player = GetPlayer(message.AboutId);
player.Name = message.PlayerName;
player.IsReady = message.PlayerReady;
player.State = message.PlayerState;
if (LocalPlayer.IsReady)
{
player.UpdateStateObjects();
}
}
public static IEnumerable<T> GetSyncObjects<T>() where T : PlayerSyncObject
=> PlayerSyncObjects.OfType<T>().Where(x => x != null);
public static IEnumerable<T> GetSyncObjects<T>() where T : PlayerSyncObject =>
PlayerSyncObjects.OfType<T>().Where(x => x != null);
public static T GetSyncObject<T>(uint id) where T : PlayerSyncObject
=> GetSyncObjects<T>().FirstOrDefault(x => x != null && x.AttachedNetId == id);
public static T GetSyncObject<T>(uint id) where T : PlayerSyncObject =>
GetSyncObjects<T>().FirstOrDefault(x => x != null && x.AttachedNetId == id);
public static bool IsBelongingToLocalPlayer(uint id)
{
return id == LocalPlayerId ||
PlayerSyncObjects.Any(x => x != null && x.AttachedNetId == id && x.IsLocalPlayer);
}
}
public static bool IsBelongingToLocalPlayer(uint id) =>
id == LocalPlayerId ||
PlayerSyncObjects.Any(x => x != null && x.AttachedNetId == id && x.IsLocalPlayer);
}
}

View File

@ -28,7 +28,7 @@ namespace QSB
public static bool HasWokenUp { get; set; }
public static bool IsServer => QSBNetworkServer.active;
private void Awake()
public void Awake()
{
Application.runInBackground = true;
@ -41,7 +41,7 @@ namespace QSB
LogFilter.currentLogLevel = LogFilter.Debug;
}
private void Start()
public void Start()
{
Helper = ModHelper;
DebugLog.ToConsole($"* Start of QSB version {Helper.Manifest.Version} - authored by {Helper.Manifest.Author}", MessageType.Info);
@ -68,12 +68,10 @@ namespace QSB
Helper.HarmonyHelper.EmptyMethod(typeof(OWTime).GetMethod("Pause"));
}
private void Update()
{
QSBNetworkIdentity.UNetStaticUpdate();
}
public void Update() =>
QSBNetworkIdentity.UNetStaticUpdate();
public override void Configure(IModConfig config)
public override void Configure(IModConfig config)
{
DefaultServerIP = config.GetSettingsValue<string>("defaultServerIP");
Port = config.GetSettingsValue<int>("port");

View File

@ -36,7 +36,7 @@ namespace QSB
"Jinha"
};
private void Awake()
public void Awake()
{
PlayerName = GetPlayerName();
CanEditName = true;
@ -54,7 +54,7 @@ namespace QSB
: _defaultNames.OrderBy(x => Guid.NewGuid()).First();
}
private void OnGUI()
public void OnGUI()
{
GUI.Label(new Rect(10, 10, 200f, 20f), "Name:");
if (CanEditName)

View File

@ -25,23 +25,23 @@ namespace QSB
{
public class QSBNetworkManager : QSBNetworkManagerUNET
{
private const int MaxConnections = 128;
private const int MaxBufferedPackets = 64;
public static QSBNetworkManager Instance { get; private set; }
public static QSBNetworkManager Instance { get; private set; }
public event Action OnNetworkManagerReady;
public event Action OnNetworkManagerReady;
public bool IsReady { get; private set; }
public GameObject OrbPrefab { get; set; }
public bool IsReady { get; private set; }
private const int MaxConnections = 128;
private const int MaxBufferedPackets = 64;
private QSBNetworkLobby _lobby;
private QSBNetworkLobby _lobby;
private AssetBundle _assetBundle;
private GameObject _shipPrefab;
private GameObject _cameraPrefab;
private GameObject _probePrefab;
public GameObject OrbPrefab;
private void Awake()
public void Awake()
{
Instance = this;
@ -49,78 +49,68 @@ namespace QSB
_assetBundle = QSBCore.NetworkAssetBundle;
playerPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
var ident = playerPrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", playerPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", playerPrefab.GetComponent<NetworkIdentity>().sceneId);
Destroy(playerPrefab.GetComponent<NetworkTransform>());
SetupNetworkId(playerPrefab);
Destroy(playerPrefab.GetComponent<NetworkTransform>());
Destroy(playerPrefab.GetComponent<NetworkIdentity>());
var transform = playerPrefab.AddComponent<QSBNetworkTransform>();
transform.SendInterval = 0.1f;
transform.SyncRotationAxis = QSBNetworkTransform.AxisSyncMode.AxisXYZ;
playerPrefab.AddComponent<PlayerTransformSync>();
SetupNetworkTransform(playerPrefab);
playerPrefab.AddComponent<PlayerTransformSync>();
playerPrefab.AddComponent<AnimationSync>();
playerPrefab.AddComponent<WakeUpSync>();
playerPrefab.AddComponent<InstrumentsManager>();
_shipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab");
ident = _shipPrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", _shipPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", _shipPrefab.GetComponent<NetworkIdentity>().sceneId);
Destroy(_shipPrefab.GetComponent<NetworkTransform>());
SetupNetworkId(_shipPrefab);
Destroy(_shipPrefab.GetComponent<NetworkTransform>());
Destroy(_shipPrefab.GetComponent<NetworkIdentity>());
transform = _shipPrefab.AddComponent<QSBNetworkTransform>();
transform.SendInterval = 0.1f;
transform.SyncRotationAxis = QSBNetworkTransform.AxisSyncMode.AxisXYZ;
_shipPrefab.AddComponent<ShipTransformSync>();
SetupNetworkTransform(_shipPrefab);
_shipPrefab.AddComponent<ShipTransformSync>();
spawnPrefabs.Add(_shipPrefab);
_cameraPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkcameraroot.prefab");
ident = _cameraPrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", _cameraPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", _cameraPrefab.GetComponent<NetworkIdentity>().sceneId);
Destroy(_cameraPrefab.GetComponent<NetworkTransform>());
SetupNetworkId(_cameraPrefab);
Destroy(_cameraPrefab.GetComponent<NetworkTransform>());
Destroy(_cameraPrefab.GetComponent<NetworkIdentity>());
transform = _cameraPrefab.AddComponent<QSBNetworkTransform>();
transform.SendInterval = 0.1f;
transform.SyncRotationAxis = QSBNetworkTransform.AxisSyncMode.AxisXYZ;
_cameraPrefab.AddComponent<PlayerCameraSync>();
SetupNetworkTransform(_cameraPrefab);
_cameraPrefab.AddComponent<PlayerCameraSync>();
spawnPrefabs.Add(_cameraPrefab);
_probePrefab = _assetBundle.LoadAsset<GameObject>("assets/networkprobe.prefab");
ident = _probePrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", _probePrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", _probePrefab.GetComponent<NetworkIdentity>().sceneId);
Destroy(_probePrefab.GetComponent<NetworkTransform>());
SetupNetworkId(_probePrefab);
Destroy(_probePrefab.GetComponent<NetworkTransform>());
Destroy(_probePrefab.GetComponent<NetworkIdentity>());
transform = _probePrefab.AddComponent<QSBNetworkTransform>();
transform.SendInterval = 0.1f;
transform.SyncRotationAxis = QSBNetworkTransform.AxisSyncMode.AxisXYZ;
_probePrefab.AddComponent<PlayerProbeSync>();
SetupNetworkTransform(_probePrefab);
_probePrefab.AddComponent<PlayerProbeSync>();
spawnPrefabs.Add(_probePrefab);
OrbPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkorb.prefab");
ident = OrbPrefab.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", OrbPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", OrbPrefab.GetComponent<NetworkIdentity>().sceneId);
Destroy(OrbPrefab.GetComponent<NetworkTransform>());
SetupNetworkId(OrbPrefab);
Destroy(OrbPrefab.GetComponent<NetworkTransform>());
Destroy(OrbPrefab.GetComponent<NetworkIdentity>());
transform = OrbPrefab.AddComponent<QSBNetworkTransform>();
transform.SendInterval = 0.1f;
transform.SyncRotationAxis = QSBNetworkTransform.AxisSyncMode.AxisXYZ;
OrbPrefab.AddComponent<NomaiOrbTransformSync>();
SetupNetworkTransform(OrbPrefab);
OrbPrefab.AddComponent<NomaiOrbTransformSync>();
spawnPrefabs.Add(OrbPrefab);
ConfigureNetworkManager();
QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded;
}
private void OnDestroy()
=> QSBSceneManager.OnUniverseSceneLoaded -= OnSceneLoaded;
private void SetupNetworkId(GameObject go)
{
var ident = go.AddComponent<QSBNetworkIdentity>();
ident.LocalPlayerAuthority = true;
ident.SetValue("m_AssetId", playerPrefab.GetComponent<NetworkIdentity>().assetId);
ident.SetValue("m_SceneId", playerPrefab.GetComponent<NetworkIdentity>().sceneId);
}
private void SetupNetworkTransform(GameObject go)
{
var trans = go.AddComponent<QSBNetworkTransform>();
trans.SendInterval = 0.1f;
trans.SyncRotationAxis = QSBNetworkTransform.AxisSyncMode.AxisXYZ;
}
public void OnDestroy() =>
QSBSceneManager.OnUniverseSceneLoaded -= OnSceneLoaded;
private void OnSceneLoaded(OWScene scene)
{

View File

@ -4,34 +4,34 @@ using System;
namespace QSB
{
public static class QSBSceneManager
{
public static OWScene CurrentScene => LoadManager.GetCurrentScene();
public static class QSBSceneManager
{
public static OWScene CurrentScene => LoadManager.GetCurrentScene();
public static bool IsInUniverse => InUniverse(CurrentScene);
public static bool IsInUniverse => InUniverse(CurrentScene);
public static event Action<OWScene, bool> OnSceneLoaded;
public static event Action<OWScene, bool> OnSceneLoaded;
public static event Action<OWScene> OnUniverseSceneLoaded;
public static event Action<OWScene> OnUniverseSceneLoaded;
static QSBSceneManager()
{
LoadManager.OnCompleteSceneLoad += OnCompleteSceneLoad;
DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success);
}
static QSBSceneManager()
{
LoadManager.OnCompleteSceneLoad += OnCompleteSceneLoad;
DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success);
}
private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
{
DebugLog.DebugWrite($"COMPLETE SCENE LOAD ({oldScene} -> {newScene})", MessageType.Info);
var universe = InUniverse(newScene);
OnSceneLoaded?.Invoke(newScene, universe);
if (universe)
{
OnUniverseSceneLoaded?.Invoke(newScene);
}
}
private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
{
DebugLog.DebugWrite($"COMPLETE SCENE LOAD ({oldScene} -> {newScene})", MessageType.Info);
var universe = InUniverse(newScene);
OnSceneLoaded?.Invoke(newScene, universe);
if (universe)
{
OnUniverseSceneLoaded?.Invoke(newScene);
}
}
private static bool InUniverse(OWScene scene)
=> scene == OWScene.SolarSystem || scene == OWScene.EyeOfTheUniverse;
}
private static bool InUniverse(OWScene scene) =>
scene == OWScene.SolarSystem || scene == OWScene.EyeOfTheUniverse;
}
}

View File

@ -17,14 +17,14 @@ namespace QSB.SectorSync
Sector.Name.Ship
};
private void Awake()
public void Awake()
{
Instance = this;
QSBSceneManager.OnUniverseSceneLoaded += (OWScene scene) => RebuildSectors();
DebugLog.DebugWrite("Sector Manager ready.", MessageType.Success);
}
private void OnDestroy()
public void OnDestroy()
{
QSBSceneManager.OnUniverseSceneLoaded -= (OWScene scene) => RebuildSectors();
}
@ -43,8 +43,8 @@ namespace QSB.SectorSync
IsReady = QSBWorldSync.GetWorldObjects<QSBSector>().Any();
}
public QSBSector GetClosestSector(Transform trans) // trans rights
{
public QSBSector GetClosestSector(Transform trans) // trans rights \o/
{
return QSBWorldSync.GetWorldObjects<QSBSector>()
.Where(sector => sector.Sector != null && !_sectorBlacklist.Contains(sector.Type))
.OrderBy(sector => Vector3.Distance(sector.Position, trans.position))

View File

@ -21,7 +21,8 @@ namespace QSB.SectorSync
{
return;
}
QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>().Where(x => x.HasAuthority).ToList().ForEach(CheckTransformSyncSector);
QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x.HasAuthority).ToList().ForEach(CheckTransformSyncSector);
_checkTimer = 0;
}
@ -41,9 +42,7 @@ namespace QSB.SectorSync
SendSector(transformSync.NetId.Value, closestSector);
}
private void SendSector(uint id, QSBSector sector)
{
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, id, sector);
}
}
private void SendSector(uint id, QSBSector sector) =>
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, id, sector);
}
}

View File

@ -18,9 +18,7 @@ namespace QSB.TimeSync.Events
LoopCount = count
};
public override void OnReceiveRemote(bool server, ServerTimeMessage message)
{
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
}
}
public override void OnReceiveRemote(bool server, ServerTimeMessage message) =>
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
}
}

View File

@ -5,7 +5,7 @@ namespace QSB.TimeSync
{
public class PreserveTimeScale : QSBNetworkBehaviour
{
private void Start()
public void Start()
{
QSBCore.Helper.Menus.PauseMenu.GetTitleButton("Button-EndCurrentLoop").Hide(); // Remove the meditation button

View File

@ -2,8 +2,8 @@
{
public enum TimeSyncType
{
None,
Pausing,
Fastforwarding
None = 0,
Pausing = 1,
Fastforwarding = 2
}
}

View File

@ -15,7 +15,7 @@ namespace QSB.TimeSync
private bool _isSetUp;
private TimeSyncType _currentType;
private void Awake()
public void Awake()
{
Instance = this;
enabled = false;
@ -32,7 +32,7 @@ namespace QSB.TimeSync
_canvas.enabled = false;
}
private void OnDestroy()
public void OnDestroy()
{
QSBSceneManager.OnUniverseSceneLoaded -= OnUniverseSceneLoad;
if (_canvas.enabled)
@ -41,9 +41,11 @@ namespace QSB.TimeSync
}
}
public static void Start(TimeSyncType type) => QSBCore.Helper.Events.Unity.RunWhen(() => Instance._isSetUp, () => Instance.StartTimeSync(type));
public static void Start(TimeSyncType type) =>
QSBCore.Helper.Events.Unity.RunWhen(() => Instance._isSetUp, () => Instance.StartTimeSync(type));
public static void Stop() => QSBCore.Helper.Events.Unity.RunWhen(() => Instance._isSetUp, () => Instance.EndTimeSync());
public static void Stop() =>
QSBCore.Helper.Events.Unity.RunWhen(() => Instance._isSetUp, () => Instance.EndTimeSync());
private void StartTimeSync(TimeSyncType type)
{
@ -75,7 +77,7 @@ namespace QSB.TimeSync
switch (_currentType)
{
case TimeSyncType.Fastforwarding:
text = $"{minutes.ToString("D2")}:{seconds.ToString("D2")}"
text = $"{minutes:D2}:{seconds:D2}"
+ Environment.NewLine
+ "Fast-forwarding to match server time...";
break;

View File

@ -32,7 +32,7 @@ namespace QSB.TimeSync
LocalInstance = this;
}
private void Start()
public void Start()
{
if (!IsLocalPlayer)
{
@ -57,7 +57,7 @@ namespace QSB.TimeSync
}
}
private void OnDestroy()
public void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
GlobalMessenger.RemoveListener(EventNames.RestartTimeLoop, OnLoopStart);
@ -184,7 +184,7 @@ namespace QSB.TimeSync
OWInput.ChangeInputMode(InputMode.Character);
}
private void Update()
public void Update()
{
if (IsServer)
{

View File

@ -36,9 +36,7 @@ namespace QSB.Tools.Events
player.FlashLight?.UpdateState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message)
{
QSBPlayerManager.LocalPlayer.UpdateState(State.Flashlight, message.ToggleValue);
}
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.Flashlight, message.ToggleValue);
}
}

View File

@ -36,9 +36,7 @@ namespace QSB.Tools.Events
player.Probe?.SetState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message)
{
QSBPlayerManager.LocalPlayer.UpdateState(State.ProbeActive, message.ToggleValue);
}
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.ProbeActive, message.ToggleValue);
}
}

View File

@ -36,9 +36,7 @@ namespace QSB.Tools.Events
player.ProbeLauncher?.ChangeEquipState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message)
{
QSBPlayerManager.LocalPlayer.UpdateState(State.ProbeLauncher, message.ToggleValue);
}
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.ProbeLauncher, message.ToggleValue);
}
}

View File

@ -36,9 +36,7 @@ namespace QSB.Tools.Events
player.Signalscope?.ChangeEquipState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message)
{
QSBPlayerManager.LocalPlayer.UpdateState(State.Signalscope, message.ToggleValue);
}
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.Signalscope, message.ToggleValue);
}
}

View File

@ -36,9 +36,7 @@ namespace QSB.Tools.Events
player.Translator?.ChangeEquipState(message.ToggleValue);
}
public override void OnReceiveLocal(bool server, ToggleMessage message)
{
QSBPlayerManager.LocalPlayer.UpdateState(State.Translator, message.ToggleValue);
}
}
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
QSBPlayerManager.LocalPlayer.UpdateState(State.Translator, message.ToggleValue);
}
}

View File

@ -59,7 +59,7 @@ namespace QSB.Tools
hold.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
}
private static GameObject CreateFlashlight(Transform cameraBody)
private static void CreateFlashlight(Transform cameraBody)
{
var flashlightRoot = Object.Instantiate(GameObject.Find("FlashlightRoot"));
flashlightRoot.SetActive(false);
@ -72,11 +72,9 @@ namespace QSB.Tools
flashlightRoot.transform.parent = cameraBody;
flashlightRoot.transform.localPosition = FlashlightOffset;
flashlightRoot.SetActive(true);
}
return flashlightRoot;
}
private static GameObject CreateSignalscope(Transform cameraBody)
private static void CreateSignalscope(Transform cameraBody)
{
var signalscopeRoot = Object.Instantiate(GameObject.Find("Signalscope"));
signalscopeRoot.SetActive(false);
@ -101,11 +99,9 @@ namespace QSB.Tools
signalscopeRoot.transform.localPosition = Vector3.zero;
signalscopeRoot.transform.localScale = SignalscopeScale;
signalscopeRoot.SetActive(true);
}
return signalscopeRoot;
}
private static GameObject CreateTranslator(Transform cameraBody)
private static void CreateTranslator(Transform cameraBody)
{
var original = GameObject.Find("NomaiTranslatorProp");
@ -142,11 +138,9 @@ namespace QSB.Tools
translatorRoot.transform.localPosition = Vector3.zero;
translatorRoot.transform.localScale = TranslatorScale;
QSBCore.Helper.Events.Unity.FireOnNextUpdate(() => translatorRoot.SetActive(true));
}
return translatorRoot;
}
private static GameObject CreateProbeLauncher(Transform cameraBody)
private static void CreateProbeLauncher(Transform cameraBody)
{
var launcherRoot = new GameObject("ProbeLauncher");
var modelOrig = GameObject.Find("PlayerCamera/ProbeLauncher/Props_HEA_ProbeLauncher");
@ -182,13 +176,9 @@ namespace QSB.Tools
launcherRoot.transform.parent = cameraBody;
launcherRoot.transform.localPosition = ProbeLauncherOffset;
launcherRoot.SetActive(true);
}
return launcherRoot;
}
private static MeshRenderer GetRenderer(GameObject root, string gameObjectName)
{
return root.GetComponentsInChildren<MeshRenderer>(true).First(x => x.name == gameObjectName);
}
}
private static MeshRenderer GetRenderer(GameObject root, string gameObjectName) =>
root.GetComponentsInChildren<MeshRenderer>(true).First(x => x.name == gameObjectName);
}
}

View File

@ -14,7 +14,7 @@ namespace QSB.Tools
private Vector3 _baseForward;
private Quaternion _baseRotation;
private void Start()
public void Start()
{
_baseForward = _basePivot.forward;
_baseRotation = _basePivot.rotation;
@ -78,9 +78,9 @@ namespace QSB.Tools
_flashlightOn = false;
}
private void FixedUpdate()
public void FixedUpdate()
{
// This really isn't needed... but it makes it look that extra bit nicer.
// This really isn't needed... but it makes it look that extra bit nicer. ^_^
var lhs = Quaternion.FromToRotation(_basePivot.up, _root.up) * Quaternion.FromToRotation(_baseForward, _root.forward);
var b = lhs * _baseRotation;
_baseRotation = Quaternion.Slerp(_baseRotation, b, 6f * Time.deltaTime);

View File

@ -31,8 +31,8 @@ namespace QSB.Tools
set => _arrivalDegrees = value;
}
private void OnEnable() => ToolGameObject?.SetActive(true);
private void OnDisable() => ToolGameObject?.SetActive(false);
public void OnEnable() => ToolGameObject?.SetActive(true);
public void OnDisable() => ToolGameObject?.SetActive(false);
public void ChangeEquipState(bool equipState)
{

View File

@ -2,8 +2,8 @@
{
public enum ToolType
{
Signalscope,
ProbeLauncher,
Translator
Signalscope = 0,
ProbeLauncher = 1,
Translator = 2
}
}

View File

@ -29,7 +29,7 @@ namespace QSB.TransformSync
_isReady = true;
}
private void OnDestroy()
public void OnDestroy()
{
QSBWorldSync.OrbSyncList.Remove(this);
}
@ -41,7 +41,7 @@ namespace QSB.TransformSync
_isInitialized = true;
}
private void Update()
public void Update()
{
if (!_isInitialized && _isReady)
{

View File

@ -11,7 +11,8 @@ namespace QSB.TransformSync
{
protected void Start()
{
var lowestBound = QSBPlayerManager.GetSyncObjects<PlayerTransformSync>().Where(x => x.NetId.Value < NetId.Value).OrderBy(x => x.NetId.Value).Last();
var lowestBound = QSBPlayerManager.GetSyncObjects<PlayerTransformSync>()
.Where(x => x.NetId.Value < NetId.Value).OrderBy(x => x.NetId.Value).Last();
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
}

View File

@ -7,91 +7,89 @@ using UnityEngine;
namespace QSB.TransformSync
{
public class PlayerProbeSync : TransformSync
{
private Transform _disabledSocket;
public class PlayerProbeSync : TransformSync
{
private Transform _disabledSocket;
protected void Start()
{
var lowestBound = QSBPlayerManager.GetSyncObjects<PlayerTransformSync>().Where(x => x.NetId.Value < NetId.Value).OrderBy(x => x.NetId.Value).Last();
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
}
protected void Start()
{
var lowestBound = QSBPlayerManager.GetSyncObjects<PlayerTransformSync>()
.Where(x => x.NetId.Value < NetId.Value).OrderBy(x => x.NetId.Value).Last();
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
}
private Transform GetProbe()
=> Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
private Transform GetProbe() =>
Locator.GetProbe().transform.Find("CameraPivot").Find("Geometry");
protected override Transform InitLocalTransform()
{
var body = GetProbe();
protected override Transform InitLocalTransform()
{
var body = GetProbe();
SetSocket(Player.Camera.transform);
Player.ProbeBody = body.gameObject;
SetSocket(Player.Camera.transform);
Player.ProbeBody = body.gameObject;
return body;
}
return body;
}
protected override Transform InitRemoteTransform()
{
var probe = GetProbe();
protected override Transform InitRemoteTransform()
{
var probe = GetProbe();
if (probe == null)
{
DebugLog.ToConsole("Error - Probe is null!", MessageType.Error);
return default;
}
if (probe == null)
{
DebugLog.ToConsole("Error - Probe is null!", MessageType.Error);
return default;
}
var body = probe.InstantiateInactive();
body.name = "RemoteProbeTransform";
var body = probe.InstantiateInactive();
body.name = "RemoteProbeTransform";
Destroy(body.GetComponentInChildren<ProbeAnimatorController>());
Destroy(body.GetComponentInChildren<ProbeAnimatorController>());
PlayerToolsManager.CreateProbe(body, Player);
PlayerToolsManager.CreateProbe(body, Player);
QSBCore.Helper.Events.Unity.RunWhen(() => (Player.ProbeLauncher != null), () => SetSocket(Player.ProbeLauncher.ToolGameObject.transform));
Player.ProbeBody = body.gameObject;
QSBCore.Helper.Events.Unity.RunWhen(() => (Player.ProbeLauncher != null), () => SetSocket(Player.ProbeLauncher.ToolGameObject.transform));
Player.ProbeBody = body.gameObject;
return body;
}
return body;
}
private void SetSocket(Transform socket)
{
_disabledSocket = socket;
}
private void SetSocket(Transform socket) => _disabledSocket = socket;
protected override void UpdateTransform()
{
base.UpdateTransform();
if (Player == null)
{
DebugLog.ToConsole($"Player is null for {AttachedNetId}!", MessageType.Error);
return;
}
if (_disabledSocket == null)
{
DebugLog.ToConsole($"DisabledSocket is null for {AttachedNetId}! (ProbeLauncher null? : {Player.ProbeLauncher == null})", MessageType.Error);
return;
}
if (Player.GetState(State.ProbeActive) || ReferenceSector?.Sector == null)
{
return;
}
if (HasAuthority)
{
transform.position = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
return;
}
if (SyncedTransform.position == Vector3.zero)
{
return;
}
SyncedTransform.localPosition = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
}
protected override void UpdateTransform()
{
base.UpdateTransform();
if (Player == null)
{
DebugLog.ToConsole($"Player is null for {AttachedNetId}!", MessageType.Error);
return;
}
if (_disabledSocket == null)
{
DebugLog.ToConsole($"DisabledSocket is null for {AttachedNetId}! (ProbeLauncher null? : {Player.ProbeLauncher == null})", MessageType.Error);
return;
}
if (Player.GetState(State.ProbeActive) || ReferenceSector?.Sector == null)
{
return;
}
if (HasAuthority)
{
transform.position = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
return;
}
if (SyncedTransform.position == Vector3.zero)
{
return;
}
SyncedTransform.localPosition = ReferenceSector.Transform.InverseTransformPoint(_disabledSocket.position);
}
public override bool IsReady => Locator.GetProbe() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.IsReady
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
}
public override bool IsReady => Locator.GetProbe() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.IsReady
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
}
}

View File

@ -5,60 +5,57 @@ using UnityEngine;
namespace QSB.TransformSync
{
public class PlayerTransformSync : TransformSync
{
public static PlayerTransformSync LocalInstance { get; private set; }
public class PlayerTransformSync : TransformSync
{
public static PlayerTransformSync LocalInstance { get; private set; }
static PlayerTransformSync()
{
AnimControllerPatch.Init();
}
static PlayerTransformSync() => AnimControllerPatch.Init();
public override void OnStartLocalPlayer()
=> LocalInstance = this;
public override void OnStartLocalPlayer() =>
LocalInstance = this;
protected override void OnDestroy()
{
base.OnDestroy();
Player.HudMarker?.Remove();
QSBPlayerManager.RemovePlayer(PlayerId);
}
protected override void OnDestroy()
{
base.OnDestroy();
Player.HudMarker?.Remove();
QSBPlayerManager.RemovePlayer(PlayerId);
}
private Transform GetPlayerModel()
=> Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2");
private Transform GetPlayerModel() =>
Locator.GetPlayerTransform().Find("Traveller_HEA_Player_v2");
protected override Transform InitLocalTransform()
{
var body = GetPlayerModel();
protected override Transform InitLocalTransform()
{
var body = GetPlayerModel();
GetComponent<AnimationSync>().InitLocal(body);
GetComponent<InstrumentsManager>().InitLocal(body);
GetComponent<AnimationSync>().InitLocal(body);
GetComponent<InstrumentsManager>().InitLocal(body);
Player.Body = body.gameObject;
Player.Body = body.gameObject;
return body;
}
return body;
}
protected override Transform InitRemoteTransform()
{
var body = Instantiate(GetPlayerModel());
protected override Transform InitRemoteTransform()
{
var body = Instantiate(GetPlayerModel());
GetComponent<AnimationSync>().InitRemote(body);
GetComponent<InstrumentsManager>().InitRemote(body);
GetComponent<AnimationSync>().InitRemote(body);
GetComponent<InstrumentsManager>().InitRemote(body);
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
marker.Init(Player);
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
marker.Init(Player);
Player.Body = body.gameObject;
Player.Body = body.gameObject;
return body;
}
return body;
}
public override bool IsReady => Locator.GetPlayerTransform() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.IsReady
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
}
public override bool IsReady => Locator.GetPlayerTransform() != null
&& Player != null
&& QSBPlayerManager.PlayerExists(Player.PlayerId)
&& Player.IsReady
&& NetId.Value != uint.MaxValue
&& NetId.Value != 0U;
}
}

View File

@ -8,18 +8,17 @@ namespace QSB.TransformSync
{
protected void Start()
{
var lowestBound = QSBPlayerManager.GetSyncObjects<PlayerTransformSync>().Where(x => x.NetId.Value < NetId.Value).OrderBy(x => x.NetId.Value).Last();
var lowestBound = QSBPlayerManager.GetSyncObjects<PlayerTransformSync>()
.Where(x => x.NetId.Value < NetId.Value).OrderBy(x => x.NetId.Value).Last();
NetIdentity.SetRootIdentity(lowestBound.NetIdentity);
}
private Transform GetShipModel() => Locator.GetShipTransform();
protected override Transform InitLocalTransform()
{
return GetShipModel().Find("Module_Cockpit/Geo_Cockpit/Cockpit_Geometry/Cockpit_Exterior");
}
protected override Transform InitLocalTransform() =>
GetShipModel().Find("Module_Cockpit/Geo_Cockpit/Cockpit_Geometry/Cockpit_Exterior");
protected override Transform InitRemoteTransform()
protected override Transform InitRemoteTransform()
{
var shipModel = GetShipModel();

View File

@ -39,12 +39,10 @@ namespace QSB.TransformSync
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
{
_isInitialized = false;
}
private void OnSceneLoaded(OWScene scene, bool isInUniverse) =>
_isInitialized = false;
protected void Init()
protected void Init()
{
SyncedTransform = HasAuthority ? InitLocalTransform() : InitRemoteTransform();
SetReferenceSector(QSBSectorManager.Instance.GetClosestSector(SyncedTransform));
@ -52,7 +50,7 @@ namespace QSB.TransformSync
_isVisible = true;
}
private void Update()
public void Update()
{
if (!_isInitialized && IsReady)
{

View File

@ -24,7 +24,7 @@ namespace QSB.Utility
bridgeVolume.AddObjectToVolume(Locator.GetPlayerCameraDetector());
}
private void Update()
public void Update()
{
if (!QSBCore.DebugMode)
{
@ -40,7 +40,7 @@ namespace QSB.Utility
}
if (Input.GetKeyDown(KeyCode.Keypad3))
{
LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, true, LoadManager.FadeType.ToWhite, 1f, true);
LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, true, LoadManager.FadeType.ToWhite);
}
}
}

View File

@ -11,7 +11,7 @@ namespace QSB.Utility
{
// make custom method name in owml log.
// i wrote the owml code for this so this is fine?? shut up i dont want to change owml
var console = (ModSocketOutput)QSBCore.Helper.Console;
var console = (ModSocketOutput)QSBCore.Helper.Console;
var method = console.GetType()
.GetMethods(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)
.Last(x => x.Name == "WriteLine");

View File

@ -25,9 +25,7 @@ namespace QSB.Utility
return copy;
}
public static Transform InstantiateInactive(this Transform original)
{
return original.gameObject.InstantiateInactive().transform;
}
}
public static Transform InstantiateInactive(this Transform original) =>
original.gameObject.InstantiateInactive().transform;
}
}

View File

@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
namespace QSB.Utility
{
public static class ListExtensions
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
var seenKeys = new HashSet<TKey>();
foreach (var element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
}
}

View File

@ -11,13 +11,14 @@ namespace QSB.WorldSync
{
public static class QSBWorldSync
{
private static readonly List<WorldObject> WorldObjects = new List<WorldObject>();
public static List<NomaiOrbTransformSync> OrbSyncList = new List<NomaiOrbTransformSync>();
public static List<NomaiInterfaceOrb> OldOrbList = new List<NomaiInterfaceOrb>();
public static List<CharacterDialogueTree> OldDialogueTrees = new List<CharacterDialogueTree>();
public static List<NomaiOrbTransformSync> OrbSyncList { get; } = new List<NomaiOrbTransformSync>();
public static List<NomaiInterfaceOrb> OldOrbList { get; set; } = new List<NomaiInterfaceOrb>();
public static List<CharacterDialogueTree> OldDialogueTrees { get; set; } = new List<CharacterDialogueTree>();
public static Dictionary<string, bool> DialogueConditions { get; } = new Dictionary<string, bool>();
public static void AddWorldObject(WorldObject worldObject)
private static readonly List<WorldObject> WorldObjects = new List<WorldObject>();
public static void AddWorldObject(WorldObject worldObject)
{
if (WorldObjects.Contains(worldObject))
{
@ -43,8 +44,8 @@ namespace QSB.WorldSync
public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state)
{
var slotList = GetWorldObjects<QSBOrbSlot>();
if (slotList.Count() == 0)
var slotList = GetWorldObjects<QSBOrbSlot>().ToList();
if (!slotList.Any())
{
return;
}