源战役客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

69 строки
1.7 KiB

4 недель назад
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace U3DExtends
  5. {
  6. [RequireComponent(typeof(RectTransform))]
  7. [ExecuteInEditMode]
  8. public class Decorate : MonoBehaviour
  9. {
  10. string spr_path = "";
  11. [SerializeField]
  12. [HideInInspector]
  13. private Image _image;
  14. Vector3 _lastPos = new Vector3(-1, -1);
  15. Vector2 _lastSize = Vector2.zero;
  16. public string SprPath
  17. {
  18. get { return spr_path; }
  19. set
  20. {
  21. LoadSpr(value);
  22. }
  23. }
  24. public void LoadSpr(string path)
  25. {
  26. InitComponent();
  27. if (spr_path != path)
  28. {
  29. spr_path = path;
  30. _image.sprite = UIEditorHelper.LoadSpriteInLocal(path);
  31. _image.SetNativeSize();
  32. gameObject.name = CommonHelper.GetFileNameByPath(path);
  33. //Debug.Log("_image.sprite :" + (_image.sprite != null).ToString());
  34. }
  35. }
  36. protected void Start()
  37. {
  38. InitComponent();
  39. }
  40. protected void InitComponent()
  41. {
  42. if (_image == null)
  43. _image = GetComponent<Image>();
  44. }
  45. public bool IsChangedTrans()
  46. {
  47. RectTransform curTrans = transform as RectTransform;
  48. if (curTrans.localPosition == _lastPos && curTrans.sizeDelta == _lastSize)
  49. return false;
  50. else
  51. return true;
  52. }
  53. public void SaveTrans()
  54. {
  55. RectTransform rectTrans = transform as RectTransform;
  56. _lastPos = rectTrans.localPosition;
  57. _lastSize = rectTrans.sizeDelta;
  58. }
  59. }
  60. }
  61. #endif