This commit is contained in:
左右看
2023-06-28 00:35:46 +08:00
parent cb5bab5ce9
commit 0d848e4d07
524 changed files with 78452 additions and 12 deletions
@@ -0,0 +1,219 @@
using System.Collections.Generic;
using UnityEngine;
namespace UnityGLTF
{
internal class AvatarUtils
{
// A static dictionary containing the mapping from joint/bones names in the model
// to the names Unity uses for them internally.
// In this case they match the naming from the included Mixamo model on the left
// and the Unity equivalent name on the right.
// This does not need to be hard-coded.
public static Dictionary<string, string> HumanSkeletonNames = new Dictionary<string, string>()
{
{"mixamorig:Spine1", "Chest"},
{"mixamorig:Head", "Head" },
{"mixamorig:Hips", "Hips" },
{"mixamorig:LeftHandIndex3", "Left Index Distal" },
{"mixamorig:LeftHandIndex2", "Left Index Intermediate" },
{"mixamorig:LeftHandIndex1", "Left Index Proximal" },
{"mixamorig:LeftHandPinky3", "Left Little Distal" },
{"mixamorig:LeftHandPinky2", "Left Little Intermediate" },
{"mixamorig:LeftHandPinky1", "Left Little Proximal" },
{"mixamorig:LeftHandMiddle3", "Left Middle Distal" },
{"mixamorig:LeftHandMiddle2", "Left Middle Intermediate" },
{"mixamorig:LeftHandMiddle1", "Left Middle Proximal" },
{"mixamorig:LeftHandRing3", "Left Ring Distal" },
{"mixamorig:LeftHandRing2", "Left Ring Intermediate" },
{"mixamorig:LeftHandRing1", "Left Ring Proximal" },
{"mixamorig:LeftHandThumb3", "Left Thumb Distal" },
{"mixamorig:LeftHandThumb2", "Left Thumb Intermediate" },
{"mixamorig:LeftHandThumb1", "Left Thumb Proximal" },
{"mixamorig:LeftFoot", "LeftFoot" },
{"mixamorig:LeftHand", "LeftHand" },
{"mixamorig:LeftForeArm", "LeftLowerArm" },
{"mixamorig:LeftLeg", "LeftLowerLeg" },
{"mixamorig:LeftShoulder", "LeftShoulder" },
{"mixamorig:LeftToeBase", "LeftToes" },
{"mixamorig:LeftArm", "LeftUpperArm" },
{"mixamorig:LeftUpLeg", "LeftUpperLeg" },
{"mixamorig:Neck", "Neck" },
{"mixamorig:RightHandIndex3", "Right Index Distal" },
{"mixamorig:RightHandIndex2", "Right Index Intermediate" },
{"mixamorig:RightHandIndex1", "Right Index Proximal" },
{"mixamorig:RightHandPinky3", "Right Little Distal" },
{"mixamorig:RightHandPinky2", "Right Little Intermediate" },
{"mixamorig:RightHandPinky1", "Right Little Proximal" },
{"mixamorig:RightHandMiddle3", "Right Middle Distal" },
{"mixamorig:RightHandMiddle2", "Right Middle Intermediate" },
{"mixamorig:RightHandMiddle1", "Right Middle Proximal" },
{"mixamorig:RightHandRing3", "Right Ring Distal" },
{"mixamorig:RightHandRing2", "Right Ring Intermediate" },
{"mixamorig:RightHandRing1", "Right Ring Proximal" },
{"mixamorig:RightHandThumb3", "Right Thumb Distal" },
{"mixamorig:RightHandThumb2", "Right Thumb Intermediate" },
{"mixamorig:RightHandThumb1", "Right Thumb Proximal" },
{"mixamorig:RightFoot", "RightFoot" },
{"mixamorig:RightHand", "RightHand" },
{"mixamorig:RightForeArm", "RightLowerArm" },
{"mixamorig:RightLeg", "RightLowerLeg" },
{"mixamorig:RightShoulder", "RightShoulder" },
{"mixamorig:RightToeBase", "RightToes" },
{"mixamorig:RightArm", "RightUpperArm" },
{"mixamorig:RightUpLeg", "RightUpperLeg" },
{"mixamorig:Spine", "Spine" },
{"mixamorig:Spine2", "UpperChest" },
// Other common Avatar formats can also be added here
// { "root", "" },
{ "hips", "Hips" },
{ "spine", "Spine" },
{ "chest", "Chest" },
{ "upperChest", "UpperChest" },
{ "neck", "Neck" },
{ "head", "Head" },
{ "leftEye", "LeftEye" },
// { "eyeL_end", "" },
{ "rightEye", "RightEye" },
// { "eyeR_end", "" },
{ "leftShoulder", "LeftShoulder" },
{ "leftUpperArm", "LeftUpperArm" },
{ "leftLowerArm", "LeftLowerArm" },
{ "leftHand", "LeftHand" },
// { "leftThumbMetacarpal", "" },
// { "leftThumbProximal", "" },
// { "leftThumbDistal", "" },
// { "thumbdistalL_end", "" },
// { "leftIndexProximal", "" },
// { "leftIndexIntermediate", "" },
// { "leftIndexDistal", "" },
// { "indexdistalL_end", "" },
// { "leftMiddleProximal", "" },
// { "leftMiddleIntermediate", "" },
// { "leftMiddleDistal", "" },
// { "middledistalL_end", "" },
// { "leftRingProximal", "" },
// { "leftRingIntermediate", "" },
// { "leftRingDistal", "" },
// { "ringdistalL_end", "" },
// { "leftLittleProximal", "" },
// { "leftLittleIntermediate", "" },
// { "leftLittleDistal", "" },
// { "littledistalL_end", "" },
{ "rightShoulder", "RightShoulder" },
{ "rightUpperArm", "RightUpperArm" },
{ "rightLowerArm", "RightLowerArm" },
{ "rightHand", "RightHand" },
// { "rightThumbMetacarpal", "" },
// { "rightThumbProximal", "" },
// { "rightThumbDistal", "" },
// { "thumbdistalR_end", "" },
// { "rightIndexProximal", "" },
// { "rightIndexIntermediate", "" },
// { "rightIndexDistal", "" },
// { "indexdistalR_end", "" },
// { "rightMiddleProximal", "" },
// { "rightMiddleIntermediate", "" },
// { "rightMiddleDistal", "" },
// { "middledistalR_end", "" },
// { "rightRingProximal", "" },
// { "rightRingIntermediate", "" },
// { "rightRingDistal", "" },
// { "ringdistalR_end", "" },
// { "rightLittleProximal", "" },
// { "rightLittleIntermediate", "" },
// { "rightLittleDistal", "" },
// { "littledistalR_end", "" },
{ "leftUpperLeg", "LeftUpperLeg" },
{ "leftLowerLeg", "LeftLowerLeg" },
{ "leftFoot", "LeftFoot" },
{ "leftToes", "LeftToes" },
// { "toesL_end", "" },
{ "rightUpperLeg", "RightUpperLeg" },
{ "rightLowerLeg", "RightLowerLeg" },
{ "rightFoot", "RightFoot" },
{ "rightToes", "RightToes" },
// { "toesR_end", "" },
};
/// <summary>
/// Create a HumanDescription out of an avatar GameObject.
/// The HumanDescription is what is needed to create an Avatar object
/// using the AvatarBuilder API. This function takes care of
/// creating the HumanDescription by going through the avatar's
/// hierarchy, defining its T-Pose in the skeleton, and defining
/// the transform/bone mapping in the HumanBone array.
/// </summary>
/// <param name="avatarRoot">Root of your avatar object</param>
/// <returns>A HumanDescription which can be fed to the AvatarBuilder API</returns>
public static HumanDescription CreateHumanDescription(GameObject avatarRoot)
{
HumanDescription description = new HumanDescription()
{
armStretch = 0.05f,
feetSpacing = 0f,
hasTranslationDoF = false,
legStretch = 0.05f,
lowerArmTwist = 0.5f,
lowerLegTwist = 0.5f,
upperArmTwist = 0.5f,
upperLegTwist = 0.5f,
skeleton = CreateSkeleton(avatarRoot),
human = CreateHuman(avatarRoot),
};
return description;
}
//Create a SkeletonBone array out of an Avatar GameObject
//This assumes that the Avatar as supplied is in a T-Pose
//The local positions of its bones/joints are used to define this T-Pose
private static SkeletonBone[] CreateSkeleton(GameObject avatarRoot)
{
List<SkeletonBone> skeleton = new List<SkeletonBone>();
Transform[] avatarTransforms = avatarRoot.GetComponentsInChildren<Transform>();
foreach (Transform avatarTransform in avatarTransforms)
{
SkeletonBone bone = new SkeletonBone()
{
name = avatarTransform.name,
position = avatarTransform.localPosition,
rotation = avatarTransform.localRotation,
scale = avatarTransform.localScale
};
skeleton.Add(bone);
}
return skeleton.ToArray();
}
//Create a HumanBone array out of an Avatar GameObject
//This is where the various bones/joints get associated with the
//joint names that Unity understands. This is done using the
//static dictionary defined at the top.
private static HumanBone[] CreateHuman(GameObject avatarRoot)
{
List<HumanBone> human = new List<HumanBone>();
Transform[] avatarTransforms = avatarRoot.GetComponentsInChildren<Transform>();
foreach (Transform avatarTransform in avatarTransforms)
{
if (HumanSkeletonNames.TryGetValue(avatarTransform.name, out string humanName))
{
HumanBone bone = new HumanBone
{
boneName = avatarTransform.name,
humanName = humanName,
limit = new HumanLimit()
};
bone.limit.useDefaultValues = true;
human.Add(bone);
}
}
return human.ToArray();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 15daddec8a84e584db94b127e7bd05b7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,271 @@
#if !NO_INTERNALS_ACCESS
using System.Linq;
using System.Text;
using UnityEngine;
#if UNITY_EDITOR
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditorInternal;
#endif
namespace UnityGLTF
{
public static class GLTFMaterialHelper
{
/// <summary>
/// Return false if other delegates should take over. Only return true if you did work and assigned material.shader = newShader.
/// </summary>
public delegate bool ConvertMaterialToGLTFDelegate(Material material, Shader oldShader, Shader newShader);
private static event ConvertMaterialToGLTFDelegate ConvertMaterialDelegates;
public static void RegisterMaterialConversionToGLTF(ConvertMaterialToGLTFDelegate converter) => ConvertMaterialDelegates += converter;
public static void UnregisterMaterialConversionToGLTF(ConvertMaterialToGLTFDelegate converter) => ConvertMaterialDelegates -= converter;
public static void ConvertMaterialToGLTF(Material material, Shader oldShader, Shader newShader)
{
if (ConvertMaterialDelegates != null)
{
var list = ConvertMaterialDelegates.GetInvocationList();
foreach (var entry in list)
{
var cb = (ConvertMaterialToGLTFDelegate) entry;
if (cb != null && cb.Invoke(material, oldShader, newShader))
{
return;
}
}
}
// IDEA ideally this would use the same code path as material export/import - would reduce the amount of code duplication considerably.
// E.g. calling something like
// var glTFMaterial = ExportMaterial(material);
// ImportAndOverrideMaterial(material, glTFMaterial);
// that uses all the same heuristics, texture conversions, ...
var msg = "No automatic conversion\nfrom " + oldShader.name + "\nto " + newShader.name + "\nfound.\n\nYou can create a conversion script, adjust which old properties map to which new properties, and switch the shader again.";
#if UNITY_EDITOR
var choice = EditorUtility.DisplayDialogComplex("Shader Conversion", msg, "Just set shader", "Cancel", "Create and open conversion script");
switch (choice)
{
case 0: // OK
material.shader = newShader;
break;
case 1: // Cancel
break;
case 2: // Alt
var path = ShaderConversion.CreateConversionScript(oldShader, newShader);
InternalEditorUtility.OpenFileAtLineExternal(path, 0);
break;
}
#else
Debug.Log(msg + " Make sure your material properties match the new shader. You can add your own conversion callbacks via `RegisterMaterialConversionToGLTF`. If you think this should have been converted automatically: please open a feature request!");
material.shader = newShader;
#endif
}
public static void ValidateMaterialKeywords(Material material)
{
// TODO ensure we're setting correct keywords for
// - existence of a normal map
// - existence of emission color values or texture
// -
// var needsVolumeTransmission = false;
// needsVolumeTransmission |= material.HasProperty(thicknessFactor) && material.GetFloat(thicknessFactor) > 0;
// needsVolumeTransmission |= material.HasProperty(transmissionFactor) && material.GetFloat(transmissionFactor) > 0;
// material.SetKeyword("_VOLUME_TRANSMISSION", needsVolumeTransmission);
//
// var needsIridescence = material.HasProperty(iridescenceFactor) && material.GetFloat(iridescenceFactor) > 0;
// material.SetKeyword("_IRIDESCENCE", needsIridescence);
//
// var needsSpecular = material.HasProperty(specularFactor) && material.GetFloat(specularFactor) > 0;
// material.SetKeyword("_SPECULAR", needsSpecular);
if (material.IsKeywordEnabled("_VOLUME_TRANSMISSION_ON"))
{
// // approximation when transmission is on but roughness == 0
// // (no opaque pass required)
// TODO does weird things with transparency but still rendering into the Opaque Texture for some reason
// if (material.HasProperty("roughnessFactor") && material.GetFloat("roughnessFactor") == 0)
// {
// // enforce transparent
// if (material.HasProperty("_QueueControl")) material.SetFloat("_QueueControl", 0);
// if (material.HasProperty("_BUILTIN_QueueControl")) material.SetFloat("_BUILTIN_QueueControl", 0);
// if (material.HasProperty("_BUILTIN_Surface")) material.SetFloat("_BUILTIN_Surface", 1);
// if (material.HasProperty("_Surface")) material.SetFloat("_Surface", 1);
// material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
// material.EnableKeyword("_BUILTIN_SURFACE_TYPE_TRANSPARENT");
// material.renderQueue = -1;
// }
// else
{
// enforce Opaque
if (material.HasProperty("_BUILTIN_Surface")) material.SetFloat("_BUILTIN_Surface", 0);
if (material.HasProperty("_Surface")) material.SetFloat("_Surface", 0);
material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
material.DisableKeyword("_BUILTIN_SURFACE_TYPE_TRANSPARENT");
// enforce queue control and render queue 3000
if (material.HasProperty("_QueueControl")) material.SetFloat("_QueueControl", 1);
if (material.HasProperty("_BUILTIN_QueueControl")) material.SetFloat("_BUILTIN_QueueControl", 1);
// not a great choice: using 2999 as magic value for "we automatically set the queue for you"
// so the change can be reverted if someone toggles transmission on and then off again.
material.renderQueue = 2999;
}
}
else
{
if (material.renderQueue == 2999)
{
if (material.HasProperty("_QueueControl")) material.SetFloat("_QueueControl", 0);
if (material.HasProperty("_BUILTIN_QueueControl")) material.SetFloat("_BUILTIN_QueueControl", 0);
material.renderQueue = -1;
}
}
if (material.HasProperty("emissiveFactor"))
material.globalIlluminationFlags = MaterialEditor.FixupEmissiveFlag(material.GetColor("emissiveFactor"), material.globalIlluminationFlags);
if (!material.IsKeywordEnabled("_TEXTURE_TRANSFORM_ON"))
{
if (material.GetTextureScale("baseColorTexture") != Vector2.one || material.GetTextureOffset("baseColorTexture") != Vector2.zero)
{
SetKeyword(material, "_TEXTURE_TRANSFORM", true);
}
}
}
public static void SetKeyword(Material material, string keyword, bool state)
{
if (state)
material.EnableKeyword(keyword + "_ON");
else
material.DisableKeyword(keyword + "_ON");
if (material.HasProperty(keyword))
material.SetFloat(keyword, state ? 1 : 0);
}
}
#if UNITY_EDITOR
internal static class ShaderConversion
{
public static string CreateConversionScript(Shader oldShader, Shader newShader)
{
var classShaderName = oldShader.name
.Replace("/", "_")
.Replace(" ", "_")
.Replace("\\", "_");
var scriptFile = ShaderConversionScriptTemplate;
scriptFile = scriptFile.Replace("<OldShader>", classShaderName);
scriptFile = scriptFile.Replace("<OldShaderName>", oldShader.name);
var sb = new StringBuilder();
foreach(var (propName, propDisplayName, type) in GetShaderProperties(oldShader))
{
sb.AppendLine($"\t\tvar {propName} = material.{MethodFromType("Get", type)}(\"{propName}\"); // {propDisplayName}");
}
var sb2 = new StringBuilder();
foreach(var (propName, propDisplayName, type) in GetShaderProperties(newShader))
{
sb2.AppendLine($"\t\t// material.{MethodFromType("Set", type)}(\"{propName}\", insert_value_here); // {propDisplayName}");
}
scriptFile = scriptFile.Replace("\t\t<OldProperties>", sb.ToString());
scriptFile = scriptFile.Replace("\t\t<NewProperties>", sb2.ToString());
const string dir = "Assets/Editor/ShaderConversions";
Directory.CreateDirectory(dir);
var fileName = dir + "/" + classShaderName + ".cs";
if (!File.Exists(fileName) || EditorUtility.DisplayDialog("File already exists", $"The file \"{fileName}\" already exists. Replace?", "Replace", "Cancel"))
File.WriteAllText(fileName, scriptFile);
AssetDatabase.Refresh();
return fileName;
}
private static IEnumerable<(string propName, string propDisplayName, ShaderUtil.ShaderPropertyType type)> GetShaderProperties(Shader shader)
{
var c = ShaderUtil.GetPropertyCount(shader);
for (var i = 0; i < c; i++)
{
if (ShaderUtil.IsShaderPropertyHidden(shader, i)) continue;
if (ShaderUtil.IsShaderPropertyNonModifiableTexureProperty(shader, i)) continue;
var propName = ShaderUtil.GetPropertyName(shader, i);
if(propName.StartsWith("unity_")) continue;
var propDisplayName = ShaderUtil.GetPropertyDescription(shader, i);
var type = ShaderUtil.GetPropertyType(shader, i);
yield return (propName, propDisplayName, type);
}
}
private static string MethodFromType(string prefix, ShaderUtil.ShaderPropertyType propertyType)
{
switch (propertyType)
{
case ShaderUtil.ShaderPropertyType.Color: return prefix + "Color";
case ShaderUtil.ShaderPropertyType.Float: return prefix + "Float";
#if UNITY_2021_1_OR_NEWER
case ShaderUtil.ShaderPropertyType.Int: return prefix + "Int";
#endif
case ShaderUtil.ShaderPropertyType.Range: return prefix + "Float";
case ShaderUtil.ShaderPropertyType.Vector: return prefix + "Vector";
case ShaderUtil.ShaderPropertyType.TexEnv: return prefix + "Texture";
}
return prefix + "UnknownPropertyType"; // compiler error
}
private const string ShaderConversionScriptTemplate =
@"using UnityEditor;
using UnityEngine;
using UnityGLTF;
class Convert_<OldShader>_to_GLTF
{
const string shaderName = ""<OldShaderName>"";
[InitializeOnLoadMethod]
private static void Register()
{
GLTFMaterialHelper.RegisterMaterialConversionToGLTF(ConvertMaterialProperties);
}
private static bool ConvertMaterialProperties(Material material, Shader oldShader, Shader newShader)
{
if (oldShader.name != shaderName) return false;
// Reading old shader properties.
<OldProperties>
material.shader = newShader;
// Assigning new shader properties.
// Uncomment lines you need, and set properties from values from the section above.
<NewProperties>
// Ensure keywords are correctly set after conversion.
// Example:
// if (material.GetFloat(""_VERTEX_COLORS"") > 0.5f) material.EnableKeyword(""_VERTEX_COLORS_ON"");
ShaderGraphHelpers.ValidateMaterialKeywords(material);
return true;
}
}
";
}
#endif
}
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ad1a4409c80a9004781468cca77d6224
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,102 @@
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace UnityGLTF
{
internal static class HumanoidSetup
{
private static MethodInfo _SetupHumanSkeleton;
internal static Avatar AddAvatarToGameObject(GameObject gameObject)
{
HumanDescription description = AvatarUtils.CreateHumanDescription(gameObject);
var bones = description.human;
SetupHumanSkeleton(gameObject, ref bones, out var skeletonBones, out var hasTranslationDoF);
description.human = bones;
description.skeleton = skeletonBones;
description.hasTranslationDoF = hasTranslationDoF;
Avatar avatar = AvatarBuilder.BuildHumanAvatar(gameObject, description);
avatar.name = "Avatar";
if (!avatar.isValid)
{
Object.DestroyImmediate(avatar);
return null;
}
var animator = gameObject.GetComponent<Animator>();
if (animator) animator.avatar = avatar;
return avatar;
}
private static void SetupHumanSkeleton(
GameObject modelPrefab,
ref HumanBone[] humanBoneMappingArray,
out SkeletonBone[] skeletonBones,
out bool hasTranslationDoF)
{
_SetupHumanSkeleton = typeof(AvatarSetupTool).GetMethod(nameof(SetupHumanSkeleton), (BindingFlags)(-1));
skeletonBones = Array.Empty<SkeletonBone>();
hasTranslationDoF = false;
_SetupHumanSkeleton?.Invoke(null, new object[]
{
modelPrefab,
humanBoneMappingArray,
skeletonBones,
hasTranslationDoF
});
}
// AvatarSetupTools
// AvatarBuilder.BuildHumanAvatar
// AvatarConfigurationStage.CreateStage
// AssetImporterTabbedEditor
// ModelImporterRigEditor
#if TESTING
[MenuItem("Tools/Copy Hierarchy Array")]
static void _Copy(MenuCommand command)
{
var gameObject = Selection.activeGameObject;
var sb = new System.Text.StringBuilder();
void Traverse(Transform tr)
{
sb.AppendLine(tr.name);
foreach (Transform child in tr)
{
Traverse(child);
}
}
Traverse(gameObject.transform);
EditorGUIUtility.systemCopyBuffer = sb.ToString();
}
[MenuItem("Tools/Setup Humanoid")]
static void _Do(MenuCommand command)
{
var gameObject = Selection.activeGameObject;
// SetupHumanSkeleton(go, ref humanBoneMappingArray, out var skeletonBones, out var hasTranslationDoF);
AddAvatarToGameObject(gameObject);
}
[MenuItem("Tools/Open Avatar Editor")]
static void _OpenEditor(MenuCommand command)
{
var gameObject = Selection.activeGameObject;
var avatar = gameObject.GetComponent<Animator>().avatar;
var e = (AvatarEditor) Editor.CreateEditor(avatar, typeof(AvatarEditor));
e.m_CameFromImportSettings = true;
Selection.activeObject = e;
e.SwitchToEditMode();
}
#endif
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 977986ddaa6e7594c81ccb48155a39a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,3 @@
{
"reference": "GUID:343deaaf83e0cee4ca978e7df0b80d21"
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 9c9262dcd4069cd4aafbfe7eabf0bf41
AssemblyDefinitionReferenceImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;
[assembly: InternalsVisibleTo("UnityGLTFEditor")]
namespace UnityGLTF
{
internal class UnityGLTFTabbedEditor : AssetImporterTabbedEditor
{
private readonly List<GltfAssetImporterTab> _tabs = new List<GltfAssetImporterTab>();
protected void AddTab(GltfAssetImporterTab tab)
{
if (!_tabs.Contains(tab)) _tabs.Add(tab);
tabs = _tabs.Select(x => (BaseAssetImporterTabUI) x).ToArray();
m_TabNames = _tabs.Select(t => t.Label).ToArray();
}
public GltfAssetImporterTab GetTab(int index)
{
if (_tabs == null || _tabs.Count < 1) return null;
if (index < 0) index = 0;
if (index >= _tabs.Count) index = _tabs.Count - 1;
return _tabs[index];
}
public override void OnEnable() => base.OnEnable();
}
internal class GltfAssetImporterTab : BaseAssetImporterTabUI
{
internal readonly string Label;
private readonly Action _tabGui;
public GltfAssetImporterTab(AssetImporterEditor panelContainer, string label, Action tabGui) : base(panelContainer)
{
this.Label = label;
this._tabGui = tabGui;
}
internal override void OnEnable() { }
public override void OnInspectorGUI() => _tabGui?.Invoke();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 198f536c3cf84dfe9d5617d32d40d7b0
timeCreated: 1678788492
@@ -0,0 +1,25 @@
using UnityEngine;
namespace UnityGLTF
{
public interface IUnityGltfShaderUpgradeMeta
{
Shader SourceShader { get; }
bool IsUnlit { get; }
bool IsTransparent { get; }
bool IsDoublesided { get; }
}
public class UnityGltfShaderUpgradeMeta : ScriptableObject
{
public Shader sourceShader;
public bool isTransparent = false;
public bool isDoublesided = false;
internal string GenerateNameString()
{
var isUnlit = sourceShader && sourceShader.name.Contains("Unlit");
return (isTransparent ? "_tr" : "") + (isDoublesided ? "_ds" : "") + (isUnlit ? "_unlit" : "");
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 26fa35d7d798408bb796a50daa5a8a6f
timeCreated: 1677690411