gg.easy.airship 0.1.2166 → 0.1.2168

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/Editor/AirAsset/AirAssetBundleEditor.cs +1 -1
  2. package/Editor/CreateAssetBundles.cs +6 -3
  3. package/Editor/EditorIntegrationsConfig.cs +0 -2
  4. package/Editor/GameConfig/GameConfigEditor.cs +8 -0
  5. package/Editor/Packages/AirshipPackagesWindow.cs +6 -3
  6. package/Editor/Settings/AirshipSettingsProvider.cs +1 -2
  7. package/Runtime/Code/Bootstrap/AirshipEntryPoint.cs +2 -0
  8. package/Runtime/Code/Bundles/SystemRoot.cs +3 -0
  9. package/Runtime/Code/GameConfig/GameConfig.cs +3 -0
  10. package/Runtime/Code/Luau/LuauBuffer.cs +17 -0
  11. package/Runtime/Code/Luau/LuauBuffer.cs.meta +3 -0
  12. package/Runtime/Code/Luau/LuauCore.cs +2 -0
  13. package/Runtime/Code/Luau/LuauCoreCallbacks.cs +13 -0
  14. package/Runtime/Code/Luau/LuauCoreReflection.cs +23 -0
  15. package/Runtime/Code/Network/Simulation/AirshipNetworkedObject.cs +18 -20
  16. package/Runtime/Code/Player/Character/Animation/CharacterAnimationHelper.cs +61 -95
  17. package/Runtime/Code/Player/Character/MovementSystems/Character/CharacterMovement.cs +125 -84
  18. package/Runtime/Code/Player/Character/MovementSystems/Character/CharacterMovementSettings.cs +2 -5
  19. package/Runtime/Code/Player/Character/MovementSystems/Character/CharacterPhysics.cs +3 -3
  20. package/Runtime/Code/TSCodeGen/Editor/CsToTs/TypeScript/Helper.cs +5 -0
  21. package/Runtime/DevConsole/Runtime/DevConsoleMono.cs +0 -335
  22. package/Runtime/Plugins/Android/libLuauPlugin.so +0 -0
  23. package/Runtime/Plugins/Linux/libLuauPlugin.so +0 -0
  24. package/Runtime/Plugins/Mac/LuauPlugin.bundle/Contents/MacOS/LuauPlugin +0 -0
  25. package/Runtime/Plugins/Windows/x64/LuauPlugin.dll +0 -0
  26. package/Runtime/Plugins/Windows/x64/LuauPlugin.pdb +0 -0
  27. package/Runtime/Plugins/iOS/LuauPluginIos.a +0 -0
  28. package/package.json +1 -1
