Exemplo n.º 1
0
        string LabelWithEditPrefix(UnityEngine.Object obj, IEnumerable <PrefsParam> prefsSet, bool editPrefix)
        {
            var keys   = prefsSet.Select(prefs => prefs.key);
            var prefix = GetPrefix(keys);

            using (new GUILayout.HorizontalScope())
            {
                extension?.GUIGroupLabelLeft(prefsSet);

                using (new RGUI.EnabledScope(false))
                {
                    EditorGUILayout.ObjectField(obj, typeof(UnityEngine.Object), true);
                }

                if (editPrefix)
                {
                    GUILayout.Label("KeyPrefix");

                    var prefixNew = GUILayout.TextField(prefix, GUILayout.MinWidth(100f));
                    if (prefix != prefixNew)
                    {
                        var prefixWithSeparator = string.IsNullOrEmpty(prefixNew) ? "" : prefixNew + separator;

                        Undo.RecordObject(obj, "Change PrefsGUI Prefix");

                        foreach (var prefs in prefsSet)
                        {
                            prefs.key = prefixWithSeparator + prefs.key.Split(separator).Last();
                        }

                        prefix = prefixNew;
                        EditorUtility.SetDirty(obj);
                    }
                }

                GUILayout.FlexibleSpace();
            }

            return(prefix);
        }
Exemplo n.º 2
0
        void LabelWithEditPrefix(ObjectPrefsUtility.ObjPrefs objPrefs)
        {
            var prefsList = objPrefs.prefsList;

            using (new GUILayout.HorizontalScope())
            {
                extension?.GUIGroupLabelLeft(prefsList);

                using (new RGUI.EnabledScope(false))
                {
                    EditorGUILayout.ObjectField(objPrefs.obj, typeof(Object), true);
                }

                const char separator = '.';
                var        prefix    = prefsList.Select(p => p.key.Split(separator))
                                       .FirstOrDefault(sepKeys => sepKeys.Length > 1)?.First();

                GUILayout.Label("KeyPrefix");

                var prefixNew = GUILayout.TextField(prefix, GUILayout.MinWidth(100f));
                if (prefix != prefixNew)
                {
                    var go = objPrefs.obj;
                    Undo.RecordObject(go, "Change PrefsGUI Prefix");

                    var prefixWithSeparator = string.IsNullOrEmpty(prefixNew) ? "" : prefixNew + separator;

                    foreach (var prefs in prefsList)
                    {
                        prefs.key = prefixWithSeparator + prefs.key.Split(separator).Last();
                        EditorUtility.SetDirty(objPrefs.GetPrefsParent(prefs));
                    }
                }

                GUILayout.FlexibleSpace();
            }
        }