gg.easy.airship 0.1.1721 → 0.1.1723

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.
@@ -18,12 +18,17 @@ namespace Code.Player.Character.API {
18
18
  [Tooltip("Should movement be applied over time as a force? Or a constant speed.")]
19
19
  public bool useAccelerationMovement = false;
20
20
 
21
- [Tooltip("Default movement speed (units per second)")] [Min(0f)]
21
+ [Tooltip("Default movement speed (units per second) when not using accesleration movement")] [Min(0f)]
22
22
  public float speed = 4.666667f;
23
23
 
24
- [Tooltip("Sprint movement speed (units per second)")] [Min(0f)]
24
+ [Tooltip("Sprint movement speed (units per second) when not using accesleration movement")] [Min(0f)]
25
25
  public float sprintSpeed = 6.666667f;
26
26
 
27
+ [Tooltip("How much to accelerate (units per second) when using acceleration movement or when going faster than the target speed")] [Min(0f)]
28
+ public float accelerationForce = 1;
29
+ [Tooltip("How much to accelerate sprinting (units per second) when using acceleration movement or when going faster than the target speed")] [Min(0f)]
30
+ public float sprintAccelerationForce = 1.4f;
31
+
27
32
  [Tooltip("Only allow sprinting forward.")]
28
33
  public bool onlySprintForward = false;
29
34
 
@@ -206,9 +206,19 @@ namespace Code.Player.Character {
206
206
  return this.replicatedLookVector;
207
207
  }
208
208
 
209
- private void FixedUpdate() {
210
- //Update the movement state of the character
211
- StartMove(BuildMoveData());
209
+ private void FixedUpdate() {
210
+ // Observers don't calculate moves
211
+ if (!isOwned){
212
+ return;
213
+ }
214
+
215
+ //Update the movement state of the character
216
+ MoveInputData md = BuildMoveData();
217
+
218
+ this.currentMoveInputData = md;
219
+ OnBeginMove?.Invoke(md);
220
+ Move(md);
221
+ OnEndMove?.Invoke(md);
212
222
  }
213
223
 
214
224
  private void Update(){
@@ -225,18 +235,6 @@ namespace Code.Player.Character {
225
235
  }
226
236
  }
227
237
 
228
- private void StartMove(MoveInputData md) {
229
- // Observers don't calculate moves
230
- if (!isOwned){
231
- return;
232
- }
233
-
234
- this.currentMoveInputData = md;
235
- OnBeginMove?.Invoke(md);
236
- Move(md);
237
- OnEndMove?.Invoke(md);
238
- }
239
-
240
238
  [ClientRpc]
241
239
  private void ObserverOnImpactWithGround(Vector3 velocity) {
242
240
  this.OnImpactWithGround?.Invoke(velocity);
@@ -256,7 +254,7 @@ namespace Code.Player.Character {
256
254
  var currentVelocity = this.rigidbody.velocity;// trackedVelocity;
257
255
  var newVelocity = currentVelocity;
258
256
  var isIntersecting = IsIntersectingWithBlock();
259
- var deltaTime = Time.deltaTime;
257
+ var deltaTime = Time.fixedDeltaTime;
260
258
 
261
259
  #region GROUNDED
262
260
  //Ground checks
@@ -656,12 +654,13 @@ namespace Code.Player.Character {
656
654
  //Instantly move at the desired speed
657
655
  var moveMagnitude = characterMoveVelocity.magnitude;
658
656
  var velMagnitude = flatVelocity.magnitude;
659
- var clampedIncrease = characterMoveVelocity.normalized * Mathf.Min(moveMagnitude, Mathf.Max(0, currentSpeed - velMagnitude));
657
+ var clampedIncrease = normalizedMoveDir * Mathf.Min(moveMagnitude, Mathf.Max(0, currentSpeed - velMagnitude));
660
658
 
661
659
 
662
660
  //Don't move character in direction its already moveing
663
661
  //Positive dot means we are already moving in this direction. Negative dot means we are moving opposite of velocity.
664
- var rawDot = Vector3.Dot(flatVelocity/ currentSpeed, characterMoveVelocity/ currentSpeed);
662
+ //var rawDot = Vector3.Dot(flatVelocity/ currentSpeed, characterMoveVelocity/ currentSpeed);
663
+ var rawDot = Vector3.Dot(flatVelocity.normalized, normalizedMoveDir);
665
664
  var dirDot = Mathf.Clamp01(1-rawDot);
666
665
 
667
666
  if(useExtraLogging){
@@ -672,7 +671,7 @@ namespace Code.Player.Character {
672
671
  clampedIncrease *= moveData.airSpeedMultiplier;
673
672
  }
674
673
 
675
- if(_flying || (velMagnitude < currentSpeed && !airborneFromImpulse)){
674
+ if(_flying || (velMagnitude < currentSpeed+1 && !isImpulsing)){
676
675
  // if(clampedIncrease.x < 0){
677
676
  // clampedIncrease.x = Mathf.Max(clampedIncrease.x, newVelocity.x + clampedIncrease.x);
678
677
  // }else{
@@ -688,7 +687,8 @@ namespace Code.Player.Character {
688
687
  }else{
689
688
  //dirDot = dirDot - 1 / 2;
690
689
  //clampedIncrease *= -Mathf.Min(0, dirDot-1);
691
- newVelocity += characterMoveVelocity * dirDot * deltaTime * 2;
690
+ newVelocity += normalizedMoveDir * dirDot *
691
+ (groundedState == CharacterState.Sprinting ? this.moveData.sprintAccelerationForce : moveData.accelerationForce);
692
692
  }
693
693
  //characterMoveVelocity = clampedIncrease;
694
694
  // if(Mathf.Abs(newVelocity.x) < Mathf.Abs(characterMoveVelocity.x)){
@@ -213,8 +213,7 @@ public class VoxelBlocks : MonoBehaviour {
213
213
  public bool detail = false;
214
214
  public bool doOcclusion = true;
215
215
 
216
- public VoxelMeshCopy mesh = null;
217
- public VoxelMeshCopy meshLod = null;
216
+ public LodSet mesh = null;
218
217
 
219
218
  public Dictionary<int, LodSet> meshTiles = new();
220
219
 
@@ -368,22 +367,28 @@ public class VoxelBlocks : MonoBehaviour {
368
367
  if (block.definition.contextStyle != ContextStyle.StaticMesh) {
369
368
  return;
370
369
  }
371
-
372
- var meshSrc = block.definition.staticMeshLOD0;
373
- if (meshSrc == null) {
370
+
371
+ if (block.definition.staticMeshLOD0 == null) {
374
372
  return;
375
373
  }
376
- VoxelMeshCopy meshCopy = new VoxelMeshCopy(meshSrc);
377
- block.mesh = meshCopy;
378
374
 
375
+ block.mesh = new();
376
+
377
+ block.mesh.lod0 = new VoxelMeshCopy(block.definition.staticMeshLOD0);
378
+
379
+ if (block.definition.staticMeshLOD1 != null){
380
+ block.mesh.lod1 = new VoxelMeshCopy(block.definition.staticMeshLOD1);
381
+ }
382
+
383
+ if (block.definition.staticMeshLOD2 != null){
384
+ block.mesh.lod2 = new VoxelMeshCopy(block.definition.staticMeshLOD2);
385
+ }
386
+
379
387
  //Apply the material to this
380
388
  if (block.meshMaterial != null) {
381
- if (block.mesh.surfaces != null) {
382
- foreach (VoxelMeshCopy.Surface surf in block.mesh.surfaces) {
383
- surf.meshMaterial = block.meshMaterial;
384
- surf.meshMaterialName = block.meshMaterial.name;
385
- }
386
- }
389
+ block.mesh.lod0.ApplyMaterial(block.meshMaterial);
390
+ block.mesh.lod1.ApplyMaterial(block.meshMaterial);
391
+ block.mesh.lod2.ApplyMaterial(block.meshMaterial);
387
392
  }
388
393
 
389
394
  }
@@ -371,5 +371,16 @@ namespace Assets.Airship.VoxelRenderer
371
371
  rotation.Add((int)rot.Key, new PrecalculatedRotation(srcVertices, srcNormals, rot.Key, rot.Value));
372
372
  }
373
373
  }
374
+
375
+ public void ApplyMaterial(Material meshMaterial) {
376
+ if (surfaces == null) {
377
+ return;
378
+ }
379
+
380
+ foreach (Surface surf in surfaces) {
381
+ surf.meshMaterial = meshMaterial;
382
+ surf.meshMaterialName = meshMaterial.name;
383
+ }
384
+ }
374
385
  }
375
386
  }
@@ -990,16 +990,21 @@ namespace VoxelWorldStuff {
990
990
  //Init the detail meshes now
991
991
  InitDetailMeshes();
992
992
 
993
- if (block.mesh != null) {
994
- EmitMesh(block, block.mesh, detailMeshData[0], world, origin, true, rotation);
995
- }
996
- if (block.meshLod != null) {
997
- EmitMesh(block, block.mesh, detailMeshData[1], world, origin, true, rotation);
993
+ if (block.mesh != null && block.mesh.lod0 != null) {
994
+ EmitMesh(block, block.mesh.lod0, detailMeshData[0], world, origin, true, rotation);
995
+
996
+ if (block.mesh.lod1 != null) {
997
+ EmitMesh(block, block.mesh.lod1, detailMeshData[1], world, origin, true, rotation);
998
+ }
999
+ if (block.mesh.lod2 != null) {
1000
+ EmitMesh(block, block.mesh.lod2, detailMeshData[2], world, origin, true, rotation);
1001
+ }
998
1002
  }
1003
+
999
1004
  }
1000
1005
  else {
1001
1006
  //same mesh that the voxels use (think stairs etc)
1002
- EmitMesh(block, block.mesh, temporaryMeshData, world, origin, true, rotation);
1007
+ EmitMesh(block, block.mesh.lod0, temporaryMeshData, world, origin, true, rotation);
1003
1008
  }
1004
1009
  //No code past here
1005
1010
  continue;
@@ -1285,8 +1290,8 @@ namespace VoxelWorldStuff {
1285
1290
  //Center around 0,0,0
1286
1291
  Vector3 origin = new Vector3(-0.5f, -0.5f, -0.5f);
1287
1292
 
1288
- if (block.mesh != null) {
1289
- EmitMesh(block, block.mesh, meshData, world, origin, false);
1293
+ if (block.mesh != null && block.mesh.lod0 != null) {
1294
+ EmitMesh(block, block.mesh.lod0, meshData, world, origin, false);
1290
1295
  }
1291
1296
  else {
1292
1297
  //Add regular cube Faces
@@ -708,8 +708,7 @@ public partial class VoxelWorld : MonoBehaviour {
708
708
  }
709
709
 
710
710
  RegenerateAllMeshes();
711
-
712
- UpdatePropertiesForAllChunksForRendering();
711
+
713
712
 
714
713
  Debug.Log("Finished loading voxel save file. Took " + (Time.realtimeSinceStartup - startTime) + " seconds.");
715
714
  Profiler.EndSample();
@@ -731,8 +730,7 @@ public partial class VoxelWorld : MonoBehaviour {
731
730
 
732
731
  DeleteChildGameObjects(gameObject);
733
732
  RegenerateAllMeshes();
734
-
735
- UpdatePropertiesForAllChunksForRendering();
733
+
736
734
  }
737
735
 
738
736
 
@@ -824,15 +822,9 @@ public partial class VoxelWorld : MonoBehaviour {
824
822
  this.voxelBlocks.Reload();
825
823
 
826
824
  RegenerateAllMeshes();
827
-
828
- UpdatePropertiesForAllChunksForRendering();
825
+
829
826
  }
830
-
831
- public void UpdatePropertiesForAllChunksForRendering() {
832
- foreach (var chunkRec in chunks) {
833
- chunkRec.Value.UpdateMaterialPropertiesForChunk();
834
- }
835
- }
827
+
836
828
 
837
829
  private void Awake() {
838
830
  this.finishedLoading = false;
@@ -1017,11 +1009,6 @@ public partial class VoxelWorld : MonoBehaviour {
1017
1009
  Profiler.BeginSample("RegenerateMissingChunkGeometry");
1018
1010
  RegenerateMissingChunkGeometry();
1019
1011
  Profiler.EndSample();
1020
-
1021
- Profiler.BeginSample("UpdatePropertiesForAllChunksForRendering");
1022
- UpdatePropertiesForAllChunksForRendering();
1023
- Profiler.EndSample();
1024
-
1025
1012
  }
1026
1013
 
1027
1014
  public void OnRenderObject() {
@@ -93,11 +93,7 @@ namespace VoxelWorldStuff {
93
93
  private Mesh[] detailMeshes;
94
94
  private MeshFilter[] detailFilters;
95
95
  private MeshRenderer[] detailRenderers;
96
-
97
- private float[] detailMeshAlpha = new float[3];
98
- private bool[] wantsToBeVisible = new bool[3];
99
- private float[] detailMeshPrevAlpha = new float[3];
100
- private bool skipLodAnimation = true;
96
+
101
97
 
102
98
  private GameObject parent;
103
99
  public List<BoxCollider> colliders = new();
@@ -451,9 +447,7 @@ namespace VoxelWorldStuff {
451
447
 
452
448
  //See if this mesh has detail meshes
453
449
  if (meshProcessor.GetHasDetailMeshes() == true) {
454
- //Debug.Log("Got a mesh");
455
- skipLodAnimation = true;
456
-
450
+
457
451
  if (detailGameObjects == null) {
458
452
  detailGameObjects = new GameObject[3];
459
453
 
@@ -474,7 +468,7 @@ namespace VoxelWorldStuff {
474
468
  if (i == 2) {
475
469
  detailGameObjects[i].name = "DetailMeshVeryFar";
476
470
  }
477
- detailGameObjects[i].layer = 6;
471
+
478
472
  detailFilters[i] = detailGameObjects[i].AddComponent<MeshFilter>();
479
473
  detailRenderers[i] = detailGameObjects[i].AddComponent<MeshRenderer>();
480
474
 
@@ -483,6 +477,23 @@ namespace VoxelWorldStuff {
483
477
 
484
478
  detailFilters[i].mesh = detailMeshes[i];
485
479
  }
480
+
481
+ LODGroup lodSystem = detailGameObjects[0].AddComponent<LODGroup>();
482
+
483
+ // Enable crossfade
484
+ lodSystem.fadeMode = LODFadeMode.CrossFade;
485
+ lodSystem.animateCrossFading = true;
486
+
487
+ // Configure LODs with the last LOD2 as the lowest and no "culled" LOD
488
+ LOD[] lods = new LOD[3] {
489
+ new LOD(0.07f, new Renderer[] { detailRenderers[0] }), //The distance is actually for the next group eg: this one sets LOD1 to 10%
490
+ new LOD(0.03f, new Renderer[] { detailRenderers[1] }),
491
+ new LOD(0.0f, new Renderer[] { detailRenderers[2] })
492
+ };
493
+
494
+ lodSystem.SetLODs(lods);
495
+
496
+
486
497
  }
487
498
  }
488
499
 
@@ -522,7 +533,7 @@ namespace VoxelWorldStuff {
522
533
 
523
534
  Profiler.BeginSample("UpdatePropertiesForChunk");
524
535
  materialPropertiesDirty = true;
525
- UpdateMaterialPropertiesForChunk();
536
+
526
537
  Profiler.EndSample();
527
538
 
528
539
  //Print out the total time taken
@@ -564,215 +575,7 @@ namespace VoxelWorldStuff {
564
575
  Array.Clear(lightColors, 0, lightColors.Length);
565
576
  Array.Clear(lightRadius, 0, lightRadius.Length);
566
577
  }
567
- public void UpdateMaterialPropertiesForChunk() {
568
- if (renderer == null) return;
569
- if (mesh == null) return;
570
-
571
- //Update the detail meshes if they're there
572
- if (detailRenderers != null && currentCamera != null) {
573
- Vector3 pos = currentCamera.transform.position;
574
- Vector3 chunkPos = (chunkKey * chunkSize) + new Vector3(chunkSize / 2, chunkSize / 2, chunkSize / 2);
575
- float distance = Vector3.Distance(pos, chunkPos);
576
- wantsToBeVisible[0] = false;
577
- wantsToBeVisible[1] = false;
578
- wantsToBeVisible[2] = false;
579
- bool somethingChanged = false;
580
- float speed = world.lodTransitionSpeed * Time.deltaTime;
581
-
582
-
583
- //mark what we saw
584
- for (int i = 0; i < 3; i++) {
585
- detailMeshPrevAlpha[i] = detailMeshAlpha[i];
586
- }
587
-
588
- //If the near one should be visible
589
- if (distance < world.lodNearDistance) {
590
- //Blend it in
591
- if (detailMeshAlpha[0] < 1.0f) {
592
- detailMeshAlpha[0] += speed;
593
- }
594
- else {
595
- //Once the near one is fully visible, we can fade 1 and 2 out
596
- detailMeshAlpha[1] -= speed;
597
- detailMeshAlpha[2] -= speed;
598
- }
599
- }
600
- else
601
- if (distance < world.lodFarDistance) {
602
- //If the far one should be visible
603
- //Blend it in
604
- if (detailMeshAlpha[1] < 1.0f) {
605
- detailMeshAlpha[1] += speed;
606
- }
607
- else {
608
- //Once the far one is fully visible, we can fade 0+2 out
609
- detailMeshAlpha[0] -= speed;
610
- detailMeshAlpha[2] -= speed;
611
- }
612
- }
613
- else {
614
- if (detailMeshAlpha[2] < 1.0f) {
615
- detailMeshAlpha[2] += speed;
616
- }
617
- else {
618
- detailMeshAlpha[0] -= speed;
619
- detailMeshAlpha[1] -= speed;
620
- }
621
- }
622
-
623
- /*
624
- for (int i = 0; i < 2; i++)
625
- {
626
- //Becoming more visible?
627
- if (wantsToBeVisible[i] == true)
628
- {
629
- detailRenderers[i].enabled = true;
630
-
631
- if (detailMeshAlpha[i] < 1)
632
- {
633
- detailMeshAlpha[i] += speed;
634
- somethingChanged = true;
635
- if (detailMeshAlpha[i] >= 1)
636
- {
637
- detailMeshAlpha[i] = 1;
638
- }
639
- }
640
- }
641
- //And backwards
642
- if (wantsToBeVisible[i] == false && detailMeshAlpha[i] > 0)
643
- {
644
- detailMeshAlpha[i] -= speed;
645
- somethingChanged = true;
646
- if (detailMeshAlpha[i] <= 0)
647
- {
648
- detailMeshAlpha[i] = 0;
649
- detailRenderers[i].enabled = false;
650
- }
651
- }
652
- }*/
653
-
654
- for (int i = 0; i < 3; i++) {
655
- //Did we hit zero from a higher value?
656
- if (detailMeshPrevAlpha[i] > 0 && detailMeshAlpha[i] <= 0) {
657
- detailRenderers[i].enabled = false;
658
-
659
- }
660
- //Did we move away from zero?
661
- if (detailMeshPrevAlpha[i] <= 0 && detailMeshAlpha[i] > 0) {
662
- detailRenderers[i].enabled = true;
663
- }
664
- //clamp it to 0, 1
665
- detailMeshAlpha[i] = Mathf.Clamp01(detailMeshAlpha[i]);
666
-
667
- //mark the change
668
- if (detailMeshPrevAlpha[i] - detailMeshAlpha[i] != 0) {
669
- somethingChanged = true;
670
- }
671
- }
672
-
673
- //On initial creation we want lod stuff to be in its correct state, so this skips the animation and just sets things directly
674
- //Note this block of code doesn't run every frame!
675
- if (skipLodAnimation == true) {
676
- //Hot start! This isnt the moment to moment logic
677
- skipLodAnimation = false;
678
- somethingChanged = true;
679
- if (distance < world.lodNearDistance) {
680
- detailRenderers[0].enabled = true;
681
- detailMeshAlpha[0] = 1;
682
- detailRenderers[1].enabled = false;
683
- detailMeshAlpha[1] = 0;
684
- detailRenderers[2].enabled = false;
685
- detailMeshAlpha[2] = 0;
686
- }
687
- else
688
- if (distance < world.lodFarDistance) {
689
- detailRenderers[0].enabled = false;
690
- detailMeshAlpha[0] = 0;
691
- detailRenderers[1].enabled = true;
692
- detailMeshAlpha[1] = 1;
693
- detailRenderers[2].enabled = false;
694
- detailMeshAlpha[2] = 0;
695
- }
696
- else {
697
- detailRenderers[0].enabled = false;
698
- detailMeshAlpha[0] = 0;
699
- detailRenderers[1].enabled = false;
700
- detailMeshAlpha[1] = 0;
701
- detailRenderers[2].enabled = true;
702
- detailMeshAlpha[2] = 1;
703
- }
704
- }
705
-
706
-
707
- //Set the alpha of the detail meshes
708
- if (somethingChanged == true) {
709
-
710
- //Create the material property blocks and store them
711
- /*if (detailPropertyBlocks == null)
712
- {
713
- detailPropertyBlocks = new List<MaterialPropertyBlock>[3];
714
- for (int i = 0; i < 3; i++)
715
- {
716
- detailPropertyBlocks[i] = new List<MaterialPropertyBlock>();
717
- for (int materialIndex = 0; materialIndex < detailRenderers[i].sharedMaterials.Length; materialIndex++)
718
- {
719
- detailPropertyBlocks[i].Add(new MaterialPropertyBlock());
720
- }
721
- }
722
- }*/
723
-
724
- //Adjust the alpha in the property block
725
- for (int i = 0; i < 3; i++) {
726
- for (int materialIndex = 0; materialIndex < detailRenderers[i].sharedMaterials.Length; materialIndex++) {
727
- Material mat = detailRenderers[i].sharedMaterials[materialIndex];
728
- if (mat == null) {
729
- continue;
730
- }
731
-
732
- /*
733
- var rendererRef = AirshipRendererManager.Instance.GetRendererReference(detailRenderers[i]);
734
-
735
- if (rendererRef != null) {
736
- MaterialPropertyBlock propertyBlock = rendererRef.GetPropertyBlock(mat, materialIndex);
737
- propertyBlock.SetFloat("_Alpha", detailMeshAlpha[i]);
738
- }
739
- */
740
-
741
- }
742
- }
743
- }
744
- }
745
-
746
- if (materialPropertiesDirty == true) {
747
- //get all the point lights in the scene
748
- /*
749
- int numHighQualityLights = 0;
750
-
751
- foreach (var lightRec in lights)
752
- {
753
- lightRec.Value.lightRef.TryGetTarget(out AirshipPointLight light);
754
- if (light == null)
755
- {
756
- continue;
757
- }
758
-
759
- lightsPositions[numHighQualityLights] = light.transform.position;
760
- lightColors[numHighQualityLights] = light.color * light.intensity;
761
- lightRadius[numHighQualityLights] = light.range;
762
- numHighQualityLights++;
763
- if (numHighQualityLights == 2)
764
- {
765
- break;
766
- }
767
- }
768
- if (numHighQualityLights > 0)
769
- {
770
- usingLocallyClonedMaterials = true;
771
- }*/
772
-
773
-
774
- }
775
- }
578
+
776
579
 
777
580
  public GameObject GetGameObject() {
778
581
  return obj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg.easy.airship",
3
- "version": "0.1.1721",
3
+ "version": "0.1.1723",
4
4
  "displayName": "Airship",
5
5
  "unity": "2021.3",
6
6
  "unityRelease": "12f1",