Exemplo n.º 1
0
        public static Type Create <Type>(string path, bool createPath = true) where Type : ScriptableObject
        {
            if (path.IsNull())
            {
                return(default(Type));
            }
            var name    = path.GetPathTerm();
            var useName = typeof(Type).Name == "ScriptableObject";
            var folder  = Application.dataPath + Singleton.storagePath;

            path = folder.GetAssetPath() + path;
            if (createPath)
            {
                File.Create(folder);
            }
            ProxyEditor.ImportAsset(folder.GetAssetPath());
            try{
                ScriptableObject instance = useName ? ScriptableObject.CreateInstance(name) : ScriptableObject.CreateInstance <Type>();
                ProxyEditor.CreateAsset(instance, path);
                ProxyEditor.RefreshAssets();
                return(instance.As <Type>());
            }
            catch { Log.Warning("[Utility] No scriptableObject exists named -- " + name + ".asset"); }
            return(null);
        }
Exemplo n.º 2
0
        public Shader Save(string path, string menuPath)
        {
            string output = this.Generate(menuPath);
            string folder = path.Substring(0, path.LastIndexOf("/")) + "/";

            File.Create(folder);
            using (StreamWriter file = new StreamWriter(path, false)){
                file.Write(output);
            }
            ProxyEditor.RefreshAssets();
            return(Shader.Find(menuPath));
        }
Exemplo n.º 3
0
 public static void RefreshEditor()
 {
     if (VariableMaterial.updates.GetInvocationList().Length > 1)
     {
         ProxyEditor.StartAssetEditing();
         VariableMaterial.writes();
         ProxyEditor.StopAssetEditing();
         //ProxyEditor.SaveAssets();
         ProxyEditor.RefreshAssets();
         File.Refresh();
         VariableMaterial.updates();
     }
     VariableMaterial.updates = () => {};
     VariableMaterial.writes  = () => {};
     VariableMaterial.dirty   = true;
     VariableMaterial.delay   = false;
     ProxyEditor.RebuildInspectors();
 }
Exemplo n.º 4
0
        public static void Step(object collection, int itemIndex)
        {
            var  materials = (FileData[])collection;
            var  file      = materials[itemIndex];
            bool last      = itemIndex == materials.Length - 1;

            Stepper.title   = "Updating " + materials.Length + " Materials";
            Stepper.message = "Updating material : " + file.name;
            string text           = file.ReadText();
            string copy           = text;
            int    index          = 0;
            bool   changed        = false;
            bool   removePrevious = false;
            string guid           = text.Parse("guid: ", ",");
            string shaderPath     = ProxyEditor.GetAssetPath(guid);

            if (!shaderPath.IsEmpty())
            {
                Material material = file.GetAsset <Material>();
                Shader   shader   = File.GetAsset <Shader>(shaderPath, false);
                if (shader != null)
                {
                    int propertyCount = ProxyEditor.GetPropertyCount(shader);
                    Dictionary <string, string> properties = new Dictionary <string, string>();
                    for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
                    {
                        string name = ProxyEditor.GetPropertyName(shader, propertyIndex);
                        properties[name] = ProxyEditor.GetPropertyType(shader, propertyIndex).ToName();
                    }
                    string keywords = text.Parse("m_ShaderKeywords:", "m_").Trim("[]");
                    if (!keywords.IsEmpty())
                    {
                        string keywordsCleaned = keywords;
                        foreach (string keyword in keywords.Replace("\n   ", "").Split(" "))
                        {
                            if (!properties.ContainsKey(keyword.Split("_")[0], true))
                            {
                                keywordsCleaned = keywordsCleaned.Replace(" " + keyword, "");
                                changed         = true;
                            }
                        }
                        copy = copy.Replace(keywords, keywordsCleaned);
                    }
                    while (true)
                    {
                        int nextIndex = text.IndexOf("data:", index + 5);
                        if (removePrevious)
                        {
                            int    nextGroup = text.IndexOf("\n    m", index);
                            int    count     = nextGroup != -1 && nextGroup < nextIndex ? nextGroup - index : nextIndex - index;
                            string section   = nextIndex < 0 ? text.Substring(index) : text.Substring(index, count);
                            copy           = copy.Replace(section, "");
                            removePrevious = false;
                            changed        = true;
                        }
                        if (nextIndex == -1)
                        {
                            break;
                        }
                        index = nextIndex;
                        int    keywordStart = text.IndexOf("name: ", index) + 6;
                        int    keywordEnd   = text.IndexOf("\n", keywordStart);
                        string name         = text.Substring(keywordStart, keywordEnd - keywordStart);
                        if (name.IsEmpty())
                        {
                            continue;
                        }
                        bool emptyTexture = properties.ContainsKey(name) && properties[name] == "Texture" && material.GetTexture(name) == null;
                        removePrevious = !properties.ContainsKey(name) || emptyTexture;
                        //if(removePrevious){Log.Show("[MaterialCleaner] : Removing " + name + " from " + file.fullName);}
                    }
                    if (changed)
                    {
                        MaterialCleaner.changes = true;
                        Log.Show("[MaterialCleaner] : Cleaned unused serialized data " + file.fullName);
                        file.Write(copy);
                    }
                }
            }
            if (last)
            {
                if (!MaterialCleaner.changes)
                {
                    Log.Show("[MaterialCleaner] : All files already clean.");
                }
                else
                {
                    Log.Show("[MaterialCleaner] : Cleaned all materials.");
                }
                Call.Delay(() => ProxyEditor.RefreshAssets(), 1);
            }
        }