Esempio n. 1
0
 public void SaveValues(KVPList kvps)
 {
     // Saving the given KVPList in the PersistSource
     if (_persistSource != null)
     {
         _persistSource.PersistValues(kvps);
     }
 }
Esempio n. 2
0
 public TValue GetValueOf(KVPList <Tkey, TValue> kvpList, Tkey key)
 {
     for (int i = 0; i < kvpList.Count; i++)
     {
         if (kvpList[i].Key.Equals(key))
         {
             return(kvpList[i].Value);
         }
     }
     return(default(TValue));
 }
        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")
                                     );
            }
        }
Esempio n. 4
0
        public ConfigValue GetValue(string key)
        {
            // Creating a new List and adding the key in the list
            IList <string> keyList = new List <string>(); keyList.Add(key);

            if (_persistSource != null)
            {
                KVPList kvpList = _persistSource.LoadValues(keyList); // Loading values from PersistSource using the list

                if (kvpList != null)                                  // If the loaded KVPList is not empty
                {
                    if (kvpList.Count == 1)                           // If the number of elements in the list is 1, return the Value (ConfigValue)
                    {
                        return(kvpList[0].Value);
                    }
                    else if (kvpList.Count > 1) // If the number of elements is more than 1, throw an exception
                    {
                        throw new Exception("ERROR! Key with Multiple Values!");
                    }
                }
            }

            return(new ConfigValue()); // If the none of the above conditions satisfy, return an empty object
        }
