Esempio n. 1
0
		private int ResolveMappingConflict(Resource input, ExportInputAssignment[] conflictingAssignments)
		{
			// Ask the input Resource which importer it would prefer
			if (input != null && input.AssetInfo != null && input.AssetInfo.ImporterId != null)
			{
				for (int i = 0; i < conflictingAssignments.Length; i++)
				{
					// If we have a match with the preferred importer, this is definitely the correct assignment to handle this.
					if (conflictingAssignments[i].Importer.Id == input.AssetInfo.ImporterId)
						return i;
				}
			}

			// By default, fall back on simply prefering the highest-priority importer
			int keepIndex = -1;
			int highestPrio = int.MinValue;
			for (int i = 0; i < conflictingAssignments.Length; i++)
			{
				if (conflictingAssignments[i].Importer.Priority > highestPrio)
				{
					highestPrio = conflictingAssignments[i].Importer.Priority;
					keepIndex = i;
				}
			}

			// If there is a conflict handler (such as "spawn a user dialog"), see if that can deal with it.
			if (this.conflictHandler != null)
			{
				ConflictData data = new ConflictData(input, conflictingAssignments, keepIndex);
				IAssetImporter selectedImporter = this.conflictHandler(data);
				int selectedIndex = conflictingAssignments.IndexOfFirst(item => item.Importer == selectedImporter);
				return selectedIndex;
			}

			return keepIndex;
		}