Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added gltf Asset informations to Importer Inspector #774

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Editor/Scripts/GLTFImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static void EnsureShadersAreLoaded()
[SerializeField] internal bool _useSceneNameIdentifier = false;
[Tooltip("Compress textures after import using the platform default settings. If you need more control, use a .gltf file instead.")]
[SerializeField] internal GLTFImporterTextureCompressionQuality _textureCompression = GLTFImporterTextureCompressionQuality.None;

[SerializeField, Multiline] internal string _gltfAsset = default;
// for humanoid importer
[SerializeField] internal bool m_OptimizeGameObjects = false;
[SerializeField] internal HumanDescription m_HumanDescription = new HumanDescription();
Expand Down Expand Up @@ -959,7 +959,7 @@ private void CreateGLTFScene(GLTFImportContext context, out GameObject scene,
scene = loader.LastLoadedScene;
animationClips = loader.CreatedAnimationClips;


_gltfAsset = loader.Root.Asset.ToString(true);
importer = loader;
}
}
Expand Down
23 changes: 23 additions & 0 deletions Editor/Scripts/GLTFImporterInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public override void OnEnable()
AddTab(new GLTFAssetImporterTab(this, "Materials", MaterialInspectorGUI));

AddTab(new GLTFAssetImporterTab(this, "Used Extensions", ExtensionInspectorGUI));
AddTab(new GLTFAssetImporterTab(this, "Info", AssetInfoInspectorGUI));

base.OnEnable();
}
Expand Down Expand Up @@ -362,6 +363,28 @@ void ExtractAsset(T subAsset, bool importImmediately)
EditorGUILayout.EndFoldoutHeaderGroup();
}

private void AssetInfoInspectorGUI()
{
var t = target as GLTFImporter;
if (!t) return;
var assetProp = serializedObject.FindProperty(nameof(GLTFImporter._gltfAsset));
if (assetProp == null)
return;

if (string.IsNullOrEmpty(t._gltfAsset))
{
EditorGUILayout.LabelField("[ No informations included ]");
return;
}
GUIStyle style = new GUIStyle(GUI.skin.label);
style.richText = true;
style.wordWrap = true;
EditorGUILayout.Space();

var rect = GUILayoutUtility.GetRect(new GUIContent(t._gltfAsset), style);
EditorGUI.SelectableLabel(rect, t._gltfAsset, style);
}

private void ExtensionInspectorGUI()
{
var t = target as GLTFImporter;
Expand Down
35 changes: 35 additions & 0 deletions Runtime/Plugins/GLTFSerialization/Schema/Asset.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text;
using Newtonsoft.Json;

namespace GLTF.Schema
Expand Down Expand Up @@ -101,5 +102,39 @@ public override void Serialize(JsonWriter writer)

writer.WriteEndObject();
}

public override string ToString()
{
return ToString(false);
}

public string ToString(bool richFormat)
{
string bStart = richFormat ? "<b>" : "";
string bEnd = richFormat ? "</b>" : "";

var sb = new StringBuilder();
if (!string.IsNullOrEmpty(Generator))
sb.AppendLine($"{bStart}{nameof(Generator)}: {bEnd}{Generator}");

if (!string.IsNullOrEmpty(Version))
sb.AppendLine($"{bStart}{nameof(Version)}: {bEnd}{Version}");

if (!string.IsNullOrEmpty(MinVersion))
sb.AppendLine($"{bStart}{nameof(MinVersion)}: {bEnd}{MinVersion}");

if (!string.IsNullOrEmpty(Copyright))
sb.AppendLine($"{bStart}{nameof(Copyright)}: {bEnd}{Copyright}");

if (Extras != null)
{
sb.AppendLine("");
sb.AppendLine($"{bStart}Extras: {bEnd}");
foreach (var extra in Extras)
sb.AppendLine(extra.ToString());
}

return sb.ToString();
}
}
}