/// <summary> /// /// Mesh Instances /// /// Parse mesh instance data /// Function decides if we are updating an already existing mesh instance ( GameObject ) or creating a new one. /// </summary> public static void ParseMeshInstanceData(System.IntPtr meshInstanceDataPtr) { try { var meshInstanceData = (MeshInstanceData)System.Runtime.InteropServices.Marshal.PtrToStructure(meshInstanceDataPtr, typeof(MeshInstanceData)); // If all dependants are here, create or update the mesh instance if (MeshInstanceHandler.DependencyCheck(meshInstanceData)) { bool newItemCreated; ParseMeshInstanceData(meshInstanceData, out newItemCreated); // Delete the data ImportMenu.stpUnityDeleteMeshInstanceData(meshInstanceDataPtr); // This loop starts over if we created a parent and a child is waiting in the store while (newItemCreated) { // Iterate through mesh instance store and try to create or update // mesh instances that this mesh instance is a dependent of IterateMeshInstanceStore(out newItemCreated); } } else { // If we are not able to create or update store the mesh data and try later meshInstanceDataStore.Add(meshInstanceDataPtr); } } catch (System.Exception e) { Debug.LogException(e); // Delete the data ImportMenu.stpUnityDeleteMeshInstanceData(meshInstanceDataPtr); } }
// Iterate through mesh instance store that were missing dependants // and check if we can create new mesh instance objects or update existing mesh objects public static void IterateMeshInstanceStore(out bool newItemCreated) { newItemCreated = false; for (int i = meshInstanceDataStore.Count - 1; i >= 0; i--) { MeshInstanceData meshInstanceData = (MeshInstanceData)System.Runtime.InteropServices.Marshal.PtrToStructure(meshInstanceDataStore[i], typeof(MeshInstanceData)); // If all dependants are here, create or update the mesh bool currentItemCreated = false; bool dependencySuccess = MeshInstanceHandler.DependencyCheck(meshInstanceData); if (dependencySuccess) { ParseMeshInstanceData(meshInstanceData, out currentItemCreated); // Delete the data ImportMenu.stpUnityDeleteMeshInstanceData(meshInstanceDataStore[i]); // Remove from the store meshInstanceDataStore.RemoveAt(i); } // True if at least one item was created newItemCreated = newItemCreated || currentItemCreated; } }