@@ -158,7 +158,7 @@ namespace Editor.AirAsset {
158
158
  var buildOutputFile = $"bundles/airassetbundle/{airId}_{AirshipPlatformUtil.GetStringName(platform)}.bundle";
159
159
  var sourceFolderPath = Path.GetRelativePath(".", Directory.GetParent(AssetDatabase.GetAssetPath(airAssetBundle))!.FullName);
160
160
 
161
- List<AssetBundleBuild> builds = CreateAssetBundles.GetPackageAssetBundleBuilds();
161
+ List<AssetBundleBuild> builds = CreateAssetBundles.GetPackageAssetBundleBuilds(false);
162
162
 
163
163
  var assetGuids = AssetDatabase.FindAssets("*", new string[] {sourceFolderPath}).ToList();
164
164
  var assetPaths = assetGuids
@@ -173,7 +173,7 @@ public static class CreateAssetBundles {
173
173
  /// Creates an AssetBundleBuild for every AirshipPackage in the project.
174
174
  /// </summary>
175
175
  /// <returns></returns>
176
- public static List<AssetBundleBuild> GetPackageAssetBundleBuilds() {
176
+ public static List<AssetBundleBuild> GetPackageAssetBundleBuilds(bool compileURPShaders) {
177
177
  List<AssetBundleBuild> builds = new();
178
178
 
179
179
  if (!Directory.Exists(Path.Join("Assets", "AirshipPackages"))) {
@@ -197,7 +197,7 @@ public static class CreateAssetBundles {
197
197
  assetGuids.AddRange(urpGuids);
198
198
  });
199
199
 
200
- if (!EditorIntegrationsConfig.instance.selfCompileAllShaders) {
200
+ if (!compileURPShaders) {
201
201
  Debug.Log("Adding URP assets to CoreMaterials bundle.");
202
202
  addUrpFiles("Packages/com.unity.render-pipelines.universal/Shaders");
203
203
  addUrpFiles("Packages/com.unity.render-pipelines.universal/ShaderLibrary");
@@ -294,7 +294,10 @@ public static class CreateAssetBundles {
294
294
  Debug.Log($"[Editor]: Building {platform} asset bundles...");
295
295
  Debug.Log("[Editor]: Build path: " + buildPath);
296
296
 
297
- List<AssetBundleBuild> builds = GetPackageAssetBundleBuilds();
297
+ // Act as if we are building all asset bundles (including CoreMaterials).
298
+ // This is so our current build target will have references to those asset bundles.
299
+ // This is paired with changes to Scriptable Build Pipeline that prevent these bundles from actually being built.
300
+ List<AssetBundleBuild> builds = GetPackageAssetBundleBuilds(gameConfig.compileURPShaders);
298
301
 
299
302
  // Make a fake asset bundle with all package content. This makes the build have the correct dependency data.
300
303
  // {
@@ -39,8 +39,6 @@ public class EditorIntegrationsConfig : ScriptableSingleton<EditorIntegrationsCo
39
39
  [SerializeField]
40
40
  public bool safeguardBundleModification = true;
41
41
 
42
- [SerializeField] public bool selfCompileAllShaders = false;
43
-
44
42
  [SerializeField] internal bool useProjectReconcileOption = false;
45
43
  [FormerlySerializedAs("reconcilerVersion")] [SerializeField] internal ReconcilerVersion projectReconcilerVersion = ReconcilerVersion.Default;
46
44
 
@@ -18,6 +18,7 @@ public class GameConfigEditor : UnityEditor.Editor {
18
18
  private Action requestRefresh;
19
19
 
20
20
  private SerializedProperty supportsMobile;
21
+ private SerializedProperty compileURPShaders;
21
22
 
22
23
  Rect buttonRect;
23
24
  public override void OnInspectorGUI() {
@@ -51,6 +52,12 @@ public class GameConfigEditor : UnityEditor.Editor {
51
52
  EditorGUILayout.PropertyField(this.supportsMobile, new GUIContent("Mobile"));
52
53
  GUILayout.Space(20);
53
54
 
55
+ EditorGUILayout.LabelField("Shaders", EditorStyles.boldLabel);
56
+ EditorGUILayout.PropertyField(this.compileURPShaders, new GUIContent("Compile URP Shaders") {
57
+ tooltip = "By default, your game will use a precompiled set of URP shaders for basic usage. Checking this box will compile URP shaders specifically for your game. If you have any advanced URP materials (or notice invisible materials on published games), you should check this box."
58
+ });
59
+ GUILayout.Space(20);
60
+
54
61
  foreach (var field in typeof(GameConfig).GetFields()) {
55
62
  if (field.Name is "gameId" or "gameLayers" || Attribute.IsDefined(field, typeof(HideInInspector))) continue; // Rendered above
56
63
 
@@ -107,6 +114,7 @@ public class GameConfigEditor : UnityEditor.Editor {
107
114
  }
108
115
 
109
116
  this.supportsMobile = serializedObject.FindProperty("supportsMobile");
117
+ this.compileURPShaders = serializedObject.FindProperty("compileURPShaders");
110
118
 
111
119
  updateSelectedGame += (update) => {
112
120
  var gameId = update.gameId;
@@ -396,8 +396,8 @@ namespace Editor.Packages {
396
396
  // Uncomment to just build iOS
397
397
  if (isCoreMaterials) {
398
398
  platforms.Clear();
399
- // platforms.Add(AirshipPlatform.iOS);
400
- platforms.Add(AirshipPlatform.Android);
399
+ platforms.Add(AirshipPlatform.iOS);
400
+ // platforms.Add(AirshipPlatform.Android);
401
401
  // platforms.Add(AirshipPlatform.Windows);
402
402
  // platforms.Add(AirshipPlatform.Mac);
403
403
  }
@@ -413,7 +413,10 @@ namespace Editor.Packages {
413
413
  Repaint();
414
414
  yield return null; // give time to repaint
415
415
 
416
- List<AssetBundleBuild> builds = CreateAssetBundles.GetPackageAssetBundleBuilds();
416
+ // Act as if we are building all asset bundles (including CoreMaterials).
417
+ // This is so our current build target will have references to those asset bundles.
418
+ // This is paired with changes to Scriptable Build Pipeline that prevent these bundles from actually being built.
419
+ List<AssetBundleBuild> builds = CreateAssetBundles.GetPackageAssetBundleBuilds(true);
417
420
 
418
421
  foreach (var platform in platforms) {
419
422
  var st = Stopwatch.StartNew();
@@ -153,8 +153,7 @@ public class AirshipSettingsProvider : SettingsProvider
153
153
  EditorIntegrationsConfig.instance.autoUpdatePackages = EditorGUILayout.Toggle(new GUIContent("Auto Update Packages", "Airship Packages will automatically update whenever a new update is available."), EditorIntegrationsConfig.instance.autoUpdatePackages);
154
154
  EditorIntegrationsConfig.instance.enableMainMenu = EditorGUILayout.Toggle(new GUIContent("Enable Main Menu", "When true, the main menu will show when pressing [Escape]."), EditorIntegrationsConfig.instance.enableMainMenu);
155
155
  EditorIntegrationsConfig.instance.buildWithoutUpload = EditorGUILayout.Toggle(new GUIContent("Build Without Upload", "When publishing, this will build the asset bundles but won't upload them to Airship. This is useful for testing file sizes with AssetBundle Browser."), EditorIntegrationsConfig.instance.buildWithoutUpload);
156
- EditorIntegrationsConfig.instance.selfCompileAllShaders = EditorGUILayout.Toggle(new GUIContent("Self Compile All Shaders", "Instead of using pre-compiled shaders from CoreMaterials, you will compile all needed URP shaders when publishing. This makes publishing take significantly longer but reduces shader stripping issues."), EditorIntegrationsConfig.instance.selfCompileAllShaders);
157
-
156
+
158
157
  // EditorIntegrationsConfig.instance.manageTypescriptProject = EditorGUILayout.Toggle(new GUIContent("Manage Typescript Projects", "Automatically update Typescript configuration files. (package.json, tsconfig.json)"), EditorIntegrationsConfig.instance.manageTypescriptProject);
159
158
 
160
159
  // EditorIntegrationsConfig.instance.typescriptAutostartCompiler = EditorGUILayout.Toggle(
@@ -8,6 +8,8 @@ using UnityEngine;
8
8
  /// </summary>
9
9
  public class AirshipEntryPoint : Singleton<AirshipEntryPoint> {
10
10
  private void Start() {
11
+ #if AIRSHIP_PLAYER
11
12
  Debug.unityLogger.logHandler = new AirshipLogHandler();
13
+ #endif
12
14
  }
13
15
  }
@@ -200,6 +200,9 @@ public class SystemRoot : Singleton<SystemRoot> {
200
200
  enums.Add(this.UnloadBundleAsync(loadedBundle, keepCodeZip));
201
201
  }
202
202
  yield return this.WaitAll(enums.ToArray());
203
+ var unloadSW = Stopwatch.StartNew();
204
+ yield return Resources.UnloadUnusedAssets();
205
+ print("Unloaded unused assets in " + unloadSW.ElapsedMilliseconds + " ms.");
203
206
 
204
207
  // code.zip
205
208
  bool openCodeZips = RunCore.IsServer() || compileLuaOnClient;
@@ -6,6 +6,7 @@ using Code.GameBundle;
6
6
  using UnityEditor;
7
7
  #endif
8
8
  using UnityEngine;
9
+ using UnityEngine.Serialization;
9
10
  using Object = UnityEngine.Object;
10
11
 
11
12
  [CreateAssetMenu(fileName = "GameConfig", menuName = "Airship/GameConfig", order = 100)]
@@ -38,6 +39,8 @@ public class GameConfig : ScriptableObject
38
39
 
39
40
  [HideInInspector] public bool supportsMobile;
40
41
 
42
+ [HideInInspector] public bool compileURPShaders = false;
43
+
41
44
  private const string TagPrefix = "AirshipTag";
42
45
  public const int MaximumTags = 64;
43
46
 
@@ -0,0 +1,17 @@
1
+ namespace Luau {
2
+ /// <summary>
3
+ /// Represents a Luau buffer value. Any C# method that takes LuauBuffer as a parameter
4
+ /// will automatically accept "buffer" types from Luau. Similarly, any C# method that
5
+ /// returns a LuauBuffer will return a buffer type to Luau.
6
+ /// </summary>
7
+ public struct LuauBuffer {
8
+ public readonly byte[] Data;
9
+
10
+ public LuauBuffer(byte[] data) {
11
+ Data = data;
12
+ }
13
+
14
+ public static implicit operator byte[](LuauBuffer buffer) => buffer.Data;
15
+ public static implicit operator LuauBuffer(byte[] data) => new (data);
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: e4fff37edb924b9885f68d18cf643b6a
3
+ timeCreated: 1754634257
@@ -44,6 +44,7 @@ public partial class LuauCore : MonoBehaviour {
44
44
  POD_VECTOR4 = 15,
45
45
  POD_FLOAT = 16,
46
46
  POD_AIRSHIP_COMPONENT = 17,
47
+ POD_BUFFER = 18,
47
48
  };
48
49
 
49
50
  private static bool s_shutdown = false;
@@ -80,6 +81,7 @@ public partial class LuauCore : MonoBehaviour {
80
81
  private static Type planeType = typeof(UnityEngine.Plane);
81
82
  private static Type colorType = typeof(UnityEngine.Color);
82
83
  private static Type binaryBlobType = typeof(Assets.Luau.BinaryBlob);
84
+ private static Type luauBufferType = typeof(LuauBuffer);
83
85
  private static Type actionType = typeof(Action);
84
86
 
85
87
  private static readonly string[] protectedScenesNames = {
@@ -639,6 +639,19 @@ public partial class LuauCore : MonoBehaviour {
639
639
  }
640
640
  break;
641
641
  }
642
+
643
+ case PODTYPE.POD_BUFFER: {
644
+ if (t.IsAssignableFrom(luauBufferType)) {
645
+ if (field != null) {
646
+ field.SetValue(objectReference, NewLuauBufferFromPointer(propertyData, propertyDataSize));
647
+ } else {
648
+ SetValue<LuauBuffer>(objectReference, NewLuauBufferFromPointer(propertyData, propertyDataSize), property);
649
+ }
650
+
651
+ return 0;
652
+ }
653
+ break;
654
+ }
642
655
  }
643
656
  }
644
657
 
@@ -471,6 +471,14 @@ public partial class LuauCore : MonoBehaviour
471
471
  WritePropertyToThreadInt32(thread, (int) value);
472
472
  return true;
473
473
  }
474
+
475
+ if (t == luauBufferType) {
476
+ var buf = (LuauBuffer)value;
477
+ fixed (byte* bytesPtr = buf.Data) {
478
+ LuauPlugin.LuauPushValueToThread(thread, (int)PODTYPE.POD_BUFFER, new IntPtr(bytesPtr), buf.Data.Length);
479
+ }
480
+ return true;
481
+ }
474
482
 
475
483
  if (t.IsEnum) {
476
484
  System.Int32 integer = (System.Int32)value;
@@ -1011,6 +1019,10 @@ public partial class LuauCore : MonoBehaviour
1011
1019
  parsedData[paramIndex] = NewMatrixFromPointer(intPtrs[i]);
1012
1020
  continue;
1013
1021
  }
1022
+ case PODTYPE.POD_BUFFER: {
1023
+ parsedData[paramIndex] = NewLuauBufferFromPointer(intPtrs[i], sizes[i]);
1024
+ continue;
1025
+ }
1014
1026
  }
1015
1027
 
1016
1028
  Debug.LogError("Param " + paramIndex + " " + podTypes[i] + " not valid type for this parameter/unhandled so far.");
@@ -1373,6 +1385,11 @@ public partial class LuauCore : MonoBehaviour
1373
1385
  continue;
1374
1386
  }
1375
1387
  break;
1388
+ case PODTYPE.POD_BUFFER:
1389
+ if (sourceParamType.IsAssignableFrom(luauBufferType)) {
1390
+ continue;
1391
+ }
1392
+ break;
1376
1393
  }
1377
1394
  return false;
1378
1395
  }
@@ -1563,6 +1580,12 @@ public partial class LuauCore : MonoBehaviour
1563
1580
  return 16 * sizeof(float);
1564
1581
  }
1565
1582
 
1583
+ public static LuauBuffer NewLuauBufferFromPointer(IntPtr data, int size) {
1584
+ var bytes = new byte[size];
1585
+ Marshal.Copy(data, bytes, 0, size);
1586
+ return new LuauBuffer(bytes);
1587
+ }
1588
+
1566
1589
  public static Plane NewPlaneFromPointer(IntPtr data) {
1567
1590
  Marshal.Copy(data, VectorData, 0, 4);
1568
1591
  return new Plane(new Vector3(VectorData[0], VectorData[1], VectorData[2]), VectorData[3]);
@@ -14,29 +14,23 @@ namespace Code.Network.Simulation
14
14
  * This component is used to allow lag compensation, prediction, and other networked state systems to
15
15
  * work with a networked object controlled by the server.
16
16
  *
17
- * When this component is placed on a object being networked with Mirror, the server can include it
17
+ * When this component is placed on a object, the server can include it
18
18
  * in lag compensation and clients can resimulate their predictions more accurately.
19
19
  */
20
- public class AirshipNetworkedObject : NetworkBehaviour
21
- {
20
+ public class AirshipNetworkedObject : MonoBehaviour {
21
+
22
+ [Tooltip("Adjusts the lag compensation timing by this amount in seconds. Useful to add or remove additional delay on the lag compensation request. Ex. Removing observer buffer delay for non-buffered entities.")]
23
+ [Range(-1, 1)]
24
+ public float bufferAdjustment = 0;
25
+
22
26
  private History<TransformSnapshot> history;
23
27
 
24
28
  private void Start()
25
29
  {
26
- if (isServer && authority)
27
- {
28
- history = new History<TransformSnapshot>(NetworkServer.sendRate);
29
- AirshipSimulationManager.Instance.OnCaptureSnapshot += this.CaptureSnapshot;
30
- AirshipSimulationManager.Instance.OnSetSnapshot += this.SetSnapshot;
31
- AirshipSimulationManager.Instance.OnLagCompensationCheck += this.LagCompensationCheck;
32
- }
33
-
34
- if (isClient && !authority)
35
- {
36
- history = new History<TransformSnapshot>(NetworkClient.sendRate);
37
- AirshipSimulationManager.Instance.OnCaptureSnapshot += this.CaptureSnapshot;
38
- AirshipSimulationManager.Instance.OnSetSnapshot += this.SetSnapshot;
39
- }
30
+ history = new History<TransformSnapshot>(1);
31
+ AirshipSimulationManager.Instance.OnCaptureSnapshot += this.CaptureSnapshot;
32
+ AirshipSimulationManager.Instance.OnSetSnapshot += this.SetSnapshot;
33
+ AirshipSimulationManager.Instance.OnLagCompensationCheck += this.LagCompensationCheck;
40
34
  }
41
35
 
42
36
  private void OnDestroy() {
@@ -74,10 +68,14 @@ namespace Code.Network.Simulation
74
68
  }
75
69
  }
76
70
 
77
- private void LagCompensationCheck(int clientId, int tick, double time, double latency, double buffer)
71
+ private void LagCompensationCheck(int clientId, int tick, double time, double latency, double bufferTime)
78
72
  {
79
- var bufferedTicks = Math.Round((latency - NetworkClient.bufferTime - Time.fixedDeltaTime) / Time.fixedDeltaTime);
80
- this.SetSnapshot(tick - bufferedTicks);
73
+ var commandBufferTime = (NetworkServer.sendInterval * (NetworkClient.bufferTimeMultiplier / 2f));
74
+
75
+ var totalBuffer = (latency * 2) + bufferTime + commandBufferTime;
76
+ var lagCompensatedTime = time - (totalBuffer + bufferAdjustment);
77
+ var lagCompensatedTick = AirshipSimulationManager.Instance.GetNearestTickForUnscaledTime(lagCompensatedTime);
78
+ this.SetSnapshot(lagCompensatedTick);
81
79
  }
82
80
  }
83
81
  }
@@ -3,19 +3,16 @@ using Code.Player.Character.MovementSystems.Character;
3
3
  using Mirror;
4
4
  using UnityEngine;
5
5
 
6
- namespace Code.Player.Character.NetworkedMovement
7
- {
6
+ namespace Code.Player.Character.NetworkedMovement {
8
7
  [LuauAPI]
9
- public class CharacterAnimationHelper : MonoBehaviour
10
- {
11
- public enum CharacterAnimationLayer
12
- {
8
+ public class CharacterAnimationHelper : MonoBehaviour {
9
+ public enum CharacterAnimationLayer {
13
10
  OVERRIDE_1 = 1,
14
11
  OVERRIDE_2 = 2,
15
12
  OVERRIDE_3 = 3,
16
13
  OVERRIDE_4 = 4,
17
14
  UPPER_BODY_1 = 5,
18
- UPPER_BODY_2 = 6,
15
+ UPPER_BODY_2 = 6
19
16
  }
20
17
 
21
18
  [Header("References")]
@@ -39,6 +36,7 @@ namespace Code.Player.Character.NetworkedMovement
39
36
 
40
37
  [Header("Animation Calibration")]
41
38
  public float animWalkSpeed = 4.4444445f;
39
+
42
40
  public float animRunSpeed = 6.6666667f;
43
41
  public float animCrouchSpeed = 2.1233335f;
44
42
 
@@ -59,27 +57,22 @@ namespace Code.Player.Character.NetworkedMovement
59
57
 
60
58
  private void Awake() {
61
59
  // Make a new instance of the animator override controller
62
- if (!this.animatorOverride)
63
- {
64
- if (this.animator.runtimeAnimatorController is AnimatorOverrideController over)
65
- {
60
+ if (!animatorOverride) {
61
+ if (animator.runtimeAnimatorController is AnimatorOverrideController over) {
66
62
  // Copy all the overrides if we already have an override controller in use
67
63
  var overrides = new List<KeyValuePair<AnimationClip, AnimationClip>>(over.overridesCount);
68
64
  over.GetOverrides(overrides);
69
- this.animatorOverride = new AnimatorOverrideController(animator.runtimeAnimatorController);
70
- this.animator.runtimeAnimatorController = this.animatorOverride;
71
- this.animatorOverride.ApplyOverrides(overrides);
72
- }
73
- else if (animator.runtimeAnimatorController)
74
- {
75
- this.animatorOverride = new AnimatorOverrideController(animator.runtimeAnimatorController);
76
- this.animator.runtimeAnimatorController = this.animatorOverride;
65
+ animatorOverride = new AnimatorOverrideController(animator.runtimeAnimatorController);
66
+ animator.runtimeAnimatorController = animatorOverride;
67
+ animatorOverride.ApplyOverrides(overrides);
68
+ } else if (animator.runtimeAnimatorController) {
69
+ animatorOverride = new AnimatorOverrideController(animator.runtimeAnimatorController);
70
+ animator.runtimeAnimatorController = animatorOverride;
77
71
  }
78
72
  }
79
73
  }
80
74
 
81
- private void Start()
82
- {
75
+ private void Start() {
83
76
  // AnimatorOverrideController animatorOverrideController =
84
77
  // new AnimatorOverrideController(this.animator.runtimeAnimatorController);
85
78
  // this.animator.runtimeAnimatorController = animatorOverrideController;
@@ -89,63 +82,51 @@ namespace Code.Player.Character.NetworkedMovement
89
82
  animator.SetFloat("AnimationOffset", offset);
90
83
  }
91
84
 
92
- public void SetFirstPerson(bool firstPerson)
93
- {
85
+ public void SetFirstPerson(bool firstPerson) {
94
86
  this.firstPerson = firstPerson;
95
- if (this.firstPerson)
96
- {
87
+ if (this.firstPerson) {
97
88
  animator.SetLayerWeight(0, 0);
98
- }
99
- else
100
- {
89
+ } else {
101
90
  animator.SetLayerWeight(0, 1);
102
- this.SetState(new() { state = this.currentState });
91
+ SetState(new CharacterAnimationSyncData { state = currentState });
103
92
  }
104
93
  }
105
94
 
106
- private void LateUpdate()
107
- {
95
+ private void LateUpdate() {
108
96
  UpdateAnimationState();
109
97
  }
110
98
 
111
- private void OnEnable()
112
- {
113
- this.animator.Rebind();
99
+ private void OnEnable() {
100
+ animator.Rebind();
114
101
  GetRandomReactionLength();
115
102
 
116
103
  //Enter default state
117
104
  SetState(new CharacterAnimationSyncData());
118
105
  }
119
106
 
120
- public bool IsInParticleDistance()
121
- {
107
+ public bool IsInParticleDistance() {
122
108
  return true;
123
109
  }
124
110
 
125
- private void UpdateAnimationState()
126
- {
127
- if (!enabled || !this.gameObject.activeInHierarchy)
128
- {
111
+ private void UpdateAnimationState() {
112
+ if (!enabled || !gameObject.activeInHierarchy) {
129
113
  return;
130
114
  }
131
115
 
132
116
  //Don't vary animation speeds if we are in the air or not moving
133
- if (currentState == CharacterState.Airborne)
134
- {
117
+ if (currentState == CharacterState.Airborne) {
135
118
  targetPlaybackSpeed = 1;
136
- }
137
- else if ((currentState == CharacterState.Crouching && targetPlaybackSpeed < .1) ||
138
- targetPlaybackSpeed < .03)
139
- {
119
+ } else if ((currentState == CharacterState.Crouching && targetPlaybackSpeed < .1) ||
120
+ targetPlaybackSpeed < .03) {
140
121
  targetVelNormalized = Vector2.zero;
141
122
  targetPlaybackSpeed = 1;
142
123
  }
143
124
 
144
- float currentMagnitude = currentVelNormalized.magnitude;
145
- float targetMagnitude = targetVelNormalized.magnitude;
146
- float blendMod = targetMagnitude > currentMagnitude
147
- ? this.directionalBlendLerpMod
148
- : this.directionalBlendLerpMod / 2f;
125
+ var currentMagnitude = currentVelNormalized.magnitude;
126
+ var targetMagnitude = targetVelNormalized.magnitude;
127
+ var blendMod = targetMagnitude > currentMagnitude
128
+ ? directionalBlendLerpMod
129
+ : directionalBlendLerpMod / 2f;
149
130
 
150
131
  //RUNNING SPEED
151
132
  //Speed up animations based on actual speed vs target speed
@@ -153,31 +134,28 @@ namespace Code.Player.Character.NetworkedMovement
153
134
  animator.SetFloat("MovementPlaybackSpeed", currentPlaybackSpeed);
154
135
 
155
136
  //Blend directional influence
156
- float smoothXVelocity = 0f;
157
- float smoothYVelocity = 0f;
158
- float smoothTime = 0.025f;
137
+ var smoothXVelocity = 0f;
138
+ var smoothYVelocity = 0f;
139
+ var smoothTime = 0.025f;
159
140
 
160
141
  currentVelNormalized.x = Mathf.SmoothDamp(currentVelNormalized.x, targetVelNormalized.x,
161
142
  ref smoothXVelocity, smoothTime, Mathf.Infinity, Time.deltaTime);
162
143
  currentVelNormalized.y = Mathf.SmoothDamp(currentVelNormalized.y, targetVelNormalized.y,
163
144
  ref smoothYVelocity, smoothTime, Mathf.Infinity, Time.deltaTime);
164
- float velX = Mathf.Abs(currentVelNormalized.x) < 0.01f ? 0 : currentVelNormalized.x;
165
- float velZ = Mathf.Abs(currentVelNormalized.y) < 0.01f ? 0 : currentVelNormalized.y;
145
+ var velX = Mathf.Abs(currentVelNormalized.x) < 0.01f ? 0 : currentVelNormalized.x;
146
+ var velZ = Mathf.Abs(currentVelNormalized.y) < 0.01f ? 0 : currentVelNormalized.y;
166
147
  animator.SetFloat("VelX", velX);
167
148
  animator.SetFloat("VelY", Mathf.Lerp(animator.GetFloat("VelY"), verticalVel, Time.deltaTime * 1.5f));
168
149
  animator.SetFloat("VelZ", velZ);
169
150
  animator.SetFloat("Speed", targetMagnitude);
170
151
 
171
152
 
172
- if (grounded)
173
- {
153
+ if (grounded) {
174
154
  lastGroundedTime = Time.time;
175
155
  isSkidding = currentSpeed >= skiddingSpeed;
176
156
  animator.SetBool("Skidding", isSkidding);
177
157
  animator.SetBool("Airborne", false);
178
- }
179
- else
180
- {
158
+ } else {
181
159
  animator.SetBool("Skidding", false);
182
160
  animator.SetBool("Airborne", Time.time - lastGroundedTime > minAirborneTime);
183
161
  }
@@ -196,65 +174,59 @@ namespace Code.Player.Character.NetworkedMovement
196
174
  // }
197
175
  }
198
176
 
199
- private void GetRandomReactionLength()
200
- {
201
- nextIdleReactionLength = this.idleRectionLength +
202
- Random.Range(-this.idleRectionLength / 2, this.idleRectionLength / 2);
177
+ private void GetRandomReactionLength() {
178
+ nextIdleReactionLength = idleRectionLength +
179
+ Random.Range(-idleRectionLength / 2, idleRectionLength / 2);
203
180
  }
204
181
 
205
- public void SetVelocity(Vector3 localVel)
206
- {
182
+ public void SetVelocity(Vector3 localVel) {
207
183
  currentSpeed = new Vector2(localVel.x, localVel.z).magnitude;
208
184
  //The target speed is the movement speed the animations were built for
209
185
  var targetSpeed = animWalkSpeed;
210
- if (currentState == CharacterState.Sprinting)
211
- {
186
+ if (currentState == CharacterState.Sprinting) {
212
187
  if (currentSpeed < animWalkSpeed) {
213
188
  //We will walk instead of run even though we are trying to run
214
189
  } else {
215
190
  targetSpeed = animRunSpeed;
216
191
  }
217
- }
218
- else if (currentState == CharacterState.Crouching)
219
- {
192
+ } else if (currentState == CharacterState.Crouching) {
220
193
  targetSpeed = animCrouchSpeed;
221
194
  }
222
-
195
+
223
196
  //Have to update sprinting state dynamically because low speeds can disable it
224
197
  animator.SetBool("Sprinting",
225
198
  currentState == CharacterState.Sprinting && currentSpeed >= animWalkSpeed);
226
199
 
227
- this.targetPlaybackSpeed = currentSpeed / targetSpeed;
200
+ targetPlaybackSpeed = currentSpeed / targetSpeed;
228
201
  targetVelNormalized = new Vector2(localVel.x, localVel.z).normalized;
229
202
  verticalVel = Mathf.Clamp(localVel.y, -10, 10);
230
203
  //print("currentSpeed: " + currentSpeed + " targetSpeed: " + targetSpeed + " playbackSpeed: " + targetPlaybackSpeed + " velNormalized: " + targetVelNormalized);
231
204
  }
232
205
 
233
- public void SetState(CharacterAnimationSyncData syncedState)
234
- {
235
- if (!enabled || !this.gameObject.activeInHierarchy)
236
- {
206
+ public void SetState(CharacterAnimationSyncData syncedState) {
207
+ if (!enabled || !gameObject.activeInHierarchy) {
237
208
  return;
238
209
  }
239
210
 
240
211
  var newState = syncedState.state;
241
- this.grounded = syncedState.grounded;
212
+ grounded = syncedState.grounded;
242
213
  animator.SetBool("Grounded", grounded);
214
+ // print("New State. Grounded: " + grounded + " state: " + syncedState.state + " Jumping: " +
215
+ // syncedState.jumping);
243
216
  animator.SetBool("Crouching", syncedState.crouching || syncedState.state == CharacterState.Crouching);
244
217
 
245
218
  if (syncedState.jumping) {
246
219
  SetTrigger("Jump");
247
220
  }
248
221
 
249
- if (this.firstPerson)
250
- {
222
+ if (firstPerson) {
251
223
  animator.SetLayerWeight(0, 0);
252
224
  }
253
225
 
254
226
  lastStateTime = Time.time;
255
227
  currentState = newState;
256
228
 
257
- this.SetVelocity(syncedState.localVelocity);
229
+ SetVelocity(syncedState.localVelocity);
258
230
  //print("Set state: " + currentState);
259
231
  }
260
232
 
@@ -267,16 +239,13 @@ namespace Code.Player.Character.NetworkedMovement
267
239
  animator.SetTrigger(trigger);
268
240
  }
269
241
 
270
- public void SetLayerWeight(CharacterAnimationLayer layer, float weight)
271
- {
242
+ public void SetLayerWeight(CharacterAnimationLayer layer, float weight) {
272
243
  var layerName = "Override" + (int)layer;
273
244
  animator.SetLayerWeight(animator.GetLayerIndex(layerName), weight);
274
245
  }
275
246
 
276
- public void PlayAnimation(AnimationClip clip, CharacterAnimationLayer layer, float fixedTransitionDuration)
277
- {
278
- if (!enabled || !this.gameObject.activeInHierarchy)
279
- {
247
+ public void PlayAnimation(AnimationClip clip, CharacterAnimationLayer layer, float fixedTransitionDuration) {
248
+ if (!enabled || !gameObject.activeInHierarchy) {
280
249
  return;
281
250
  }
282
251
 
@@ -291,10 +260,8 @@ namespace Code.Player.Character.NetworkedMovement
291
260
  animator.GetLayerIndex(stateName));
292
261
  }
293
262
 
294
- public void StopAnimation(CharacterAnimationLayer layer, float fixedTransitionDuration)
295
- {
296
- if (!enabled || !this.gameObject.activeInHierarchy)
297
- {
263
+ public void StopAnimation(CharacterAnimationLayer layer, float fixedTransitionDuration) {
264
+ if (!enabled || !gameObject.activeInHierarchy) {
298
265
  return;
299
266
  }
300
267
 
@@ -302,9 +269,8 @@ namespace Code.Player.Character.NetworkedMovement
302
269
  animator.SetBool("Override" + (int)layer + "Looping", false);
303
270
  }
304
271
 
305
- public float GetPlaybackSpeed()
306
- {
307
- return this.targetPlaybackSpeed;
272
+ public float GetPlaybackSpeed() {
273
+ return targetPlaybackSpeed;
308
274
  }
309
275
  }
310
276
  }