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