コード例 #1
0
    public DebugLayout ValueSlider(FieldPresentSettings name, float min, float max, IValueRW <float> val, bool wholeNumbers = false,
                                   DebugLayoutOptions opts = default(DebugLayoutOptions))
    {
        var slider = NamedElementOrLayouted <Slider>(name, factory.slider, opts);

        slider.minValue     = min;
        slider.maxValue     = max;
        slider.wholeNumbers = wholeNumbers;
        slider.value        = val.value;

        var input = slider.GetComponentInChildren <InputField>();

        input.text = val.value.ToString();
        input.onValueChanged.AddListener(i =>
        {
            slider.value = float.Parse(i);
            val.value    = slider.value;
        });
        slider.onValueChanged.AddListener(i =>
        {
            val.value  = i;
            input.text = i.ToString();
        });

        return(this);
    }
コード例 #2
0
    public void ColumnSelectorEnum <T>(ICellRW <T> curr, Action <T, DebugLayout> fillFunc,
                                       DebugLayoutOptions opts = default(DebugLayoutOptions))
    {
        Func <string, T> parse = s => (T)Enum.Parse(typeof(T), s);

        ColumnSelector(Enum.GetNames(typeof(T)), curr.MapToString(parse), (s, l) => fillFunc(parse(s), l), opts);
    }
コード例 #3
0
    public T InstantiateInLayout <T>(T rtPrefab, DebugLayoutOptions options = default(DebugLayoutOptions)) where T : Component
    {
        var obj = Instantiate(rtPrefab, rect, false);

        AdjustIntoLayout(obj, options);
        return(obj);
    }
コード例 #4
0
    void AdjustIntoLayout <T>(T obj, DebugLayoutOptions options = default(DebugLayoutOptions)) where T : Component
    {
        var le = obj.gameObject.GetOrAddComponent <LayoutElement>();

        if (options.fitSize)
        {
            le.gameObject.AddComponent <ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
        }
        if (type == LayoutType.Vertical)
        {
            le.flexibleHeight  = options.flexibleSpace;
            le.preferredHeight = options.forceSize == 0 ? obj.GetComponent <RectTransform>().sizeDelta.y : options.forceSize;
        }
        else if (type == LayoutType.Horizontal)
        {
            le.flexibleWidth  = options.flexibleSpace;
            le.preferredWidth = options.forceSize == 0 ? obj.GetComponent <RectTransform>().sizeDelta.x : options.forceSize;
        }
        else
        {
            le.flexibleWidth   = options.flexibleSpace;
            le.flexibleHeight  = options.subflexibleSpace;
            le.preferredWidth  = options.forceSize == 0 ? obj.GetComponent <RectTransform>().sizeDelta.x : options.forceSize;
            le.preferredHeight = options.forceSubSize == 0 ? obj.GetComponent <RectTransform>().sizeDelta.y : options.forceSubSize;
        }
    }
コード例 #5
0
    public DebugLayout Label(ICell <string> textCell, DebugLayoutOptions opts)
    {
        var t = InstantiateInLayout(factory.labelPrefab, opts).GetComponentInChildren <Text>();

        connections += textCell.Bind(text => t.text = text);
        return(this);
    }
コード例 #6
0
    public DebugLayout Title(string name, DebugLayoutOptions opts = default(DebugLayoutOptions))
    {
        var t = InstantiateInLayout(factory.titlePrefab, opts).GetComponentInChildren <Text>();

        t.text = name;
        return(this);
    }
コード例 #7
0
    public DebugLayout Row(DebugLayoutOptions opts)
    {
        var l = NewLayout(factory, LayoutType.Horizontal);

        l.rect.SetParent(rect, false);
        AdjustIntoLayout(l, opts);
        return(l);
    }
コード例 #8
0
    public DebugLayout Column(DebugLayoutOptions opts)
    {
        var l = NewLayout(factory, LayoutType.Vertical);

        l.rect.SetParent(rect, false);
        AdjustIntoLayout(l, opts);
        return(l);
    }
コード例 #9
0
    public DebugLayout Label(ICell <string> name, int fontSize = 40)
    {
        var t = InstantiateInLayout(factory.titlePrefab, DebugLayoutOptions.Fixed(fontSize + 6)).GetComponentInChildren <Text>();

        t.resizeTextForBestFit = true;
        t.resizeTextMaxSize    = (int)fontSize;
        connections           += name.Bind(n => t.text = n);
        return(this);
    }
