Exemplo n.º 1
0
    public static void Import(FileInfo scriptFile)
    {
        if (scriptFile.Name != "NewBehaviourScript.cs")
        {
            throw new ArgumentException("Import needs a path to a NewBehaviorScript.cs file", "scriptFilePath");
        }
        string[] scriptLines = File.ReadAllLines(scriptFile.FullName);
        scriptFile.Delete();

        string newScriptFilename = EditorUtility.SaveFilePanel("Enter Script Name", scriptFile.DirectoryName, "NewScript", "cs");

        if (String.IsNullOrEmpty(newScriptFilename))
        {
            return;
        }

        FileInfo scriptFileInfo = new FileInfo(newScriptFilename);
        string   className      = scriptFileInfo.Name.Substring(0, scriptFileInfo.Name.Length - ".cs".Length);
        string   author         = EditorUserSettings.GetSetting("UserName");

        if (author == String.Empty)
        {
            author = "UserNameEmpty";
            EditorUserSettings.SetSetting("UserName", author);
            EditorUserSettings.SaveToDisk();
        }
        string date = DateTime.Now.ToShortDateString();

        StringBuilder processedScript = new StringBuilder();

        foreach (string line in scriptLines)
        {
            string newLine;
            newLine = line.Replace(mAuthorKey, author);
            newLine = newLine.Replace(mDateKey, date);
            newLine = newLine.Replace(mClassNameKey, className);
            newLine = newLine.Replace(mFileNameKey, scriptFileInfo.Name);

            processedScript.AppendLine(newLine);
        }

        File.WriteAllText(scriptFileInfo.FullName, processedScript.ToString());

        System.Threading.Thread.Sleep(100);         // Give textmate some time to notice if the file's in a project
        System.Diagnostics.Process.Start("open", scriptFileInfo.FullName);
    }
Exemplo n.º 2
0
 private void DrawSaveCancelButtons()
 {
     GUILayout.BeginHorizontal();
     try{
         GUILayout.FlexibleSpace();
         if (GUILayout.Button("Save", GUILayout.Width(64.0f)))
         {
             EditorUserSettings.SaveToDisk();
             this.Close();
         }
         GUILayout.Space(4.0f);
         if (GUILayout.Button("Cancel", GUILayout.Width(64.0f)))
         {
             EditorUserSettings.CancelPendingChanges();
             this.Close();
         }
     } finally {
         GUILayout.EndHorizontal();
     }
 }