gg.easy.airship 0.1.2176 → 0.1.2177
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/BuildMenu.cs
CHANGED
|
@@ -6,16 +6,14 @@ using Code.GameBundle;
|
|
|
6
6
|
using UnityEditor;
|
|
7
7
|
#endif
|
|
8
8
|
using UnityEngine;
|
|
9
|
-
using UnityEngine.Serialization;
|
|
10
9
|
using Object = UnityEngine.Object;
|
|
11
10
|
|
|
12
11
|
[CreateAssetMenu(fileName = "GameConfig", menuName = "Airship/GameConfig", order = 100)]
|
|
13
|
-
public class GameConfig : ScriptableObject
|
|
14
|
-
{
|
|
12
|
+
public class GameConfig : ScriptableObject {
|
|
15
13
|
public string gameId;
|
|
16
|
-
|
|
14
|
+
#if UNITY_EDITOR
|
|
17
15
|
public SceneAsset startingScene;
|
|
18
|
-
|
|
16
|
+
#endif
|
|
19
17
|
public Object[] gameScenes;
|
|
20
18
|
|
|
21
19
|
[Obsolete]
|
|
@@ -27,7 +25,10 @@ public class GameConfig : ScriptableObject
|
|
|
27
25
|
[HideInInspector] public string[] gameLayers;
|
|
28
26
|
[HideInInspector] public string[] gameTags;
|
|
29
27
|
[HideInInspector] public bool[] physicsMatrix;
|
|
30
|
-
[HideInInspector] public
|
|
28
|
+
[HideInInspector] public bool[] physicsMatrix2D;
|
|
29
|
+
|
|
30
|
+
//3D Physics
|
|
31
|
+
[HideInInspector] public Vector3 gravity = new(0, -9.81f, 0);
|
|
31
32
|
[HideInInspector] public float bounceThreshold = 2;
|
|
32
33
|
[HideInInspector] public float defaultMaxDepenetrationVelocity = 10;
|
|
33
34
|
[HideInInspector] public float sleepThreshold = 0.005f;
|
|
@@ -38,6 +39,27 @@ public class GameConfig : ScriptableObject
|
|
|
38
39
|
[HideInInspector] public bool queriesHitTriggers = true;
|
|
39
40
|
[HideInInspector] public float fixedDeltaTime = .025f;
|
|
40
41
|
|
|
42
|
+
[HideInInspector] public Vector3 gravity2D = new(0, -9.81f, 0);
|
|
43
|
+
[HideInInspector] public int velocityIterations2D = 8;
|
|
44
|
+
[HideInInspector] public int positionIterations2D = 3;
|
|
45
|
+
[HideInInspector] public float bounceThreshold2D = 1;
|
|
46
|
+
[HideInInspector] public float maxLinearCorrection2D = .2f;
|
|
47
|
+
[HideInInspector] public float maxAngularCorrection2D = 8;
|
|
48
|
+
[HideInInspector] public float maxTranslationSpeed2D = 100;
|
|
49
|
+
[HideInInspector] public float maxRotationSpeed2D = 360;
|
|
50
|
+
[HideInInspector] public float baumgarteScale2D = .2f;
|
|
51
|
+
[HideInInspector] public float baumgarteTOIScale2D = .75f;
|
|
52
|
+
[HideInInspector] public float timeToSleep2D = .5f;
|
|
53
|
+
[HideInInspector] public float linearSleepTolerance2D = .01f;
|
|
54
|
+
[HideInInspector] public float angularSleepTolerance2D = 2;
|
|
55
|
+
[HideInInspector] public float defaultContactOffset2D = .01f;
|
|
56
|
+
[HideInInspector] public float contactThreshold2D = 0f;
|
|
57
|
+
[HideInInspector] public bool queriesHitTriggers2D = true;
|
|
58
|
+
[HideInInspector] public bool queriesStartInColliders2D = true;
|
|
59
|
+
[HideInInspector] public bool callbacksOnDisable2D = true;
|
|
60
|
+
[HideInInspector] public bool reuseCollisionCallbacks2D = true;
|
|
61
|
+
[HideInInspector] public bool autoSyncTransforms2D = false;
|
|
62
|
+
|
|
41
63
|
[HideInInspector] public bool supportsMobile;
|
|
42
64
|
|
|
43
65
|
[HideInInspector] public bool compileURPShaders = false;
|
|
@@ -61,18 +83,20 @@ public class GameConfig : ScriptableObject
|
|
|
61
83
|
userTag = null;
|
|
62
84
|
return false;
|
|
63
85
|
}
|
|
64
|
-
|
|
86
|
+
|
|
65
87
|
var offset = int.Parse(runtimeTag[TagPrefix.Length..]);
|
|
66
88
|
userTag = gameTags[offset];
|
|
67
89
|
return userTag != null;
|
|
68
90
|
}
|
|
69
|
-
|
|
91
|
+
|
|
70
92
|
public static GameConfig Load() {
|
|
71
93
|
#if UNITY_EDITOR
|
|
72
94
|
var gameConfig = AssetDatabase.LoadAssetAtPath<GameConfig>("Assets/GameConfig.asset");
|
|
73
95
|
// I believe AssetDatabase might not have loaded GameConfig sometimes (like during a publish)
|
|
74
96
|
// TODO if file doesn't exist we could generate GameConfig here
|
|
75
|
-
if (gameConfig == null)
|
|
97
|
+
if (gameConfig == null) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
76
100
|
|
|
77
101
|
#if !AIRSHIP_PLAYER && !AIRSHIP_INTERNAL
|
|
78
102
|
if (gameConfig.packages.Find((p) => p.id == "@Easy/Core") == null) {
|
|
@@ -100,15 +124,15 @@ public class GameConfig : ScriptableObject
|
|
|
100
124
|
private void OnValidate() {
|
|
101
125
|
#if UNITY_EDITOR
|
|
102
126
|
#pragma warning disable CS0612
|
|
103
|
-
if (
|
|
127
|
+
if (startingScene == null && !string.IsNullOrEmpty(startingSceneName)) {
|
|
104
128
|
var guids = AssetDatabase.FindAssets("t:Scene").ToList();
|
|
105
129
|
var paths = guids.Select((guid) => AssetDatabase.GUIDToAssetPath(guid));
|
|
106
130
|
foreach (var path in paths) {
|
|
107
131
|
if (path.StartsWith("Assets/")) {
|
|
108
|
-
if (path.EndsWith(
|
|
132
|
+
if (path.EndsWith(startingSceneName + ".unity")) {
|
|
109
133
|
var sceneAsset = AssetDatabase.LoadAssetAtPath<SceneAsset>(path);
|
|
110
|
-
|
|
111
|
-
|
|
134
|
+
startingScene = sceneAsset;
|
|
135
|
+
startingSceneName = "";
|
|
112
136
|
}
|
|
113
137
|
}
|
|
114
138
|
}
|
|
@@ -126,58 +150,153 @@ public class GameConfig : ScriptableObject
|
|
|
126
150
|
return json;
|
|
127
151
|
}
|
|
128
152
|
|
|
129
|
-
public void SerializeSettings(){
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
153
|
+
public void SerializeSettings() {
|
|
154
|
+
try {
|
|
155
|
+
// Update physics matrix
|
|
156
|
+
var areLayersIgnored = new bool[15 * 32];
|
|
157
|
+
var TheMatrixLog = "SAVING GAME LAYER MATRIX: \n";
|
|
158
|
+
// 15 Game Layers and how they collide with all 32 layers
|
|
159
|
+
for (var i = 0; i < 15; i++) {
|
|
160
|
+
//Check
|
|
161
|
+
for (var otherLayerI = 0; otherLayerI < 32; otherLayerI++) {
|
|
162
|
+
var gameLayerI = 17 + i;
|
|
163
|
+
var ignored = Physics.GetIgnoreLayerCollision(gameLayerI, otherLayerI);
|
|
164
|
+
areLayersIgnored[i * 32 + otherLayerI] = ignored;
|
|
165
|
+
TheMatrixLog += "GameLayer" + i + " and Layer: " + otherLayerI + " ignored: " + ignored + " \n";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Debug.Log(TheMatrixLog);
|
|
170
|
+
physicsMatrix = areLayersIgnored;
|
|
171
|
+
|
|
172
|
+
// Physics settings
|
|
173
|
+
gravity = Physics.gravity;
|
|
174
|
+
bounceThreshold = Physics.bounceThreshold;
|
|
175
|
+
defaultMaxDepenetrationVelocity = Physics.defaultMaxDepenetrationVelocity;
|
|
176
|
+
sleepThreshold = Physics.sleepThreshold;
|
|
177
|
+
defaultContactOffset = Physics.defaultContactOffset;
|
|
178
|
+
defaultSolverIterations = Physics.defaultSolverIterations;
|
|
179
|
+
defaultSolverVelocityIterations = Physics.defaultSolverVelocityIterations;
|
|
180
|
+
queriesHitBackfaces = Physics.queriesHitBackfaces;
|
|
181
|
+
queriesHitTriggers = Physics.queriesHitTriggers;
|
|
182
|
+
fixedDeltaTime = Time.fixedDeltaTime;
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
// Update physics 2D matrix
|
|
186
|
+
areLayersIgnored = new bool[15 * 32];
|
|
187
|
+
TheMatrixLog = "SAVING 2D GAME LAYER MATRIX: \n";
|
|
188
|
+
// 15 Game Layers and how they collide with all 32 layers
|
|
189
|
+
for (var i = 0; i < 15; i++) {
|
|
190
|
+
//Check
|
|
191
|
+
for (var otherLayerI = 0; otherLayerI < 32; otherLayerI++) {
|
|
192
|
+
var gameLayerI = 17 + i;
|
|
193
|
+
var ignored = Physics2D.GetIgnoreLayerCollision(gameLayerI, otherLayerI);
|
|
194
|
+
areLayersIgnored[i * 32 + otherLayerI] = ignored;
|
|
195
|
+
TheMatrixLog += "2D GameLayer" + i + " and Layer: " + otherLayerI + " ignored: " + ignored + " \n";
|
|
196
|
+
}
|
|
141
197
|
}
|
|
198
|
+
|
|
199
|
+
// Debug.Log(TheMatrixLog);
|
|
200
|
+
physicsMatrix2D = areLayersIgnored;
|
|
201
|
+
|
|
202
|
+
// Physics 2D settings
|
|
203
|
+
gravity2D = Physics2D.gravity;
|
|
204
|
+
velocityIterations2D = Physics2D.velocityIterations;
|
|
205
|
+
positionIterations2D = Physics2D.positionIterations;
|
|
206
|
+
bounceThreshold2D = Physics2D.bounceThreshold;
|
|
207
|
+
maxLinearCorrection2D = Physics2D.maxLinearCorrection;
|
|
208
|
+
maxAngularCorrection2D = Physics2D.maxAngularCorrection;
|
|
209
|
+
maxTranslationSpeed2D = Physics2D.maxTranslationSpeed;
|
|
210
|
+
maxRotationSpeed2D = Physics2D.maxRotationSpeed;
|
|
211
|
+
baumgarteScale2D = Physics2D.baumgarteScale;
|
|
212
|
+
baumgarteTOIScale2D = Physics2D.baumgarteTOIScale;
|
|
213
|
+
timeToSleep2D = Physics2D.timeToSleep;
|
|
214
|
+
linearSleepTolerance2D = Physics2D.linearSleepTolerance;
|
|
215
|
+
angularSleepTolerance2D = Physics2D.angularSleepTolerance;
|
|
216
|
+
defaultContactOffset2D = Physics2D.defaultContactOffset;
|
|
217
|
+
contactThreshold2D = Physics2D.contactThreshold;
|
|
218
|
+
queriesHitTriggers2D = Physics2D.queriesHitTriggers;
|
|
219
|
+
queriesStartInColliders2D = Physics2D.queriesStartInColliders;
|
|
220
|
+
callbacksOnDisable2D = Physics2D.callbacksOnDisable;
|
|
221
|
+
reuseCollisionCallbacks2D = Physics2D.reuseCollisionCallbacks;
|
|
222
|
+
autoSyncTransforms2D = Physics2D.autoSyncTransforms;
|
|
223
|
+
} catch (Exception e) {
|
|
224
|
+
Debug.LogError("Error in Serialize Game Config: " + e);
|
|
142
225
|
}
|
|
143
|
-
//Debug.Log(TheMatrixLog);
|
|
144
|
-
physicsMatrix = areLayersIgnored;
|
|
145
|
-
gravity = Physics.gravity;
|
|
146
|
-
bounceThreshold = Physics.bounceThreshold;
|
|
147
|
-
defaultMaxDepenetrationVelocity = Physics.defaultMaxDepenetrationVelocity;
|
|
148
|
-
sleepThreshold = Physics.sleepThreshold;
|
|
149
|
-
defaultContactOffset = Physics.defaultContactOffset;
|
|
150
|
-
defaultSolverIterations = Physics.defaultSolverIterations;
|
|
151
|
-
defaultSolverVelocityIterations = Physics.defaultSolverVelocityIterations;
|
|
152
|
-
queriesHitBackfaces = Physics.queriesHitBackfaces;
|
|
153
|
-
queriesHitTriggers = Physics.queriesHitTriggers;
|
|
154
|
-
fixedDeltaTime = Time.fixedDeltaTime;
|
|
155
226
|
}
|
|
156
227
|
|
|
157
|
-
public void DeserializeSettings(){
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
for(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
228
|
+
public void DeserializeSettings() {
|
|
229
|
+
try {
|
|
230
|
+
// 15 Game Layers and how they collide with all 32 layers
|
|
231
|
+
var gameLayerI = 17;
|
|
232
|
+
var TheMatrixLog = "LOADING GAME LAYER MATRIX: \n";
|
|
233
|
+
for (var byteI = 0; byteI < physicsMatrix.Length; byteI += 32) {
|
|
234
|
+
for (var otherLayerI = 0; otherLayerI < 32; otherLayerI++) {
|
|
235
|
+
var ignored = physicsMatrix[byteI + otherLayerI];
|
|
236
|
+
Physics.IgnoreLayerCollision(gameLayerI, otherLayerI, ignored);
|
|
237
|
+
TheMatrixLog += "GameLayer" + gameLayerI + " and Layer: " + otherLayerI +" ignored: " + ignored + " \n";
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
gameLayerI++;
|
|
241
|
+
}
|
|
242
|
+
// Debug.Log(TheMatrixLog);
|
|
243
|
+
|
|
244
|
+
// Physics Settings
|
|
245
|
+
Physics.gravity = gravity;
|
|
246
|
+
Physics.bounceThreshold = bounceThreshold;
|
|
247
|
+
Physics.defaultMaxDepenetrationVelocity = defaultMaxDepenetrationVelocity;
|
|
248
|
+
Physics.sleepThreshold = sleepThreshold;
|
|
249
|
+
Physics.defaultContactOffset = defaultContactOffset;
|
|
250
|
+
Physics.defaultSolverIterations = defaultSolverIterations;
|
|
251
|
+
Physics.defaultSolverVelocityIterations = defaultSolverVelocityIterations;
|
|
252
|
+
Physics.queriesHitBackfaces = queriesHitBackfaces;
|
|
253
|
+
Physics.queriesHitTriggers = queriesHitTriggers;
|
|
254
|
+
Time.fixedDeltaTime = fixedDeltaTime;
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
// 2D Setup
|
|
258
|
+
if (physicsMatrix2D != null && physicsMatrix2D.Length > 0) {
|
|
259
|
+
gameLayerI = 17;
|
|
260
|
+
TheMatrixLog = "LOADING 2D GAME LAYER MATRIX: \n";
|
|
261
|
+
for (var byteI = 0; byteI < physicsMatrix2D.Length; byteI += 32) {
|
|
262
|
+
for (var otherLayerI = 0; otherLayerI < 32; otherLayerI++) {
|
|
263
|
+
var ignored = physicsMatrix2D[byteI + otherLayerI];
|
|
264
|
+
Physics2D.IgnoreLayerCollision(gameLayerI, otherLayerI, ignored);
|
|
265
|
+
TheMatrixLog += "2D GameLayer" + gameLayerI + " and Layer: " + otherLayerI + " ignored: " + ignored +
|
|
266
|
+
" \n";
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
gameLayerI++;
|
|
270
|
+
}
|
|
271
|
+
// Debug.Log(TheMatrixLog);
|
|
272
|
+
|
|
273
|
+
// Physics 2D Settings
|
|
274
|
+
Physics2D.gravity = gravity2D;
|
|
275
|
+
Physics2D.velocityIterations = velocityIterations2D;
|
|
276
|
+
Physics2D.positionIterations = positionIterations2D;
|
|
277
|
+
Physics2D.bounceThreshold = bounceThreshold2D;
|
|
278
|
+
Physics2D.maxLinearCorrection = maxLinearCorrection2D;
|
|
279
|
+
Physics2D.maxAngularCorrection = maxAngularCorrection2D;
|
|
280
|
+
Physics2D.maxTranslationSpeed = maxTranslationSpeed2D;
|
|
281
|
+
Physics2D.maxRotationSpeed = maxRotationSpeed2D;
|
|
282
|
+
Physics2D.baumgarteScale = baumgarteScale2D;
|
|
283
|
+
Physics2D.baumgarteTOIScale = baumgarteTOIScale2D;
|
|
284
|
+
Physics2D.timeToSleep = timeToSleep2D;
|
|
285
|
+
Physics2D.linearSleepTolerance = linearSleepTolerance2D;
|
|
286
|
+
Physics2D.angularSleepTolerance = angularSleepTolerance2D;
|
|
287
|
+
Physics2D.defaultContactOffset = defaultContactOffset2D;
|
|
288
|
+
Physics2D.contactThreshold = contactThreshold2D;
|
|
289
|
+
Physics2D.queriesHitTriggers = queriesHitTriggers2D;
|
|
290
|
+
Physics2D.queriesStartInColliders = queriesStartInColliders2D;
|
|
291
|
+
Physics2D.callbacksOnDisable = callbacksOnDisable2D;
|
|
292
|
+
Physics2D.reuseCollisionCallbacks = reuseCollisionCallbacks2D;
|
|
293
|
+
Physics2D.autoSyncTransforms = autoSyncTransforms2D;
|
|
294
|
+
} else {
|
|
295
|
+
Debug.LogError("Game hasn't generated a 2D game config yet");
|
|
166
296
|
}
|
|
167
|
-
|
|
297
|
+
|
|
298
|
+
} catch (Exception e) {
|
|
299
|
+
Debug.LogError("Error in Deserialize Game Config: " + e);
|
|
168
300
|
}
|
|
169
|
-
//Debug.Log(TheMatrixLog);
|
|
170
|
-
|
|
171
|
-
//Physics Settings
|
|
172
|
-
Physics.gravity = gravity;
|
|
173
|
-
Physics.bounceThreshold = bounceThreshold;
|
|
174
|
-
Physics.defaultMaxDepenetrationVelocity = defaultMaxDepenetrationVelocity;
|
|
175
|
-
Physics.sleepThreshold = sleepThreshold;
|
|
176
|
-
Physics.defaultContactOffset = defaultContactOffset;
|
|
177
|
-
Physics.defaultSolverIterations = defaultSolverIterations;
|
|
178
|
-
Physics.defaultSolverVelocityIterations = defaultSolverVelocityIterations;
|
|
179
|
-
Physics.queriesHitBackfaces = queriesHitBackfaces;
|
|
180
|
-
Physics.queriesHitTriggers = queriesHitTriggers;
|
|
181
|
-
Time.fixedDeltaTime = fixedDeltaTime;
|
|
182
301
|
}
|
|
183
302
|
}
|
|
@@ -19,14 +19,12 @@ public class SetupManager : AssetPostprocessor {
|
|
|
19
19
|
|
|
20
20
|
[MenuItem("Airship/Misc/Repair Project")]
|
|
21
21
|
public static void FixProject() {
|
|
22
|
-
|
|
23
|
-
PhysicsSetup.Setup(config);
|
|
22
|
+
PhysicsSetup.Setup();
|
|
24
23
|
}
|
|
25
24
|
|
|
26
25
|
[MenuItem("Airship/Misc/Reset Physics To Airship Defaults")]
|
|
27
26
|
public static void ResetPhysics() {
|
|
28
|
-
|
|
29
|
-
PhysicsSetup.ResetDefaults(config);
|
|
27
|
+
PhysicsSetup.ResetDefaults();
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
#endif
|
|
@@ -8,15 +8,16 @@ public static class PhysicsSetup {
|
|
|
8
8
|
private static List<int> corelayers;
|
|
9
9
|
private static List<int> gameLayers;
|
|
10
10
|
|
|
11
|
-
//Setup required settings for Airship that all games need
|
|
12
|
-
public static void Setup(
|
|
11
|
+
// Setup required settings for Airship that all games need
|
|
12
|
+
public static void Setup() {
|
|
13
13
|
InitLayerCollection();
|
|
14
14
|
|
|
15
|
-
//Set the physics mat
|
|
16
|
-
//How the heck do I set this?
|
|
17
|
-
//UnityEditor.physicsMat??? = AssetDatabase.LoadAllAssetsAtPath("defaultphysicsmat");
|
|
15
|
+
// Set the physics mat
|
|
16
|
+
// How the heck do I set this?
|
|
17
|
+
// UnityEditor.physicsMat??? = AssetDatabase.LoadAllAssetsAtPath("defaultphysicsmat");
|
|
18
18
|
|
|
19
19
|
Physics.simulationMode = SimulationMode.FixedUpdate;
|
|
20
|
+
Physics2D.simulationMode = SimulationMode2D.FixedUpdate;
|
|
20
21
|
|
|
21
22
|
#if UNITY_EDITOR
|
|
22
23
|
//Airship Core Layers
|
|
@@ -34,14 +35,14 @@ public static class PhysicsSetup {
|
|
|
34
35
|
PhysicsLayerEditor.SetLayer(11, "LocalStencilMask");
|
|
35
36
|
PhysicsLayerEditor.SetLayer(12, "StencilMask");
|
|
36
37
|
|
|
37
|
-
//Reserved for future use
|
|
38
|
+
// Reserved for future use
|
|
38
39
|
for (var i = NumberOfCoreLayers; i < GameLayerStartIndex; i++) {
|
|
39
40
|
PhysicsLayerEditor.SetLayer(i, "");
|
|
40
41
|
}
|
|
41
42
|
#endif
|
|
42
43
|
|
|
43
|
-
//Create the Physics Matrix
|
|
44
|
-
//Non colliding layers
|
|
44
|
+
// Create the Physics Matrix
|
|
45
|
+
// Non colliding layers
|
|
45
46
|
IgnoreAllLayers(LayerMask.NameToLayer("Viewmodel"), true);
|
|
46
47
|
IgnoreAllLayers(LayerMask.NameToLayer("IgnoreCollision"), true);
|
|
47
48
|
IgnoreAllLayers(LayerMask.NameToLayer("AvatarEditor"), true);
|
|
@@ -50,13 +51,12 @@ public static class PhysicsSetup {
|
|
|
50
51
|
IgnoreAllLayers(LayerMask.NameToLayer("Water"), true);
|
|
51
52
|
IgnoreAllLayers(LayerMask.NameToLayer("UI"), true);
|
|
52
53
|
IgnoreAllLayers(LayerMask.NameToLayer("WorldUI"), true);
|
|
53
|
-
//Only collide with game layers
|
|
54
|
+
// Only collide with game layers
|
|
54
55
|
IgnoreAllLayers(LayerMask.NameToLayer("Character"), false);
|
|
55
56
|
IgnoreAllLayers(LayerMask.NameToLayer("LocalStencilMask"), false);
|
|
56
57
|
IgnoreAllLayers(LayerMask.NameToLayer("StencilMask"), false);
|
|
57
58
|
|
|
58
|
-
//
|
|
59
|
-
//Collides with
|
|
59
|
+
// 3D Matrix
|
|
60
60
|
Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Character"), LayerMask.NameToLayer("Default"), false);
|
|
61
61
|
Physics.IgnoreLayerCollision(LayerMask.NameToLayer("Character"), LayerMask.NameToLayer("VisuallyHidden"),
|
|
62
62
|
false);
|
|
@@ -70,31 +70,52 @@ public static class PhysicsSetup {
|
|
|
70
70
|
Physics.IgnoreLayerCollision(LayerMask.NameToLayer("StencilMask"), LayerMask.NameToLayer("VisuallyHidden"),
|
|
71
71
|
false);
|
|
72
72
|
Physics.IgnoreLayerCollision(LayerMask.NameToLayer("StencilMask"), LayerMask.NameToLayer("Water"), false);
|
|
73
|
+
|
|
74
|
+
// 2D Matrix
|
|
75
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Character"), LayerMask.NameToLayer("Default"), false);
|
|
76
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Character"), LayerMask.NameToLayer("VisuallyHidden"),
|
|
77
|
+
false);
|
|
78
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("Character"), LayerMask.NameToLayer("Water"), false);
|
|
79
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("LocalStencilMask"), LayerMask.NameToLayer("Default"),
|
|
80
|
+
false);
|
|
81
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("LocalStencilMask"),
|
|
82
|
+
LayerMask.NameToLayer("VisuallyHidden"),
|
|
83
|
+
false);
|
|
84
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("LocalStencilMask"), LayerMask.NameToLayer("Water"),
|
|
85
|
+
false);
|
|
86
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("StencilMask"), LayerMask.NameToLayer("Default"), false);
|
|
87
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("StencilMask"), LayerMask.NameToLayer("VisuallyHidden"),
|
|
88
|
+
false);
|
|
89
|
+
Physics2D.IgnoreLayerCollision(LayerMask.NameToLayer("StencilMask"), LayerMask.NameToLayer("Water"), false);
|
|
73
90
|
}
|
|
74
91
|
|
|
75
92
|
|
|
76
93
|
public static void IgnoreAllLayers(int layer, bool ignoreGameLayers) {
|
|
77
94
|
foreach (var otherLayer in corelayers) {
|
|
78
95
|
Physics.IgnoreLayerCollision(layer, otherLayer, true);
|
|
96
|
+
Physics2D.IgnoreLayerCollision(layer, otherLayer, true);
|
|
79
97
|
}
|
|
80
98
|
|
|
81
99
|
foreach (var otherLayer in gameLayers) {
|
|
82
100
|
Physics.IgnoreLayerCollision(layer, otherLayer, ignoreGameLayers);
|
|
101
|
+
Physics2D.IgnoreLayerCollision(layer, otherLayer, ignoreGameLayers);
|
|
83
102
|
}
|
|
84
103
|
}
|
|
85
104
|
|
|
86
105
|
public static void CollideWithAllLayers(int layer, bool collideWithGameLayers) {
|
|
87
106
|
foreach (var otherLayer in corelayers) {
|
|
88
107
|
Physics.IgnoreLayerCollision(layer, otherLayer, false);
|
|
108
|
+
Physics2D.IgnoreLayerCollision(layer, otherLayer, false);
|
|
89
109
|
}
|
|
90
110
|
|
|
91
111
|
foreach (var otherLayer in gameLayers) {
|
|
92
112
|
Physics.IgnoreLayerCollision(layer, otherLayer, !collideWithGameLayers);
|
|
113
|
+
Physics2D.IgnoreLayerCollision(layer, otherLayer, !collideWithGameLayers);
|
|
93
114
|
}
|
|
94
115
|
}
|
|
95
116
|
|
|
96
117
|
private static void InitLayerCollection() {
|
|
97
|
-
//Compile all of the layer indexes we use
|
|
118
|
+
// Compile all of the layer indexes we use
|
|
98
119
|
corelayers = new List<int>();
|
|
99
120
|
gameLayers = new List<int>();
|
|
100
121
|
for (var i = 0; i < NumberOfCoreLayers; i++) {
|
|
@@ -106,15 +127,16 @@ public static class PhysicsSetup {
|
|
|
106
127
|
}
|
|
107
128
|
}
|
|
108
129
|
|
|
109
|
-
//Reset physics values that users may have changed
|
|
110
|
-
public static void ResetDefaults(
|
|
130
|
+
// Reset physics values that users may have changed
|
|
131
|
+
public static void ResetDefaults() {
|
|
111
132
|
InitLayerCollection();
|
|
112
133
|
|
|
113
|
-
//PHYSICS SETTINGS
|
|
134
|
+
// PHYSICS SETTINGS
|
|
114
135
|
SetPhysicsSettings();
|
|
136
|
+
SetPhysics2DSettings();
|
|
115
137
|
|
|
116
|
-
//PHYSICS MATRIX
|
|
117
|
-
//Make Game Layers Collide With Everything
|
|
138
|
+
// PHYSICS MATRIX
|
|
139
|
+
// Make Game Layers Collide With Everything
|
|
118
140
|
var gameId = 0;
|
|
119
141
|
for (var i = GameLayerStartIndex; i <= 31; i++) {
|
|
120
142
|
CollideWithAllLayers(i, true);
|
|
@@ -125,13 +147,13 @@ public static class PhysicsSetup {
|
|
|
125
147
|
gameId++;
|
|
126
148
|
}
|
|
127
149
|
|
|
128
|
-
//Run setup to make the game layers collide properly with core layers
|
|
129
|
-
Setup(
|
|
150
|
+
// Run setup to make the game layers collide properly with core layers
|
|
151
|
+
Setup();
|
|
130
152
|
}
|
|
131
153
|
|
|
132
154
|
private static void SetPhysicsSettings(
|
|
133
155
|
Vector3? gravity = null,
|
|
134
|
-
float
|
|
156
|
+
float bounceThreshold = 2,
|
|
135
157
|
float defaultMaxDepenetrationVelocity = 10,
|
|
136
158
|
float sleepThreshold = 0.005f,
|
|
137
159
|
float defaultContactOffset = 0.01f,
|
|
@@ -140,8 +162,8 @@ public static class PhysicsSetup {
|
|
|
140
162
|
bool queriesHitBackfaces = false,
|
|
141
163
|
bool queriesHitTriggers = true,
|
|
142
164
|
float fixedDeltaTime = 0.025f) {
|
|
143
|
-
Physics.gravity = gravity??new Vector3(0
|
|
144
|
-
Physics.bounceThreshold =
|
|
165
|
+
Physics.gravity = gravity ?? new Vector3(0, -9.81f, 0);
|
|
166
|
+
Physics.bounceThreshold = bounceThreshold;
|
|
145
167
|
Physics.defaultMaxDepenetrationVelocity = defaultMaxDepenetrationVelocity;
|
|
146
168
|
Physics.sleepThreshold = sleepThreshold;
|
|
147
169
|
Physics.defaultContactOffset = defaultContactOffset;
|
|
@@ -152,17 +174,64 @@ public static class PhysicsSetup {
|
|
|
152
174
|
Time.fixedDeltaTime = fixedDeltaTime;
|
|
153
175
|
}
|
|
154
176
|
|
|
177
|
+
private static void SetPhysics2DSettings(
|
|
178
|
+
Vector3? gravity = null,
|
|
179
|
+
float bounceThreshold = 1,
|
|
180
|
+
int velocityIterations = 8,
|
|
181
|
+
int positionIterations = 3,
|
|
182
|
+
float maxLinearCorrection = .2f,
|
|
183
|
+
float maxAngularCorrection = 8,
|
|
184
|
+
float maxTranslationSpeed = 100,
|
|
185
|
+
float maxRotationSpeed = 360,
|
|
186
|
+
float baumgarteScale = .2f,
|
|
187
|
+
float baumgarteTOIScale = .75f,
|
|
188
|
+
float timeToSleep = .5f,
|
|
189
|
+
float linearSleepTolerance = .01f,
|
|
190
|
+
float angularSleepTolerance = 2,
|
|
191
|
+
float defaultContactOffset = 0.01f,
|
|
192
|
+
float contactThreshold = 0,
|
|
193
|
+
bool queriesHitTriggers = true,
|
|
194
|
+
bool queriesStartInColliders = true,
|
|
195
|
+
bool callbacksOnDisable = true,
|
|
196
|
+
bool reuseCollisionCallbacks = true,
|
|
197
|
+
bool autoSyncTransforms = false) {
|
|
198
|
+
Physics2D.gravity = gravity ?? new Vector3(0, -9.81f, 0);
|
|
199
|
+
Physics2D.velocityIterations = velocityIterations;
|
|
200
|
+
Physics2D.positionIterations = positionIterations;
|
|
201
|
+
Physics2D.bounceThreshold = bounceThreshold;
|
|
202
|
+
Physics2D.maxLinearCorrection = maxLinearCorrection;
|
|
203
|
+
Physics2D.maxAngularCorrection = maxAngularCorrection;
|
|
204
|
+
Physics2D.maxTranslationSpeed = maxTranslationSpeed;
|
|
205
|
+
Physics2D.maxRotationSpeed = maxRotationSpeed;
|
|
206
|
+
Physics2D.baumgarteScale = baumgarteScale;
|
|
207
|
+
Physics2D.baumgarteTOIScale = baumgarteTOIScale;
|
|
208
|
+
Physics2D.timeToSleep = timeToSleep;
|
|
209
|
+
Physics2D.linearSleepTolerance = linearSleepTolerance;
|
|
210
|
+
Physics2D.angularSleepTolerance = angularSleepTolerance;
|
|
211
|
+
Physics2D.defaultContactOffset = defaultContactOffset;
|
|
212
|
+
Physics2D.contactThreshold = contactThreshold;
|
|
213
|
+
Physics2D.queriesHitTriggers = queriesHitTriggers;
|
|
214
|
+
Physics2D.queriesStartInColliders = queriesStartInColliders;
|
|
215
|
+
Physics2D.callbacksOnDisable = callbacksOnDisable;
|
|
216
|
+
Physics2D.reuseCollisionCallbacks = reuseCollisionCallbacks;
|
|
217
|
+
Physics2D.autoSyncTransforms = autoSyncTransforms;
|
|
218
|
+
}
|
|
219
|
+
|
|
155
220
|
public static void SetupFromGameConfig() {
|
|
156
221
|
#if AIRSHIP_PLAYER || !UNITY_EDITOR
|
|
157
|
-
//Reset Unity to Airship defaults and GameConfig customizations
|
|
222
|
+
// Reset Unity to Airship defaults and GameConfig customizations
|
|
158
223
|
var gameConfig = AssetBridge.Instance.LoadGameConfigAtRuntime();
|
|
159
224
|
if (gameConfig) {
|
|
160
225
|
// Debug.Log("Loading project settings from GameConfig. Physics: " + gameConfig.gravity + " matrix size: " +
|
|
161
226
|
// gameConfig.physicsMatrix.Length);
|
|
162
|
-
//Setup the Core Layers
|
|
163
|
-
Setup(
|
|
164
|
-
//Load in game specific Layers and Settings
|
|
227
|
+
// Setup the Core Layers
|
|
228
|
+
Setup();
|
|
229
|
+
// Load in game specific Layers and Settings
|
|
165
230
|
gameConfig.DeserializeSettings();
|
|
231
|
+
} else {
|
|
232
|
+
// Use default Airship values if we aren't setting up game specific values
|
|
233
|
+
// Debug.Log("No custom GameConfig settings found. Resetting to defaults");
|
|
234
|
+
ResetDefaults();
|
|
166
235
|
}
|
|
167
236
|
#endif
|
|
168
237
|
}
|