| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using UnityEngine.Events; |
| | | using System; |
| | | using TableConfig; |
| | | |
| | | public static class ComponentExtersion |
| | | { |
| | | |
| | | public static T AddMissingComponent<T>(this Component _compoent) where T : Component |
| | | { |
| | | if (_compoent == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | T component = _compoent.GetComponent<T>(); |
| | | if (component == null) |
| | | { |
| | | component = _compoent.gameObject.AddComponent<T>(); |
| | | } |
| | | |
| | | return component; |
| | | } |
| | | |
| | | public static T AddMissingComponent<T>(this Transform _transform) where T : Component |
| | | { |
| | | if (_transform == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | T component = _transform.GetComponent<T>(); |
| | | if (component == null) |
| | | { |
| | | component = _transform.gameObject.AddComponent<T>(); |
| | | } |
| | | |
| | | return component; |
| | | } |
| | | |
| | | public static T AddMissingComponent<T>(this GameObject _gameObject) where T : Component |
| | | { |
| | | if (_gameObject == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | T component = _gameObject.GetComponent<T>(); |
| | | if (component == null) |
| | | { |
| | | component = _gameObject.AddComponent<T>(); |
| | | } |
| | | |
| | | return component; |
| | | } |
| | | |
| | | public static void AddListener(this Button _button, UnityAction _action) |
| | | { |
| | | if (_button == null) |
| | | { |
| | | return; |
| | | } |
| | | _button.onClick.AddListener(_action); |
| | | } |
| | | |
| | | public static void RemoveAllListeners(this Button _button) |
| | | { |
| | | if (_button == null) |
| | | { |
| | | return; |
| | | } |
| | | _button.onClick.RemoveAllListeners(); |
| | | } |
| | | |
| | | public static void AddListener(this Toggle _toggle, UnityAction<bool> _action) |
| | | { |
| | | if (_toggle == null) |
| | | { |
| | | return; |
| | | } |
| | | _toggle.onValueChanged.AddListener(_action); |
| | | } |
| | | |
| | | public static void RemoveAllListeners(this Toggle _toggle) |
| | | { |
| | | if (_toggle == null) |
| | | { |
| | | return; |
| | | } |
| | | _toggle.onValueChanged.RemoveAllListeners(); |
| | | } |
| | | |
| | | public static void AddListener(this Slider _slider, UnityAction<float> _action) |
| | | { |
| | | if (_slider == null) |
| | | { |
| | | return; |
| | | } |
| | | _slider.onValueChanged.AddListener(_action); |
| | | } |
| | | |
| | | public static void RemoveAllListeners(this Slider _slider) |
| | | { |
| | | if (_slider == null) |
| | | { |
| | | return; |
| | | } |
| | | _slider.onValueChanged.RemoveAllListeners(); |
| | | } |
| | | |
| | | public static void AddListener(this InputField _inputField, UnityAction<string> _action) |
| | | { |
| | | if (_inputField == null) |
| | | { |
| | | return; |
| | | } |
| | | _inputField.onValueChanged.AddListener(_action); |
| | | } |
| | | |
| | | public static void RemoveAllListeners(this InputField _inputField) |
| | | { |
| | | if (_inputField == null) |
| | | { |
| | | return; |
| | | } |
| | | _inputField.onValueChanged.RemoveAllListeners(); |
| | | } |
| | | |
| | | public static void SetEnable(this Button _btn, Text _btnTxt, bool _enable, EnableButtonConfig.EnableButtonType _type = |
| | | EnableButtonConfig.EnableButtonType.Default) |
| | | { |
| | | EnableButtonConfig.SetEnable(_btn, _btnTxt, _enable, _type); |
| | | } |
| | | |
| | | public static void SetInteractable(this Button _btn, Text _btnText, bool _interactable) |
| | | { |
| | | if (_btn != null) |
| | | { |
| | | _btn.interactable = _interactable; |
| | | var imageEx = _btn.image as ImageEx; |
| | | if (imageEx != null) |
| | | { |
| | | imageEx.gray = !_interactable; |
| | | } |
| | | } |
| | | if (_btnText != null) |
| | | { |
| | | _btnText.color = UIHelper.GetUIColor(_interactable ? TextColType.NavyBrown : TextColType.White); |
| | | _btnText.color = _btnText.color.SetA(_interactable ? 1 : 0.5f); |
| | | } |
| | | } |
| | | |
| | | public static void SetSprite(this Image _image, string _id) |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var sprite = UILoader.LoadSprite(_id); |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static void SetSprite(this TextImage _textImage, string _id) |
| | | { |
| | | if (_textImage == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var sprite = UILoader.LoadSprite(_id); |
| | | _textImage.sprite = sprite; |
| | | } |
| | | |
| | | } |
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | | using UnityEngine;
|
| | | using UnityEngine.UI;
|
| | | using UnityEngine.Events;
|
| | | using System;
|
| | | using TableConfig;
|
| | |
|
| | | public static class ComponentExtersion
|
| | | {
|
| | |
|
| | | public static T AddMissingComponent<T>(this Component _compoent) where T : Component
|
| | | {
|
| | | if (_compoent == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | T component = _compoent.GetComponent<T>();
|
| | | if (component == null)
|
| | | {
|
| | | component = _compoent.gameObject.AddComponent<T>();
|
| | | }
|
| | |
|
| | | return component;
|
| | | }
|
| | |
|
| | | public static T AddMissingComponent<T>(this Transform _transform) where T : Component
|
| | | {
|
| | | if (_transform == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | T component = _transform.GetComponent<T>();
|
| | | if (component == null)
|
| | | {
|
| | | component = _transform.gameObject.AddComponent<T>();
|
| | | }
|
| | |
|
| | | return component;
|
| | | }
|
| | |
|
| | | public static T AddMissingComponent<T>(this GameObject _gameObject) where T : Component
|
| | | {
|
| | | if (_gameObject == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | |
|
| | | T component = _gameObject.GetComponent<T>();
|
| | | if (component == null)
|
| | | {
|
| | | component = _gameObject.AddComponent<T>();
|
| | | }
|
| | |
|
| | | return component;
|
| | | }
|
| | |
|
| | | public static void AddListener(this Button _button, UnityAction _action)
|
| | | {
|
| | | if (_button == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | _button.onClick.AddListener(_action);
|
| | | }
|
| | |
|
| | | public static void RemoveAllListeners(this Button _button)
|
| | | {
|
| | | if (_button == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | _button.onClick.RemoveAllListeners();
|
| | | }
|
| | |
|
| | | public static void AddListener(this Toggle _toggle, UnityAction<bool> _action)
|
| | | {
|
| | | if (_toggle == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | _toggle.onValueChanged.AddListener(_action);
|
| | | }
|
| | |
|
| | | public static void RemoveAllListeners(this Toggle _toggle)
|
| | | {
|
| | | if (_toggle == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | _toggle.onValueChanged.RemoveAllListeners();
|
| | | }
|
| | |
|
| | | public static void AddListener(this Slider _slider, UnityAction<float> _action)
|
| | | {
|
| | | if (_slider == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | _slider.onValueChanged.AddListener(_action);
|
| | | }
|
| | |
|
| | | public static void RemoveAllListeners(this Slider _slider)
|
| | | {
|
| | | if (_slider == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | _slider.onValueChanged.RemoveAllListeners();
|
| | | }
|
| | |
|
| | | public static void AddListener(this InputField _inputField, UnityAction<string> _action)
|
| | | {
|
| | | if (_inputField == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | _inputField.onValueChanged.AddListener(_action);
|
| | | }
|
| | |
|
| | | public static void RemoveAllListeners(this InputField _inputField)
|
| | | {
|
| | | if (_inputField == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | _inputField.onValueChanged.RemoveAllListeners();
|
| | | }
|
| | |
|
| | | public static void SetEnable(this Button _btn, Text _btnTxt, bool _enable, EnableButtonConfig.EnableButtonType _type =
|
| | | EnableButtonConfig.EnableButtonType.Default)
|
| | | {
|
| | | EnableButtonConfig.SetEnable(_btn, _btnTxt, _enable, _type);
|
| | | }
|
| | |
|
| | | public static void SetInteractable(this Button _btn, Text _btnText, bool _interactable)
|
| | | {
|
| | | if (_btn != null)
|
| | | {
|
| | | _btn.interactable = _interactable;
|
| | | var imageEx = _btn.image as ImageEx;
|
| | | if (imageEx != null)
|
| | | {
|
| | | imageEx.gray = !_interactable;
|
| | | }
|
| | | }
|
| | | if (_btnText != null)
|
| | | {
|
| | | _btnText.color = UIHelper.GetUIColor(_interactable ? TextColType.NavyBrown : TextColType.White);
|
| | | _btnText.color = _btnText.color.SetA(_interactable ? 1 : 0.5f);
|
| | | }
|
| | | }
|
| | |
|
| | | public static void SetSprite(this Image _image, string _id)
|
| | | {
|
| | | if (_image == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | var sprite = UILoader.LoadSprite(_id);
|
| | | _image.overrideSprite = sprite;
|
| | | }
|
| | |
|
| | | public static void SetSprite(this TextImage _textImage, string _id)
|
| | | {
|
| | | if (_textImage == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | var sprite = UILoader.LoadSprite(_id);
|
| | | _textImage.sprite = sprite;
|
| | | }
|
| | |
|
| | | }
|