Пример #1
0
 public void SetTarget(object target)
 {
     Clear();
     _target = target;
     if (target != null)
     {
         ScrollRect         scroll = GetComponent <ScrollRect>();
         BrowsableAttribute browse;
         foreach (PropertyInfo prop in _target.GetType().GetProperties())
         {
             browse = PropertyEditors.FindAttribute <BrowsableAttribute>(prop);
             if (browse != null && browse.Browsable)
             {
                 ValueEditor editor = PropertyEditors.Instance.CreateEditor(target, prop);
                 if (editor != null)
                 {
                     editor.transform.SetParent(scroll.content.transform, false);
                 }
                 else
                 {
                     Debug.LogError(string.Format("Failed to create editor for property: {0} ({1})",
                                                  prop.Name, target.GetType().Name));
                 }
             }
         }
         // Ensure the spacer appears at the end.
         Spacer.transform.SetParent(null, false);
         Spacer.transform.SetParent(scroll.content.transform, false);
     }
 }
Пример #2
0
        public ValueEditor CreateEditor(object target, PropertyInfo prop)
        {
            ValueEditor editor = null;

            if (prop.PropertyType.IsEnum)
            {
                editor = Enum;
            }
            else if (NumericEditor.IsNumericType(prop.PropertyType))
            {
                editor = Numeric;
            }
            else if (prop.PropertyType == typeof(bool))
            {
                editor = Boolean;
            }
            else if (prop.PropertyType == typeof(string))
            {
                editor = String;
            }

            if (editor == null)
            {
                string typeName = prop.PropertyType.ToString();
                for (int i = 0; i < ValueEditors.Length; ++i)
                {
                    if (string.Compare(ValueEditors[i].Name, typeName) == 0)
                    {
                        editor = ValueEditors[i].Editor;
                        break;
                    }
                }
            }

            if (editor == null)
            {
                editor = Default;
                if (editor == null)
                {
                    return(null);
                }
            }

            editor = Instantiate(editor);
            editor.SetTarget(target, prop);

            return(editor);
        }