public static Dropdown AddDropdown(string _name, Transform _parent, Vector2 _size, AnchorPresets _anchor, PivotPresets _pivot, Rect _offset, Color _color, string _label) { if (_parent == null) { return(null); } Dropdown _dropdown = null; RectTransform _transform = CreateRectTransformObject(_name, _parent, _size, _anchor, _pivot, _offset); if (_transform != null) { _transform.gameObject.AddComponent <CanvasRenderer>(); Image _image = _transform.gameObject.AddComponent <Image>(); #if UNITY_EDITOR _image.sprite = UnityEditor.AssetDatabase.GetBuiltinExtraResource <Sprite>("UI/Skin/UISprite.psd"); #endif _dropdown = _transform.gameObject.AddComponent <Dropdown>(); //Text _text = InterfaceTools.AddText("Label", _dropdown.transform, new Vector2(0, 0), AnchorPresets.StretchAll, PivotPresets.MiddleCenter, new Rect(30, 0, 0, 0), Color.gray, _label); //Image _arrow = InterfaceTools.AddImage("Arrow", _transform, new Vector2(20, 20), AnchorPresets.MiddleRight, PivotPresets.MiddleRight, new Rect(-15, 0, 0, 0), Color.clear); } return(_dropdown); }
public static Toggle AddToggle(string _name, Transform _parent, Vector2 _size, AnchorPresets _anchor, PivotPresets _pivot, Rect _offset, Color _color, string _label) { if (_parent == null) { return(null); } Toggle _toggle = null; RectTransform _transform = CreateRectTransformObject(_name, _parent, _size, _anchor, _pivot, _offset); if (_transform != null) { _transform.gameObject.AddComponent <CanvasRenderer>(); _toggle = _transform.gameObject.AddComponent <Toggle>(); //_button.color = _color; #if UNITY_EDITOR _toggle.graphic = UnityEditor.AssetDatabase.GetBuiltinExtraResource <Graphic>("UI/Skin/Background.psd"); _toggle.targetGraphic = UnityEditor.AssetDatabase.GetBuiltinExtraResource <Graphic>("UI/Skin/Checkmark.psd"); #endif /* * Image _background = InterfaceTools.AddImage( "Background", _transform, new Vector2( 20, 20 ), AnchorPresets.TopLeft, PivotPresets.TopLeft, new Rect(0,0,0,0), Color.clear ); * Image _checkmark = InterfaceTools.AddImage( "Checkmark", _background.transform, new Vector2( 20, 20 ), AnchorPresets.MiddleCenter, PivotPresets.MiddleCenter, new Rect(0,0,0,0), Color.clear ); * #if UNITY_EDITOR * _checkmark.sprite = UnityEditor.AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Checkmark.psd"); #endif */ //Text _text = InterfaceTools.AddText("Text", _transform, new Vector2(0, 0), AnchorPresets.StretchAll, PivotPresets.MiddleCenter, new Rect(30, 0, 0, 0), Color.gray, _label); } return(_toggle); }