Example #1
0
        public static void CreatePrefabFromXml(string xmlPath)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(xmlPath);
            XmlNode root = xml.DocumentElement;

            string path     = root.SelectSingleNode("Path").InnerText;
            string fileName = Path.GetFileNameWithoutExtension(xmlPath);
            string fullPath = Path.Combine(path, fileName + ".prefab");

            if (PrefabExists(fileName))
            {
                SmallLogger.Log(SmallLogger.LogType.PreImport, "Prefab '" + fileName + "' already exists.");
            }
            else
            {
                GameObject prefab = new GameObject();
                prefab.name = fileName;

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                SmallLogger.Log(SmallLogger.LogType.PreImport, "Creating prefab '" + fileName + "' from xml '" + xmlPath + "'");

                PrefabUtility.SaveAsPrefabAsset(prefab, fullPath);
                GameObject.DestroyImmediate(prefab);
            }

            // Update the created asset to ensure we trigger the 'OnPostprocessAllAssets' method
            AssetDatabase.ImportAsset(fullPath);
        }
Example #2
0
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            // Post import all assets if dependecies can be loaded
            List <string> toDelete = new List <string>();

            foreach (KeyValuePair <string, AAssetImporter> item in _importers)
            {
                if (item.Value.CanLoadDependencies())
                {
                    SmallLogger.Log(SmallLogger.LogType.AssetPostProcessor, "Post import asset: " + item.Key);
                    item.Value.OnPostImport(item.Key);
                    toDelete.Add(item.Key);
                }
            }

            // Delete imported assets
            foreach (string key in toDelete)
            {
                _importers.Remove(key);
            }

            SmallLogger.Log(SmallLogger.LogType.Dependency, _importers.Count + " asset(s) waiting for dependencies");
            foreach (KeyValuePair <string, AAssetImporter> item in _importers)
            {
                SmallLogger.Log(SmallLogger.LogType.Dependency, Path.GetFileName(item.Key) + " -> " + item.Value.ToString());
            }
        }
Example #3
0
        public static Material CreateMaterialFromXml(string xmlPath)
        {
            XmlDocument xml = new XmlDocument();

            xml.Load(xmlPath);
            XmlNode root = xml.DocumentElement;

            string fileName = Path.GetFileNameWithoutExtension(xmlPath);
            string path     = Path.Combine(root.SelectSingleNode("Path").InnerText, fileName + ".mat");

            // If the material does not exists, we create it
            bool     isCreating = false;
            Material material   = AssetDatabase.LoadAssetAtPath <Material>(path);

            if (material == null)
            {
                isCreating = true;
                material   = new Material(Shader.Find("Standard"));
                AssetDatabase.CreateAsset(material, path);
            }

            // Try to set the shader
            XmlNode shaderNode = root.SelectSingleNode("Shader");
            string  shaderName = "Standard";

            if (shaderNode != null)
            {
                shaderName = root.SelectSingleNode("Shader").InnerText;
            }
            else
            {
                SmallLogger.LogWarning(SmallLogger.LogType.PreImport, "Shader name not found in material '" + fileName + "'. The material is probably missing a group node.");
            }

            Shader shader = GetShaderFromName(shaderName);

            if (shader != null)
            {
                material.shader = shader;
                SmallLogger.Log(SmallLogger.LogType.PreImport, (isCreating ? "Creating" : "Loading") + " material '" + fileName + "' from xml '" + xmlPath + "' using shader '" + shaderName + "'");
            }
            else
            {
                SmallLogger.Log(SmallLogger.LogType.PreImport, (isCreating ? "Creating" : "Loading") + " material '" + fileName + "'from xml '" + xmlPath + "'. Shader name is invalid '" + shaderName + "'");
            }

            return(material);
        }
Example #4
0
        void OnGUI()
        {
            GUILayout.Label("Small Importer:", EditorStyles.boldLabel);
            prefixPrefab = EditorGUILayout.TextField("Prefix Identification", prefixPrefab);
            logMask      = (SmallLogger.LogType)EditorGUILayout.MaskField("Log", (int)logMask, Enum.GetNames(typeof(SmallLogger.LogType)));

            if (GUILayout.Button("Refresh SUBlime"))
            {
                SmallLogger.Log(SmallLogger.LogType.Debug, "Sublime refreshed.");
                SmallAssetPostprocessor.Reset();
            }

            // Save in EditorPlayerPrefs
            EditorPrefs.SetString("SBI_prefixPrefab", prefixPrefab);
            EditorPrefs.SetInt("SBI_log", (int)logMask);
        }
Example #5
0
        public void AddDependency <T>(string assetPath)
        {
            bool            duplicate     = false;
            AssetDependency newDependency = new AssetDependency(assetPath, typeof(T));

            foreach (AssetDependency dependency in _dependencies)
            {
                if (dependency.IsEqual(newDependency))
                {
                    duplicate = true;
                }
            }

            if (!duplicate)
            {
                SmallLogger.Log(SmallLogger.LogType.Dependency, "Add dependency '" + newDependency.ToString() + "' for asset '" + System.IO.Path.GetFileName(assetPath) + "'");
                _dependencies.Add(newDependency);
            }
        }
Example #6
0
        void OnPreprocessAsset()
        {
            // During this phase we create the needed assets without linking them together
            AAssetImporter importer = GetAssetImporter(assetPath);

            if (importer != null)
            {
                if (!_importers.ContainsKey(assetPath))
                {
                    importer.CreateDependencies(assetPath);
                    SmallLogger.Log(SmallLogger.LogType.AssetPostProcessor, "Importing asset: " + Path.GetFileName(assetPath) + " with " + importer.DependencyCount + (importer.DependencyCount == 1 ? " dependency" : " dependencies"));
                    importer.OnPreImport(assetPath);
                    _importers.Add(assetPath, importer);
                }
                else
                {
                    SmallLogger.LogError(SmallLogger.LogType.AssetPostProcessor, "Asset already in the list : " + assetPath);
                }
            }
        }