コード例 #10
0
    public DebugLayout Selector(FieldPresentSettings name, IList <string> options, ICellRW <string> value
                                , DebugLayoutOptions opts = default(DebugLayoutOptions))
    {
        Dropdown selector = NamedElementOrLayouted <Dropdown>(name, factory.dropdownPrefab, opts).GetComponentInChildren <Dropdown>();

        selector.options = options.Select(elemName => new Dropdown.OptionData(elemName)).ToList();
        value.Bind(v => selector.value = options.IndexOf(v));
        selector.onValueChanged.AddListener(new UnityAction <int>(i =>
        {
            value.value = options[i];
        }));
        return(this);
    }
コード例 #11
0
    RectTransform BoxedNameElement(string name, RectTransform prefab, DebugLayoutOptions options = default(DebugLayoutOptions))
    {
        var option = InstantiateInLayout(factory.boxer, options);

        option.title.text = name.CamelCaseToReadableText();
        var t          = Instantiate(prefab, option.content, false);
        var controllRt = t.GetComponent <RectTransform>();

        controllRt.pivot            = new Vector2(0.5f, 0.5f);
        controllRt.anchorMin        = new Vector2(0, 0f);
        controllRt.anchorMax        = new Vector2(1, 1f);
        controllRt.anchoredPosition = Vector2.zero;
        controllRt.sizeDelta        = Vector2.zero;
        return(t);
    }
コード例 #12
0
 public void ColumnSelector(string[] names, ICellRW <string> curr, Action <string, DebugLayout> fillFunc,
                            DebugLayoutOptions opts = default(DebugLayoutOptions))
 {
     Selector("", names, curr);
     foreach (var name in names)
     {
         var c = Column(opts);
         if (opts.fitSize)
         {
             c.GetComponent <VerticalLayoutGroup>().childControlHeight = false;
         }
         c.HideIf(curr.IsNot(name));
         fillFunc(name, c);
     }
 }
コード例 #13
0
    public DebugLayout NumberSelector(FieldPresentSettings name, IValueRW <int> value,
                                      DebugMenuIntRange range = null, DebugLayoutOptions opts = default(DebugLayoutOptions))
    {
        var attr = range;

        if (attr != null)
        {
            var input = ValueSlider(name, attr.min, attr.max, value, opts);
        }
        else
        {
            var input = NamedElementOrLayouted <InputField>(name, factory.stringInputPrefab, opts);
            input.contentType = UnityEngine.UI.InputField.ContentType.IntegerNumber;
            input.text        = value.value.ToString();
            input.onValueChanged.AddListener(new UnityAction <string>(i => value.value = int.Parse(i)));
        }
        return(this);
    }
コード例 #14
0
    RectTransform LinedNameElement(string name, RectTransform prefab, DebugLayoutOptions options = default(DebugLayoutOptions))
    {
        var option = InstantiateInLayout(factory.optionPrefab, options);

        option.GetComponentInChildren <Text>().text = name.CamelCaseToReadableText() + ":";
        var textRt = option.GetComponentInChildren <Text>().GetComponent <RectTransform>();
        var textLE = textRt.transform.parent.gameObject.AddComponent <LayoutElement>();

        textLE.flexibleWidth = 1;
        var rt = option.GetComponent <RectTransform>();

        var t          = Instantiate(prefab, option.transform, false);
        var controllRt = t.GetComponent <RectTransform>();

        controllRt.gameObject.GetOrAddComponent <LayoutElement>().flexibleWidth = 2;
        controllRt.pivot            = new Vector2(1, 0.5f);
        controllRt.anchorMin        = new Vector2(1, 0f);
        controllRt.anchorMax        = new Vector2(1, 1f);
        controllRt.anchoredPosition = Vector2.zero;
        controllRt.sizeDelta        = new Vector2(controllRt.sizeDelta.x, 0);

        return(t);
    }
コード例 #15
0
 public DebugLayout ValueSlider(FieldPresentSettings name, int min, int max, IValueRW <int> val,
                                DebugLayoutOptions opts = default(DebugLayoutOptions))
 {
     return(ValueSlider(name, min, max, val.MapValue(i => (float)i, f => (int)f), true, opts));
 }
コード例 #16
0
    public T NamedElementOrLayouted <T>(FieldPresentSettings name, RectTransform prefab, DebugLayoutOptions options = default(DebugLayoutOptions))
        where T : MonoBehaviour
    {
        RectTransform elem = null;

        if (string.IsNullOrEmpty(name.name))
        {
            elem = InstantiateInLayout(prefab, options);
        }
        else if (name.type == NamingType.Lined)
        {
            elem = LinedNameElement(name.name, prefab, options);
        }
        else if (name.type == NamingType.Boxed)
        {
            elem = BoxedNameElement(name.name, prefab, options);
        }
        return(elem.GetComponentInChildren <T>());
    }
コード例 #17
0
 public DebugLayout Row(float screenPart)
 {
     return(Row(DebugLayoutOptions.Part(screenPart)));
 }
