Skip to content

Commit e0a129c

Browse files
committed
update new stuff to work with unity
1 parent 410e5fe commit e0a129c

7 files changed

Lines changed: 49 additions & 6 deletions

File tree

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/ParameterData.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,11 @@ public cTransform(Vector3 position, Vector3 rotation)
167167
if (y == null) return x;
168168

169169

170-
170+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
171+
return new cTransform(x.position + y.position, x.rotation + y.rotation);
172+
#else
171173
return new cTransform(x.position + y.position, x.rotation.AddEulerAngles(y.rotation));
174+
#endif
172175
}
173176

174177
public override string ToString()

CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/CommandsUtils.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6-
using System.Numerics;
76
using System.Text;
87
using System.Threading.Tasks;
8+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
9+
using UnityEngine;
10+
#else
11+
using System.Numerics;
12+
#endif
913

1014
namespace CATHODE.Scripting
1115
{
@@ -343,7 +347,11 @@ public static (Vector3, Quaternion) CalculateInstancedPosition(EntityPath hierar
343347
if (comp == null)
344348
break;
345349
}
350+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
351+
return (globalTransform.position, Quaternion.Euler(globalTransform.rotation.x, globalTransform.rotation.y, globalTransform.rotation.z));
352+
#else
346353
return (globalTransform.position, Quaternion.CreateFromYawPitchRoll(globalTransform.rotation.Y * (float)Math.PI / 180.0f, globalTransform.rotation.X * (float)Math.PI / 180.0f, globalTransform.rotation.Z * (float)Math.PI / 180.0f));
354+
#endif
347355
}
348356

349357
/* CA's CAGE doesn't properly tidy up hierarchies pointing to deleted entities - so we can do that to save confusion */
@@ -460,6 +468,6 @@ public static bool PurgeDeadLinks(Commands commands, Composite composite, bool f
460468
"\n - " + (originalLinkCount - newLinkCount) + " entity links (of " + originalLinkCount + ")");
461469
return true;
462470
}
463-
#endregion
471+
#endregion
464472
}
465473
}

CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/ParameterUtils.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using System.IO;
77
using System.Linq;
88
using System.Text;
9+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
10+
using UnityEngine;
11+
#endif
912

1013
namespace CATHODE.Scripting
1114
{

CathodeLib/Scripts/CATHODE/EnvironmentAnimations.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ override protected bool SaveInternal()
163163
int stacked_Entries1 = 0;
164164
for (int i = 0; i < Entries.Count; i++)
165165
{
166+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
167+
Utilities.Write(writer, Matrix4x4.identity);
168+
#else
166169
Utilities.Write(writer, Matrix4x4.Identity);
170+
#endif
167171
Utilities.Write(writer, Utilities.AnimationHashedString(Entries[i].SkeletonName));
168172
writer.Write((Int32)0);
169173
Utilities.Write(writer, Entries[i].ResourceIndex);
@@ -186,7 +190,7 @@ override protected bool SaveInternal()
186190
}
187191
return true;
188192
}
189-
#endregion
193+
#endregion
190194

191195
#region HELPERS
192196
private List<T> PopulateArray<T>(BinaryReader reader, T[] array)

CathodeLib/Scripts/CATHODE/PhysicsMaps.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,38 @@ override protected bool LoadInternal()
4646
Vector4 Row2 = Utilities.Consume<Vector4>(reader);
4747
double[,] matrix = new double[,]
4848
{
49+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
50+
{Row0.x, Row0.y, Row0.z, Row0.w},
51+
{Row1.x, Row1.y, Row1.z, Row1.w},
52+
{Row2.x, Row2.y, Row2.z, Row2.w},
53+
#else
4954
{Row0.X, Row0.Y, Row0.Z, Row0.W},
5055
{Row1.X, Row1.Y, Row1.Z, Row1.W},
5156
{Row2.X, Row2.Y, Row2.Z, Row2.W},
57+
#endif
5258
};
5359

