|
|
|
|
|
|
[RequireComponent(typeof(ARTrackedImageManager))] |
|
|
|
public class DynamicPrefab : MonoBehaviour |
|
|
|
{ |
|
|
|
[SerializeField] |
|
|
|
[HideInInspector] |
|
|
|
GameObject m_OrigianlPrefab; |
|
|
|
|
|
|
|
GameObject originalPrefab |
|
|
|
{ |
|
|
|
get => m_OrigianlPrefab; |
|
|
|
set => m_OrigianlPrefab = value; |
|
|
|
} |
|
|
|
GameObject m_OriginalPrefab; |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
GameObject m_AlternativePrefab; |
|
|
|
|
|
|
switch (m_State) |
|
|
|
{ |
|
|
|
case State.OriginalPrefab: |
|
|
|
{ |
|
|
|
if (GUILayout.Button("Alternative Prefab for Rafflesia")) |
|
|
|
m_State = State.ChangeToAlternativePrefab; |
|
|
|
if (GUILayout.Button("Alternative Prefab for Rafflesia")) |
|
|
|
{ |
|
|
|
m_State = State.ChangeToAlternativePrefab; |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
{ |
|
|
|
if (GUILayout.Button("Original Prefab for Rafflesia")) |
|
|
|
m_State = State.ChangeToOriginalPrefab; |
|
|
|
if (GUILayout.Button("Original Prefab for Rafflesia")) |
|
|
|
{ |
|
|
|
m_State = State.ChangeToOriginalPrefab; |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
{ |
|
|
|
GUILayout.Label(m_ErrorMessage); |
|
|
|
break; |
|
|
|
} |
|
|
|
{ |
|
|
|
GUILayout.Label(m_ErrorMessage); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
GUILayout.EndArea(); |
|
|
|
|
|
|
switch (m_State) |
|
|
|
{ |
|
|
|
case State.ChangeToAlternativePrefab: |
|
|
|
{ |
|
|
|
if (alternativePrefab == null) |
|
|
|
SetError("No alternative prefab is given."); |
|
|
|
break; |
|
|
|
} |
|
|
|
if (alternativePrefab == null) |
|
|
|
{ |
|
|
|
SetError("No alternative prefab is given."); |
|
|
|
break; |
|
|
|
} |
|
|
|
var manager = GetComponent<MultiTrackedImageInfoManager>(); |
|
|
|
if (manager == null) |
|
|
|
{ |
|
|
|
SetError($"No {nameof(MultiTrackedImageInfoManager)} available."); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
var library = manager.ImageLibrary; |
|
|
|
if (library == null) |
|
|
|
{ |
|
|
|
SetError($"No image library available."); |
|
|
|
break; |
|
|
|
} |
|
|
|
var manager = GetComponent<MultiTrackedImageInfoManager>(); |
|
|
|
if (manager == null) |
|
|
|
{ |
|
|
|
SetError($"No {nameof(MultiTrackedImageInfoManager)} available."); |
|
|
|
break; |
|
|
|
} |
|
|
|
if (originalPrefab == null) |
|
|
|
originalPrefab = manager.GetPrefabForReferenceImage(library[0]); |
|
|
|
var library = manager.imageLibrary; |
|
|
|
if (library == null) |
|
|
|
{ |
|
|
|
SetError($"No image library available."); |
|
|
|
break; |
|
|
|
} |
|
|
|
manager.SetPrefabForReferenceImage(library[0], alternativePrefab); |
|
|
|
m_State = State.AlternativePrefab; |
|
|
|
break; |
|
|
|
} |
|
|
|
if (m_OriginalPrefab == null) |
|
|
|
m_OriginalPrefab = manager.GetPrefabForReferenceImage(library[0]); |
|
|
|
case State.ChangeToOriginalPrefab: |
|
|
|
{ |
|
|
|
if (originalPrefab == null) |
|
|
|
{ |
|
|
|
SetError("No original prefab is given."); |
|
|
|
manager.SetPrefabForReferenceImage(library[0], alternativePrefab); |
|
|
|
m_State = State.AlternativePrefab; |
|
|
|
var manager = GetComponent<MultiTrackedImageInfoManager>(); |
|
|
|
if (manager == null) |
|
|
|
case State.ChangeToOriginalPrefab: |
|
|
|
SetError($"No {nameof(MultiTrackedImageInfoManager)} available."); |
|
|
|
break; |
|
|
|
} |
|
|
|
if (m_OriginalPrefab == null) |
|
|
|
{ |
|
|
|
SetError("No original prefab is given."); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
var manager = GetComponent<MultiTrackedImageInfoManager>(); |
|
|
|
if (manager == null) |
|
|
|
{ |
|
|
|
SetError($"No {nameof(MultiTrackedImageInfoManager)} available."); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
var library = manager.imageLibrary; |
|
|
|
if (library == null) |
|
|
|
{ |
|
|
|
SetError($"No image library available."); |
|
|
|
break; |
|
|
|
} |
|
|
|
var library = manager.ImageLibrary; |
|
|
|
if (library == null) |
|
|
|
{ |
|
|
|
SetError($"No image library available."); |
|
|
|
manager.SetPrefabForReferenceImage(library[0], m_OriginalPrefab); |
|
|
|
m_State = State.OriginalPrefab; |
|
|
|
manager.SetPrefabForReferenceImage(library[0], originalPrefab); |
|
|
|
m_State = State.OriginalPrefab; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |