浏览代码

simplified logic

/4.1
Shan Jiang 4 年前
当前提交
1b269f86
共有 2 个文件被更改,包括 10 次插入35 次删除
  1. 41
      Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/MultiTrackedImageInfoManager.cs
  2. 4
      ProjectSettings/ProjectSettings.asset

41
Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/MultiTrackedImageInfoManager.cs


List<NamedPrefab> m_PrefabsList = new List<NamedPrefab>();
Dictionary<Guid, GameObject> m_PrefabsDictionary = new Dictionary<Guid, GameObject>();
Dictionary<Guid, GameObject> m_InstantiatedPrefabsDictionary = new Dictionary<Guid, GameObject>();
Dictionary<Guid, GameObject> m_Instantiated = new Dictionary<Guid, GameObject>();
ARTrackedImageManager m_TrackedImageManager;
[SerializeField]

// Give the initial image a reasonable default scale
var minLocalScalar = Mathf.Min(trackedImage.size.x, trackedImage.size.y) / 2;
trackedImage.transform.localScale = new Vector3(minLocalScalar, minLocalScalar, minLocalScalar);
AssignOrShowPrefab(trackedImage);
}
foreach (var trackedImage in eventArgs.updated)
{
if (trackedImage.trackingState != TrackingState.Tracking)
{
if (m_InstantiatedPrefabsDictionary.TryGetValue(trackedImage.referenceImage.guid, out GameObject instantiatedPrefab))
instantiatedPrefab.SetActive(false);
}
else
AssignOrShowPrefab(trackedImage);
AssignPrefab(trackedImage);
void AssignOrShowPrefab(ARTrackedImage trackedImage)
void AssignPrefab(ARTrackedImage trackedImage)
{
if (!m_InstantiatedPrefabsDictionary.ContainsKey(trackedImage.referenceImage.guid))
{
var instantiatedPrefab = Instantiate(prefab, trackedImage.transform);
m_InstantiatedPrefabsDictionary.Add(trackedImage.referenceImage.guid, instantiatedPrefab);
}
else
{
var instantiatedPrefab = m_InstantiatedPrefabsDictionary[trackedImage.referenceImage.guid];
instantiatedPrefab.SetActive(true);
}
}
m_Instantiated.Add(trackedImage.referenceImage.guid, Instantiate(prefab, trackedImage.transform));
}
public GameObject GetPrefabForReferenceImage(XRReferenceImage referenceImage)

{
if (m_PrefabsDictionary.TryGetValue(referenceImage.guid, out GameObject targetPrefabInDictionary))
m_PrefabsDictionary[referenceImage.guid] = alternativePrefab;
if (m_Instantiated.TryGetValue(referenceImage.guid, out GameObject instantiatedPrefab))
m_PrefabsDictionary[referenceImage.guid] = alternativePrefab;
if (m_InstantiatedPrefabsDictionary.TryGetValue(referenceImage.guid, out GameObject instantiatedPrefab))
{
Destroy(instantiatedPrefab);
m_InstantiatedPrefabsDictionary.Remove(referenceImage.guid);
}
m_Instantiated[referenceImage.guid] = Instantiate(alternativePrefab, instantiatedPrefab.transform.parent);
Destroy(instantiatedPrefab);
}
}

4
ProjectSettings/ProjectSettings.asset


Others: 1
bundleVersion: 0.1
preloadedAssets:
- {fileID: 4800000, guid: e7c77f6eaab324a819efdc13b8125a39, type: 3}
- {fileID: -7479341934665344595, guid: e2f869774b12e400996eb546603602e3, type: 2}
- {fileID: -6122771651556369562, guid: e2f869774b12e400996eb546603602e3, type: 2}
- {fileID: 4800000, guid: c9f956787b1d945e7b36e0516201fc76, type: 3}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1

正在加载...
取消
保存