-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gun Tools.cs
156 lines (151 loc) · 6.72 KB
/
Gun Tools.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using UnityEngine;
using System.Collections.Generic;
namespace PiratePack
{
public static class GunTools
{
public static tk2dSpriteDefinition CopyDefinitionFrom(this tk2dSpriteDefinition other)
{
tk2dSpriteDefinition result = new tk2dSpriteDefinition
{
boundsDataCenter = new Vector3
{
x = other.boundsDataCenter.x,
y = other.boundsDataCenter.y,
z = other.boundsDataCenter.z
},
boundsDataExtents = new Vector3
{
x = other.boundsDataExtents.x,
y = other.boundsDataExtents.y,
z = other.boundsDataExtents.z
},
colliderConvex = other.colliderConvex,
colliderSmoothSphereCollisions = other.colliderSmoothSphereCollisions,
colliderType = other.colliderType,
colliderVertices = other.colliderVertices,
collisionLayer = other.collisionLayer,
complexGeometry = other.complexGeometry,
extractRegion = other.extractRegion,
flipped = other.flipped,
indices = other.indices,
material = new Material(other.material),
materialId = other.materialId,
materialInst = new Material(other.materialInst),
metadata = other.metadata,
name = other.name,
normals = other.normals,
physicsEngine = other.physicsEngine,
position0 = new Vector3
{
x = other.position0.x,
y = other.position0.y,
z = other.position0.z
},
position1 = new Vector3
{
x = other.position1.x,
y = other.position1.y,
z = other.position1.z
},
position2 = new Vector3
{
x = other.position2.x,
y = other.position2.y,
z = other.position2.z
},
position3 = new Vector3
{
x = other.position3.x,
y = other.position3.y,
z = other.position3.z
},
regionH = other.regionH,
regionW = other.regionW,
regionX = other.regionX,
regionY = other.regionY,
tangents = other.tangents,
texelSize = new Vector2
{
x = other.texelSize.x,
y = other.texelSize.y
},
untrimmedBoundsDataCenter = new Vector3
{
x = other.untrimmedBoundsDataCenter.x,
y = other.untrimmedBoundsDataCenter.y,
z = other.untrimmedBoundsDataCenter.z
},
untrimmedBoundsDataExtents = new Vector3
{
x = other.untrimmedBoundsDataExtents.x,
y = other.untrimmedBoundsDataExtents.y,
z = other.untrimmedBoundsDataExtents.z
}
};
List<Vector2> uvs = new List<Vector2>();
foreach (Vector2 vector in other.uvs)
{
uvs.Add(new Vector2
{
x = vector.x,
y = vector.y
});
}
result.uvs = uvs.ToArray();
List<Vector3> colliderVertices = new List<Vector3>();
foreach (Vector3 vector in other.colliderVertices)
{
colliderVertices.Add(new Vector3
{
x = vector.x,
y = vector.y,
z = vector.z
});
}
result.colliderVertices = colliderVertices.ToArray();
return result;
}
public static void SetProjectileSpriteRight(this Projectile proj, string name, int pixelWidth, int pixelHeight, int? overrideColliderPixelWidth = null, int? overrideColliderPixelHeight = null)
{
try
{
bool flag = overrideColliderPixelWidth == null;
if (flag)
{
overrideColliderPixelWidth = new int?(pixelWidth);
}
bool flag2 = overrideColliderPixelHeight == null;
if (flag2)
{
overrideColliderPixelHeight = new int?(pixelHeight);
}
float num = (float)pixelWidth / 16f;
float num2 = (float)pixelHeight / 16f;
float x = (float)overrideColliderPixelWidth.Value / 16f;
float y = (float)overrideColliderPixelHeight.Value / 16f;
proj.GetAnySprite().spriteId = ETGMod.Databases.Items.ProjectileCollection.inst.GetSpriteIdByName(name);
tk2dSpriteDefinition tk2dSpriteDefinition = ETGMod.Databases.Items.ProjectileCollection.inst.spriteDefinitions[(PickupObjectDatabase.GetById(12) as Gun).DefaultModule.projectiles[0].GetAnySprite().spriteId].CopyDefinitionFrom();
tk2dSpriteDefinition.boundsDataCenter = new Vector3(num / 2f, num2 / 2f, 0f);
tk2dSpriteDefinition.boundsDataExtents = new Vector3(num, num2, 0f);
tk2dSpriteDefinition.untrimmedBoundsDataCenter = new Vector3(num / 2f, num2 / 2f, 0f);
tk2dSpriteDefinition.untrimmedBoundsDataExtents = new Vector3(num, num2, 0f);
tk2dSpriteDefinition.position0 = new Vector3(0f, 0f, 0f);
tk2dSpriteDefinition.position1 = new Vector3(0f + num, 0f, 0f);
tk2dSpriteDefinition.position2 = new Vector3(0f, 0f + num2, 0f);
tk2dSpriteDefinition.position3 = new Vector3(0f + num, 0f + num2, 0f);
tk2dSpriteDefinition.colliderVertices[1].x = x;
tk2dSpriteDefinition.colliderVertices[1].y = y;
tk2dSpriteDefinition.name = name;
ETGMod.Databases.Items.ProjectileCollection.inst.spriteDefinitions[proj.GetAnySprite().spriteId] = tk2dSpriteDefinition;
proj.baseData.force = 0f;
}
catch (Exception ex)
{
ETGModConsole.Log("Ooops! Seems like something got very, Very, VERY wrong. Here's the exception:", false);
ETGModConsole.Log(ex.ToString(), false);
}
}
}
}