Пример #1
0
        static void OnGUIMaterial(GltfScriptedImporter importer, GltfParser parser)
        {
            var canExtract = !importer.GetExternalObjectMap().Any(x => x.Value is Material || x.Value is Texture2D);

            using (new TmpGuiEnable(canExtract))
            {
                if (GUILayout.Button("Extract Materials And Textures ..."))
                {
                    importer.ExtractMaterialsAndTextures();
                }
            }

            // ObjectMap
            s_foldMaterials = EditorGUILayout.Foldout(s_foldMaterials, "Remapped Materials");
            if (s_foldMaterials)
            {
                DrawRemapGUI <UnityEngine.Material>(importer, parser.GLTF.materials.Select(x => x.name));
            }

            s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures");
            if (s_foldTextures)
            {
                DrawRemapGUI <UnityEngine.Texture2D>(importer, parser.EnumerateTextures().Select(x => x.Name));
            }

            if (GUILayout.Button("Clear"))
            {
                importer.ClearExternalObjects <UnityEngine.Material>();
                importer.ClearExternalObjects <UnityEngine.Texture2D>();
            }
        }
Пример #2
0
        static void DrawRemapGUI <T>(GltfScriptedImporter importer, IEnumerable <string> names) where T : UnityEngine.Object
        {
            EditorGUI.indentLevel++;
            var map = importer.GetExternalObjectMap()
                      .Select(x => (x.Key.name, x.Value as T))
                      .Where(x => x.Item2 != null)
                      .ToDictionary(x => x.Item1, x => x.Item2)
            ;

            foreach (var name in names)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new System.ArgumentNullException();
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(name);
                map.TryGetValue(name, out T value);
                var asset = EditorGUILayout.ObjectField(value, typeof(T), true) as T;
                if (asset != value)
                {
                    importer.SetExternalUnityObject(new AssetImporter.SourceAssetIdentifier(value), asset);
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUI.indentLevel--;
        }
Пример #3
0
 static void OnGUIAnimation(GltfScriptedImporter importer, GltfParser parser)
 {
     foreach (var a in parser.GLTF.animations)
     {
         GUILayout.Label(a.name);
     }
 }
        public override void OnEnable()
        {
            base.OnEnable();

            m_importer = target as GltfScriptedImporter;
            m_parser   = new GltfParser();
            m_parser.ParsePath(m_importer.assetPath);
        }
        public override void OnEnable()
        {
            base.OnEnable();

            m_importer = target as GltfScriptedImporter;
            m_data     = new AmbiguousGltfFileParser(m_importer.assetPath).Parse();

            var materialGenerator = new GltfMaterialDescriptorGenerator();
            var materialKeys      = m_data.GLTF.materials.Select((_, i) => materialGenerator.Get(m_data, i).SubAssetKey);
            var textureKeys       = new GltfTextureDescriptorGenerator(m_data).Get().GetEnumerable().Select(x => x.SubAssetKey);

            m_materialEditor  = new RemapEditorMaterial(materialKeys.Concat(textureKeys), GetEditorMap, SetEditorMap);
            m_animationEditor = new RemapEditorAnimation(AnimationImporterUtil.EnumerateSubAssetKeys(m_data.GLTF), GetEditorMap, SetEditorMap);
        }