Improve variable names in LevelLoader
This commit is contained in:
parent
9bb357de38
commit
3142c035eb
1 changed files with 85 additions and 85 deletions
|
@ -83,8 +83,8 @@ public class LevelLoader : MonoBehaviour
|
||||||
|
|
||||||
private void ReadLevel(BinaryReader reader)
|
private void ReadLevel(BinaryReader reader)
|
||||||
{
|
{
|
||||||
int num = reader.ReadInt32();
|
int objectCount = reader.ReadInt32();
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < objectCount; i++)
|
||||||
{
|
{
|
||||||
this.ReadObject(null, reader);
|
this.ReadObject(null, reader);
|
||||||
}
|
}
|
||||||
|
@ -92,14 +92,14 @@ public class LevelLoader : MonoBehaviour
|
||||||
|
|
||||||
private void ReadObject(GameObject parent, BinaryReader reader)
|
private void ReadObject(GameObject parent, BinaryReader reader)
|
||||||
{
|
{
|
||||||
short num = reader.ReadInt16();
|
short childCount = reader.ReadInt16();
|
||||||
if (num == 0)
|
if (childCount == 0)
|
||||||
{
|
{
|
||||||
this.ReadPrefabInstance(parent, reader);
|
this.ReadPrefabInstance(parent, reader);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.ReadParentObject(num, parent, reader);
|
this.ReadParentObject(childCount, parent, reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,9 +183,9 @@ public class LevelLoader : MonoBehaviour
|
||||||
|
|
||||||
private void ReadPrefabOverrides(GameObject obj, BinaryReader reader)
|
private void ReadPrefabOverrides(GameObject obj, BinaryReader reader)
|
||||||
{
|
{
|
||||||
int num = reader.ReadInt32();
|
int count = reader.ReadInt32();
|
||||||
byte[] buffer = new byte[num];
|
byte[] buffer = new byte[count];
|
||||||
reader.Read(buffer, 0, num);
|
reader.Read(buffer, 0, count);
|
||||||
using (MemoryStream memoryStream = new MemoryStream(buffer))
|
using (MemoryStream memoryStream = new MemoryStream(buffer))
|
||||||
{
|
{
|
||||||
using (StreamReader streamReader = new StreamReader(memoryStream, Encoding.UTF8))
|
using (StreamReader streamReader = new StreamReader(memoryStream, Encoding.UTF8))
|
||||||
|
@ -199,36 +199,36 @@ public class LevelLoader : MonoBehaviour
|
||||||
|
|
||||||
private void ReadTerrain(GameObject obj, BinaryReader reader)
|
private void ReadTerrain(GameObject obj, BinaryReader reader)
|
||||||
{
|
{
|
||||||
e2dTerrain component = obj.GetComponent<e2dTerrain>();
|
e2dTerrain terrain = obj.GetComponent<e2dTerrain>();
|
||||||
component.FillTextureTileOffsetX = reader.ReadSingle();
|
terrain.FillTextureTileOffsetX = reader.ReadSingle();
|
||||||
component.FillTextureTileOffsetY = reader.ReadSingle();
|
terrain.FillTextureTileOffsetY = reader.ReadSingle();
|
||||||
GameObject gameObject = obj.transform.Find("_fill").gameObject;
|
GameObject fill = obj.transform.Find("_fill").gameObject;
|
||||||
MeshFilter component2 = gameObject.GetComponent<MeshFilter>();
|
MeshFilter filter = fill.GetComponent<MeshFilter>();
|
||||||
Mesh sharedMesh = this.ReadMesh(false, true, false, reader, component);
|
Mesh sharedMesh = this.ReadMesh(false, true, false, reader, terrain);
|
||||||
Color color = this.ReadColor(reader);
|
Color color = this.ReadColor(reader);
|
||||||
int index = reader.ReadInt32();
|
int index = reader.ReadInt32();
|
||||||
component2.sharedMesh = sharedMesh;
|
filter.sharedMesh = sharedMesh;
|
||||||
gameObject.GetComponent<Renderer>().sharedMaterial.color = color;
|
fill.GetComponent<Renderer>().sharedMaterial.color = color;
|
||||||
gameObject.GetComponent<Renderer>().sharedMaterial.mainTexture = (this.m_references[index] as Texture2D);
|
fill.GetComponent<Renderer>().sharedMaterial.mainTexture = (this.m_references[index] as Texture2D);
|
||||||
GameObject gameObject2 = obj.transform.Find("_curve").gameObject;
|
GameObject curve = obj.transform.Find("_curve").gameObject;
|
||||||
component2 = gameObject2.GetComponent<MeshFilter>();
|
filter = curve.GetComponent<MeshFilter>();
|
||||||
sharedMesh = this.ReadMesh(false, false, true, reader, component);
|
sharedMesh = this.ReadMesh(false, false, true, reader, terrain);
|
||||||
component2.sharedMesh = sharedMesh;
|
filter.sharedMesh = sharedMesh;
|
||||||
int num = reader.ReadInt32();
|
int curveTextureCount = reader.ReadInt32();
|
||||||
for (int i = 0; i < num; i++)
|
for (int i = 0; i < curveTextureCount; i++)
|
||||||
{
|
{
|
||||||
if (i >= component.CurveTextures.Count)
|
if (i >= terrain.CurveTextures.Count)
|
||||||
{
|
{
|
||||||
component.CurveTextures.Add(new e2dCurveTexture(null));
|
terrain.CurveTextures.Add(new e2dCurveTexture(null));
|
||||||
}
|
}
|
||||||
int index2 = reader.ReadInt32();
|
int index2 = reader.ReadInt32();
|
||||||
component.CurveTextures[i].texture = (this.m_references[index2] as Texture);
|
terrain.CurveTextures[i].texture = (this.m_references[index2] as Texture);
|
||||||
component.CurveTextures[i].size = this.ReadVector2(reader);
|
terrain.CurveTextures[i].size = this.ReadVector2(reader);
|
||||||
component.CurveTextures[i].fixedAngle = reader.ReadBoolean();
|
terrain.CurveTextures[i].fixedAngle = reader.ReadBoolean();
|
||||||
component.CurveTextures[i].fadeThreshold = reader.ReadSingle();
|
terrain.CurveTextures[i].fadeThreshold = reader.ReadSingle();
|
||||||
}
|
}
|
||||||
int num2 = reader.ReadInt32();
|
int hasControlTexture = reader.ReadInt32();
|
||||||
if (num2 > 0)
|
if (hasControlTexture > 0)
|
||||||
{
|
{
|
||||||
int count = reader.ReadInt32();
|
int count = reader.ReadInt32();
|
||||||
byte[] data = reader.ReadBytes(count);
|
byte[] data = reader.ReadBytes(count);
|
||||||
|
@ -240,15 +240,15 @@ public class LevelLoader : MonoBehaviour
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Can't load control texture");
|
throw new InvalidOperationException("Can't load control texture");
|
||||||
}
|
}
|
||||||
component.CurveMesh.ControlTextures.Clear();
|
terrain.CurveMesh.ControlTextures.Clear();
|
||||||
component.CurveMesh.ControlTextures.Add(texture2D);
|
terrain.CurveMesh.ControlTextures.Add(texture2D);
|
||||||
component.CurveMesh.RebuildMaterial();
|
terrain.CurveMesh.RebuildMaterial();
|
||||||
}
|
}
|
||||||
bool flag = reader.ReadBoolean();
|
bool hasCollision = reader.ReadBoolean();
|
||||||
if (flag)
|
if (hasCollision)
|
||||||
{
|
{
|
||||||
component2 = gameObject.GetComponent<MeshFilter>();
|
filter = fill.GetComponent<MeshFilter>();
|
||||||
Mesh sharedMesh2 = component2.sharedMesh;
|
Mesh sharedMesh2 = filter.sharedMesh;
|
||||||
this.CreateCollider(obj, sharedMesh2.vertices);
|
this.CreateCollider(obj, sharedMesh2.vertices);
|
||||||
}
|
}
|
||||||
else if (obj.transform.Find(e2dConstants.COLLIDER_MESH_NAME))
|
else if (obj.transform.Find(e2dConstants.COLLIDER_MESH_NAME))
|
||||||
|
@ -260,66 +260,66 @@ public class LevelLoader : MonoBehaviour
|
||||||
private Mesh ReadMesh(bool readUV, bool fillMesh, bool readColor, BinaryReader reader, e2dTerrain terrain)
|
private Mesh ReadMesh(bool readUV, bool fillMesh, bool readColor, BinaryReader reader, e2dTerrain terrain)
|
||||||
{
|
{
|
||||||
Mesh mesh = new Mesh();
|
Mesh mesh = new Mesh();
|
||||||
int num = reader.ReadInt32();
|
int count = reader.ReadInt32();
|
||||||
Vector3[] array = new Vector3[num];
|
Vector3[] vertices = new Vector3[count];
|
||||||
if (fillMesh)
|
if (fillMesh)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < array.Length; i++)
|
for (int i = 0; i < vertices.Length; i++)
|
||||||
{
|
{
|
||||||
array[i] = this.ReadVector2(reader);
|
vertices[i] = this.ReadVector2(reader);
|
||||||
}
|
}
|
||||||
Vector2[] array2 = new Vector2[array.Length];
|
Vector2[] uv = new Vector2[vertices.Length];
|
||||||
float num2 = 1f / terrain.FillTextureTileWidth;
|
float num2 = 1f / terrain.FillTextureTileWidth;
|
||||||
float num3 = 1f / terrain.FillTextureTileHeight;
|
float num3 = 1f / terrain.FillTextureTileHeight;
|
||||||
for (int j = 0; j < array2.Length; j++)
|
for (int j = 0; j < uv.Length; j++)
|
||||||
{
|
{
|
||||||
array2[j].x = (array[j].x - terrain.FillTextureTileOffsetX) * num2;
|
uv[j].x = (vertices[j].x - terrain.FillTextureTileOffsetX) * num2;
|
||||||
array2[j].y = (array[j].y - terrain.FillTextureTileOffsetY) * num3;
|
uv[j].y = (vertices[j].y - terrain.FillTextureTileOffsetY) * num3;
|
||||||
}
|
}
|
||||||
mesh.vertices = array;
|
mesh.vertices = vertices;
|
||||||
mesh.uv = array2;
|
mesh.uv = uv;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Color[] array3 = new Color[array.Length];
|
Color[] colors = new Color[vertices.Length];
|
||||||
for (int k = 0; k < array.Length; k++)
|
for (int k = 0; k < vertices.Length; k++)
|
||||||
{
|
{
|
||||||
array[k] = this.ReadVector2(reader);
|
vertices[k] = this.ReadVector2(reader);
|
||||||
array[k].z = -0.01f;
|
vertices[k].z = -0.01f;
|
||||||
array3[k].r = (float)((k + 1) % 2);
|
colors[k].r = (float)((k + 1) % 2);
|
||||||
}
|
}
|
||||||
Vector2[] array4 = new Vector2[array.Length];
|
Vector2[] uv = new Vector2[vertices.Length];
|
||||||
int num4 = num / 2;
|
int num4 = count / 2;
|
||||||
float num5 = 0f;
|
float num5 = 0f;
|
||||||
for (int l = 1; l < num4; l++)
|
for (int l = 1; l < num4; l++)
|
||||||
{
|
{
|
||||||
int num6 = l;
|
int num6 = l;
|
||||||
int num7 = 2 * num6;
|
int num7 = 2 * num6;
|
||||||
float magnitude = (array[num7] - array[num7 - 2]).magnitude;
|
float magnitude = (vertices[num7] - vertices[num7 - 2]).magnitude;
|
||||||
num5 += magnitude;
|
num5 += magnitude;
|
||||||
array4[num7] = (array4[num7 + 1] = new Vector2(num5, (float)num6));
|
uv[num7] = (uv[num7 + 1] = new Vector2(num5, (float)num6));
|
||||||
}
|
}
|
||||||
mesh.vertices = array;
|
mesh.vertices = vertices;
|
||||||
mesh.colors = array3;
|
mesh.colors = colors;
|
||||||
mesh.uv = array4;
|
mesh.uv = uv;
|
||||||
}
|
}
|
||||||
if (readUV)
|
if (readUV)
|
||||||
{
|
{
|
||||||
int num8 = reader.ReadInt32();
|
int uvCount = reader.ReadInt32();
|
||||||
Vector2[] array5 = new Vector2[num8];
|
Vector2[] uv = new Vector2[uvCount];
|
||||||
for (int m = 0; m < array5.Length; m++)
|
for (int m = 0; m < uv.Length; m++)
|
||||||
{
|
{
|
||||||
array5[m] = this.ReadVector2(reader);
|
uv[m] = this.ReadVector2(reader);
|
||||||
}
|
}
|
||||||
mesh.uv = array5;
|
mesh.uv = uv;
|
||||||
}
|
}
|
||||||
int num9 = reader.ReadInt32();
|
int triangleCount = reader.ReadInt32();
|
||||||
int[] array6 = new int[num9];
|
int[] triangles = new int[triangleCount];
|
||||||
for (int n = 0; n < num9; n++)
|
for (int n = 0; n < triangleCount; n++)
|
||||||
{
|
{
|
||||||
array6[n] = (int)reader.ReadInt16();
|
triangles[n] = (int)reader.ReadInt16();
|
||||||
}
|
}
|
||||||
mesh.triangles = array6;
|
mesh.triangles = triangles;
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,34 +332,34 @@ public class LevelLoader : MonoBehaviour
|
||||||
|
|
||||||
public void CreateCollider(GameObject obj, Vector3[] polygon)
|
public void CreateCollider(GameObject obj, Vector3[] polygon)
|
||||||
{
|
{
|
||||||
Vector3[] array = new Vector3[2 * polygon.Length];
|
Vector3[] vertices = new Vector3[2 * polygon.Length];
|
||||||
int[] array2 = new int[6 * polygon.Length];
|
int[] triangles = new int[6 * polygon.Length];
|
||||||
for (int i = 0; i < polygon.Length; i++)
|
for (int i = 0; i < polygon.Length; i++)
|
||||||
{
|
{
|
||||||
int num = 2 * i;
|
int num = 2 * i;
|
||||||
array[num] = new Vector3(polygon[i].x, polygon[i].y, -0.5f * e2dConstants.COLLISION_MESH_Z_DEPTH);
|
vertices[num] = new Vector3(polygon[i].x, polygon[i].y, -0.5f * e2dConstants.COLLISION_MESH_Z_DEPTH);
|
||||||
array[num + 1] = new Vector3(polygon[i].x, polygon[i].y, 0.5f * e2dConstants.COLLISION_MESH_Z_DEPTH);
|
vertices[num + 1] = new Vector3(polygon[i].x, polygon[i].y, 0.5f * e2dConstants.COLLISION_MESH_Z_DEPTH);
|
||||||
int num2 = 6 * i;
|
int num2 = 6 * i;
|
||||||
array2[num2] = num % array.Length;
|
triangles[num2] = num % vertices.Length;
|
||||||
array2[num2 + 1] = (num + 1) % array.Length;
|
triangles[num2 + 1] = (num + 1) % vertices.Length;
|
||||||
array2[num2 + 2] = (num + 2) % array.Length;
|
triangles[num2 + 2] = (num + 2) % vertices.Length;
|
||||||
array2[num2 + 3] = (num + 2) % array.Length;
|
triangles[num2 + 3] = (num + 2) % vertices.Length;
|
||||||
array2[num2 + 4] = (num + 1) % array.Length;
|
triangles[num2 + 4] = (num + 1) % vertices.Length;
|
||||||
array2[num2 + 5] = (num + 3) % array.Length;
|
triangles[num2 + 5] = (num + 3) % vertices.Length;
|
||||||
}
|
}
|
||||||
Transform transform = obj.transform.Find(e2dConstants.COLLIDER_MESH_NAME);
|
Transform transform = obj.transform.Find(e2dConstants.COLLIDER_MESH_NAME);
|
||||||
MeshCollider component = transform.GetComponent<MeshCollider>();
|
MeshCollider collider = transform.GetComponent<MeshCollider>();
|
||||||
component.sharedMesh = new Mesh
|
collider.sharedMesh = new Mesh
|
||||||
{
|
{
|
||||||
vertices = array,
|
vertices = vertices,
|
||||||
triangles = array2
|
triangles = triangles
|
||||||
};
|
};
|
||||||
transform.localPosition = Vector3.zero;
|
transform.localPosition = Vector3.zero;
|
||||||
transform.localRotation = Quaternion.identity;
|
transform.localRotation = Quaternion.identity;
|
||||||
transform.localScale = Vector3.one;
|
transform.localScale = Vector3.one;
|
||||||
if (obj.layer != LayerMask.NameToLayer("IceGround"))
|
if (obj.layer != LayerMask.NameToLayer("IceGround"))
|
||||||
{
|
{
|
||||||
component.gameObject.layer = LayerMask.NameToLayer("Ground");
|
collider.gameObject.layer = LayerMask.NameToLayer("Ground");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue