graywolf69

Create/Delete file

Mar 6th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. public void CreateNewFile (string fileName) {
  2.         File.Create (Application.streamingAssetsPath + "/" + fileName + ".lua"); //creates a new file
  3.     }
  4.  
  5.     public void DeleteFile (int index) {
  6.         //Debug.Log (index);
  7.         File.Delete (Application.streamingAssetsPath + "/" + files[index].EditButton.transform.GetChild (0).GetComponent<Text> ().text + ".lua"); //deletes the .lua file
  8.         File.Delete (Application.streamingAssetsPath + "/" + files[index].EditButton.transform.GetChild (0).GetComponent<Text> ().text + ".meta"); //deletes the accompanying .meta file
  9.         foreach (Transform child in contentArea) {
  10.             if (child != contentArea.GetChild(0)) {
  11.                 GameObject.Destroy (child.gameObject); //destroys the UI elements that point to files
  12.             }
  13.         }
  14.         currentList.Clear (); //clearing these two lists allows the remaining files in the streaming assets folder to be regenerated in the UI after clearing all elements, with correctly ordered file id's.
  15.         files.Clear ();
  16.     }
Advertisement
Add Comment
Please, Sign In to add comment