5460
entry.Position = new Vector3(
5561
(float)matrix[0, 3],
5662
(float)matrix[1, 3],
5763
(float)matrix[2, 3]
5864
);
65+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
66+
Matrix4x4 matrix4x4 = new Matrix4x4(
67+
new Vector4((float)matrix[0, 0], (float)matrix[0, 1], (float)matrix[0, 2], 0),
68+
new Vector4((float)matrix[1, 0], (float)matrix[1, 1], (float)matrix[1, 2], 0),
69+
new Vector4((float)matrix[2, 0], (float)matrix[2, 1], (float)matrix[2, 2], 0),
70+
new Vector4(0, 0, 0, 1)
71+
);
72+
entry.Rotation = Quaternion.LookRotation(matrix4x4.GetColumn(2), matrix4x4.GetColumn(1));
73+
#else
5974
entry.Rotation = Quaternion.CreateFromRotationMatrix(new Matrix4x4(
6075
(float)matrix[0, 0], (float)matrix[0, 1], (float)matrix[0, 2], 0,
6176
(float)matrix[1, 0], (float)matrix[1, 1], (float)matrix[1, 2], 0,
6277
(float)matrix[2, 0], (float)matrix[2, 1], (float)matrix[2, 2], 0,
6378
0, 0, 0, 1
6479
));
80+
#endif
6581

6682
reader.BaseStream.Position += 8;
6783
Entries.Add(entry);
@@ -87,10 +103,17 @@ override protected bool SaveInternal()
87103
Utilities.Write(writer, Entries[i].composite_instance_id);
88104
Utilities.Write(writer, Entries[i].entity);
89105

106+
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
107+
Matrix4x4 rotationMatrix4x4 = Matrix4x4.Rotate(Entries[i].Rotation);
108+
Vector4 Row0 = new Vector4(rotationMatrix4x4.m11, rotationMatrix4x4.m12, rotationMatrix4x4.m13, Entries[i].Position.x);
109+
Vector4 Row1 = new Vector4(rotationMatrix4x4.m21, rotationMatrix4x4.m22, rotationMatrix4x4.m23, Entries[i].Position.y);
110+
Vector4 Row2 = new Vector4(rotationMatrix4x4.m31, rotationMatrix4x4.m32, rotationMatrix4x4.m33, Entries[i].Position.z);
111+
#else
90112
Matrix4x4 rotationMatrix4x4 = Matrix4x4.CreateFromQuaternion(Entries[i].Rotation);
91113
Vector4 Row0 = new Vector4(rotationMatrix4x4.M11, rotationMatrix4x4.M12, rotationMatrix4x4.M13, Entries[i].Position.X);
92114
Vector4 Row1 = new Vector4(rotationMatrix4x4.M21, rotationMatrix4x4.M22, rotationMatrix4x4.M23, Entries[i].Position.Y);
93115
Vector4 Row2 = new Vector4(rotationMatrix4x4.M31, rotationMatrix4x4.M32, rotationMatrix4x4.M33, Entries[i].Position.Z);
116+
#endif
94117

95118
Utilities.Write<Vector4>(writer, Row0);
96119
Utilities.Write<Vector4>(writer, Row1);
@@ -100,7 +123,7 @@ override protected bool SaveInternal()
100123
}
101124
return true;
102125
}
103-
#endregion
126+
#endregion
104127

105128
#region STRUCTURES
106129
public class Entry

CathodeLib/Scripts/CATHODE/Traversals.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Linq;
7+
using System.Runtime.InteropServices;
8+
79
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
810
using UnityEngine;
911
#else

CathodeLib/Scripts/LEGACY_DAN/CathodePAK.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CathodeLib;
1+
using CathodeLib;
22
using System;
33
using System.Buffers.Binary;
44
using System.Collections;

0 commit comments

Comments
 (0)