legendxs

Search directories for buddy

Mar 10th, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.IO;
  3. using UnityEditor;
  4. using UnityEngine;
  5.  
  6. public class Synchronize : EditorWindow
  7. {
  8.     [MenuItem("Ultimate MMORPG Kit/Synchronize NPC")]
  9.     public static void ShowWindow()
  10.     {
  11.         EditorWindow.GetWindow(typeof(Synchronize));
  12.         isPositive = false;
  13.         path = string.Empty;
  14.     }
  15.    
  16.     string[] appPath = Application.dataPath.Split('/');
  17.     static string path = string.Empty;
  18.     string[] client2;
  19.     static bool isPositive;
  20.     string fileS = string.Empty;
  21.     string pathS = Application.dataPath + "/UMK_Files/NPCfile.umk";
  22.     bool isOn;
  23.    
  24.     void OnGUI()
  25.     {
  26.         if(!isPositive)
  27.         {
  28.             for(int i = 0; i < appPath.Length - 3; i++)
  29.             {
  30.                 path += appPath[i]  + "/";
  31.             }
  32.  
  33.             isPositive = true;
  34.         }
  35.  
  36.         GUILayout.Space(10);
  37.         if(GUILayout.Button("Synchronize NPCs", GUILayout.Width(350), GUILayout.Height(40)))
  38.         {
  39.             client2 = Directory.GetFiles(path, "NPCfileC.umk", SearchOption.AllDirectories);
  40.             isOn = true;
  41.             if(client2.Length > 0)
  42.             {
  43.                 isOn = false;
  44.                 fileS = client2[0];
  45.                 string str1;
  46.  
  47.                 using (System.IO.StreamReader reader = System.IO.File.OpenText(pathS))
  48.                 {
  49.                     str1 = reader.ReadToEnd();
  50.                 }
  51.  
  52.                 using (System.IO.StreamWriter file = new System.IO.StreamWriter(fileS))
  53.                 {              
  54.                     file.Write(str1);
  55.                 }
  56.             }
  57.         }
  58.  
  59.         if(client2 != null)
  60.         {
  61.             if(client2.Length == 0 && isOn)
  62.             {
  63.                 GUILayout.Label("Set the NPC Editor in the Client's Project firstly!", EditorStyles.boldLabel);    
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment