示例#1
0
        private static void AddDrawingDLLDefineToRSP(string rsp_path)
        {
            string rsp_data = FileHelper.ReadFileIntoString(rsp_path);

            rsp_data += RSP_DRAWING_DLL_DEFINE_CODE;
            FileHelper.WriteStringToFile(rsp_data, rsp_path);
        }
        private static void Save()
        {
            Dictionary <string, List <Material> > save_linked_materials = new Dictionary <string, List <Material> >(linked_materials);

            List <string[]>  save_structre          = new List <string[]>();
            HashSet <string> has_already_been_saved = new HashSet <string>();

            foreach (KeyValuePair <string, List <Material> > link in save_linked_materials)
            {
                if (has_already_been_saved.Contains(link.Key))
                {
                    continue;
                }
                string[] value = new string[link.Value.Count + 1];
                value[0] = System.Text.RegularExpressions.Regex.Split(link.Key, @"###")[1];
                int i = 1;
                foreach (Material m in link.Value)
                {
                    string guid = UnityHelper.GetGUID(m);
                    has_already_been_saved.Add(guid + "###" + value[0]);
                    value[i++] = guid;
                }
                save_structre.Add(value);
            }
            FileHelper.WriteStringToFile(Parser.ObjectToString(save_structre), PATH.LINKED_MATERIALS_FILE);
        }
        private static void InstallModuleFilesDownloaded(Module module, string temp_dir)
        {
            string modules_path = "Assets/thry_modules";

            if (!Directory.Exists(modules_path))
            {
                AssetDatabase.CreateFolder("Assets", "thry_modules");
            }
            string install_path = modules_path + "/" + module.id;

            module.installed_module = module.available_module;
            string guid = AssetDatabase.CreateFolder(modules_path, module.id);

            SaveModuleLocationData(module, guid);

            FileHelper.WriteStringToFile(Parser.ObjectToString(module.available_module), temp_dir + "/module.json");
            foreach (string d in Directory.GetDirectories(temp_dir))
            {
                Directory.Move(d, install_path + "/" + Path.GetFileName(d));
            }
            foreach (string f in Directory.GetFiles(temp_dir))
            {
                File.Move(f, install_path + "/" + Path.GetFileName(f));
            }
            Directory.Delete(temp_dir);
            AssetDatabase.Refresh();
        }
示例#4
0
 private static void Save(string data, string add_string)
 {
     string path = AssetDatabase.GetAssetPath(Selection.activeObject);
     path = path.RemoveFileName() + path.RemovePath().RemoveFileExtension() + add_string;
     Debug.Log(path);
     FileHelper.WriteStringToFile(data, path);
     AssetDatabase.Refresh();
 }
示例#5
0
        private static void Save(string data, string add_string)
        {
            string path = AssetDatabase.GetAssetPath(Selection.activeObject);

            path = Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + add_string;
            FileHelper.WriteStringToFile(data, path);
            AssetDatabase.Refresh();
            EditorGUIUtility.PingObject(AssetDatabase.LoadMainAssetAtPath(path));
        }
示例#6
0
        private static void Save(string data, string add_string)
        {
            string path = AssetDatabase.GetAssetPath(Selection.activeObject);

            path = Path.GetDirectoryName(path) + "/" + Path.GetFileNameWithoutExtension(path) + add_string;
            Debug.Log(path);
            FileHelper.WriteStringToFile(data, path);
            AssetDatabase.Refresh();
        }
示例#7
0
        private void removeProperty(string path, string property, string value)
        {
            string       shaderCode = FileHelper.ReadFileIntoString(path);
            string       pattern    = @"\r?\n.*" + Regex.Escape(property) + " ?= ?" + value;
            RegexOptions options    = RegexOptions.Multiline;

            shaderCode = Regex.Replace(shaderCode, pattern, "", options);

            FileHelper.WriteStringToFile(shaderCode, path);
        }