Esempio n. 5
0
        public override void OnGUI()
        {
            if (_invalidKeyType)
            {
                gui.HelpBox("Unsuported key type: {0}. Only Value-types and strings are, sorry!"
                            .FormatWith(typeof(TK)), MessageType.Error);
                return;
            }

            if (memberValue == null)
            {
                memberValue = new TD();
            }

            if (_kvpList == null)
            {
                _kvpList = new KVPList <TK, TV>();
            }
            else
            {
                _kvpList.Clear();
            }

            // Read
            {
                var iter = memberValue.GetEnumerator();
                while (iter.MoveNext())
                {
                    var key   = iter.Current.Key;
                    var value = iter.Current.Value;
                    _kvpList[key] = value;
                }
            }

            #if PROFILE
            Profiler.BeginSample("DictionaryDrawer Header");
            #endif

            using (gui.Horizontal())
            {
                foldout = gui.Foldout(displayText, foldout, Layout.sExpandWidth());

                if (!_isReadonly)
                {
                    gui.FlexibleSpace();

                    using (gui.State(_kvpList.Count > 0))
                    {
                        if (gui.ClearButton("dictionary"))
                        {
                            _kvpList.Clear();
                        }

                        if (gui.RemoveButton("last dictionary pair"))
                        {
                            _kvpList.RemoveFirst();
                        }
                    }

                    if (gui.AddButton("pair", MiniButtonStyle.ModRight))
                    {
                        AddNewPair();
                    }
                }
            }

            #if PROFILE
            Profiler.EndSample();
            #endif

            if (!foldout)
            {
                return;
            }

            if (memberValue.Count == 0)
            {
                using (gui.Indent())
                    gui.HelpBox("Dictionary is empty");
            }
            else
            {
                #if PROFILE
                Profiler.BeginSample("DictionaryDrawer Pairs");
                #endif
                using (gui.Indent())
                {
                    for (int i = 0; i < _kvpList.Count; i++)
                    {
                        var dKey   = _kvpList.Keys[i];
                        var dValue = _kvpList.Values[i];

                        #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer KVP assignments");
                        #endif

                        var pairStr  = FormatPair(dKey, dValue);
                        var entryKey = RuntimeHelper.CombineHashCodes(id, i, "entry");
                        foldouts[entryKey] = gui.Foldout(pairStr, foldouts[entryKey], Layout.sExpandWidth());

                        #if PROFILE
                        Profiler.EndSample();
                        #endif

                        if (!foldouts[entryKey])
                        {
                            continue;
                        }

                        #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer SinglePair");
                        #endif
                        using (gui.Indent())
                        {
                            var keyMember = GetElement(_keyElements, _kvpList.Keys, i, entryKey + 1);
                            gui.Member(keyMember, !_perKeyDrawing);

                            var valueMember = GetElement(_valueElements, _kvpList.Values, i, entryKey + 2);
                            gui.Member(valueMember, !_perValueDrawing);
                        }
                        #if PROFILE
                        Profiler.EndSample();
                        #endif
                    }
                }
                #if PROFILE
                Profiler.EndSample();
                #endif

                // Write
                {
                    memberValue.Clear();
                    for (int i = 0; i < _kvpList.Count; i++)
                    {
                        var key   = _kvpList.Keys[i];
                        var value = _kvpList.Values[i];
                        try
                        {
                            memberValue.Add(key, value);
                        }
                        catch (ArgumentException)
                        {
                            Log("Key already exists: " + key);
                        }
                    }
                }
            }
        }
        public override void OnGUI()
        {
            if (!(foldout = gui.Foldout(dictionaryName, foldout, Layout.sExpandWidth())))
            {
                return;
            }

            if (memberValue == null)
            {
                                #if DBG
                Log("Dictionary null " + dictionaryName);
                                #endif
                memberValue = new Dictionary <TKey, TValue>();
            }

            shouldRead |= (kvpList == null || memberValue.Count != kvpList.Count);

            if (shouldRead)
            {
                                #if DBG
                Log("Reading " + dictionaryName);
                                #endif
                kvpList    = memberValue.ToKVPList();
                shouldRead = false;
            }

            if (!Readonly)
            {
                                #if PROFILE
                Profiler.BeginSample("DictionaryDrawer Header");
                                #endif
                using (gui.Indent())
                {
                    var pStr   = FormatPair(addInfo.key, addInfo.value);
                    var addKey = id + "add";

                    using (gui.Horizontal())
                    {
                        foldouts[addKey] = gui.Foldout("Add pair:", foldouts[addKey], Layout.sWidth(65f));

                        gui.TextLabel(pStr);

                        using (gui.State(kvpList.Count > 0))
                        {
                            if (gui.ClearButton("entries"))
                            {
                                kvpList.Clear();
                                shouldWrite = true;
                            }

                            if (gui.RemoveButton("Last dictionary pair"))
                            {
                                kvpList.RemoveLast();
                                shouldWrite = true;
                            }
                        }

                        if (gui.AddButton("pair", MiniButtonStyle.ModRight))
                        {
                            AddPair(addInfo.key, addInfo.value);
                            shouldWrite = true;
                        }
                    }

                    if (foldouts[addKey])
                    {
                                                #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer AddingPair");
                                                #endif
                        using (gui.Indent())
                        {
                            gui.Member(addKeyInfo, attributes, ignoreAddArea || !perKeyDrawing);
                            gui.Member(addValueInfo, attributes, ignoreAddArea || !perValueDrawing);
                        }
                                                #if PROFILE
                        Profiler.EndSample();
                                                #endif
                    }
                }
                                #if PROFILE
                Profiler.EndSample();
                                #endif
            }

            if (kvpList.Count == 0)
            {
                gui.HelpBox("Dictionary is empty");
            }
            else
            {
                                #if PROFILE
                Profiler.BeginSample("DictionaryDrawer Pairs");
                                #endif
                using (gui.Indent())
                {
                    for (int i = 0; i < kvpList.Count; i++)
                    {
                        var dKey   = kvpList.Keys[i];
                        var dValue = kvpList.Values[i];

                        TValue val;
                        if (memberValue.TryGetValue(dKey, out val))
                        {
                            shouldRead |= !dValue.GenericEqual(val);
                        }

                                                #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer KVP assignments");
                                                #endif

                        var pairStr  = FormatPair(dKey, dValue);
                        var entryKey = id + i + "entry";
                        foldouts[entryKey] = gui.Foldout(pairStr, foldouts[entryKey], Layout.sExpandWidth());

                                                #if PROFILE
                        Profiler.EndSample();
                                                #endif

                        if (!foldouts[entryKey])
                        {
                            continue;
                        }

                                                #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer SinglePair");
                                                #endif
                        using (gui.Indent())
                        {
                            var keyMember = GetElement(keyElements, kvpList.Keys, i, entryKey + "key");
                            shouldWrite |= gui.Member(keyMember, !perKeyDrawing);

                            var valueMember = GetElement(valueElements, kvpList.Values, i, entryKey + "value");
                            shouldWrite |= gui.Member(valueMember, !perValueDrawing);
                        }
                                                #if PROFILE
                        Profiler.EndSample();
                                                #endif
                    }
                }
                                #if PROFILE
                Profiler.EndSample();
                                #endif

                shouldWrite |= memberValue.Count > kvpList.Count;
            }

            if (shouldWrite)
            {
                                #if DBG
                Log("Writing " + dictionaryName);
                                #endif
                memberValue = kvpList.ToDictionary();
                shouldWrite = false;
            }
        }
