浏览代码

cleaned up and removed hard-coded label

/4.1
Shan Jiang 4 年前
当前提交
5b6a124f
共有 6 个文件被更改,包括 39 次插入70 次删除
  1. 6
      Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/DynamicPrefab.cs
  2. 77
      Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/MultiTrackedImageInfoManager.cs
  3. 7
      Assets/Scripts/UX/CheckAvailableFeatures.cs
  4. 4
      ProjectSettings/ProjectSettings.asset
  5. 7
      Assets/Scenes/ImageTracking/Prefabs/FlowerAl.unitypackage.meta
  6. 8
      Assets/StreamingAssets.meta

6
Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/DynamicPrefab.cs


namespace UnityEngine.XR.ARFoundation.Samples
{
/// <summary>
/// Change the prefab for Rafflesia at runtime.
/// Change the prefab for the first image in library at runtime.
/// </summary>
[RequireComponent(typeof(ARTrackedImageManager))]
public class DynamicPrefab : MonoBehaviour

{
case State.OriginalPrefab:
{
if (GUILayout.Button("Alternative Prefab for Rafflesia"))
if (GUILayout.Button($"Alternative Prefab for {GetComponent<MultiTrackedImageInfoManager>().imageLibrary[0].name}"))
{
m_State = State.ChangeToAlternativePrefab;
}

{
if (GUILayout.Button("Original Prefab for Rafflesia"))
if (GUILayout.Button($"Original Prefab for {GetComponent<MultiTrackedImageInfoManager>().imageLibrary[0].name}"))
{
m_State = State.ChangeToOriginalPrefab;
}

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


}
[SerializeField]
[Tooltip("Each prefab corresponds to each image in the Image Library.")]
[HideInInspector]
List<NamedPrefab> m_PrefabsList = new List<NamedPrefab>();
Dictionary<Guid, GameObject> m_PrefabsDictionary = new Dictionary<Guid, GameObject>();

m_TrackedImageManager.trackedImagesChanged -= OnTrackedImagesChanged;
}
void OnLibraryChanged(XRReferenceImageLibrary library)
{
if (library)
{
var tempDictionary = new Dictionary<Guid, GameObject>();
foreach (var referenceImage in library)
{
tempDictionary.Add(referenceImage.guid, (m_PrefabsDictionary.TryGetValue(referenceImage.guid, out GameObject prefab)) ? prefab : null);
}
m_PrefabsDictionary = tempDictionary;
}
}
trackedImage.transform.localScale = new Vector3(trackedImage.size.x / 2, trackedImage.size.x / 2, trackedImage.size.x / 2);
AssignPrefab(trackedImage);
var minLocalScalar = Mathf.Min(trackedImage.size.x, trackedImage.size.y);
trackedImage.transform.localScale = new Vector3(minLocalScalar / 2, minLocalScalar / 2, minLocalScalar / 2);
AssignOrShowPrefab(trackedImage);
RemoveInstantiatedPrefab(trackedImage);
else if (trackedImage.trackingState == TrackingState.Tracking)
AssignPrefab(trackedImage);
{
if (m_InstantiatedPrefabsDictionary.TryGetValue(trackedImage.referenceImage.guid, out GameObject instantiatedPrefab))
instantiatedPrefab.SetActive(false);
}
else
AssignOrShowPrefab(trackedImage);
void AssignPrefab(ARTrackedImage trackedImage)
void AssignOrShowPrefab(ARTrackedImage trackedImage)
{
if (m_PrefabsDictionary.TryGetValue(trackedImage.referenceImage.guid, out GameObject prefab))
{

m_InstantiatedPrefabsDictionary.Add(trackedImage.referenceImage.guid, instantiatedPrefab);
}
}
}
void RemoveInstantiatedPrefab(ARTrackedImage trackedImage)
{
if (m_InstantiatedPrefabsDictionary.TryGetValue(trackedImage.referenceImage.guid, out GameObject instantiatedPrefab))
{
Destroy(instantiatedPrefab);
m_InstantiatedPrefabsDictionary.Remove(trackedImage.referenceImage.guid);
}
}
void RemoveInstantiatedPrefab(XRReferenceImage referenceImage)
{
if (m_InstantiatedPrefabsDictionary.TryGetValue(referenceImage.guid, out GameObject instantiatedPrefab))
{
Destroy(instantiatedPrefab);
m_InstantiatedPrefabsDictionary.Remove(referenceImage.guid);
else
{
var instantiatedPrefab = m_InstantiatedPrefabsDictionary[trackedImage.referenceImage.guid];
instantiatedPrefab.SetActive(true);
}
}
}

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

EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Script"));
}
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_ImageLibrary"));
var library = serializedObject.FindProperty("m_ImageLibrary").objectReferenceValue as XRReferenceImageLibrary;
var libraryProperty = serializedObject.FindProperty(nameof(m_ImageLibrary));
EditorGUILayout.PropertyField(libraryProperty);
var library = libraryProperty.objectReferenceValue as XRReferenceImageLibrary;
behaviour.OnLibraryChanged(library);
{
if (library)
{
var tempDictionary = new Dictionary<Guid, GameObject>();
foreach (var referenceImage in library)
{
tempDictionary.Add(referenceImage.guid, behaviour.GetPrefabForReferenceImage(referenceImage));
}
behaviour.m_PrefabsDictionary = tempDictionary;
}
}
// update current
m_ReferenceImages.Clear();

7
Assets/Scripts/UX/CheckAvailableFeatures.cs


cameraDescriptor.supportsAverageColorTemperature && cameraDescriptor.supportsCameraConfigurations &&
cameraDescriptor.supportsCameraImage)
{
Debug.Log("###Unity");
Debug.Log(cameraDescriptor.supportsAverageBrightness);
Debug.Log(cameraDescriptor.supportsAverageIntensityInLumens);
Debug.Log(cameraDescriptor.supportsAverageColorTemperature);
Debug.Log(cameraDescriptor.supportsCameraConfigurations);
Debug.Log(cameraDescriptor.supportsCameraImage);
Debug.Log("~~~~~~~~");
m_LightEstimation.interactable = true;
}

4
ProjectSettings/ProjectSettings.asset


16:9: 1
Others: 1
bundleVersion: 0.1
preloadedAssets:
- {fileID: -6122771651556369562, guid: e2f869774b12e400996eb546603602e3, type: 2}
- {fileID: 4800000, guid: c9f956787b1d945e7b36e0516201fc76, type: 3}
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1

7
Assets/Scenes/ImageTracking/Prefabs/FlowerAl.unitypackage.meta


fileFormatVersion: 2
guid: f07e4540bbdcb43f1a518b4c22cfbb1a
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
Assets/StreamingAssets.meta


fileFormatVersion: 2
guid: deab931f1d58b4e8c8d0fe61e6c5ff42
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存