This repository has been archived by the owner on Jun 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
/
ClassificationPlacementManager.cs
168 lines (138 loc) · 4.9 KB
/
ClassificationPlacementManager.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.EventSystems;
#if UNITY_IOS
using UnityEngine.XR.ARKit;
#endif // UNITY_IOS
using UnityEngine.XR.ARSubsystems;
public class ClassificationPlacementManager : MonoBehaviour
{
[SerializeField]
List<GameObject> m_FloorPrefabs;
public List<GameObject> floorPrefabs
{
get => m_FloorPrefabs;
set => m_FloorPrefabs = value;
}
[SerializeField]
List<GameObject> m_TablePrefabs;
public List<GameObject> tablePrefabs
{
get => m_TablePrefabs;
set => m_TablePrefabs = value;
}
[SerializeField]
List<GameObject> m_WallPrefabs;
public List<GameObject> wallPrefabs
{
get => m_WallPrefabs;
set => m_WallPrefabs = value;
}
[SerializeField]
MeshClassificationManager m_ClassificationManager;
public MeshClassificationManager classificationManager
{
get => m_ClassificationManager;
set => m_ClassificationManager = value;
}
[SerializeField]
PlacementReticle m_Reticle;
public PlacementReticle reticle
{
get => m_Reticle;
set => m_Reticle = value;
}
[SerializeField]
GameObject m_FloorUI;
public GameObject floorUI
{
get => m_FloorUI;
set => m_FloorUI = value;
}
[SerializeField]
GameObject m_WallUI;
public GameObject wallUI
{
get => m_WallUI;
set => m_WallUI = value;
}
[SerializeField]
GameObject m_TableUI;
public GameObject tableUI
{
get => m_TableUI;
set => m_TableUI = value;
}
[SerializeField]
Transform m_ARCameraTransform;
public Transform arCameraTransform
{
get => m_ARCameraTransform;
set => m_ARCameraTransform = value;
}
bool m_ShowingSelectionUI;
GameObject m_SpawnedObject;
Ease m_TweenEase = Ease.OutQuart;
const float k_TweenTime = 0.4f;
void Update()
{
#if UNITY_IOS
if (m_ClassificationManager.currentClassification == ARMeshClassification.Table ||
m_ClassificationManager.currentClassification == ARMeshClassification.Floor ||
m_ClassificationManager.currentClassification == ARMeshClassification.Wall)
{
switch (m_ClassificationManager.currentClassification)
{
case ARMeshClassification.Floor:
m_FloorUI.SetActive(true);
m_WallUI.SetActive(false);
m_TableUI.SetActive(false);
break;
case ARMeshClassification.Wall:
m_WallUI.SetActive(true);
m_FloorUI.SetActive(false);
m_TableUI.SetActive(false);
break;
case ARMeshClassification.Table:
m_TableUI.SetActive(true);
m_FloorUI.SetActive(false);
m_WallUI.SetActive(false);
break;
}
}
else
{
m_FloorUI.SetActive(false);
m_WallUI.SetActive(false);
m_TableUI.SetActive(false);
}
#endif
}
public void PlaceFloorObject(int indexToPlace)
{
m_SpawnedObject = Instantiate(m_FloorPrefabs[indexToPlace], m_Reticle.GetReticlePosition().position, m_Reticle.GetReticlePosition().rotation);
m_SpawnedObject.transform.localScale = Vector3.zero;
// look at device but stay 'flat'
m_SpawnedObject.transform.LookAt(m_ARCameraTransform, Vector3.up);
m_SpawnedObject.transform.rotation = Quaternion.Euler(0, m_SpawnedObject.transform.eulerAngles.y, 0);
m_SpawnedObject.transform.DOScale(Vector3.one, k_TweenTime).SetEase(m_TweenEase);
}
public void PlaceWallObject(int indexToPlace)
{
m_SpawnedObject = Instantiate(m_WallPrefabs[indexToPlace], m_Reticle.GetReticlePosition().position, m_Reticle.GetReticlePosition().rotation);
m_SpawnedObject.transform.localScale = Vector3.zero;
m_SpawnedObject.transform.DOScale(Vector3.one, k_TweenTime).SetEase(m_TweenEase);
}
public void PlaceTableObject(int indexToPlace)
{
m_SpawnedObject = Instantiate(m_TablePrefabs[indexToPlace], m_Reticle.GetReticlePosition().position, m_Reticle.GetReticlePosition().rotation);
m_SpawnedObject.transform.localScale = Vector3.zero;
// look at device but stay 'flat'
m_SpawnedObject.transform.LookAt(m_ARCameraTransform, Vector3.up);
m_SpawnedObject.transform.rotation = Quaternion.Euler(0, m_SpawnedObject.transform.eulerAngles.y, 0);
m_SpawnedObject.transform.DOScale(Vector3.one, k_TweenTime).SetEase(m_TweenEase);
}
}