mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-15 00:40:04 +00:00
parent
4ec5a39aa6
commit
d7c0c06698
@ -1,21 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Messaging
|
||||
{
|
||||
// Extend this to create new message handlers.
|
||||
// You'll also need to create a new message type (add it to the enum).
|
||||
public abstract class MessageHandler : MonoBehaviour
|
||||
{
|
||||
protected abstract MessageType Type { get; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
NetworkServer.RegisterHandler((short)Type, OnServerReceiveMessage);
|
||||
NetworkManager.singleton.client.RegisterHandler((short)Type, OnClientReceiveMessage);
|
||||
}
|
||||
|
||||
protected abstract void OnClientReceiveMessage(NetworkMessage netMsg);
|
||||
protected abstract void OnServerReceiveMessage(NetworkMessage netMsg);
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("QSB.Messaging")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("QSB.Messaging")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("d6bb93aa-f405-48d5-9c4c-49c3f8e81e9a")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
@ -1,92 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D6BB93AA-F405-48D5-9C4C-49C3F8E81E9A}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>QSB.Messaging</RootNamespace>
|
||||
<AssemblyName>QSB.Messaging</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony, Version=1.2.0.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Lib.Harmony.1.2.0.1\lib\net35\0Harmony.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NAudio-Unity, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.0.3.37\lib\net35\NAudio-Unity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Json.Net.Unity3D.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.0.3.37\lib\net35\OWML.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.0.3.37\lib\net35\OWML.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.0.3.37\lib\net35\OWML.ModHelper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper.Assets, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.0.3.37\lib\net35\OWML.ModHelper.Assets.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper.Events, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.0.3.37\lib\net35\OWML.ModHelper.Events.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OWML.ModHelper.Menus, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\OWML.0.3.37\lib\net35\OWML.ModHelper.Menus.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>$(StartWorkingDirectory)\..\OuterWilds_Data\Managed\UnityEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>$(StartWorkingDirectory)\..\OuterWilds_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.Networking">
|
||||
<HintPath>$(StartWorkingDirectory)\..\OuterWilds_Data\Managed\UnityEngine.Networking.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MessageHandler.cs" />
|
||||
<Compile Include="MessageType.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SectorMessage.cs" />
|
||||
<Compile Include="WakeUpMessage.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
|
||||
<StartWorkingDirectory>C:\Program Files\Epic Games\OuterWilds\OWML</StartWorkingDirectory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ProjectView>ProjectFiles</ProjectView>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Json.Net.Unity3D" version="9.0.1" targetFramework="net35" />
|
||||
<package id="Lib.Harmony" version="1.2.0.1" targetFramework="net35" />
|
||||
<package id="OWML" version="0.3.37" targetFramework="net35" />
|
||||
</packages>
|
6
QSB.sln
6
QSB.sln
@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.29613.14
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QSB", "QSB\QSB.csproj", "{1F00090A-C697-4C55-B401-192F3CFB9DC2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QSB.Messaging", "QSB.Messaging\QSB.Messaging.csproj", "{D6BB93AA-F405-48D5-9C4C-49C3F8E81E9A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -17,10 +15,6 @@ Global
|
||||
{1F00090A-C697-4C55-B401-192F3CFB9DC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1F00090A-C697-4C55-B401-192F3CFB9DC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1F00090A-C697-4C55-B401-192F3CFB9DC2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D6BB93AA-F405-48D5-9C4C-49C3F8E81E9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D6BB93AA-F405-48D5-9C4C-49C3F8E81E9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D6BB93AA-F405-48D5-9C4C-49C3F8E81E9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D6BB93AA-F405-48D5-9C4C-49C3F8E81E9A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -1,8 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class FloatAnimParam
|
||||
public class AnimFloatParam
|
||||
{
|
||||
public float Current { get; private set; }
|
||||
public float Target { get; set; }
|
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class AnimationSync : NetworkBehaviour
|
||||
{
|
@ -2,7 +2,7 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB
|
||||
namespace QSB.Animation
|
||||
{
|
||||
public class AnimatorMirror : MonoBehaviour
|
||||
{
|
||||
@ -12,7 +12,7 @@ namespace QSB
|
||||
private Animator _to;
|
||||
private bool _isRunning;
|
||||
|
||||
private readonly Dictionary<string, FloatAnimParam> _floatParams = new Dictionary<string, FloatAnimParam>();
|
||||
private readonly Dictionary<string, AnimFloatParam> _floatParams = new Dictionary<string, AnimFloatParam>();
|
||||
|
||||
public void Init(Animator from, Animator to)
|
||||
{
|
||||
@ -28,7 +28,7 @@ namespace QSB
|
||||
}
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, new FloatAnimParam());
|
||||
_floatParams.Add(param.name, new AnimFloatParam());
|
||||
}
|
||||
_isRunning = true;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
static class Helpers
|
||||
{
|
||||
// Stolen from here: https://gist.github.com/maxattack/4c7b4de00f5c1b95a33b
|
||||
public static Quaternion QuaternionSmoothDamp(Quaternion rot, Quaternion target, ref Quaternion deriv, float time)
|
||||
{
|
||||
// account for double-cover
|
||||
var Dot = Quaternion.Dot(rot, target);
|
||||
var Multi = Dot > 0f ? 1f : -1f;
|
||||
target.x *= Multi;
|
||||
target.y *= Multi;
|
||||
target.z *= Multi;
|
||||
target.w *= Multi;
|
||||
// smooth damp (nlerp approx)
|
||||
var Result = new Vector4(
|
||||
Mathf.SmoothDamp(rot.x, target.x, ref deriv.x, time),
|
||||
Mathf.SmoothDamp(rot.y, target.y, ref deriv.y, time),
|
||||
Mathf.SmoothDamp(rot.z, target.z, ref deriv.z, time),
|
||||
Mathf.SmoothDamp(rot.w, target.w, ref deriv.w, time)
|
||||
).normalized;
|
||||
// compute deriv
|
||||
var dtInv = 1f / Time.deltaTime;
|
||||
deriv.x = (Result.x - rot.x) * dtInv;
|
||||
deriv.y = (Result.y - rot.y) * dtInv;
|
||||
deriv.z = (Result.z - rot.z) * dtInv;
|
||||
deriv.w = (Result.w - rot.w) * dtInv;
|
||||
return new Quaternion(Result.x, Result.y, Result.z, Result.w);
|
||||
}
|
||||
}
|
||||
}
|
42
QSB/Messaging/MessageHandler.cs
Normal file
42
QSB/Messaging/MessageHandler.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Messaging
|
||||
{
|
||||
// Extend this to create new message handlers.
|
||||
public class MessageHandler<T> where T : QSBMessage, new()
|
||||
{
|
||||
public event Action<T> OnClientReceiveMessage;
|
||||
public event Action<T> OnServerReceiveMessage;
|
||||
|
||||
public MessageHandler()
|
||||
{
|
||||
var message = (T)Activator.CreateInstance(typeof(T));
|
||||
NetworkServer.RegisterHandler((short)message.MessageType, OnServerReceiveMessageHandler);
|
||||
NetworkManager.singleton.client.RegisterHandler((short)message.MessageType, OnClientReceiveMessageHandler);
|
||||
}
|
||||
|
||||
public void SendToAll(T message)
|
||||
{
|
||||
NetworkServer.SendToAll((short)message.MessageType, message);
|
||||
}
|
||||
|
||||
public void SendToServer(T message)
|
||||
{
|
||||
NetworkManager.singleton.client.Send((short)message.MessageType, message);
|
||||
}
|
||||
|
||||
private void OnClientReceiveMessageHandler(NetworkMessage netMsg)
|
||||
{
|
||||
var message = netMsg.ReadMessage<T>();
|
||||
OnClientReceiveMessage?.Invoke(message);
|
||||
}
|
||||
|
||||
private void OnServerReceiveMessageHandler(NetworkMessage netMsg)
|
||||
{
|
||||
var message = netMsg.ReadMessage<T>();
|
||||
OnServerReceiveMessage?.Invoke(message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ namespace QSB.Messaging
|
||||
public enum MessageType
|
||||
{
|
||||
Sector = MsgType.Highest + 1,
|
||||
WakeUp = MsgType.Highest + 2,
|
||||
WakeUp = MsgType.Highest + 2
|
||||
// Add other message types here, incrementing the value.
|
||||
}
|
||||
}
|
9
QSB/Messaging/QSBMessage.cs
Normal file
9
QSB/Messaging/QSBMessage.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Messaging
|
||||
{
|
||||
public abstract class QSBMessage : MessageBase
|
||||
{
|
||||
public abstract MessageType MessageType { get; }
|
||||
}
|
||||
}
|
@ -2,11 +2,11 @@
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
class PreserveTimeScale : QSBBehaviour
|
||||
public class PreserveTimeScale : QSBBehaviour
|
||||
{
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
if (isPlayerAwake)
|
||||
if (IsPlayerAwake)
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
}
|
||||
|
@ -16,12 +16,6 @@ namespace QSB
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Helper = ModHelper;
|
||||
@ -31,6 +25,6 @@ namespace QSB
|
||||
gameObject.AddComponent<NetworkManagerHUD>();
|
||||
gameObject.AddComponent<PreserveTimeScale>();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -94,33 +94,32 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AnimationSync.cs" />
|
||||
<Compile Include="AnimatorMirror.cs" />
|
||||
<Compile Include="FloatAnimParam.cs" />
|
||||
<Compile Include="Animation\AnimationSync.cs" />
|
||||
<Compile Include="Animation\AnimatorMirror.cs" />
|
||||
<Compile Include="Animation\AnimFloatParam.cs" />
|
||||
<Compile Include="DebugLog.cs" />
|
||||
<Compile Include="Helpers.cs" />
|
||||
<Compile Include="Messaging\MessageHandler.cs" />
|
||||
<Compile Include="Messaging\MessageType.cs" />
|
||||
<Compile Include="Messaging\QSBMessage.cs" />
|
||||
<Compile Include="TransformSync\QuaternionHelper.cs" />
|
||||
<Compile Include="QSBBehaviour.cs" />
|
||||
<Compile Include="PreserveTimeScale.cs" />
|
||||
<Compile Include="ShipTransformSync.cs" />
|
||||
<Compile Include="TransformSync.cs" />
|
||||
<Compile Include="TransformSync\ShipTransformSync.cs" />
|
||||
<Compile Include="TransformSync\TransformSync.cs" />
|
||||
<Compile Include="TransformSync\SectorMessage.cs" />
|
||||
<Compile Include="TransformSync\SectorSync.cs" />
|
||||
<Compile Include="WakeUpMessage.cs" />
|
||||
<Compile Include="WakeUpSync.cs" />
|
||||
<Compile Include="QSBNetworkManager.cs" />
|
||||
<Compile Include="QSB.cs" />
|
||||
<Compile Include="NetworkPlayer.cs" />
|
||||
<Compile Include="TransformSync\PlayerTransformSync.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SectorSync.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="default-config.json" />
|
||||
<None Include="manifest.json" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\QSB.Messaging\QSB.Messaging.csproj">
|
||||
<Project>{d6bb93aa-f405-48d5-9c4c-49c3f8e81e9a}</Project>
|
||||
<Name>QSB.Messaging</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>md "$(StartWorkingDirectory)\Mods\$(ProjectName)"
|
||||
@ -128,7 +127,6 @@ md "$(StartWorkingDirectory)\Mods\$(ProjectName)\assets"
|
||||
del "$(StartWorkingDirectory)\Mods\$(ProjectName)\config.json"
|
||||
|
||||
copy /y "$(TargetPath)" "$(StartWorkingDirectory)\Mods\$(ProjectName)"
|
||||
copy /y "$(TargetDir)\QSB.Messaging.dll" "$(StartWorkingDirectory)\Mods\$(ProjectName)"
|
||||
|
||||
copy /y "$(ProjectDir)\default-config.json" "$(StartWorkingDirectory)\Mods\$(ProjectName)"
|
||||
|
||||
|
@ -3,9 +3,9 @@ using UnityEngine.SceneManagement;
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
abstract class QSBBehaviour : MonoBehaviour
|
||||
public abstract class QSBBehaviour : MonoBehaviour
|
||||
{
|
||||
protected bool isPlayerAwake;
|
||||
protected bool IsPlayerAwake;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
@ -27,7 +27,7 @@ namespace QSB
|
||||
|
||||
protected virtual void PlayerWokeUp()
|
||||
{
|
||||
isPlayerAwake = true;
|
||||
IsPlayerAwake = true;
|
||||
}
|
||||
|
||||
protected virtual void StartSolarSystem() { }
|
||||
|
@ -1,17 +1,20 @@
|
||||
using UnityEngine;
|
||||
using QSB.Animation;
|
||||
using QSB.TransformSync;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
public class QSBNetworkManager : NetworkManager
|
||||
{
|
||||
AssetBundle _assetBundle;
|
||||
GameObject _shipPrefab;
|
||||
private AssetBundle _assetBundle;
|
||||
private GameObject _shipPrefab;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_assetBundle = QSB.Helper.Assets.LoadBundle("assets/network");
|
||||
playerPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkplayer.prefab");
|
||||
playerPrefab.AddComponent<NetworkPlayer>();
|
||||
playerPrefab.AddComponent<PlayerTransformSync>();
|
||||
playerPrefab.AddComponent<AnimationSync>();
|
||||
|
||||
_shipPrefab = _assetBundle.LoadAsset<GameObject>("assets/networkship.prefab");
|
||||
|
@ -1,10 +1,11 @@
|
||||
using UnityEngine;
|
||||
using QSB.Animation;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public class NetworkPlayer : TransformSync
|
||||
public class PlayerTransformSync : TransformSync
|
||||
{
|
||||
public static NetworkPlayer LocalInstance { get; private set; }
|
||||
public static PlayerTransformSync LocalInstance { get; private set; }
|
||||
|
||||
private Transform _playerModel;
|
||||
|
33
QSB/TransformSync/QuaternionHelper.cs
Normal file
33
QSB/TransformSync/QuaternionHelper.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public static class QuaternionHelper
|
||||
{
|
||||
// Stolen from here: https://gist.github.com/maxattack/4c7b4de00f5c1b95a33b
|
||||
public static Quaternion SmoothDamp(Quaternion rot, Quaternion target, ref Quaternion deriv, float time)
|
||||
{
|
||||
// account for double-cover
|
||||
var dot = Quaternion.Dot(rot, target);
|
||||
var multi = dot > 0f ? 1f : -1f;
|
||||
target.x *= multi;
|
||||
target.y *= multi;
|
||||
target.z *= multi;
|
||||
target.w *= multi;
|
||||
// smooth damp (nlerp approx)
|
||||
var result = new Vector4(
|
||||
Mathf.SmoothDamp(rot.x, target.x, ref deriv.x, time),
|
||||
Mathf.SmoothDamp(rot.y, target.y, ref deriv.y, time),
|
||||
Mathf.SmoothDamp(rot.z, target.z, ref deriv.z, time),
|
||||
Mathf.SmoothDamp(rot.w, target.w, ref deriv.w, time)
|
||||
).normalized;
|
||||
// compute deriv
|
||||
var dtInv = 1f / Time.deltaTime;
|
||||
deriv.x = (result.x - rot.x) * dtInv;
|
||||
deriv.y = (result.y - rot.y) * dtInv;
|
||||
deriv.z = (result.z - rot.z) * dtInv;
|
||||
deriv.w = (result.w - rot.w) * dtInv;
|
||||
return new Quaternion(result.x, result.y, result.z, result.w);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
using UnityEngine.Networking;
|
||||
using QSB.Messaging;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Messaging
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public class SectorMessage : MessageBase
|
||||
public class SectorMessage : QSBMessage
|
||||
{
|
||||
public override MessageType MessageType => MessageType.Sector;
|
||||
|
||||
public int SectorId;
|
||||
public uint SenderId;
|
||||
|
||||
@ -18,5 +21,6 @@ namespace QSB.Messaging
|
||||
writer.Write(SectorId);
|
||||
writer.Write(SenderId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,31 +1,36 @@
|
||||
using QSB.Messaging;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using QSB.Messaging;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public class SectorSync : MessageHandler
|
||||
public class SectorSync : MonoBehaviour
|
||||
{
|
||||
protected override MessageType Type => MessageType.Sector;
|
||||
public static SectorSync Instance { get; private set; }
|
||||
|
||||
private static Dictionary<uint, Transform> _playerSectors;
|
||||
private static Sector[] _allSectors;
|
||||
private Dictionary<uint, Transform> _playerSectors;
|
||||
private Sector[] _allSectors;
|
||||
private MessageHandler<SectorMessage> _sectorHandler;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Instance = this;
|
||||
DebugLog.Screen("Start SectorSync");
|
||||
_playerSectors = new Dictionary<uint, Transform>();
|
||||
|
||||
_sectorHandler = new MessageHandler<SectorMessage>();
|
||||
_sectorHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
||||
_sectorHandler.OnServerReceiveMessage += OnServerReceiveMessage;
|
||||
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<SectorDetector>("AddSector", typeof(Patches), "PreAddSector");
|
||||
}
|
||||
|
||||
public static void SetSector(uint id, Transform sectorTransform)
|
||||
public void SetSector(uint id, Transform sectorTransform)
|
||||
{
|
||||
_playerSectors[id] = sectorTransform;
|
||||
}
|
||||
|
||||
public static void SetSector(uint id, Sector.Name sectorName)
|
||||
public void SetSector(uint id, Sector.Name sectorName)
|
||||
{
|
||||
DebugLog.Screen("Gonna set sector");
|
||||
|
||||
@ -36,16 +41,15 @@ namespace QSB
|
||||
SectorId = (int)sectorName,
|
||||
SenderId = id
|
||||
};
|
||||
NetworkManager.singleton.client.Send((short)MessageType.Sector, msg);
|
||||
|
||||
_sectorHandler.SendToServer(msg);
|
||||
}
|
||||
|
||||
public static Transform GetSector(uint id)
|
||||
public Transform GetSector(uint id)
|
||||
{
|
||||
return _playerSectors[id];
|
||||
}
|
||||
|
||||
private static Transform FindSectorTransform(Sector.Name sectorName)
|
||||
private Transform FindSectorTransform(Sector.Name sectorName)
|
||||
{
|
||||
if (_allSectors == null)
|
||||
{
|
||||
@ -61,12 +65,11 @@ namespace QSB
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void OnClientReceiveMessage(NetworkMessage netMsg)
|
||||
private void OnClientReceiveMessage(SectorMessage message)
|
||||
{
|
||||
DebugLog.Screen("OnClientReceiveMessage SectorSync");
|
||||
var msg = netMsg.ReadMessage<SectorMessage>();
|
||||
|
||||
var sectorName = (Sector.Name)msg.SectorId;
|
||||
var sectorName = (Sector.Name)message.SectorId;
|
||||
var sectorTransform = FindSectorTransform(sectorName);
|
||||
|
||||
if (sectorTransform == null)
|
||||
@ -75,15 +78,14 @@ namespace QSB
|
||||
return;
|
||||
}
|
||||
|
||||
DebugLog.Screen("Found sector", sectorName, ", setting for", msg.SenderId);
|
||||
_playerSectors[msg.SenderId] = sectorTransform;
|
||||
DebugLog.Screen("Found sector", sectorName, ", setting for", message.SenderId);
|
||||
_playerSectors[message.SenderId] = sectorTransform;
|
||||
}
|
||||
|
||||
protected override void OnServerReceiveMessage(NetworkMessage netMsg)
|
||||
private void OnServerReceiveMessage(SectorMessage message)
|
||||
{
|
||||
DebugLog.Screen("OnServerReceiveMessage SectorSync");
|
||||
var msg = netMsg.ReadMessage<SectorMessage>();
|
||||
NetworkServer.SendToAll((short)MessageType.Sector, msg);
|
||||
_sectorHandler.SendToAll(message);
|
||||
}
|
||||
|
||||
private static class Patches
|
||||
@ -95,9 +97,9 @@ namespace QSB
|
||||
return;
|
||||
}
|
||||
|
||||
if (____occupantType == DynamicOccupant.Player && NetworkPlayer.LocalInstance != null)
|
||||
if (____occupantType == DynamicOccupant.Player && PlayerTransformSync.LocalInstance != null)
|
||||
{
|
||||
NetworkPlayer.LocalInstance.EnterSector(sector);
|
||||
PlayerTransformSync.LocalInstance.EnterSector(sector);
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public class ShipTransformSync : TransformSync
|
||||
{
|
@ -1,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB
|
||||
namespace QSB.TransformSync
|
||||
{
|
||||
public abstract class TransformSync : NetworkBehaviour
|
||||
{
|
||||
@ -33,12 +33,12 @@ namespace QSB
|
||||
private void SetFirstSector()
|
||||
{
|
||||
_isSectorSetUp = true;
|
||||
SectorSync.SetSector(netId.Value, Locator.GetAstroObject(AstroObject.Name.TimberHearth).transform);
|
||||
SectorSync.Instance.SetSector(netId.Value, Locator.GetAstroObject(AstroObject.Name.TimberHearth).transform);
|
||||
}
|
||||
|
||||
public void EnterSector(Sector sector)
|
||||
{
|
||||
SectorSync.SetSector(netId.Value, sector.GetName());
|
||||
SectorSync.Instance.SetSector(netId.Value, sector.GetName());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@ -48,7 +48,7 @@ namespace QSB
|
||||
return;
|
||||
}
|
||||
|
||||
var sectorTransform = SectorSync.GetSector(netId.Value);
|
||||
var sectorTransform = SectorSync.Instance.GetSector(netId.Value);
|
||||
|
||||
if (hasAuthority)
|
||||
{
|
||||
@ -60,7 +60,7 @@ namespace QSB
|
||||
_syncedTransform.parent = sectorTransform;
|
||||
|
||||
_syncedTransform.localPosition = Vector3.SmoothDamp(_syncedTransform.localPosition, transform.position, ref _positionSmoothVelocity, SmoothTime);
|
||||
_syncedTransform.localRotation = Helpers.QuaternionSmoothDamp(_syncedTransform.localRotation, transform.rotation, ref _rotationSmoothVelocity, Time.deltaTime);
|
||||
_syncedTransform.localRotation = QuaternionHelper.SmoothDamp(_syncedTransform.localRotation, transform.rotation, ref _rotationSmoothVelocity, Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
using UnityEngine.Networking;
|
||||
using QSB.Messaging;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace QSB.Messaging
|
||||
namespace QSB
|
||||
{
|
||||
public class WakeUpMessage : MessageBase
|
||||
public class WakeUpMessage : QSBMessage
|
||||
{
|
||||
public override MessageType MessageType => MessageType.WakeUp;
|
||||
|
||||
private bool _wakeUp = true;
|
||||
|
||||
public override void Deserialize(NetworkReader reader)
|
||||
@ -15,5 +18,6 @@ namespace QSB.Messaging
|
||||
{
|
||||
writer.Write(_wakeUp);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,20 +1,20 @@
|
||||
using OWML.ModHelper.Events;
|
||||
using QSB.Messaging;
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
public class WakeUpSync : MessageHandler
|
||||
public class WakeUpSync : MonoBehaviour
|
||||
{
|
||||
public static bool IsServer;
|
||||
|
||||
protected override MessageType Type => MessageType.WakeUp;
|
||||
private MessageHandler<WakeUpMessage> _wakeUpHandler;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
DebugLog.Screen("Start WakeUpSync");
|
||||
GlobalMessenger.AddListener("WakeUp", OnWakeUp);
|
||||
_wakeUpHandler = new MessageHandler<WakeUpMessage>();
|
||||
_wakeUpHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
||||
}
|
||||
|
||||
private void OnWakeUp()
|
||||
@ -22,12 +22,11 @@ namespace QSB
|
||||
DebugLog.Screen("Sending wakeup to all my friends");
|
||||
if (IsServer)
|
||||
{
|
||||
var message = new WakeUpMessage();
|
||||
NetworkServer.SendToAll((short)MessageType.WakeUp, message);
|
||||
_wakeUpHandler.SendToAll(new WakeUpMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClientReceiveMessage(NetworkMessage netMsg)
|
||||
private void OnClientReceiveMessage(WakeUpMessage message)
|
||||
{
|
||||
if (IsServer)
|
||||
{
|
||||
@ -56,10 +55,5 @@ namespace QSB
|
||||
GlobalMessenger.FireEvent("TakeFirstFlashbackSnapshot");
|
||||
}
|
||||
|
||||
protected override void OnServerReceiveMessage(NetworkMessage netMsg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user