浏览代码

serialization works

/4.1
Shan Jiang 4 年前
当前提交
d10a48d3
共有 3 个文件被更改,包括 77 次插入84 次删除
  1. 124
      Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/DynamicPrefab.cs
  2. 9
      Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/Multi-Image Tracking.unity
  3. 28
      Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/MultiTrackedImageInfoManager.cs

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


[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;
}
}
}
}

9
Assets/Scenes/ImageTracking/Multi Prefab - Image Tracking/Multi-Image Tracking.unity


--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
serializedVersion: 12
m_GIWorkflowMode: 1
m_GISettings:
serializedVersion: 2

m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
m_LightingSettings: {fileID: 0}
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2

manualTileSize: 0
tileSize: 256
accuratePlacement: 0
maxJobWorkers: 0
preserveTilesOutsideBounds: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}

m_Script: {fileID: 11500000, guid: a6d5323815f004189af1fb658b6c9369, type: 3}
m_Name:
m_EditorClassIdentifier:
m_OrigianlPrefab: {fileID: 0}
m_AlternativePrefab: {fileID: 4354704932497689857, guid: 3760319adcbe74905bf3e2a7dced4830,
type: 3}
--- !u!114 &264295716

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 264295714}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4dea56a9eaadd1c439095de4f9a371cb, type: 3}
m_Name:

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


{
// System.Guid isn't serializable, so we store the Guid as a string. At runtime, this is converted back to a System.Guid
[SerializeField]
public readonly string m_ImageGuid;
string m_ImageGuid;
public string imageGuid => m_ImageGuid;
[SerializeField]
public GameObject m_Prefab;

/// <summary>
/// Get the <c>XRReferenceImageLibrary</c>
/// </summary>
public XRReferenceImageLibrary ImageLibrary
public XRReferenceImageLibrary imageLibrary
{
get => m_ImageLibrary;
set => m_ImageLibrary = value;

{
Debug.Log("serialize");
m_PrefabsList.Clear();
foreach (var kvp in m_PrefabsDictionary)
{

public void OnAfterDeserialize()
{
if (ImageLibrary.count != 0)
if (imageLibrary.count != 0)
m_PrefabsDictionary.Add(ImageLibrary[i].guid, m_PrefabsList[i].m_Prefab);
m_PrefabsDictionary.Add(Guid.Parse(m_PrefabsList[i].imageGuid), m_PrefabsList[i].m_Prefab);
}
}
}

class MultiTrackedImageInfoManagerInspector : Editor
{
List<XRReferenceImage> m_ReferenceImages = new List<XRReferenceImage>();
bool isExpanded = true;
bool m_IsExpanded = true;
bool HasLibraryChanged(XRReferenceImageLibrary library)
{

}
//show prefab list
isExpanded = EditorGUILayout.Foldout(isExpanded, "Prefab List");
if (isExpanded)
m_IsExpanded = EditorGUILayout.Foldout(m_IsExpanded, "Prefab List");
if (m_IsExpanded)
if (behaviour.m_PrefabsDictionary.TryGetValue(image.guid, out GameObject prefab))
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField(image.name, GUILayout.Width(200f));
EditorGUILayout.ObjectField(prefab, typeof(GameObject), false);
EditorGUILayout.EndHorizontal();
}
var prefab = (GameObject)EditorGUILayout.ObjectField(image.name, behaviour.m_PrefabsDictionary[image.guid], typeof(GameObject), false);
behaviour.m_PrefabsDictionary[image.guid] = prefab;
Undo.RecordObject(target, "Update Prefab");
EditorUtility.SetDirty(target);
}
}
#endif
正在加载...
取消
保存