/
BuildCeiling.cs
68 lines (44 loc) · 2.05 KB
/
BuildCeiling.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
#if UNITY_EDITOR
using UnityEngine;
using System.Collections;
public class BuildCeiling : Create2DPanel {
private int mPlaceableLayerCheckLayer = 11;
private float mLengthOfMeshEnd = 0.1f;
private float mOffsetOfMeshInYDirection = -0.03f;
public void Build(Vector3 start, Vector3 end){
GameObject tempObject = CreatePlaneObject();
tempObject.transform.Rotate(0,0,90);
tempObject.transform.position = SetTilePosition(start, end);
tempObject.transform.localScale = SetTileScale(start, end);
Shader tileShader = Shader.Find("Mobile/Diffuse");
Material tempMaterial = new Material(tileShader);
Texture wallTexture = Resources.Load ("Prefabs/Background/SideWallTexture") as Texture;
tempMaterial.mainTexture = wallTexture;
tempMaterial.mainTextureScale = new Vector2( 1, tempObject.transform.localScale.y);
tempObject.renderer.material = tempMaterial;
tempObject.tag = "Wall";
}
public override GameObject CreatePlaneObject(){
GameObject tempObject = Instantiate(Resources.Load ("Prefabs/Background/SideWall"), Vector3.one, Quaternion.identity) as GameObject;
tempObject.transform.localRotation = Quaternion.identity;
tempObject.transform.forward = Vector3.back;
tempObject.AddComponent("MeshCollider");
tempObject.AddComponent("BoxCollider");
tempObject.layer = mPlaceableLayerCheckLayer;
return tempObject;
}
Vector3 SetTilePosition(Vector3 startPosition, Vector3 endPosition){
Vector3 tempPosition = startPosition;
tempPosition.x = (endPosition.x - mLevelScaling/2)/2;
tempPosition.y = CameraMovement.mLevelSize.y + mAdditionalQuadHeight + mOffsetOfMeshInYDirection;
tempPosition.z = mZDistance;
return tempPosition;
}
Vector3 SetTileScale(Vector3 startPosition, Vector3 endPosition){
Vector3 tempScale = new Vector3(1,1,1);
tempScale.x = mZScale * mMeshScale;
tempScale.y = Mathf.Abs(startPosition.x - endPosition.x)/(mStandardTileSideLength * mLevelScaling) * mMeshScale + 2 * mLengthOfMeshEnd;
return tempScale;
}
}
#endif