using System.Collections.Generic; using UnityEngine; public abstract class e2dTerrainMesh { private e2dTerrain mTerrain; protected e2dTerrain Terrain { get { return mTerrain; } } protected Transform transform { get { return mTerrain.transform; } } protected List TerrainCurve { get { return mTerrain.TerrainCurve; } } protected List CurveTextures { get { return mTerrain.CurveTextures; } } protected List CurveControlTextures { get { return mTerrain.CurveMesh.CurveControlTextures; } } protected e2dTerrainBoundary Boundary { get { return mTerrain.Boundary; } } public e2dTerrainMesh(e2dTerrain terrain) { mTerrain = terrain; } protected void ResetMeshObjectsTransforms() { transform.FindChild(e2dConstants.FILL_MESH_NAME).transform.localPosition = Vector3.zero; transform.FindChild(e2dConstants.FILL_MESH_NAME).transform.localRotation = Quaternion.identity; transform.FindChild(e2dConstants.FILL_MESH_NAME).transform.localScale = Vector3.one; transform.FindChild(e2dConstants.CURVE_MESH_NAME).transform.localPosition = Vector3.zero; transform.FindChild(e2dConstants.CURVE_MESH_NAME).transform.localRotation = Quaternion.identity; transform.FindChild(e2dConstants.CURVE_MESH_NAME).transform.localScale = Vector3.one; transform.FindChild(e2dConstants.COLLIDER_MESH_NAME).transform.localPosition = Vector3.zero; transform.FindChild(e2dConstants.COLLIDER_MESH_NAME).transform.localRotation = Quaternion.identity; transform.FindChild(e2dConstants.COLLIDER_MESH_NAME).transform.localScale = Vector3.one; } protected void EnsureMeshObjectsExist() { if (transform.FindChild(e2dConstants.FILL_MESH_NAME) == null) { GameObject gameObject = new GameObject(e2dConstants.FILL_MESH_NAME); gameObject.transform.parent = transform; } if (transform.FindChild(e2dConstants.CURVE_MESH_NAME) == null) { GameObject gameObject2 = new GameObject(e2dConstants.CURVE_MESH_NAME); gameObject2.transform.parent = transform; } if (transform.FindChild(e2dConstants.COLLIDER_MESH_NAME) == null) { GameObject gameObject3 = new GameObject(e2dConstants.COLLIDER_MESH_NAME); gameObject3.transform.parent = transform; } } protected void EnsureMeshComponentsExist() { EnsureMeshObjectsExist(); GameObject gameObject = transform.FindChild(e2dConstants.FILL_MESH_NAME).gameObject; EnsureMeshFilterExists(gameObject); EnsureMeshRendererExists(gameObject); EnsureScriptsAttached(gameObject); gameObject = transform.FindChild(e2dConstants.CURVE_MESH_NAME).gameObject; EnsureMeshFilterExists(gameObject); EnsureMeshRendererExists(gameObject); EnsureScriptsAttached(gameObject); gameObject = transform.FindChild(e2dConstants.COLLIDER_MESH_NAME).gameObject; EnsureMeshColliderExists(gameObject); EnsureScriptsAttached(gameObject); } protected void EnsureScriptsAttached(GameObject meshObject) { if (meshObject.GetComponent() == null) { meshObject.AddComponent(); } } protected void EnsureMeshFilterExists(GameObject meshObject) { if (meshObject.GetComponent() == null) { Mesh mesh = new Mesh(); mesh.name = meshObject.name; meshObject.AddComponent().mesh = mesh; } else if (meshObject.GetComponent().sharedMesh == null) { Mesh mesh2 = new Mesh(); mesh2.name = meshObject.name; meshObject.GetComponent().mesh = mesh2; } } protected void EnsureMeshRendererExists(GameObject meshObject) { if (meshObject.GetComponent() == null) { meshObject.AddComponent(); } } protected void EnsureMeshColliderExists(GameObject meshObject) { if (meshObject.GetComponent() == null) { Mesh mesh = new Mesh(); mesh.name = meshObject.name; meshObject.AddComponent().sharedMesh = mesh; } else if (meshObject.GetComponent().sharedMesh == null) { Mesh mesh2 = new Mesh(); mesh2.name = meshObject.name; meshObject.GetComponent().sharedMesh = mesh2; } } public void DeleteAllSubobjects() { EnsureMeshObjectsExist(); Object.DestroyImmediate(transform.FindChild(e2dConstants.FILL_MESH_NAME).gameObject); Object.DestroyImmediate(transform.FindChild(e2dConstants.CURVE_MESH_NAME).gameObject); Object.DestroyImmediate(transform.FindChild(e2dConstants.COLLIDER_MESH_NAME).gameObject); } }