first commit

This commit is contained in:
lethanhsonvsp
2025-11-17 15:36:52 +07:00
commit 6f2eafa33c
14093 changed files with 1253472 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Unity.AI.Navigation.Updater")]

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a86108f91b07e4fe3b5cd8fedc9f1797
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
using System;
namespace Unity.AI.Navigation.Editor.Converter
{
/// <summary>
/// A structure holding the information for each Item that needs to be Converted.
/// Name = The Name of the asset that is being converted.
/// Info = Information that can be used to store some data. This will also be shown in the UI.
/// WarningMessage = If there are some issues with the converter that we already know about.
/// Example: If we know it is a custom shader, we can not convert it so we add the information here.
/// AdditionalData = Additional data that can be used to store some data. This will not be shown in the UI.
/// </summary>
[Serializable]
internal struct ConverterItemDescriptor
{
/// <summary> Name of the asset being converted. This will be shown in the UI. </summary>
public string name;
/// <summary> Information that can be used to store some data. This will also be shown in the UI. </summary>
public string info;
/// <summary> If there are some issues with the converter that we already know about during init phase. This will be added as a tooltip on the warning icon. </summary>
public string warningMessage;
/// <summary> Additional data that can be used to store data related to the item to be converted.</summary>
public string additionalData;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3f72db493d3cd4e03ae748a6cd15534d
timeCreated: 1618229698

View File

@@ -0,0 +1,16 @@
namespace Unity.AI.Navigation.Editor.Converter
{
/// <summary>
/// A structure holding the information for each Item that needs to be Converted.
/// Descriptor = The ConverterItemDescriptor this item contain.
/// Index = The index for this item in the list of converter items.
/// </summary>
internal struct ConverterItemInfo
{
/// <summary> The ConverterItemDescriptor this item contain. </summary>
public ConverterItemDescriptor descriptor { get; internal set; }
/// <summary> The index for this item in the list of converter items. </summary>
public int index { get; internal set; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fac6f414adf2e4556865a180b1529cbb
timeCreated: 1618230361

View File

@@ -0,0 +1,23 @@
using UnityEditor;
using UnityEngine;
namespace Unity.AI.Navigation.Editor.Converter
{
internal static class EditorStyles
{
public static Texture iconHelp;
public static Texture2D iconPending;
public static Texture2D iconWarn;
public static Texture2D iconFail;
public static Texture2D iconSuccess;
static EditorStyles()
{
iconFail = EditorGUIUtility.Load("icons/console.erroricon.png") as Texture2D;
iconWarn = EditorGUIUtility.Load("icons/console.warnicon.png") as Texture2D;
iconHelp = EditorGUIUtility.Load("icons/console.infoicon.png") as Texture2D;
iconSuccess = EditorGUIUtility.FindTexture("TestPassed");
iconPending = EditorGUIUtility.FindTexture("Toolbar Minus");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c0c4a4a1781441ff8c5f9585d5a3462
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System.Collections.Generic;
namespace Unity.AI.Navigation.Editor.Converter
{
/// <summary>
/// A structure needed for the initialization step of the converter.
/// Stores data to be visible in the UI.
/// </summary>
internal struct InitializeConverterContext
{
/// <summary>
/// Stores the list of ConverterItemDescriptor that will be filled in during the initialization step.
/// </summary>
internal List<ConverterItemDescriptor> items;
/// <summary>
/// Add to the list of assets to be converted.
/// This will be used to display information to the user in the UI.
/// </summary>
/// <param name="item">The item to add to the list items to convert</param>
internal void AddAssetToConvert(ConverterItemDescriptor item)
{
items.Add(item);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a5cf3eb6bee954ca5953487784e68715
timeCreated: 1618230672

View File

@@ -0,0 +1,27 @@
namespace Unity.AI.Navigation.Editor.Converter
{
/// <summary>
/// A structure needed for the conversion part of the converter. <br />
/// This holds the items that are being converted. <br />
/// All arrays are the same length and the index of each array corresponds to the same item.
/// </summary>
internal struct RunItemContext
{
/// <summary> The items that will go through the conversion code. </summary>
public ConverterItemInfo[] items { get; }
/// <summary> A bool to set if these items failed to convert. </summary>
public bool[] didFail { get; }
/// <summary> Info to store data to be shown in the UI. </summary>
public string[] info { get; }
/// <summary> Constructor for the RunItemContext. </summary>
public RunItemContext(ConverterItemInfo[] items)
{
this.items = items;
didFail = new bool[this.items.Length];
info = new string[this.items.Length];
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a841ce8d078944bb8dc02dc43952c91
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
using System;
namespace Unity.AI.Navigation.Editor.Converter
{
internal abstract class SystemConverter
{
/// <summary>
/// Name of the converter.
/// </summary>
public abstract string name { get; }
/// <summary>
/// The information when hovering over the converter.
/// </summary>
public abstract string info { get; }
/// <summary>
/// A check if the converter is enabled or not. Can be used to do a check if prerequisites are met to have it enabled or disabled.
/// </summary>
public virtual bool isEnabled => true;
/// <summary>
/// A priority of the converter. The lower the number (can be negative), the earlier it will be executed. Can be used to make sure that a converter runs before another converter.
/// </summary>
public virtual int priority => 0;
/// <summary>
/// A check to see if the converter needs to create the index.
/// This will only need to be set to true if the converter is using search api, and search queries.
/// If set to true the converter framework will create the indexer and remove it after all search queries are done.
/// </summary>
public virtual bool needsIndexing => false;
/// <summary>
/// This method getting triggered when clicking the listview item in the UI.
/// </summary>
public virtual void OnClicked(int index)
{
}
// This is so that we can have different segment in our UI, example Unity converters, your custom converters etc..
// This is not implemented yet
public virtual string category { get; }
// This is in which drop down item the converter belongs to.
// Not properly implemented yet
public abstract Type container { get; }
/// <summary>
/// This runs when initializing the converter. To gather data for the UI and also for the converter if needed.
/// </summary>
/// <param name="context">The context that will be used to initialize data for the converter.</param>
public abstract void OnInitialize(InitializeConverterContext context, Action callback);
/// <summary>
/// The method that will be run before Run method if needed.
/// </summary>
public virtual void OnPreRun()
{
}
/// <summary>
/// The method that will be run when converting the assets.
/// </summary>
/// <param name="context">The context that will be used when executing converter.</param>
public abstract void OnRun(ref RunItemContext context);
/// <summary>
/// The method that will be run after the converters are done if needed.
/// </summary>
public virtual void OnPostRun()
{
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0c9fba05c2cea421a8771ca17afce238
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
namespace Unity.AI.Navigation.Editor.Converter
{
/// <summary>
/// A class to contain converters. This is for a common set of converters.
/// For example: Converters that is for Built-in to URP would have it's own container.
/// </summary>
public abstract class SystemConverterContainer
{
/// <summary>
/// The name of the Container. This will show up int the UI.
/// </summary>
public abstract string name { get; }
/// <summary>
/// The information for this container.
/// This will be shown in the UI to tell the user some information about the converters that this container are targeting.
/// </summary>
public abstract string info { get; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6c78b1d765d234b9c9e3a1d2b0667c47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,685 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using UnityEditor.Search;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using UnityEngine.Assertions;
namespace Unity.AI.Navigation.Editor.Converter
{
// Status for each row item to say in which state they are in.
// This will make sure they are showing the correct icon
[Serializable]
enum Status
{
Pending,
Warning,
Error,
Success
}
// This is the serialized class that stores the state of each item in the list of items to convert
[Serializable]
class ConverterItemState
{
public bool isActive;
// Message that will be displayed on the icon if warning or failed.
public string message;
// Status of the converted item, Pending, Warning, Error or Success
public Status status;
internal bool hasConverted = false;
}
// Each converter uses the active bool
// Each converter has a list of active items/assets
// We do this so that we can use the binding system of the UI Elements
[Serializable]
class ConverterState
{
// This is the enabled state of the whole converter
public bool isEnabled;
public bool isActive;
public bool isLoading; // to name
public bool isInitialized;
public List<ConverterItemState> items = new List<ConverterItemState>();
public int pending;
public int warnings;
public int errors;
public int success;
internal int index;
public bool isActiveAndEnabled => isEnabled && isActive;
public bool requiresInitialization => !isInitialized && isActiveAndEnabled;
}
[Serializable]
internal struct ConverterItems
{
public List<ConverterItemDescriptor> itemDescriptors;
}
[Serializable]
internal class SystemConvertersEditor : EditorWindow
{
public VisualTreeAsset converterEditorAsset;
public VisualTreeAsset converterListAsset;
public VisualTreeAsset converterItem;
ScrollView m_ScrollView;
List<SystemConverter> m_CoreConvertersList = new List<SystemConverter>();
private bool convertButtonActive = false;
// This list needs to be as long as the amount of converters
List<ConverterItems> m_ItemsToConvert = new List<ConverterItems>();
SerializedObject m_SerializedObject;
List<string> m_ContainerChoices = new List<string>();
List<SystemConverterContainer> m_Containers = new List<SystemConverterContainer>();
int m_ContainerChoiceIndex = 0;
// This is a list of Converter States which holds a list of which converter items/assets are active
// There is one for each Converter.
[SerializeField] List<ConverterState> m_ConverterStates = new List<ConverterState>();
TypeCache.TypeCollection m_ConverterContainers;
// Name of the index file
string m_ConverterIndex = "SystemConverterIndex";
public void DontSaveToLayout(EditorWindow wnd)
{
// Making sure that the window is not saved in layouts.
Assembly assembly = typeof(EditorWindow).Assembly;
var editorWindowType = typeof(EditorWindow);
var hostViewType = assembly.GetType("UnityEditor.HostView");
var containerWindowType = assembly.GetType("UnityEditor.ContainerWindow");
var parentViewField = editorWindowType.GetField("m_Parent", BindingFlags.Instance | BindingFlags.NonPublic);
var parentViewValue = parentViewField.GetValue(wnd);
// window should not be saved to layout
var containerWindowProperty =
hostViewType.GetProperty("window", BindingFlags.Instance | BindingFlags.Public);
var parentContainerWindowValue = containerWindowProperty.GetValue(parentViewValue);
var dontSaveToLayoutField =
containerWindowType.GetField("m_DontSaveToLayout", BindingFlags.Instance | BindingFlags.NonPublic);
dontSaveToLayoutField.SetValue(parentContainerWindowValue, true);
}
void OnEnable()
{
InitIfNeeded();
}
void InitIfNeeded()
{
if (m_CoreConvertersList.Any())
return;
m_CoreConvertersList = new List<SystemConverter>();
// This is the drop down choices.
m_ConverterContainers = TypeCache.GetTypesDerivedFrom<SystemConverterContainer>();
foreach (var containerType in m_ConverterContainers)
{
var container = (SystemConverterContainer)Activator.CreateInstance(containerType);
m_Containers.Add(container);
m_ContainerChoices.Add(container.name);
}
if (m_ConverterContainers.Any())
{
GetConverters();
}
else
{
ClearConverterStates();
}
}
void ClearConverterStates()
{
m_CoreConvertersList.Clear();
m_ConverterStates.Clear();
m_ItemsToConvert.Clear();
}
void GetConverters()
{
ClearConverterStates();
var converterList = TypeCache.GetTypesDerivedFrom<SystemConverter>();
for (var i = 0; i < converterList.Count; ++i)
{
// Iterate over the converters that are used by the current container
var conv = (SystemConverter)Activator.CreateInstance(converterList[i]);
if (conv.container == m_ConverterContainers[m_ContainerChoiceIndex])
{
m_CoreConvertersList.Add(conv);
}
}
// this need to be sorted by Priority property
m_CoreConvertersList = m_CoreConvertersList
.OrderBy(o => o.priority).ToList();
for (var i = 0; i < m_CoreConvertersList.Count; i++)
{
// Create a new ConvertState which holds the active state of the converter
var converterState = new ConverterState
{
isEnabled = m_CoreConvertersList[i].isEnabled,
isActive = true,
isInitialized = false,
items = new List<ConverterItemState>(),
index = i,
};
m_ConverterStates.Add(converterState);
// This just creates empty entries in the m_ItemsToConvert.
// This list need to have the same amount of entries as the converters
var converterItemInfos = new List<ConverterItemDescriptor>();
//m_ItemsToConvert.Add(converterItemInfos);
m_ItemsToConvert.Add(new ConverterItems { itemDescriptors = converterItemInfos });
}
}
public void CreateGUI()
{
InitIfNeeded();
if (m_ConverterContainers.Any())
{
m_SerializedObject = new SerializedObject(this);
converterEditorAsset.CloneTree(rootVisualElement);
RecreateUI();
var button = rootVisualElement.Q<Button>("convertButton");
button.RegisterCallback<ClickEvent>(Convert);
button.SetEnabled(false);
var initButton = rootVisualElement.Q<Button>("initializeButton");
initButton.RegisterCallback<ClickEvent>(InitializeAllActiveConverters);
}
}
void RecreateUI()
{
m_SerializedObject.Update();
var currentContainer = m_Containers[m_ContainerChoiceIndex];
rootVisualElement.Q<Label>("conversionName").text = currentContainer.name;
rootVisualElement.Q<TextElement>("conversionInfo").text = currentContainer.info;
rootVisualElement.Q<Image>("converterContainerHelpIcon").image = EditorStyles.iconHelp;
// Getting the scrollview where the converters should be added
m_ScrollView = rootVisualElement.Q<ScrollView>("convertersScrollView");
m_ScrollView.Clear();
for (int i = 0; i < m_CoreConvertersList.Count; ++i)
{
// Making an item using the converterListAsset as a template.
// Then adding the information needed for each converter
VisualElement item = new VisualElement();
converterListAsset.CloneTree(item);
var conv = m_CoreConvertersList[i];
item.SetEnabled(conv.isEnabled);
item.Q<Label>("converterName").text = conv.name;
item.Q<Label>("converterInfo").text = conv.info;
// setup the images
item.Q<Image>("pendingImage").image = EditorStyles.iconPending;
item.Q<Image>("pendingImage").tooltip = "Pending";
var pendingLabel = item.Q<Label>("pendingLabel");
item.Q<Image>("warningImage").image = EditorStyles.iconWarn;
item.Q<Image>("warningImage").tooltip = "Warnings";
var warningLabel = item.Q<Label>("warningLabel");
item.Q<Image>("errorImage").image = EditorStyles.iconFail;
item.Q<Image>("errorImage").tooltip = "Failed";
var errorLabel = item.Q<Label>("errorLabel");
item.Q<Image>("successImage").image = EditorStyles.iconSuccess;
item.Q<Image>("successImage").tooltip = "Success";
var successLabel = item.Q<Label>("successLabel");
var converterEnabledToggle = item.Q<Toggle>("converterEnabled");
converterEnabledToggle.bindingPath =
$"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.isActive)}";
pendingLabel.bindingPath =
$"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.pending)}";
warningLabel.bindingPath =
$"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.warnings)}";
errorLabel.bindingPath =
$"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.errors)}";
successLabel.bindingPath =
$"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.success)}";
VisualElement child = item;
ListView listView = child.Q<ListView>("converterItems");
listView.showBoundCollectionSize = false;
listView.bindingPath = $"{nameof(m_ConverterStates)}.Array.data[{i}].{nameof(ConverterState.items)}";
int id = i;
listView.makeItem = () =>
{
var convertItem = converterItem.CloneTree();
// Adding the contextual menu for each item
convertItem.AddManipulator(new ContextualMenuManipulator(evt => AddToContextMenu(evt, id)));
return convertItem;
};
listView.bindItem = (element, index) =>
{
m_SerializedObject.Update();
var property = m_SerializedObject.FindProperty($"{listView.bindingPath}.Array.data[{index}]");
// ListView doesn't bind the child elements for us properly, so we do that for it
// In the UXML our root is a BindableElement, as we can't bind otherwise.
var bindable = (BindableElement)element;
bindable.BindProperty(property);
// Adding index here to userData so it can be retrieved later
element.userData = index;
var status = (Status)property.FindPropertyRelative("status").enumValueIndex;
var info = property.FindPropertyRelative("message").stringValue;
// Update the amount of things to convert
child.Q<Label>("converterStats").text = $"{m_ItemsToConvert[id].itemDescriptors.Count} items";
var convItemDesc = m_ItemsToConvert[id].itemDescriptors[index];
element.Q<Label>("converterItemName").text = convItemDesc.name;
element.Q<Label>("converterItemPath").text = convItemDesc.info;
// Changing the icon here depending on the status.
Texture2D icon = null;
switch (status)
{
case Status.Pending:
icon = EditorStyles.iconPending;
break;
case Status.Error:
icon = EditorStyles.iconFail;
break;
case Status.Warning:
icon = EditorStyles.iconWarn;
break;
case Status.Success:
icon = EditorStyles.iconSuccess;
break;
}
element.Q<Image>("converterItemStatusIcon").image = icon;
element.Q<Image>("converterItemStatusIcon").tooltip = info;
};
listView.selectionChanged += obj => { m_CoreConvertersList[id].OnClicked(listView.selectedIndex); };
listView.unbindItem = (element, index) =>
{
var bindable = (BindableElement)element;
bindable.Unbind();
};
m_ScrollView.Add(item);
}
rootVisualElement.Bind(m_SerializedObject);
var button = rootVisualElement.Q<Button>("convertButton");
button.RegisterCallback<ClickEvent>(Convert);
button.SetEnabled(convertButtonActive);
var initButton = rootVisualElement.Q<Button>("initializeButton");
initButton.RegisterCallback<ClickEvent>(InitializeAllActiveConverters);
}
void GetAndSetData(int i, Action onAllConvertersCompleted = null)
{
// This need to be in Init method
// Need to get the assets that this converter is converting.
// Need to return Name, Path, Initial info, Help link.
// New empty list of ConverterItemInfos
List<ConverterItemDescriptor> converterItemInfos = new List<ConverterItemDescriptor>();
var initCtx = new InitializeConverterContext { items = converterItemInfos };
var conv = m_CoreConvertersList[i];
m_ConverterStates[i].isLoading = true;
// This should also go to the init method
// This will fill out the converter item infos list
int id = i;
conv.OnInitialize(initCtx, OnConverterCompleteDataCollection);
void OnConverterCompleteDataCollection()
{
// Set the item infos list to to the right index
m_ItemsToConvert[id] = new ConverterItems { itemDescriptors = converterItemInfos };
m_ConverterStates[id].items = new List<ConverterItemState>(converterItemInfos.Count);
// Default all the entries to true
for (var j = 0; j < converterItemInfos.Count; j++)
{
string message = string.Empty;
Status status;
bool active = true;
// If this data hasn't been filled in from the init phase then we can assume that there are no issues / warnings
if (string.IsNullOrEmpty(converterItemInfos[j].warningMessage))
{
status = Status.Pending;
}
else
{
status = Status.Warning;
message = converterItemInfos[j].warningMessage;
active = false;
m_ConverterStates[id].warnings++;
}
m_ConverterStates[id].items.Add(new ConverterItemState
{
isActive = active,
message = message,
status = status,
hasConverted = false,
});
}
m_ConverterStates[id].isLoading = false;
m_ConverterStates[id].isInitialized = true;
// Making sure that the pending amount is set to the amount of items needs converting
m_ConverterStates[id].pending = m_ConverterStates[id].items.Count;
EditorUtility.SetDirty(this);
m_SerializedObject.ApplyModifiedProperties();
CheckAllConvertersCompleted();
convertButtonActive = true;
// Make sure that the Convert Button is turned back on
var button = rootVisualElement.Q<Button>("convertButton");
button.SetEnabled(convertButtonActive);
}
void CheckAllConvertersCompleted()
{
int convertersToInitialize = 0;
int convertersInitialized = 0;
for (var j = 0; j < m_ConverterStates.Count; j++)
{
var converter = m_ConverterStates[j];
// Skip inactive converters
if (!converter.isActiveAndEnabled)
continue;
if (converter.isInitialized)
convertersInitialized++;
else
convertersToInitialize++;
}
var sum = convertersToInitialize + convertersInitialized;
Assert.IsFalse(sum == 0);
// Show our progress so far
EditorUtility.ClearProgressBar();
EditorUtility.DisplayProgressBar($"Initializing converters", $"Initializing converters ({convertersInitialized}/{sum})...", (float)convertersInitialized / sum);
// If all converters are initialized call the complete callback
if (convertersToInitialize == 0)
{
onAllConvertersCompleted?.Invoke();
}
}
}
void InitializeAllActiveConverters(ClickEvent evt)
{
// If we use search index, go async
if (ShouldCreateSearchIndex())
{
CreateSearchIndex(m_ConverterIndex);
}
// Otherwise do everything directly
else
{
ConverterCollectData(() => { EditorUtility.ClearProgressBar(); });
}
void CreateSearchIndex(string name)
{
// Create <guid>.index in the project
var title = $"Building {name} search index";
EditorUtility.DisplayProgressBar(title, "Creating search index...", -1f);
// Private implementation of a file naming function which puts the file at the selected path.
Type assetdatabase = typeof(AssetDatabase);
var indexPath = (string)assetdatabase.GetMethod("GetUniquePathNameAtSelectedPath", BindingFlags.NonPublic | BindingFlags.Static).Invoke(assetdatabase, new object[] { $"Assets/{name}.index" });
// Write search index manifest
System.IO.File.WriteAllText(indexPath,
@"{
""roots"": [""Assets""],
""includes"": [],
""excludes"": [],
""options"": {
""types"": true,
""properties"": true,
""extended"": true,
""dependencies"": true
},
""baseScore"": 9999
}");
// Import the search index
AssetDatabase.ImportAsset(indexPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.DontDownloadFromCacheServer);
EditorApplication.delayCall += () =>
{
// Create dummy request to ensure indexing has finished
var context = SearchService.CreateContext("asset", $"p: a=\"{name}\"");
SearchService.Request(context, (_, items) =>
{
OnSearchIndexCreated(name, indexPath, () =>
{
DeleteSearchIndex(context, indexPath);
});
});
};
}
void OnSearchIndexCreated(string name, string path, Action onComplete)
{
EditorUtility.ClearProgressBar();
ConverterCollectData(onComplete);
}
void ConverterCollectData(Action onConverterDataCollectionComplete)
{
EditorUtility.DisplayProgressBar($"Initializing converters", $"Initializing converters...", -1f);
var convertersToInitialize = 0;
for (var i = 0; i < m_ConverterStates.Count; ++i)
{
if (m_ConverterStates[i].isEnabled)
{
GetAndSetData(i, onConverterDataCollectionComplete);
convertersToInitialize++;
}
}
// If we don't have any converters to initialize, call the complete callback directly.
if (convertersToInitialize == 0)
onConverterDataCollectionComplete?.Invoke();
}
void DeleteSearchIndex(SearchContext context, string indexPath)
{
context?.Dispose();
// Client code has finished with the created index. We can delete it.
AssetDatabase.DeleteAsset(indexPath);
EditorUtility.ClearProgressBar();
}
}
bool ShouldCreateSearchIndex()
{
for (int i = 0; i < m_ConverterStates.Count; ++i)
{
if (m_ConverterStates[i].requiresInitialization)
{
var converter = m_CoreConvertersList[i];
if (converter.needsIndexing)
{
return true;
}
}
}
return false;
}
void AddToContextMenu(ContextualMenuPopulateEvent evt, int coreConverterIndex)
{
var ve = (VisualElement)evt.target;
// Checking if this context menu should be enabled or not
var isActive = m_ConverterStates[coreConverterIndex].items[(int)ve.userData].isActive &&
!m_ConverterStates[coreConverterIndex].items[(int)ve.userData].hasConverted;
evt.menu.AppendAction("Run converter for this asset",
e => { ConvertIndex(coreConverterIndex, (int)ve.userData); },
isActive ? DropdownMenuAction.AlwaysEnabled : DropdownMenuAction.AlwaysDisabled);
}
void Convert(ClickEvent evt)
{
var activeConverterStates = new List<ConverterState>();
// Get the names of the converters
// Get the amount of them
// Make the string "name x/y"
// Getting all the active converters to use in the cancelable progressbar
foreach (var state in m_ConverterStates)
{
if (state.isActive && state.isInitialized)
activeConverterStates.Add(state);
}
var converterCount = 0;
var activeConvertersCount = activeConverterStates.Count;
foreach (var activeConverterState in activeConverterStates)
{
if (activeConverterState.items.Count == 0)
continue;
var hasItemsToConvert = false;
foreach (var item in activeConverterState.items)
{
if (item.isActive && !item.hasConverted)
{
hasItemsToConvert = true;
break;
}
}
if (!hasItemsToConvert)
continue;
var converterIndex = activeConverterState.index;
m_CoreConvertersList[converterIndex].OnPreRun();
var converterName = m_CoreConvertersList[converterIndex].name;
var progressTitle = $"{converterName} Converter : {converterCount++}/{activeConvertersCount}";
BatchConvert(activeConverterState, progressTitle);
m_CoreConvertersList[converterIndex].OnPostRun();
AssetDatabase.SaveAssets();
EditorUtility.ClearProgressBar();
}
}
void BatchConvert(ConverterState converterState, string progressBarTile)
{
var converterIndex = converterState.index;
var itemsFound = converterState.items;
var itemsToConvert = new List<ConverterItemInfo>(itemsFound.Count);
for (var i = 0; i < itemsFound.Count; ++i)
{
if (itemsFound[i].isActive && !itemsFound[i].hasConverted)
itemsToConvert.Add(new ConverterItemInfo()
{
index = i,
descriptor = m_ItemsToConvert[converterIndex].itemDescriptors[i]
});
}
// Since this is a batched process, we don't have progress to show, so we stick it to 50%.
EditorUtility.DisplayProgressBar(progressBarTile, $"Processing {itemsToConvert.Count} items.", 0.5f);
var ctx = new RunItemContext(itemsToConvert.ToArray());
m_CoreConvertersList[converterIndex].OnRun(ref ctx);
UpdateInfo(converterIndex, ctx);
}
void ConvertIndex(int converterIndex, int index)
{
if (!m_ConverterStates[converterIndex].items[index].hasConverted)
{
m_ConverterStates[converterIndex].items[index].hasConverted = true;
var item = new ConverterItemInfo()
{
index = index,
descriptor = m_ItemsToConvert[converterIndex].itemDescriptors[index],
};
var ctx = new RunItemContext(new[] { item });
m_CoreConvertersList[converterIndex].OnRun(ref ctx);
UpdateInfo(converterIndex, ctx);
}
}
void UpdateInfo(int converterIndex, RunItemContext ctx)
{
// Reset converter stats, so that they don't contain old data from previous runs.
m_ConverterStates[converterIndex].warnings = 0;
m_ConverterStates[converterIndex].errors = 0;
m_ConverterStates[converterIndex].success = 0;
var items = ctx.items;
for (var i = 0; i < items.Length; ++i)
{
var itemIndex = items[i].index;
if (ctx.didFail[i])
{
m_ConverterStates[converterIndex].items[itemIndex].message = ctx.info[i];
m_ConverterStates[converterIndex].items[itemIndex].status = Status.Error;
m_ConverterStates[converterIndex].errors++;
}
else
{
m_ConverterStates[converterIndex].items[itemIndex].status = Status.Success;
m_ConverterStates[converterIndex].success++;
m_ConverterStates[converterIndex].items[itemIndex].hasConverted = true;
}
// If the item was converted, we deselect it in the conversion list.
m_ConverterStates[converterIndex].items[itemIndex].isActive = false;
}
if (m_ConverterStates[converterIndex].pending > 0)
m_ConverterStates[converterIndex].pending--;
var child = m_ScrollView[converterIndex];
child.Q<ListView>("converterItems").Rebuild();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 030df50ef7a3d40deaa58109d30100c4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_ViewDataDictionary: {instanceID: 0}
- converterEditorAsset: {fileID: 9197481963319205126, guid: cd1eb3c3c695c494d855ea678fe7395b,
type: 3}
- converterListAsset: {fileID: 9197481963319205126, guid: aaa3e510761864dac9b71f85526490d6,
type: 3}
- converterItem: {fileID: 9197481963319205126, guid: d6de7697d63d64fabbfb31425d93541e,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
{
"name": "Unity.AI.Navigation.Editor.ConversionSystem",
"rootNamespace": "",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c57630adab7a340ec94f10e4fcac12f1
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
.convertersListView {
--unity-item-height: 16;
height: 120px;
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3eb99c80b411349188e1e5167887ac6c
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0

View File

@@ -0,0 +1,19 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement style="max-width: 620px; min-width: 620px; flex-grow: 1; padding-left: 19px; padding-right: 1px; padding-top: 15px;">
<ui:VisualElement style="height: 25px; width: 604px; flex-shrink: 0; flex-direction: row;">
<ui:Label name="conversionName" style="-unity-font-style: bold; font-size: 16px; width: 593px; padding-right: 16px; flex-grow: 1; flex-shrink: 1;" />
<ui:Image name="converterContainerHelpIcon" />
</ui:VisualElement>
<ui:TextElement name="conversionInfo" style="height: 46px; width: 606px; flex-shrink: 0;" />
<ui:HelpBox message-type="Warning" text="This process makes irreversible changes to the project. Back up your project before proceeding." />
<ui:VisualElement style="flex-direction: row;">
<ui:VisualElement style="flex-grow: 1;" />
</ui:VisualElement>
<ui:ScrollView scroll-deceleration-rate="0,135" elasticity="0,1" name="convertersScrollView" style="flex-grow: 1; flex-shrink: 1; max-width: none; width: 632px; padding-right: 0; padding-left: 4px;" />
</ui:VisualElement>
<ui:VisualElement style="flex-direction: row-reverse; flex-shrink: 0; padding-left: 15px; padding-right: 14px;">
<ui:Button text=" Convert Assets" name="convertButton" style="flex-direction: column; margin-bottom: 15px;" />
<ui:Label style="flex-grow: 1;" />
<ui:Button text="Initialize Converters" name="initializeButton" tooltip="This will initialize all the converters that have been toggled on." style="flex-direction: column; margin-bottom: 15px;" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: cd1eb3c3c695c494d855ea678fe7395b
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63cb84b97408b4d25a6925daccffcd22
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0

View File

@@ -0,0 +1,24 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:VisualElement name="converterTopVisualElement" style="flex-grow: 1; height: 250px; width: 606px; flex-shrink: 0; border-bottom-width: 2px; border-top-width: 2px; border-bottom-color: rgb(0, 0, 0); margin-bottom: 20px; padding-bottom: 0; margin-top: 20px; padding-right: 0; border-left-width: 2px; border-right-width: 2px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0);">
<ui:VisualElement style="width: 613px; flex-direction: row; flex-grow: 0; margin-left: 0; margin-right: 0; margin-top: 0; margin-bottom: 0; flex-shrink: 0; padding-bottom: 4px; padding-left: 2px; border-top-width: 0; border-top-color: rgb(0, 0, 0); padding-top: 11px;">
<ui:Toggle name="converterEnabled" value="false" tooltip="Enabling this will start the pre-processing of this converter." style="flex-grow: 0; height: 24px; margin-top: 0; margin-bottom: 0;" />
<ui:Label name="converterName" text="Name Of The Converter" style="width: 143px; -unity-text-align: middle-left; flex-grow: 1; flex-direction: column; max-height: 20%; height: 20px; min-height: 20px; padding-top: 3px; -unity-font-style: bold; padding-left: 4px;" />
<ui:Label name="converterStats" style="flex-grow: 0; -unity-text-align: middle-right; -unity-font-style: bold; padding-right: 20px;" />
</ui:VisualElement>
<ui:VisualElement style="width: 596px; flex-direction: row; flex-grow: 0; flex-shrink: 1; padding-right: 0; padding-left: 2px; padding-bottom: 4px; overflow: hidden;">
<ui:Label text="info" name="converterInfo" style="-unity-text-align: middle-left; flex-grow: 1; flex-wrap: nowrap; overflow: visible; white-space: normal; padding-top: 0;" />
</ui:VisualElement>
<ui:VisualElement style="flex-direction: row; height: 19px; flex-grow: 0; margin-top: 0; margin-bottom: 0; padding-right: 14px; width: 608px; flex-shrink: 1;">
<ui:Label text="&#10;" style="flex-grow: 1;" />
<ui:Image name="pendingImage" style="max-width: 16px; max-height: 16px; min-width: 16px; min-height: 16px;" />
<ui:Label name="pendingLabel" />
<ui:Image name="warningImage" style="max-width: 16px; max-height: 16px; min-width: 16px; min-height: 16px;" />
<ui:Label name="warningLabel" />
<ui:Image name="errorImage" style="max-width: 16px; max-height: 16px; min-width: 16px; min-height: 16px;" />
<ui:Label name="errorLabel" />
<ui:Image name="successImage" style="max-width: 16px; max-height: 16px; min-width: 16px; min-height: 16px;" />
<ui:Label name="successLabel" style="flex-grow: 0; flex-shrink: 0;" />
</ui:VisualElement>
<ui:ListView focusable="true" name="converterItems" show-alternating-row-backgrounds="All" text="Info" style="flex-grow: 1; flex-shrink: 0; height: 100px; width: 602px; padding-bottom: 0; margin-bottom: 0; margin-top: 0;" />
</ui:VisualElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: aaa3e510761864dac9b71f85526490d6
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@@ -0,0 +1,11 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:BindableElement style="flex-grow: 1; flex-direction: row; align-items: center; flex-shrink: 0; padding-right: 20px;">
<ui:Toggle value="true" name="converterItemActive" binding-path="isActive" />
<ui:Label name="converterItemName" text="name" style="flex-grow: 0; width: 200px; overflow: hidden; padding-left: 4px;" />
<ui:Label name="converterItemInfo" style="visibility: hidden;" />
<ui:Label name="converterItemPath" text="path..." style="flex-grow: 0; flex-wrap: nowrap; white-space: nowrap; width: 300px; overflow: hidden; padding-left: 21px;" />
<ui:Label display-tooltip-when-elided="true" style="flex-grow: 1;" />
<ui:Image name="converterItemStatusIcon" style="max-width: 16px; max-height: 16px; min-width: 16px; min-height: 16px; justify-content: center; flex-grow: 0; width: 16px; height: 16px;" />
<ui:Image name="converterItemHelpIcon" style="max-width: 16px; max-height: 16px; min-width: 16px; min-height: 16px; justify-content: center; flex-grow: 0;" />
</ui:BindableElement>
</ui:UXML>

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d6de7697d63d64fabbfb31425d93541e
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}