示例#8
0
        private static void addProperty(string path, string property, string value)
        {
            string       shaderCode = FileHelper.ReadFileIntoString(path);
            string       pattern    = @"Properties.*\n?\s*{";
            RegexOptions options    = RegexOptions.Multiline;

            shaderCode = Regex.Replace(shaderCode, pattern, "Properties \r\n  {" + " \r\n      " + property + "=" + value, options);

            FileHelper.WriteStringToFile(shaderCode, path);
        }
示例#9
0
        private void revertEditor(string path)
        {
            string shaderCode = FileHelper.ReadFileIntoString(path);
            string pattern    = @"//originalEditor.*\n";
            Match  m          = Regex.Match(shaderCode, pattern);

            if (m.Success)
            {
                string orignialEditor = m.Value.Replace("//originalEditor", "");
                pattern    = @"//originalEditor.*\n.*\n";
                shaderCode = Regex.Replace(shaderCode, pattern, orignialEditor);
                FileHelper.WriteStringToFile(shaderCode, path);
            }
        }
        //copys og shader and changed render queue and name in there
        public static Shader createRenderQueueShaderIfNotExists(Shader defaultShader, int renderQueue, bool import)
        {
            string newShaderName     = ".differentQueues/" + defaultShader.name + "-queue" + renderQueue;
            Shader renderQueueShader = Shader.Find(newShaderName);

            if (renderQueueShader != null)
            {
                return(renderQueueShader);
            }

            string defaultPath      = AssetDatabase.GetAssetPath(defaultShader);
            string shaderCode       = FileHelper.ReadFileIntoString(defaultPath);
            string pattern          = @"""Queue"" ?= ?""\w+(\+\d+)?""";
            string replacementQueue = "Background+" + (renderQueue - 1000);

            if (renderQueue == 1000)
            {
                replacementQueue = "Background";
            }
            else if (renderQueue < 1000)
            {
                replacementQueue = "Background-" + (1000 - renderQueue);
            }
            shaderCode = Regex.Replace(shaderCode, pattern, "\"Queue\" = \"" + replacementQueue + "\"");
            pattern    = @"Shader *""(\w|\/|\.)+";
            string ogShaderName = Regex.Match(shaderCode, pattern).Value;

            ogShaderName = Regex.Replace(ogShaderName, @"Shader *""", "");
            string newerShaderName = ".differentQueues/" + ogShaderName + "-queue" + renderQueue;

            shaderCode = Regex.Replace(shaderCode, pattern, "Shader \"" + newerShaderName);
            pattern    = @"#include\s*""(?!(Lighting.cginc)|(AutoLight)|(UnityCG)|(UnityShaderVariables)|(HLSLSupport)|(TerrainEngine))";
            shaderCode = Regex.Replace(shaderCode, pattern, "#include \"../", RegexOptions.Multiline);
            string[] pathParts = defaultPath.Split('/');
            string   fileName  = pathParts[pathParts.Length - 1];
            string   newPath   = defaultPath.Replace(fileName, "") + "_differentQueues";

            Directory.CreateDirectory(newPath);
            newPath = newPath + "/" + fileName.Replace(".shader", "-queue" + renderQueue + ".shader");
            FileHelper.WriteStringToFile(shaderCode, newPath);
            ShaderImportFixer.scriptImportedAssetPaths.Add(newPath);
            if (import)
            {
                AssetDatabase.ImportAsset(newPath);
            }

            return(Shader.Find(newerShaderName));
        }
 private static void InstallModule(string url, string name)
 {
     EditorUtility.DisplayProgressBar(name + " download progress", "", 0);
     WebHelper.DownloadStringASync(url, delegate(string s)
     {
         if (s.StartsWith("404"))
         {
             Debug.LogWarning(s);
             return;
         }
         //Debug.Log(s);
         ModuleInfo module_info   = Parser.ParseToObject <ModuleInfo>(s);
         string thry_modules_path = ThryEditor.GetThryEditorDirectoryPath();
         string temp_path         = "temp_" + name;
         if (thry_modules_path == null)
         {
             thry_modules_path = "Assets";
         }
         thry_modules_path  += "/thry_modules";
         string install_path = thry_modules_path + "/" + name;
         string base_url     = url.RemoveFileName();
         FileHelper.WriteStringToFile(s, temp_path + "/module.json");
         int i = 0;
         foreach (string f in module_info.files)
         {
             //Debug.Log(base_url + f);
             WebHelper.DownloadFileASync(base_url + f, temp_path + "/" + f, delegate(string data)
             {
                 i++;
                 EditorUtility.DisplayProgressBar("Downloading files for " + name, "Downloaded " + base_url + f, (float)i / module_info.files.Count);
                 if (i == module_info.files.Count)
                 {
                     EditorUtility.ClearProgressBar();
                     if (!Directory.Exists(thry_modules_path))
                     {
                         Directory.CreateDirectory(thry_modules_path);
                     }
                     Directory.Move(temp_path, install_path);
                     AssetDatabase.Refresh();
                 }
             });
         }
     });
 }