Esempio n. 7
0
 public static Dictionary <TKey, TValue> ToDictionary <TKey, TValue>(this KVPList <TKey, TValue> d)
 {
     return(RTHelper.CreateDictionary(d.Keys, d.Values));
 }
Esempio n. 8
0
 public void SaveValues(App app, User user, KVPList kvps)
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
        public override void OnGUI()
        {
            if (invalidKeyType)
            {
                gui.HelpBox("Key type {0} must either be a ValueType or a 'new'able ReferenceType (not an abstract type/a UnityEngine.Object and has an empty or implicit/compiler-generated constructor)".FormatWith(typeof(TK).Name),
                            MessageType.Error);
                return;
            }

            if (memberValue == null)
            {
                #if DBG
                Log("Dictionary null " + dictionaryName);
                #endif
                memberValue = new TD();
            }

            // if the member is a kvpList, we can read immediately because we don't have to worry about allocation or anything it's just an assignment
            if (isKvpList)
            {
                kvpList = memberValue as KVPList <TK, TV>;
            }
            else
            {
                shouldRead |= (kvpList == null || (!shouldWrite && memberValue.Count != kvpList.Count));

                if (shouldRead)
                {
                    #if DBG
                    Log("Reading " + dictionaryName);
                    #endif
                    kvpList    = memberValue.ToKVPList();
                    shouldRead = false;
                }
            }


            #if PROFILE
            Profiler.BeginSample("DictionaryDrawer Header");
            #endif

            using (gui.Horizontal())
            {
                foldout = gui.Foldout(dictionaryName, foldout, Layout.sExpandWidth());

                if (!Readonly)
                {
                    gui.FlexibleSpace();

                    using (gui.State(kvpList.Count > 0))
                    {
                        if (gui.ClearButton("dictionary"))
                        {
                            kvpList.Clear();
                            shouldWrite = true;
                        }

                        if (gui.RemoveButton("last dictionary pair"))
                        {
                            kvpList.RemoveFirst();
                            shouldWrite = true;
                        }
                    }

                    if (gui.AddButton("pair"))
                    {
                        AddNewPair();
                        shouldWrite = true;
                    }

                    Color col;
                    if (!kvpList.Keys.IsUnique())
                    {
                        col = dupKeyColor;
                    }
                    else if (shouldWrite)
                    {
                        col = shouldWriteColor;
                    }
                    else
                    {
                        col = Color.white;
                    }

                    using (gui.ColorBlock(col))
                        if (gui.MiniButton("w", "Write dictionary (Orange means you modified the dictionary and should write, Red means you have a duplicate key and must address it before writing)", MiniButtonStyle.ModRight))
                        {
                        #if DBG
                            Log("Writing " + dictionaryName);
                        #endif
                            if (isKvpList)
                            {
                                memberValue = kvpList as TD;
                            }
                            else
                            {
                                try
                                {
                                    var newDict = new TD();
                                    for (int i = 0; i < kvpList.Count; i++)
                                    {
                                        var k = kvpList.Keys[i];
                                        var v = kvpList.Values[i];
                                        newDict.Add(k, v);
                                    }
                                    memberValue = newDict;
                                }
                                catch (ArgumentException e)
                                {
                                    Log(e.Message);
                                }
                            }

                            shouldWrite = false;
                        }
                }
            }

            #if PROFILE
            Profiler.EndSample();
            #endif

            if (!foldout)
            {
                return;
            }

            if (kvpList.Count == 0)
            {
                gui.HelpBox("Dictionary is empty");
            }
            else
            {
                #if PROFILE
                Profiler.BeginSample("DictionaryDrawer Pairs");
                #endif
                using (gui.Indent())
                {
                    for (int i = 0; i < kvpList.Count; i++)
                    {
                        var dKey   = kvpList.Keys[i];
                        var dValue = kvpList.Values[i];

                        #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer KVP assignments");
                        #endif

                        var pairStr  = FormatPair(dKey, dValue);
                        var entryKey = RuntimeHelper.CombineHashCodes(id, i, "entry");
                        foldouts[entryKey] = gui.Foldout(pairStr, foldouts[entryKey], Layout.sExpandWidth());

                        #if PROFILE
                        Profiler.EndSample();
                        #endif

                        if (!foldouts[entryKey])
                        {
                            continue;
                        }

                        #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer SinglePair");
                        #endif
                        using (gui.Indent())
                        {
                            var keyMember = GetElement(keyElements, kvpList.Keys, i, entryKey + 1);
                            shouldWrite |= gui.Member(keyMember, !perKeyDrawing);

                            var valueMember = GetElement(valueElements, kvpList.Values, i, entryKey + 2);
                            shouldWrite |= gui.Member(valueMember, !perValueDrawing);
                        }
                        #if PROFILE
                        Profiler.EndSample();
                        #endif
                    }
                }
                #if PROFILE
                Profiler.EndSample();
                #endif

                shouldWrite |= memberValue.Count > kvpList.Count;
            }
        }
