gg.easy.airship 0.1.2128 → 0.1.2129
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.
- package/Editor/Artifacts/AirshipLocalArtifactDatabase.cs +17 -17
- package/Editor/Artifacts/AirshipReconciliationService.cs +3 -3
- package/Runtime/Code/Luau/AirshipComponent.cs +8 -3
- package/Runtime/Code/Network/StateSystem/AirshipNetworkedStateManager.cs +8 -5
- package/Runtime/Code/Player/Character/MovementSystems/Character/CharacterMovement.cs +71 -22
- package/Runtime/Code/VoiceChat/AirshipUniVoiceNetwork.cs +21 -0
- package/Runtime/Code/VoxelWorld/Editor/VoxelBuilderEditorWindow.cs +49 -62
- package/Runtime/Code/VoxelWorld/Editor/VoxelWorldEditor.cs +296 -251
- package/Runtime/Code/VoxelWorld/VoxelWorldChunk.cs +218 -190
- package/Runtime/Plugins/Android/libLuauPlugin.so +0 -0
- package/Runtime/Plugins/Linux/libLuauPlugin.so +0 -0
- package/Runtime/Plugins/Mac/LuauPlugin.bundle/Contents/MacOS/LuauPlugin +0 -0
- package/Runtime/Plugins/Windows/x64/LuauPlugin.dll +0 -0
- package/Runtime/Plugins/Windows/x64/LuauPlugin.pdb +0 -0
- package/Runtime/Plugins/iOS/LuauPluginIos.a +0 -0
- package/package.json +1 -1
|
@@ -51,17 +51,17 @@ namespace Airship.Editor {
|
|
|
51
51
|
|
|
52
52
|
[CanBeNull] public GameObject Prefab => asset != null ? AssetDatabase.LoadAssetAtPath<GameObject>(asset) : null;
|
|
53
53
|
|
|
54
|
-
/// <summary>
|
|
55
|
-
/// Will return if the given component is synchronized with this data
|
|
56
|
-
/// </summary>
|
|
57
|
-
/// <param name="component">The component</param>
|
|
58
|
-
/// <returns>True if the component matches this data</returns>
|
|
59
|
-
public bool IsSyncedWith(AirshipComponent component) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
54
|
+
// /// <summary>
|
|
55
|
+
// /// Will return if the given component is synchronized with this data
|
|
56
|
+
// /// </summary>
|
|
57
|
+
// /// <param name="component">The component</param>
|
|
58
|
+
// /// <returns>True if the component matches this data</returns>
|
|
59
|
+
// public bool IsSyncedWith(AirshipComponent component) {
|
|
60
|
+
// if (guid != component.guid) return false;
|
|
61
|
+
// if (metadata == null) return false;
|
|
62
|
+
//
|
|
63
|
+
// return component.componentHash == metadata.hash;
|
|
64
|
+
// }
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
[Serializable]
|
|
@@ -94,12 +94,12 @@ namespace Airship.Editor {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
|
|
97
|
-
/// <summary>
|
|
98
|
-
/// Will return true if the hash of the component isn't the same as the DB stored script hash
|
|
99
|
-
/// </summary>
|
|
100
|
-
public bool IsNotSameHashAsComponent(AirshipComponent component) {
|
|
101
|
-
|
|
102
|
-
}
|
|
97
|
+
// /// <summary>
|
|
98
|
+
// /// Will return true if the hash of the component isn't the same as the DB stored script hash
|
|
99
|
+
// /// </summary>
|
|
100
|
+
// public bool IsNotSameHashAsComponent(AirshipComponent component) {
|
|
101
|
+
// return component.componentHash != metadata.hash;
|
|
102
|
+
// }
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
/// <summary>
|
|
@@ -192,7 +192,7 @@ namespace Airship.Editor {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
#endif
|
|
195
|
-
component.componentHash = component.script.sourceFileHash;
|
|
195
|
+
// component.componentHash = component.script.sourceFileHash;
|
|
196
196
|
return true;
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -328,7 +328,7 @@ namespace Airship.Editor {
|
|
|
328
328
|
// We can run a default reconcile, it wont matter tbh.
|
|
329
329
|
var component = eventData.Component;
|
|
330
330
|
ReconcileComponent(component);
|
|
331
|
-
component.componentHash = component.scriptHash;
|
|
331
|
+
//component.componentHash = component.scriptHash;
|
|
332
332
|
return;
|
|
333
333
|
}
|
|
334
334
|
|
|
@@ -374,7 +374,7 @@ namespace Airship.Editor {
|
|
|
374
374
|
else {
|
|
375
375
|
var component = eventData.Component;
|
|
376
376
|
ReconcileComponent(component);
|
|
377
|
-
component.componentHash = component.scriptHash;
|
|
377
|
+
//component.componentHash = component.scriptHash;
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
}
|
|
@@ -72,11 +72,16 @@ public class AirshipComponent : MonoBehaviour {
|
|
|
72
72
|
#if UNITY_EDITOR
|
|
73
73
|
internal static event ReconcileAirshipComponent Reconcile;
|
|
74
74
|
[SerializeField] internal string guid;
|
|
75
|
-
[SerializeField] private string hash;
|
|
75
|
+
// [SerializeField] private string hash;
|
|
76
76
|
|
|
77
|
+
[Obsolete]
|
|
77
78
|
internal string componentHash {
|
|
78
|
-
get
|
|
79
|
-
|
|
79
|
+
get {
|
|
80
|
+
return "";
|
|
81
|
+
}
|
|
82
|
+
set {
|
|
83
|
+
_ = value;
|
|
84
|
+
}
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
internal string scriptHash => script.sourceFileHash;
|
|
@@ -6,6 +6,7 @@ using Code.Network.StateSystem.Structures;
|
|
|
6
6
|
using Code.Player.Character.Net;
|
|
7
7
|
using Mirror;
|
|
8
8
|
using RSG.Promises;
|
|
9
|
+
using Unity.Mathematics;
|
|
9
10
|
using Unity.VisualScripting;
|
|
10
11
|
using UnityEngine;
|
|
11
12
|
using UnityEngine.Serialization;
|
|
@@ -423,8 +424,8 @@ namespace Code.Network.StateSystem
|
|
|
423
424
|
// TODO: We treat estimatedCommandDelay as a constant, but we should determine this by calculating how long the command that triggered the lag comp was buffered
|
|
424
425
|
// we would need to pass that into lag comp event as an additional parameter since it would need to be calculated in the predicted character component that generated the command.
|
|
425
426
|
// That may prove difficult, so we use a constant for now.
|
|
426
|
-
var estimatedCommandDelay = this.serverCommandBufferTargetSize * Time.fixedDeltaTime;
|
|
427
|
-
var clientBufferTime = NetworkServer.connections[clientId].bufferTime;
|
|
427
|
+
var estimatedCommandDelay = this.serverCommandBufferTargetSize * Time.fixedDeltaTime;
|
|
428
|
+
var clientBufferTime = NetworkServer.connections[clientId].bufferTime / Math.Min(Time.timeScale, 1); // client buffers more when timescale is set lower than 1
|
|
428
429
|
// Debug.Log("Calculated rollback time for " + this.gameObject.name + " as ping: " + ping + " buffer time: " + clientBufferTime + " command delay: " + estimatedCommandDelay + " for a result of: " + (- ping -
|
|
429
430
|
// clientBufferTime - estimatedCommandDelay));
|
|
430
431
|
var lagCompensatedTickTime =
|
|
@@ -845,14 +846,16 @@ namespace Code.Network.StateSystem
|
|
|
845
846
|
if (this.observerHistory.Values.Count == 0) return;
|
|
846
847
|
|
|
847
848
|
// Get the time we should render on the client.
|
|
848
|
-
var clientTime = (float)NetworkTime.time - NetworkClient.bufferTime;
|
|
849
|
+
var clientTime = (float)NetworkTime.time - (NetworkClient.bufferTime / Math.Min(Time.timeScale, 1)); // Don't reduce buffer on TS higher than one since send rate is unaffected
|
|
849
850
|
|
|
850
851
|
// Get the state history around the time that's currently being rendered.
|
|
851
852
|
if (!this.observerHistory.GetAround(clientTime, out State prevState, out State nextState))
|
|
852
853
|
{
|
|
853
|
-
|
|
854
|
+
if (clientTime < this.observerHistory.Keys[0]) return; // Our local time hasn't advanced enough to render the positions reported.
|
|
855
|
+
Debug.LogWarning("Frame " + Time.frameCount + " not enough state history for rendering. " + this.observerHistory.Keys.Count +
|
|
854
856
|
" entries. First " + this.observerHistory.Keys[0] + " Last " +
|
|
855
|
-
this.observerHistory.Keys[^1] + " Target " + clientTime)
|
|
857
|
+
this.observerHistory.Keys[^1] + " Target " + clientTime + " Buffer is: " + NetworkClient.bufferTime + " Estimated Latency (1 way): " +
|
|
858
|
+
(NetworkTime.rtt / 2) + " Network Time: " + NetworkTime.time + " TScale: " + Time.timeScale);
|
|
856
859
|
return;
|
|
857
860
|
}
|
|
858
861
|
|
|
@@ -6,6 +6,7 @@ using Code.Network.StateSystem;
|
|
|
6
6
|
using Code.Player.Character.NetworkedMovement;
|
|
7
7
|
using Mirror;
|
|
8
8
|
using UnityEngine;
|
|
9
|
+
using UnityEngine.Serialization;
|
|
9
10
|
|
|
10
11
|
namespace Code.Player.Character.MovementSystems.Character
|
|
11
12
|
{
|
|
@@ -47,7 +48,10 @@ namespace Code.Player.Character.MovementSystems.Character
|
|
|
47
48
|
|
|
48
49
|
[Header("Visual Variables")]
|
|
49
50
|
public bool autoCalibrateSkiddingSpeed = true;
|
|
50
|
-
|
|
51
|
+
|
|
52
|
+
[Tooltip("Controls the speed in which local character rotates to face look direction.")]
|
|
53
|
+
public float ownerRotationLerpMod = 6;
|
|
54
|
+
|
|
51
55
|
[Tooltip("If true animations will be played on the server. This should be true if you care about character movement animations server-side (like for hit boxes).")]
|
|
52
56
|
public bool playAnimationOnServer = true;
|
|
53
57
|
|
|
@@ -112,33 +116,34 @@ namespace Code.Player.Character.MovementSystems.Character
|
|
|
112
116
|
public event Action<object> OnInterpolateReachedState;
|
|
113
117
|
|
|
114
118
|
public event Action<object, object> OnCompareSnapshots;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Fired when lag compensated checks should occur. ID of check is passed as the event parameter.
|
|
122
|
+
*/
|
|
123
|
+
public event Action<object> OnLagCompensationCheck;
|
|
124
|
+
/**
|
|
125
|
+
* Fired when lag compensated check is over and physics can be modified. ID of check is passed as the event parameter.
|
|
126
|
+
*/
|
|
127
|
+
public event Action<object> OnLagCompensationComplete;
|
|
128
|
+
|
|
129
|
+
public event Action<object> OnMoveDirectionChanged;
|
|
115
130
|
|
|
116
131
|
/// <summary>
|
|
117
|
-
///
|
|
132
|
+
/// Called when the look vector is externally set
|
|
133
|
+
/// Params: Vector3 currentLookVector
|
|
118
134
|
/// </summary>
|
|
119
|
-
public event Action<object
|
|
120
|
-
|
|
121
|
-
|
|
135
|
+
public event Action<object> OnNewLookVector;
|
|
136
|
+
|
|
122
137
|
/// <summary>
|
|
123
138
|
/// Called when movement processes a new jump
|
|
124
139
|
/// Params: Vector3 velocity
|
|
125
140
|
/// </summary>
|
|
126
141
|
public event Action<object> OnJumped;
|
|
127
|
-
|
|
142
|
+
|
|
128
143
|
/// <summary>
|
|
129
|
-
///
|
|
130
|
-
/// Params: Vector3 currentLookVector
|
|
144
|
+
/// Params: Vector3 velocity, RaycastHit hitInfo
|
|
131
145
|
/// </summary>
|
|
132
|
-
public event Action<object>
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Fired when lag compensated checks should occur. ID of check is passed as the event parameter.
|
|
136
|
-
*/
|
|
137
|
-
public event Action<object> OnLagCompensationCheck;
|
|
138
|
-
/**
|
|
139
|
-
* Fired when lag compensated check is over and physics can be modified. ID of check is passed as the event parameter.
|
|
140
|
-
*/
|
|
141
|
-
public event Action<object> OnLagCompensationComplete;
|
|
146
|
+
public event Action<object, object> OnImpactWithGround;
|
|
142
147
|
|
|
143
148
|
#endregion
|
|
144
149
|
|
|
@@ -183,7 +188,7 @@ namespace Code.Player.Character.MovementSystems.Character
|
|
|
183
188
|
|
|
184
189
|
public override void SetMode(NetworkedStateSystemMode mode)
|
|
185
190
|
{
|
|
186
|
-
Debug.Log("Running movement in " + mode + " mode.");
|
|
191
|
+
Debug.Log("Running movement in " + mode + " mode for " + this.name + ".");
|
|
187
192
|
if (mode == NetworkedStateSystemMode.Observer)
|
|
188
193
|
{
|
|
189
194
|
rigidbody.isKinematic = true;
|
|
@@ -300,8 +305,7 @@ namespace Code.Player.Character.MovementSystems.Character
|
|
|
300
305
|
{
|
|
301
306
|
grounded = true;
|
|
302
307
|
}
|
|
303
|
-
|
|
304
|
-
currentMoveSnapshot.isGrounded = grounded;
|
|
308
|
+
|
|
305
309
|
this.groundedRaycastHit = groundHit;
|
|
306
310
|
|
|
307
311
|
if (grounded)
|
|
@@ -335,6 +339,13 @@ namespace Code.Player.Character.MovementSystems.Character
|
|
|
335
339
|
currentMoveSnapshot.jumpCount = 0;
|
|
336
340
|
currentMoveSnapshot.timeSinceBecameGrounded = 0f;
|
|
337
341
|
this.OnImpactWithGround?.Invoke(currentVelocity, groundHit);
|
|
342
|
+
if (this.mode == NetworkedStateSystemMode.Authority && isServer)
|
|
343
|
+
{
|
|
344
|
+
SAuthImpactEvent(currentVelocity, groundHit);
|
|
345
|
+
} else if (this.mode == NetworkedStateSystemMode.Authority && isClient)
|
|
346
|
+
{
|
|
347
|
+
CAuthImpactEvent(currentVelocity, groundHit);
|
|
348
|
+
}
|
|
338
349
|
}
|
|
339
350
|
else
|
|
340
351
|
{
|
|
@@ -442,6 +453,14 @@ namespace Code.Player.Character.MovementSystems.Character
|
|
|
442
453
|
newVelocity.y = movementSettings.jumpSpeed;
|
|
443
454
|
currentMoveSnapshot.airborneFromImpulse = false;
|
|
444
455
|
OnJumped?.Invoke(newVelocity);
|
|
456
|
+
if (mode == NetworkedStateSystemMode.Authority && isServer)
|
|
457
|
+
{
|
|
458
|
+
SAuthJumpedEvent(newVelocity);
|
|
459
|
+
}
|
|
460
|
+
else if (mode == NetworkedStateSystemMode.Authority && isClient)
|
|
461
|
+
{
|
|
462
|
+
CAuthJumpedEvent(newVelocity);
|
|
463
|
+
}
|
|
445
464
|
}
|
|
446
465
|
}
|
|
447
466
|
|
|
@@ -1070,7 +1089,7 @@ namespace Code.Player.Character.MovementSystems.Character
|
|
|
1070
1089
|
airshipTransform.rotation = Quaternion.Lerp(
|
|
1071
1090
|
airshipTransform.rotation,
|
|
1072
1091
|
Quaternion.LookRotation(lookTarget),
|
|
1073
|
-
|
|
1092
|
+
ownerRotationLerpMod * Time.deltaTime);
|
|
1074
1093
|
}
|
|
1075
1094
|
}
|
|
1076
1095
|
|
|
@@ -1400,6 +1419,36 @@ namespace Code.Player.Character.MovementSystems.Character
|
|
|
1400
1419
|
#endregion
|
|
1401
1420
|
|
|
1402
1421
|
#region RPCs
|
|
1422
|
+
|
|
1423
|
+
[Command]
|
|
1424
|
+
public void CAuthJumpedEvent(Vector3 velocity)
|
|
1425
|
+
{
|
|
1426
|
+
// Only used in the client authoritative networking mode.
|
|
1427
|
+
if (mode != NetworkedStateSystemMode.Observer) return;
|
|
1428
|
+
OnJumped?.Invoke(velocity);
|
|
1429
|
+
SAuthJumpedEvent(velocity);
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
[Command]
|
|
1433
|
+
public void CAuthImpactEvent(Vector3 velocity, RaycastHit hitInfo)
|
|
1434
|
+
{
|
|
1435
|
+
// Only used in the client authoritative networking mode.
|
|
1436
|
+
if (mode != NetworkedStateSystemMode.Observer) return;
|
|
1437
|
+
OnImpactWithGround(velocity, hitInfo);
|
|
1438
|
+
SAuthImpactEvent(velocity, hitInfo);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
[ClientRpc(includeOwner = false)]
|
|
1442
|
+
public void SAuthJumpedEvent(Vector3 velocity)
|
|
1443
|
+
{
|
|
1444
|
+
OnJumped?.Invoke(velocity);
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
[ClientRpc(includeOwner = false)]
|
|
1448
|
+
public void SAuthImpactEvent(Vector3 velocity, RaycastHit hitInfo)
|
|
1449
|
+
{
|
|
1450
|
+
OnImpactWithGround?.Invoke(velocity, hitInfo);
|
|
1451
|
+
}
|
|
1403
1452
|
|
|
1404
1453
|
/**
|
|
1405
1454
|
* RPCs are used in client authoritative networking to allow server side code to move clients. These
|
|
@@ -300,10 +300,31 @@ namespace Code.VoiceChat {
|
|
|
300
300
|
// print($"[client] received audio from server for peer {senderPeerId}. Frame={Time.frameCount} Nonce={nonce}");
|
|
301
301
|
this.EmitAudioInScene(senderPeerId, bytes);
|
|
302
302
|
}
|
|
303
|
+
|
|
304
|
+
private void PreProcessAudio(ChatroomAudioSegment segment) {
|
|
305
|
+
const float maxAmplitude = 0.25f;
|
|
306
|
+
|
|
307
|
+
// find peak
|
|
308
|
+
float peak = 0f;
|
|
309
|
+
for (int i = 0; i < segment.samples.Length; i++) {
|
|
310
|
+
float absSample = Math.Abs(segment.samples[i]);
|
|
311
|
+
if (absSample > peak) peak = absSample;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// if too loud, scale down
|
|
315
|
+
if (peak > maxAmplitude) {
|
|
316
|
+
float scale = maxAmplitude / peak;
|
|
317
|
+
for (int i = 0; i < segment.samples.Length; i++) {
|
|
318
|
+
segment.samples[i] *= scale;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
303
322
|
|
|
304
323
|
private void EmitAudioInScene(short senderPeerId, byte[] bytes) {
|
|
305
324
|
var segment = FromByteArray<ChatroomAudioSegment>(bytes);
|
|
306
325
|
|
|
326
|
+
this.PreProcessAudio(segment);
|
|
327
|
+
|
|
307
328
|
if (senderPeerId == LocalPeerId && RunCore.IsClient() && NetworkClient.isConnected) {
|
|
308
329
|
// Local speaking
|
|
309
330
|
var speakingLevel = this.ComputeSpeakingLevel(segment.samples);
|
|
@@ -4,30 +4,27 @@ using UnityEngine;
|
|
|
4
4
|
|
|
5
5
|
namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
6
6
|
public class VoxelBuilderEditorWindow : EditorWindow {
|
|
7
|
-
|
|
8
|
-
Vector2 scrollPos;
|
|
7
|
+
private Vector2 scrollPos;
|
|
9
8
|
|
|
10
9
|
// Enum to represent the different modes
|
|
11
|
-
enum Mode
|
|
12
|
-
{
|
|
10
|
+
private enum Mode {
|
|
13
11
|
Add,
|
|
14
|
-
Delete
|
|
12
|
+
Delete
|
|
15
13
|
}
|
|
16
14
|
|
|
17
|
-
int gridWidth = 4;
|
|
18
|
-
bool[,] grid;
|
|
15
|
+
private int gridWidth = 4;
|
|
16
|
+
private bool[,] grid;
|
|
19
17
|
|
|
20
18
|
// The current mode
|
|
21
|
-
Mode currentMode;
|
|
19
|
+
private Mode currentMode;
|
|
22
20
|
public static bool active = true;
|
|
23
21
|
|
|
24
22
|
[MenuItem("Airship/Misc/VoxelEditor")]
|
|
25
|
-
static void Init() {
|
|
23
|
+
private static void Init() {
|
|
26
24
|
ShowWindow();
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
public static void ForceRepaint() {
|
|
30
|
-
|
|
31
28
|
if (active) {
|
|
32
29
|
GetWindow<VoxelBuilderEditorWindow>().Repaint();
|
|
33
30
|
}
|
|
@@ -38,25 +35,22 @@ namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
|
38
35
|
|
|
39
36
|
if (HasOpenInstances<VoxelBuilderEditorWindow>()) {
|
|
40
37
|
GetWindow<VoxelBuilderEditorWindow>().Close();
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
38
|
+
} else {
|
|
43
39
|
var myWindow = GetWindow<VoxelBuilderEditorWindow>();
|
|
44
40
|
myWindow.titleContent = new GUIContent("Voxel Editor");
|
|
45
41
|
}
|
|
46
42
|
}
|
|
47
|
-
|
|
43
|
+
|
|
48
44
|
public static bool Enabled() {
|
|
49
45
|
return active && HasOpenInstances<VoxelBuilderEditorWindow>();
|
|
50
46
|
}
|
|
51
47
|
|
|
52
|
-
VoxelWorld GetVoxelWorld() {
|
|
53
|
-
|
|
48
|
+
private VoxelWorld GetVoxelWorld() {
|
|
54
49
|
//See if the currently selected object in the world is a voxelworld
|
|
55
50
|
var selectedObject = Selection.activeGameObject;
|
|
56
51
|
if (selectedObject) {
|
|
57
52
|
var voxelWorld = selectedObject.GetComponent<VoxelWorld>();
|
|
58
53
|
if (voxelWorld) {
|
|
59
|
-
|
|
60
54
|
return voxelWorld;
|
|
61
55
|
}
|
|
62
56
|
}
|
|
@@ -70,25 +64,22 @@ namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
|
70
64
|
|
|
71
65
|
return null;
|
|
72
66
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
void ShowSelectionGui() {
|
|
76
67
|
|
|
68
|
+
|
|
69
|
+
private void ShowSelectionGui() {
|
|
77
70
|
//Label
|
|
78
71
|
GUILayout.Label("Select VoxelWorld", EditorStyles.boldLabel);
|
|
79
72
|
|
|
80
73
|
//Shows a list of all the VoxelWorld objects in the scene as clickable buttons
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
for (int i = 0; i < voxelWorlds.Length; i++) {
|
|
74
|
+
var voxelWorlds = FindObjectsOfType<VoxelWorld>();
|
|
84
75
|
|
|
76
|
+
for (var i = 0; i < voxelWorlds.Length; i++) {
|
|
77
|
+
var selectionZone = voxelWorlds[i].GetComponentInChildren<SelectionZone>();
|
|
85
78
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (Selection.activeGameObject == voxelWorlds[i].gameObject || (selectionZone!=null && Selection.activeGameObject == selectionZone.gameObject)) {
|
|
79
|
+
if (Selection.activeGameObject == voxelWorlds[i].gameObject || (selectionZone != null &&
|
|
80
|
+
Selection.activeGameObject == selectionZone.gameObject)) {
|
|
89
81
|
GUI.backgroundColor = Color.green;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
82
|
+
} else {
|
|
92
83
|
GUI.backgroundColor = Color.white;
|
|
93
84
|
}
|
|
94
85
|
|
|
@@ -104,9 +95,9 @@ namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
|
104
95
|
|
|
105
96
|
GUI.backgroundColor = Color.white;
|
|
106
97
|
}
|
|
107
|
-
|
|
108
98
|
|
|
109
|
-
|
|
99
|
+
|
|
100
|
+
private void OnGUI() {
|
|
110
101
|
//Create an active toggle as a button that toggles on and off
|
|
111
102
|
active = GUILayout.Toggle(active, "Voxel Editor Active");
|
|
112
103
|
|
|
@@ -115,14 +106,14 @@ namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
|
115
106
|
}
|
|
116
107
|
|
|
117
108
|
ShowSelectionGui();
|
|
118
|
-
|
|
119
|
-
|
|
109
|
+
|
|
110
|
+
var world = GetVoxelWorld();
|
|
120
111
|
SelectionZone selection = null;
|
|
121
112
|
if (world == null || world.voxelBlocks == null) {
|
|
122
113
|
GUI.enabled = true; //cleanup from above
|
|
123
|
-
return;
|
|
114
|
+
return;
|
|
124
115
|
}
|
|
125
|
-
|
|
116
|
+
|
|
126
117
|
//See if we're in the selection mode
|
|
127
118
|
if (VoxelWorldSelectionToolBase.buttonActive == true) {
|
|
128
119
|
//Find or create the SelectionZone for this voxelWorld
|
|
@@ -136,30 +127,32 @@ namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
|
136
127
|
selection.transform.localScale = Vector3.one;
|
|
137
128
|
selection.voxelWorld = world;
|
|
138
129
|
}
|
|
130
|
+
|
|
139
131
|
//Select this
|
|
140
132
|
selection.gameObject.SetActive(true);
|
|
141
133
|
Selection.activeGameObject = selection.gameObject;
|
|
142
|
-
|
|
143
134
|
}
|
|
135
|
+
|
|
144
136
|
if (VoxelWorldEditorToolBase.buttonActive == true) {
|
|
145
|
-
|
|
146
137
|
//If we're not in selection mode, disable the selection zone
|
|
147
138
|
selection = world.GetComponentInChildren<SelectionZone>();
|
|
148
|
-
|
|
139
|
+
|
|
149
140
|
if (selection) {
|
|
150
141
|
//Select the world
|
|
151
142
|
Selection.activeGameObject = world.gameObject;
|
|
152
143
|
//disable it
|
|
153
144
|
selection.gameObject.SetActive(false);
|
|
154
|
-
|
|
145
|
+
|
|
155
146
|
//we used to destroy it
|
|
156
147
|
//DestroyImmediate(selection.gameObject);
|
|
157
148
|
}
|
|
158
149
|
}
|
|
159
150
|
|
|
160
151
|
//Show a foldable help box
|
|
161
|
-
EditorGUILayout.HelpBox(
|
|
162
|
-
|
|
152
|
+
EditorGUILayout.HelpBox(
|
|
153
|
+
"Left click to add\nShift+click to delete\nCtrl+click for repeat placement\nA to rotate highlighted block",
|
|
154
|
+
MessageType.Info);
|
|
155
|
+
|
|
163
156
|
//active = EditorGUILayout.Toggle("Active", active);
|
|
164
157
|
|
|
165
158
|
//gap
|
|
@@ -167,23 +160,24 @@ namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
|
167
160
|
|
|
168
161
|
//Prefab
|
|
169
162
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
163
|
+
var prefab = world.GetPrefabAt(world.highlightedBlockPos);
|
|
164
|
+
|
|
165
|
+
var blockData = world.GetVoxelAt(world.highlightedBlockPos);
|
|
173
166
|
|
|
174
167
|
GUILayout.Label("Highlighted Block");
|
|
175
168
|
|
|
176
169
|
if (VoxelWorld.VoxelDataToBlockId(blockData) == 0) {
|
|
177
170
|
GUI.enabled = false;
|
|
178
171
|
}
|
|
179
|
-
int flipBits = VoxelWorld.GetVoxelFlippedBits(blockData);
|
|
180
172
|
|
|
181
|
-
|
|
173
|
+
var flipBits = VoxelWorld.GetVoxelFlippedBits(blockData);
|
|
174
|
+
|
|
175
|
+
var def = GUI.backgroundColor;
|
|
182
176
|
|
|
183
177
|
GUILayout.BeginHorizontal();
|
|
184
178
|
|
|
185
179
|
GUILayout.Label("Rotation: " + VoxelWorld.flipNames[flipBits]);
|
|
186
|
-
|
|
180
|
+
|
|
187
181
|
GUI.backgroundColor = def;
|
|
188
182
|
GUILayout.EndHorizontal();
|
|
189
183
|
GUI.enabled = true;
|
|
@@ -199,13 +193,12 @@ namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
|
199
193
|
GUILayout.Label("If no blocks are visible, re-load the Voxel World.");
|
|
200
194
|
}
|
|
201
195
|
|
|
202
|
-
|
|
196
|
+
var selectedStyle = new GUIStyle(GUI.skin.button);
|
|
203
197
|
selectedStyle.normal.textColor = Color.green;
|
|
204
198
|
selectedStyle.hover.textColor = Color.green;
|
|
205
|
-
|
|
206
|
-
foreach (var pair in world.voxelBlocks.loadedBlocks) {
|
|
207
199
|
|
|
208
|
-
|
|
200
|
+
foreach (var pair in world.voxelBlocks.loadedBlocks) {
|
|
201
|
+
var name = pair.Value.definition.name;
|
|
209
202
|
if (name == "") {
|
|
210
203
|
name = "Air";
|
|
211
204
|
}
|
|
@@ -218,27 +211,21 @@ namespace Code.Airship.Resources.VoxelRenderer.Editor {
|
|
|
218
211
|
}
|
|
219
212
|
}
|
|
220
213
|
}
|
|
214
|
+
|
|
221
215
|
GUILayout.EndScrollView();
|
|
222
216
|
GUI.enabled = true;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
void onSceneGUIDelegate(SceneView sceneView) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
217
|
}
|
|
232
218
|
|
|
233
|
-
void
|
|
234
|
-
|
|
219
|
+
private void onSceneGUIDelegate(SceneView sceneView) { }
|
|
220
|
+
|
|
221
|
+
private void OnEnable() {
|
|
222
|
+
autoRepaintOnSceneChange = true;
|
|
235
223
|
SceneView.duringSceneGui += onSceneGUIDelegate;
|
|
236
|
-
|
|
237
|
-
|
|
224
|
+
}
|
|
225
|
+
|
|
238
226
|
private void OnDisable() {
|
|
239
227
|
SceneView.duringSceneGui -= onSceneGUIDelegate;
|
|
240
228
|
}
|
|
241
229
|
}
|
|
242
|
-
|
|
243
230
|
}
|
|
244
231
|
#endif
|