浏览代码

added tooltips and notes to asset sources

/generic-asset-sources
sleal-unity 4 年前
当前提交
10fc7559
共有 4 个文件被更改,包括 76 次插入18 次删除
  1. 19
      com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetSourceElement.uxml
  2. 40
      com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetSourceElement.cs
  3. 24
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSourceLocationNotes.cs
  4. 11
      com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSourceLocationNotes.cs.meta

19
com.unity.perception/Editor/Randomization/Uxml/AssetSource/AssetSourceElement.uxml


<Label name="name" text="Field Name" class="unity-base-field__label"/>
<VisualElement style="margin-left: 18px;">
<VisualElement style="flex-direction: row; align-items: center;">
<Label text="Archetype" class="unity-base-field__label"/>
<editor:ToolbarMenu name="archetype-dropdown" text="Type" class="sampler__type-menu"/>
<Label
text="Location"
class="unity-base-field__label"
tooltip="The asset source location to load assets from"/>
<editor:ToolbarMenu name="location-dropdown" text="Type" class="sampler__type-menu"/>
</VisualElement>
<VisualElement style="margin-left: 18px;">
<VisualElement name="fields-container" style="flex-grow: 1;"/>
<TextElement name="location-notes" class="scenario__info-box"/>
<Label text="Location" class="unity-base-field__label"/>
<editor:ToolbarMenu name="location-dropdown" text="Type" class="sampler__type-menu"/>
<Label
text="Archetype"
class="unity-base-field__label"
tooltip="Archetypes preprocess assets loaded from the selected asset source location"/>
<editor:ToolbarMenu name="archetype-dropdown" text="Type" class="sampler__type-menu"/>
<VisualElement name="fields-container" style="flex-grow: 1;"/>
</VisualElement>
</VisualElement>
</UXML>

40
com.unity.perception/Editor/Randomization/VisualElements/AssetSource/AssetSourceElement.cs


ToolbarMenu m_ArchetypeToolbarMenu;
ToolbarMenu m_LocationToolbarMenu;
VisualElement m_FieldsContainer;
TextElement m_LocationNotes;
Type m_AssetType;
ArchetypeBase archetype =>

var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/AssetSource/AssetSourceElement.uxml");
template.CloneTree(this);
if (assetSourceLocation == null)
CreateAssetSourceLocation(typeof(LocalAssetSourceLocation));
var nameLabel = this.Q<Label>("name");
nameLabel.text = property.displayName;

a => DropdownMenuAction.Status.Normal);
}
m_LocationNotes = this.Q<TextElement>("location-notes");
m_LocationToolbarMenu.text = GetDisplayName(assetSourceLocation.GetType());
foreach (var type in StaticData.assetSourceLocationTypes)
{
m_LocationToolbarMenu.menu.AppendAction(

}
CreatePropertyFields();
}
void ReplaceLocation(Type type)
{
CreateAssetSourceLocation(type);
m_LocationToolbarMenu.text = GetDisplayName(type);
CreatePropertyFields();
if (assetSourceLocation == null)
CreateAssetSourceLocation(typeof(LocalAssetSourceLocation));
UpdateLocationUI(assetSourceLocation.GetType());
}
void ReplaceArchetype(Type type)

var newLocation = (AssetSourceLocation)Activator.CreateInstance(type);
m_LocationProperty.managedReferenceValue = newLocation;
m_LocationProperty.serializedObject.ApplyModifiedProperties();
}
void ReplaceLocation(Type type)
{
CreateAssetSourceLocation(type);
UpdateLocationUI(type);
}
void UpdateLocationUI(Type type)
{
m_LocationToolbarMenu.text = GetDisplayName(type);
var notesAttribute = (AssetSourceLocationNotes)Attribute.GetCustomAttribute(type, typeof(AssetSourceLocationNotes));
if (notesAttribute != null)
{
m_LocationNotes.text = notesAttribute.notes;
m_LocationNotes.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.Flex);
}
else
{
m_LocationNotes.style.display = new StyleEnum<DisplayStyle>(DisplayStyle.None);
}
CreatePropertyFields();
}
void CreatePropertyFields()

24
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSourceLocationNotes.cs


using System;
namespace UnityEngine.Perception.Randomization
{
/// <summary>
/// Used to annotate an AssetSourceLocation with notes within the inspector UI
/// </summary>
public class AssetSourceLocationNotes : Attribute
{
/// <summary>
/// The text notes to display in the AssetSourceLocation's UI.
/// </summary>
public string notes;
/// <summary>
/// Constructs a new AssetSourceLocationNotes attribute
/// </summary>
/// <param name="notes">The text notes to display in the inspector</param>
public AssetSourceLocationNotes(string notes)
{
this.notes = notes;
}
}
}

11
com.unity.perception/Runtime/Randomization/Randomizers/AssetSources/AssetSourceLocationNotes.cs.meta


fileFormatVersion: 2
guid: b10fba6f9bbaaef498a12faefec212f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存