Пример #1
0
        //
        public static void DrawProperties(IPropertiesInfoSet p, System.Func <IPropertiesInfoSet, BTPrjSetting, bool> onDrawProperty, ref bool hasChanged2)
        {
            GUILayout.Label("");
            int  numNC      = 0;
            bool hasChanged = false;

            //Selection.activeObject = this;
            if (p == null || p.Keys == null)
            {
                GUILayout.Label("could not draw properties (null)");
                return;
            }

            if (p.Keys.Length == 0)
            {
                GUILayout.Label("could not draw properties (no keys)");
                return;
            }

            // sort properties into groups.
            int iter = 0;

            System.Collections.Generic.List <string> groups = new System.Collections.Generic.List <string>();
            groups.Add("");
            foreach (var k in p.Keys)
            {
                if (k == null)
                {
                    Debug.LogError("Error key in collection is null");
                }
                int    i     = iter;
                string s_grp = p.GetGroup(i).ToLower();
                if (!groups.Contains(s_grp))
                {
                    groups.Add(s_grp);
                }
                iter++;
            }

            //
            foreach (var g in groups)
            {
                if (g == null || g == "" || g == "default")                   // You're not able to fold or Unfold a default group.
                {
                    p.ForEachPropertyInGroup(g, ( BTPrjSetting propInfo ) => {
                        if (onDrawProperty == null || onDrawProperty(p, propInfo) == false)
                        {
                            DrawProperty(p, propInfo, ref numNC, ref hasChanged);
                        }
                    });
                }
                else
                {
                    var  v1 = GetGroupFoldValue(g);
                    bool v2 = EditorGUILayout.Foldout(v1, g);
                    if (v1 != v2)
                    {
                        SetGroupFoldValue(g, v2);
                    }
                    if (v2)
                    {
                        p.ForEachPropertyInGroup(g, ( BTPrjSetting propInfo ) => {
                            if (onDrawProperty == null || onDrawProperty(p, propInfo) == false)
                            {
                                DrawProperty(p, propInfo, ref numNC, ref hasChanged);
                            }
                        });
                    }
                }
            }

            if (numNC > 0)
            {
                var normColor = GUI.color;
                GUI.color = Color.yellow;
                GUILayout.Label("* the marked items needs to be filled out before you can continue.");
                GUI.color = normColor;
            }

            hasChanged2 = hasChanged;
        }
Пример #2
0
        public static void DrawProperty(IPropertiesInfoSet p, BTPrjSetting setting, ref int numNC, ref bool hasChanged)
        {
            int    i  = setting.index;
            string k  = setting.key;
            var    wr = p.WriteEnabled(k);

            if (wr)
            {
                GUI.enabled = true;
                bool nc = p.NeedsChange(k) && p.HasChangedFromDefault(k);
                if (nc)
                {
                    numNC++;
                }
                var normColor = GUI.color;
                GUI.color = nc ? Color.yellow : normColor;
                string reason = "";
                if (nc == false && p.IsValidValue(k, out reason) == false)
                {
                    GUI.color = Color.red;
                }
                //GUILayout.Label( "" + p.DispName( k ) + " = " + p.GetValue( k ) );
                string oldvalue = p.GetValue(k);

                string strT = p.GetStrType(k);
                if (strT.StartsWith("string:"))
                {
                    var    str_options = strT.Replace("string:", "").Replace(" ", "").Split(new char[] { ',' }).ToList();
                    int    iof         = str_options.IndexOf(p.GetValue(i));
                    string str_option  = str_options[iof];
                    if (str_options.Count > 0)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("" + k, GUILayout.Width(145));
                        int inew = EditorGUILayout.Popup(iof, str_options.ToArray());
                        if (inew != iof)
                        {
                            iof = inew;
                            //Debug.Log( "SetVAlue = str_options[iof] = " + str_options[iof] );
                            p.SetValue(k, str_options[iof]);
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        GUI.enabled = false;
                        EditorGUILayout.TextField(p.DispName(k), "NO OPTIONS AVAIL");
                    }
                }
                else
                {
                    try {
                        bool   drawn;
                        object objvalue  = FieldByType(p.GetSystemType(k), p.DispName(k), p.GetValueAsRealButAnonType(k), out drawn);
                        string strNewVal = System.Convert.ToString(objvalue);
                        if (strNewVal != oldvalue)
                        {
                            hasChanged = true;
                            if (strNewVal == "")
                            {
                                //Debug.LogError("new value is empty");
                            }
                            //Debug.Log( "Setting value : oldval = " + oldvalue + " newv=" + strNewVal );
                            p.SetValue(k, strNewVal);
                        }
                    } catch (System.Exception e) {
                        Debug.LogError("" + e);
                    }
                }

                if (!string.IsNullOrEmpty(reason))
                {
                    GUILayout.Label("* " + reason);
                }
                GUI.color = normColor;
            }
            else
            {
                GUI.enabled = false;
                EditorGUILayout.TextField(p.DispName(k), p.GetValue(k));
            }
        }