-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SmoothThrust now supports more than one simulteneous controller
some code cleanup
- Loading branch information
Showing
10 changed files
with
190 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"filename": "OWML.TestMod.dll", | ||
"author": "Alek", | ||
"name": "TestMod", | ||
"uniqueName": "Alek.TestMod", | ||
"version": "0.1", | ||
"enabled": false | ||
"filename": "ControllerFix.dll", | ||
"author": "TAImatem", | ||
"name": "XBoxControllerFix", | ||
"uniqueName": "TruAI.XBoxControllerFix", | ||
"version": "1.0", | ||
"owmlVersion": "0.2.1", | ||
"enabled": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,57 @@ | ||
using OWML.Common; | ||
using OWML.Events; | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Harmony; | ||
using System.Reflection; | ||
|
||
namespace SmoothThrustContainer | ||
namespace TAI_SmoothThrust | ||
{ | ||
|
||
//[HarmonyPatch(typeof(ThrusterModel), "AddTranslationalInput")] | ||
class ThrusterModel_AddTranslationalInput | ||
class ThrusterModel_SmoothPatch | ||
{ | ||
public static void Prefix(ThrusterModel __instance, ref Vector3 input) | ||
{ | ||
if (!SmoothThrust.container.ContainsKey(__instance)) | ||
{ | ||
SmoothThrust.container.Add(__instance, new SmoothThrust.SmoothCont()); | ||
} | ||
SmoothThrust.SmoothCont iter = SmoothThrust.container[__instance]; | ||
if (OWInput.IsNewlyPressed(InputLibrary.interact, InputMode.All)) | ||
{ | ||
SmoothThrustContainer._prevTranslation = input; | ||
SmoothThrustContainer._buildupVelocity = Vector3.zero; | ||
iter._prevTranslation = input; | ||
iter._buildupVelocity = Vector3.zero; | ||
} | ||
if (input.magnitude > 0.0001f && OWInput.IsHeld(InputLibrary.interact, 0.05f, InputMode.All)) | ||
{ | ||
SmoothThrustContainer._prevTranslation.x = Mathf.SmoothDamp(SmoothThrustContainer._prevTranslation.x, input.x, ref SmoothThrustContainer._buildupVelocity.x, SmoothThrustContainer._analogSmoothTime); | ||
SmoothThrustContainer._prevTranslation.z = Mathf.SmoothDamp(SmoothThrustContainer._prevTranslation.z, input.z, ref SmoothThrustContainer._buildupVelocity.z, SmoothThrustContainer._analogSmoothTime); | ||
SmoothThrustContainer._prevTranslation.y = Mathf.SmoothDamp(SmoothThrustContainer._prevTranslation.y, input.y, ref SmoothThrustContainer._buildupVelocity.y, SmoothThrustContainer._analogSmoothTime); | ||
input = SmoothThrustContainer._prevTranslation; | ||
iter._prevTranslation.x = Mathf.SmoothDamp(iter._prevTranslation.x, input.x, ref iter._buildupVelocity.x, SmoothThrust._analogSmoothTime); | ||
iter._prevTranslation.z = Mathf.SmoothDamp(iter._prevTranslation.z, input.z, ref iter._buildupVelocity.z, SmoothThrust._analogSmoothTime); | ||
iter._prevTranslation.y = Mathf.SmoothDamp(iter._prevTranslation.y, input.y, ref iter._buildupVelocity.y, SmoothThrust._analogSmoothTime); | ||
input = iter._prevTranslation; | ||
} | ||
iter._prevTranslation = input; | ||
SmoothThrust.container[__instance] = iter; | ||
} | ||
|
||
public static void Postfix(ThrusterModel __instance) | ||
{ | ||
if (SmoothThrust.container.ContainsKey(__instance)) | ||
{ | ||
SmoothThrust.container.Remove(__instance); | ||
} | ||
SmoothThrustContainer._prevTranslation = input; | ||
} | ||
} | ||
public class SmoothThrustContainer:ModBehaviour | ||
public class SmoothThrust : ModBehaviour | ||
{ | ||
private void Start() | ||
{ | ||
ModHelper.HarmonyHelper.AddPrefix<ThrusterModel>("AddTranslationalInput", typeof(ThrusterModel_AddTranslationalInput), "Prefix"); | ||
ModHelper.HarmonyHelper.AddPrefix<ThrusterModel>("AddTranslationalInput", typeof(ThrusterModel_SmoothPatch), "Prefix"); | ||
ModHelper.HarmonyHelper.AddPostfix<ThrusterModel>("OnDestroy", typeof(ThrusterModel_SmoothPatch), "Postfix"); | ||
ModHelper.Console.WriteLine("Smooth Thrust Ready!"); | ||
} | ||
public static Vector3 _prevTranslation; | ||
public static Vector3 _buildupVelocity; | ||
|
||
public static Dictionary<MonoBehaviour, SmoothCont> container = new Dictionary<MonoBehaviour, SmoothCont>(); | ||
public static float _analogSmoothTime = 0.3f; | ||
public struct SmoothCont | ||
{ | ||
public Vector3 _prevTranslation; | ||
public Vector3 _buildupVelocity; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
{ | ||
"filename": "OWML.TestMod.dll", | ||
"author": "Alek", | ||
"name": "TestMod", | ||
"uniqueName": "Alek.TestMod", | ||
"version": "0.1", | ||
"enabled": false | ||
"filename": "KeyboardSmoothThrust.dll", | ||
"author": "TAImatem & Schinken", | ||
"name": "SmoothThrust", | ||
"uniqueName": "TruAI.SmoothThrust", | ||
"version": "1.0", | ||
"owmlVersion": "0.2.1", | ||
"enabled": true | ||
} |
Oops, something went wrong.