/// <summary> /// Evaluates saved Adapter IDs to real adapters /// Note: DO NOT use useEditorUtility=true because it will grab the old adapter!!! /// </summary> /// <returns></returns> public static ChildGroupPack Apply(SaveablePack saveablePack) { #if DEBUG if (DebugMode) { Debug.Log(@"*** WRITING PACK *** " + saveablePack); } #endif // Note: we have to call the override having the second argument, supplying "true" // This is because if this is the adapter existing prior to play mode start, the dictionary points to the "old" adapter (a stale one) // this way we are making sure that the system looks for the specified adapter in the scene first, and then uses the dictionary (for the "new" adapters) GroupAdapter parentAdapter = ComponentRegistry.Instance.Get(saveablePack.ParentInstanceId, true) as GroupAdapter; ChildGroupPack childGroupPack = Read(parentAdapter); int index = 0; foreach (List <int> childGroupIds in saveablePack.InstanceIds) { List <ComponentAdapter> adapters = new List <ComponentAdapter>(); foreach (int adapterId in childGroupIds) { ComponentAdapter childAdapter = (ComponentAdapter)ComponentRegistry.Instance.Get(adapterId, true); // FALSE!!! /*if (null == childAdapter) * throw new Exception("Cannot find child adapter in dictionary: " + adapterId);*/ adapters.Add(childAdapter); } var actualGroup = childGroupPack.Groups[index]; actualGroup.Clear(); actualGroup.AddRange(adapters); index++; } #if DEBUG if (DebugMode) { Debug.Log("Apply. childGroupPack: " + childGroupPack); } #endif return(childGroupPack); }
public SaveablePack ToSaveablePack() { SaveablePack saveablePack = new SaveablePack(_parentAdapter.GetInstanceID()); foreach (ChildGroup childGroup in _groups) { List <int> ids = new List <int>(); foreach (ComponentAdapter adapter in childGroup.Adapters) { if (null == adapter) { Debug.LogWarning("No adapter found"); continue; } ids.Add(adapter.GetInstanceID()); } saveablePack.Add(ids); } return(saveablePack); }
/// <summary> /// Evaluates saved Adapter IDs to real adapters /// Note: DO NOT use useEditorUtility=true because it will grab the old adapter!!! /// </summary> /// <returns></returns> public static ChildGroupPack Apply(SaveablePack saveablePack) { #if DEBUG if (DebugMode) { Debug.Log(@"*** WRITING PACK *** " + saveablePack); } #endif // Note: we have to call the override having the second argument, supplying "true" // This is because if this is the adapter existing prior to play mode start, the dictionary points to the "old" adapter (a stale one) // this way we are making sure that the system looks for the specified adapter in the scene first, and then uses the dictionary (for the "new" adapters) GroupAdapter parentAdapter = ComponentRegistry.Instance.Get(saveablePack.ParentInstanceId, true) as GroupAdapter; ChildGroupPack childGroupPack = Read(parentAdapter); int index = 0; foreach (List<int> childGroupIds in saveablePack.InstanceIds) { List<ComponentAdapter> adapters = new List<ComponentAdapter>(); foreach (int adapterId in childGroupIds) { ComponentAdapter childAdapter = (ComponentAdapter) ComponentRegistry.Instance.Get(adapterId, true); // FALSE!!! /*if (null == childAdapter) throw new Exception("Cannot find child adapter in dictionary: " + adapterId);*/ adapters.Add(childAdapter); } var actualGroup = childGroupPack.Groups[index]; actualGroup.Clear(); actualGroup.AddRange(adapters); index++; } #if DEBUG if (DebugMode) { Debug.Log("Apply. childGroupPack: " + childGroupPack); } #endif return childGroupPack; }
public SaveablePack ToSaveablePack() { SaveablePack saveablePack = new SaveablePack(_parentAdapter.GetInstanceID()); foreach (ChildGroup childGroup in _groups) { List<int> ids = new List<int>(); foreach (ComponentAdapter adapter in childGroup.Adapters) { if (null == adapter) { Debug.LogWarning("No adapter found"); continue; } ids.Add(adapter.GetInstanceID()); } saveablePack.Add(ids); } return saveablePack; }