示例#12
0
        private void replaceEditorInShader(string path, string newEditor)
        {
            string shaderCode = FileHelper.ReadFileIntoString(path);
            string pattern    = @"CustomEditor ?.*\n";
            Match  m          = Regex.Match(shaderCode, pattern);

            if (m.Success)
            {
                string oldEditor = "//originalEditor" + m.Value;
                shaderCode = Regex.Replace(shaderCode, pattern, oldEditor + "CustomEditor \"" + newEditor + "\"\r\n");
            }
            else
            {
                pattern = @"SubShader.*\r?\n?\s*{";
                RegexOptions options = RegexOptions.Multiline;
                shaderCode = Regex.Replace(shaderCode, pattern, "CustomEditor \"" + newEditor + "\" \r\n    SubShader \r\n  {", options);
            }

            FileHelper.WriteStringToFile(shaderCode, path);
        }
示例#13
0
        public static void backupSingleMaterial(Material m)
        {
            if (restoring_in_progress)
            {
                return;
            }
            string[] mats = new string[0];
            if (!File.Exists(PATH.MATERIALS_BACKUP_FILE))
            {
                File.CreateText(PATH.MATERIALS_BACKUP_FILE).Close();
            }
            else
            {
                mats = FileHelper.ReadFileIntoString(PATH.MATERIALS_BACKUP_FILE).Split(new string[] { "\n" }, System.StringSplitOptions.None);
            }
            bool   updated   = false;
            string matGuid   = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(m.GetInstanceID()));
            string newString = "";

            for (int mat = 0; mat < mats.Length; mat++)
            {
                if (mats[mat].Contains(matGuid))
                {
                    updated    = true;
                    newString += matGuid + ":" + ShaderHelper.getDefaultShaderName(m.shader.name) + ":" + m.renderQueue + "\r\n";
                }
                else
                {
                    newString += mats[mat] + "\n";
                }
            }
            if (!updated)
            {
                newString += matGuid + ":" + ShaderHelper.getDefaultShaderName(m.shader.name) + ":" + m.renderQueue;
            }
            else
            {
                newString = newString.Substring(0, newString.LastIndexOf("\n"));
            }
            FileHelper.WriteStringToFile(newString, PATH.MATERIALS_BACKUP_FILE);
        }
示例#14
0
 public void save()
 {
     FileHelper.WriteStringToFile(JsonUtility.ToJson(this), PATH_CONFIG_FILE);
 }
示例#15
0
 public Config Save()
 {
     FileHelper.WriteStringToFile(JsonUtility.ToJson(this), PATH_CONFIG_FILE);
     return(this);
 }
 private static void Save()
 {
     FileHelper.WriteStringToFile(Parser.ObjectToString(thry_editor_shaders), PATH.THRY_EDITOR_SHADERS);
 }