forked from IndieVisualLab/UnityGraphicsProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoom.cs
More file actions
83 lines (71 loc) · 2.63 KB
/
Room.cs
File metadata and controls
83 lines (71 loc) · 2.63 KB
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
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
namespace RoomProjection
{
public class Room : MonoBehaviour
{
public enum Face
{
Front,
Right,
Back,
Left,
Bottom
}
static Dictionary<Face, Quaternion> _faceToRot = new Dictionary<Face, Quaternion>()
{
{Face.Front, Quaternion.Euler(0f, 0f, 0f)},
{Face.Right, Quaternion.Euler(0f, 90f, 0f)},
{Face.Back, Quaternion.Euler(0f, 180f, 0f)},
{Face.Left, Quaternion.Euler(0f, 270f, 0f)},
{Face.Bottom, Quaternion.Euler(90f, 0f, 0f)},
};
public static Quaternion FaceToRot(Face face)
{
return _faceToRot[face];
}
public Vector3 _size = new Vector3(20f, 5f, 10f);
public class FaceData
{
public Face face;
public Vector2 size;
public float distance;
}
List<FaceData> _faceDatas;
public List<FaceData> GetFaceDatas()
{
if (_faceDatas == null)
{
_faceDatas = new FaceData[]{
new FaceData(){face = Face.Front, size = new Vector2(_size.x, _size.y), distance=_size.z * 0.5f},
new FaceData(){face = Face.Right, size = new Vector2(_size.z, _size.y), distance=_size.x * 0.5f},
new FaceData(){face = Face.Back, size = new Vector2(_size.x, _size.y), distance=_size.z * 0.5f},
new FaceData(){face = Face.Left, size = new Vector2(_size.z, _size.y), distance=_size.x * 0.5f},
new FaceData(){face = Face.Bottom, size = new Vector2(_size.x, _size.z), distance=_size.y * 0.5f},
}
.ToList();
}
return _faceDatas;
}
public Dictionary<Face, GameObject> faces { get; protected set; } = new Dictionary<Face, GameObject>();
void Awake()
{
var center = Vector3.up * _size.y * 0.5f + transform.position;
GetFaceDatas().ForEach(data =>
{
var go = GameObject.CreatePrimitive(PrimitiveType.Quad);
go.name = data.face.ToString();
go.layer = gameObject.layer;
faces[data.face] = go;
var trans = go.transform;
trans.SetParent(transform);
var rot = FaceToRot(data.face);
trans.localScale = new Vector3(data.size.x, data.size.y, 1);
trans.SetPositionAndRotation(
rot * Vector3.forward * data.distance + center,
rot);
});
}
}
}