コード例 #18
0
 public DebugLayout Delimiter(float size = 50)
 {
     InstantiateInLayout(factory.delimiterPrefab, DebugLayoutOptions.Fixed(size));
     return(this);
 }
コード例 #19
0
 public DebugLayout FlowDelimiterCut()
 {
     InstantiateInLayout(factory.delimiterPrefab, DebugLayoutOptions.Fixed(2000, 0.001f));
     return(this);
 }
コード例 #20
0
 public DebugLayout EnumSelector(FieldPresentSettings name, Type enumType, ICellRW <object> value,
                                 DebugLayoutOptions opts = default(DebugLayoutOptions), ExcudeEnumNameInSelector exclude = null)
 {
     return(Selector(name, Enum.GetNames(enumType).Where(n => exclude == null || exclude.name.Contains(n) == false).ToList(),
                     value.MapRW(v => v.ToString(), s => Enum.Parse(enumType, s)), opts));
 }
コード例 #21
0
 public DebugLayout Column(float screenPart)
 {
     return(Column(DebugLayoutOptions.Part(screenPart)));
 }
コード例 #22
0
    public DebugLayout DrawAllFields(object obj, float selectorSize = 65, NamingType naming = NamingType.Lined, Func <object, FieldInfo, DebugLayout, bool> customFactory = null)
    {
        if (obj == null)
        {
            Label("null", 40);
            return(this);
        }
        var opts = DebugLayoutOptions.Fixed(selectorSize);

        foreach (var fieldInfo in obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy))
        {
            if (customFactory != null && customFactory(obj, fieldInfo, this))
            {
                continue;
            }
            if (fieldInfo.HasAttribute <ExcudeFromDebugMenu>())
            {
                continue;
            }
            if (fieldInfo.FieldType.IsEnum)
            {
                EnumSelector(fieldInfo.WithNaming(naming), fieldInfo.FieldType, obj.ReflectionFieldToRW <object>(fieldInfo.Name),
                             exclude: fieldInfo.GetCustomAttribute <ExcudeEnumNameInSelector>(), opts: opts);
            }
            else if (fieldInfo.FieldType == typeof(string))
            {
                var input = NamedElementOrLayouted <InputField>(fieldInfo.WithNaming(naming), factory.stringInputPrefab, opts);
                input.text = (string)fieldInfo.GetValue(obj);
                input.onValueChanged.AddListener(new UnityAction <string>(i => { fieldInfo.SetValue(obj, i); }));
            }
            else if (
                fieldInfo.FieldType == typeof(long))
            {
                var attr = fieldInfo.GetCustomAttributes <DebugMenuIntRange>().FirstOrDefault();
                NumberSelector(fieldInfo.WithNaming(naming), obj.ReflectionFieldToRW <long>(fieldInfo).MapValue(i => (int)i, i => (long)i), attr, opts);
            }
            else if (fieldInfo.FieldType == typeof(int))
            {
                var attr = fieldInfo.GetCustomAttributes <DebugMenuIntRange>().FirstOrDefault();
                NumberSelector(fieldInfo.WithNaming(naming), obj.ReflectionFieldToRW <int>(fieldInfo), attr, opts);
            }
            else if (fieldInfo.FieldType == typeof(bool))
            {
                var input = NamedElementOrLayouted <Toggle>(fieldInfo.WithNaming(naming), factory.togglePrefab, opts);
                input.isOn = (bool)fieldInfo.GetValue(obj);
                input.onValueChanged.AddListener(new UnityAction <bool>(i => { fieldInfo.SetValue(obj, i); }));
            }
            else if (fieldInfo.FieldType.IsClass)
            {
                if (type == LayoutType.Flow)
                {
                    FlowDelimiterCut();
                }
                Title(fieldInfo.Name, type == LayoutType.Flow ? DebugLayoutOptions.Fixed(1000) : opts);
                if (type == LayoutType.Flow)
                {
                    FlowDelimiterCut();
                }
                DrawAllFields(fieldInfo.GetValue(obj), selectorSize, naming, customFactory);
                if (type == LayoutType.Flow)
                {
                    FlowDelimiterCut();
                }
                else
                {
                    Delimiter();
                }
            }
        }

        //        var delimiter = Instantiate(factory.optionPrefab, rect);
        //        delimiter.GetComponentInChildren<Text>().text = "";
        //        delimiter.sizeDelta = new Vector2(100, 20);

        return(this);
    }
コード例 #23
0
 public DebugLayout EnumSelector <T>(FieldPresentSettings name, ICellRW <T> value, DebugLayoutOptions opts = default(DebugLayoutOptions))
 {
     return(Selector(name, Enum.GetNames(typeof(T)),
                     value.MapRW(v => v.ToString(), s => (T)Enum.Parse(typeof(T), s)), opts));
 }