private void AddPair(TKey key, TValue value) { try { if (typeof(TKey) == typeof(string)) { var str = key as string; if (str == null) { key = (TKey)(object)string.Empty; } } kvpList.Add(key, value); } catch (ArgumentException e) { Log(e.Message); } }
public override void OnRightGUI() { if (gui.SelectionButton()) { Func <string[]> getScenes = () => Directory.GetFiles("Assets", "*.unity", SearchOption.AllDirectories) .Select(f => f.Substring(f.IndexOf("Assets") + 6).RemoveExtension()) .ToArray(); Func <string, string> getSceneName = path => path.Substring(path.Replace('\\', '/').LastIndexOf('/') + 1); var dictionary = new KVPList <string, string>(); var allScenes = getScenes(); foreach (var s in allScenes) { dictionary.Add(getSceneName(s), s); } Func <Func <string[]>, string, Tab <string> > sceneTab = (scenes, title) => new Tab <string>( @getValues: scenes, @getCurrent: () => dictionary.ContainsKey(memberValue) ? dictionary[memberValue] : memberValue, @setTarget: s => memberValue = getSceneName(s), @getValueName: s => s, @title: title ); var buildScenes = EditorBuildSettings.scenes.Select(s => s.path); SelectionWindow.Show("Select scene", sceneTab(getScenes, "All"), sceneTab(getScenes().Where(s => buildScenes.Any(bs => Regex.Replace(bs, "/", "\\").Contains(s))).ToArray, "Build") ); } }