public void writePNGField (StreamWriter wr, string path, string textureName, int tabs, EditorPNG p, bool dark) { wr.WriteLine (Tabs (tabs) + "if(" + textureName + " == null)"); wr.WriteLine (Tabs (tabs) + "{"); wr.WriteLine (Tabs (tabs + 1) + textureName + " = EditorGUIUtility.Load (\"" + p.getPath (dark) + "\") as Texture2D;"); wr.WriteLine (Tabs (tabs) + "}"); wr.WriteLine (Tabs (tabs) + "EditorGUILayout.BeginHorizontal ();"); wr.WriteLine (Tabs (tabs) + "guitContent.image = " + textureName + ";"); wr.WriteLine (Tabs (tabs) + "EditorGUILayout.TextField(\"" + p.getPath (dark) + "\");"); wr.WriteLine (Tabs (tabs) + "GUILayout.Label(guitContent);"); wr.WriteLine (Tabs (tabs) + "EditorGUILayout.EndHorizontal ();"); }
public Dictionary<string, object> generateTree (List<string> paths) { Dictionary<string, object> tree = new Dictionary<string, object> (); foreach (string path in paths) { if (string.IsNullOrEmpty (path)) { continue; } Texture2D texture = EditorGUIUtility.Load (path) as Texture2D; if (texture == null) { continue; } UnityEngine.Debug.Log ("adding: " + path); string[] components = path.Split ('/'); Dictionary<string, object> subDict = tree; int i = 0; while (i < components.Length - 1) { var comp = components [i]; if (! subDict.ContainsKey (comp)) { subDict [comp] = new Dictionary<string, object> (); subDict = subDict [comp] as Dictionary<string, object>; } else { if (subDict [comp].GetType () == typeof(Dictionary<string, object>)) { subDict = (Dictionary<string, object>)subDict [comp]; } else { Dispatch.Sync (() => { UnityEngine.Debug.LogError ("Unexpected type: " + subDict [comp].GetType ().ToString ()); }); } } i++; } string[] nameComponents = components [i].Split ('.'); int j = 0; while (j<nameComponents.Length -2) { var comp = nameComponents [j]; if (! subDict.ContainsKey (comp)) { subDict [comp] = new Dictionary<string, object> (); subDict = (Dictionary<string, object>)subDict [comp]; } else { if (subDict [comp].GetType () == typeof(Dictionary<string, object>)) { subDict = (Dictionary<string, object>)subDict [comp]; } else { Dispatch.Sync (() => { UnityEngine.Debug.LogError ("unexpected type 2: " + subDict [comp].GetType ().Name); }); } } j++; } string filename = nameComponents [j] + "_png"; bool darkVersion = false; darkVersion = filename.StartsWith ("d_"); if (darkVersion) { filename = filename.Substring (2); } object entry; if (! subDict.TryGetValue (filename, out entry)) { subDict [filename] = new EditorPNG (path, darkVersion); } else { EditorPNG e = (EditorPNG)entry; if (! e.darkVersion) { e.darkVersion = darkVersion; } } } Dispatch.Sync (() => { UnityEngine.Debug.Log (paths.Count); }); return tree; }