Esempio n. 10
0
        public override void OnGUI()
        {
            if (_invalidKeyType)
            {
                gui.HelpBox("Unsuported key type: {0}. Only Value-types and strings are, sorry!"
                            .FormatWith(typeof(TK)), MessageType.Error);
                return;
            }

            if (memberValue == null)
            {
                if (_options.ManualAlloc)
                {
                    using (gui.Horizontal())
                    {
                        gui.Label(member.NiceName + " (Null)");
                        if (gui.Button("New", GUIStyles.MiniRight, Layout.sFit()))
                        {
                            memberValue = memberType.Instance <IDictionary <TK, TV> >();
                        }
                    }
                }
                else
                {
                    memberValue = memberType.Instance <IDictionary <TK, TV> >();
                }
            }

            if (memberValue == null)
            {
                return;
            }

            member.CollectionCount = memberValue.Count;

            if (UpdateCount && _lastUpdatedCount != memberValue.Count)
            {
                _lastUpdatedCount = memberValue.Count;
                displayText       = Regex.Replace(_originalDisplay, @"\$count", _lastUpdatedCount.ToString());
            }

            if (_kvpList == null)
            {
                _kvpList = new KVPList <TK, TV>();
            }
            else
            {
                _kvpList.Clear();
            }

            // Read
            {
                var iter = memberValue.GetEnumerator();
                while (iter.MoveNext())
                {
                    var key   = iter.Current.Key;
                    var value = iter.Current.Value;
                    _kvpList[key] = value;
                }
            }

            #if PROFILE
            Profiler.BeginSample("DictionaryDrawer Header");
            #endif

            // header
            if (!_options.HideHeader)
            {
                using (gui.Horizontal())
                {
                    if (_options.ForceExpand)
                    {
                        gui.Label(displayText);
                    }
                    else
                    {
                        foldout = gui.Foldout(displayText, foldout, Layout.Auto);
                    }

                    if (_options.Filter)
                    {
                        _filter.Field(gui, 70f);
                    }

                    if (!_options.Readonly)
                    {
                        if (_options.TempKey)
                        {
                            string controlName = "TempKey";
                            GUI.SetNextControlName(controlName);
                            gui.Member(_tempKeyMember);
                            var e = Event.current;
                            if (e.type == EventType.KeyUp && e.keyCode == KeyCode.Return && GUI.GetNameOfFocusedControl() == controlName)
                            {
                                AddNewPair();
                                EditorGUI.FocusTextInControl(controlName);
                            }
                        }
                        else
                        {
                            gui.FlexibleSpace();
                        }

                        if (!_options.HideButtons)
                        {
                            using (gui.State(_kvpList.Count > 0))
                            {
                                if (gui.ClearButton("dictionary"))
                                {
                                    _kvpList.Clear();
                                }

                                if (gui.RemoveButton("last added dictionary pair"))
                                {
                                    if (_options.AddToLast)
                                    {
                                        _kvpList.RemoveLast();
                                    }
                                    else
                                    {
                                        _kvpList.RemoveFirst();
                                    }
                                }
                            }
                            if (gui.AddButton("pair", MiniButtonStyle.ModRight))
                            {
                                AddNewPair();
                            }
                        }
                    }
                }
                gui.Space(3f);
            }

            #if PROFILE
            Profiler.EndSample();
            #endif

            if (!foldout && !_options.ForceExpand)
            {
                return;
            }

            if (memberValue.Count == 0)
            {
                using (gui.Indent())
                    gui.HelpBox("Dictionary is empty");
            }
            else
            {
                #if PROFILE
                Profiler.BeginSample("DictionaryDrawer Pairs");
                #endif
                using (gui.Indent())
                {
                    for (int i = 0; i < _kvpList.Count; i++)
                    {
                        var dKey   = _kvpList.Keys[i];
                        var dValue = _kvpList.Values[i];

                        #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer KVP assignments");
                        #endif

                        int entryKey = RuntimeHelper.CombineHashCodes(id, i, "entry");

                        string pairStr = null;

                        if (_filter != null)
                        {
                            pairStr = FormatPair(dKey, dValue);
                            #if PROFILE
                            Profiler.BeginSample("DictionaryDrawer Filter");
                            #endif
                            bool match = _filter.IsMatch(pairStr);
                            #if PROFILE
                            Profiler.EndSample();
                            #endif
                            if (!match)
                            {
                                continue;
                            }
                        }

                        if (!_options.HorizontalPairs)
                        {
                            if (pairStr == null)
                            {
                                pairStr = FormatPair(dKey, dValue);
                            }
                            foldouts[entryKey] = gui.Foldout(pairStr, foldouts[entryKey], Layout.Auto);
                        }

                        #if PROFILE
                        Profiler.EndSample();
                        #endif

                        if (!foldouts[entryKey] && !_options.HorizontalPairs)
                        {
                            continue;
                        }

                        #if PROFILE
                        Profiler.BeginSample("DictionaryDrawer SinglePair");
                        #endif
                        if (_options.HorizontalPairs)
                        {
                            using (gui.Horizontal())
                            {
                                DrawKey(i, entryKey + 1);
                                DrawValue(i, entryKey + 2);
                            }
                        }
                        else
                        {
                            using (gui.Indent())
                            {
                                DrawKey(i, entryKey + 1);
                                DrawValue(i, entryKey + 2);
                            }
                        }
                        #if PROFILE
                        Profiler.EndSample();
                        #endif
                    }
                }
                #if PROFILE
                Profiler.EndSample();
                #endif

                #if PROFILE
                Profiler.BeginSample("DictionaryDrawer Write");
                #endif
                // Write
                {
                    Write();
                }
                #if PROFILE
                Profiler.EndSample();
                #endif
            }
        }