/// <summary> /// 创建HandUI /// </summary> /// <param name="handSprite">默认值</param> /// <param name="size">大小</param> /// <returns></returns> public static MHandUI CreateHandUI(Transform parent, HandIcon handSprite, Vector2?size = null) { if (HandParent == null) { HandParent = GameObject.Instantiate <Transform>(Resources.Load <Transform>("Hands/HandCanvas")); if (parent != null) { HandParent.SetParent(parent); HandParent.localPosition = Vector3.zero; } } var handObject = GameObject.Instantiate <GameObject>(Resources.Load <GameObject>("Hands/HandIcon"), HandParent); var handUI = handObject.AddComponent <MHandUI>(); handUI.OnInitialized(handSprite, size); HandUIs.Add(handUI); return(handUI); }
/// <summary> /// 初始化 /// </summary> /// <param name="handSprite">手精灵对象</param> /// <param name="size"></param> public void OnInitialized(HandIcon handSprite, Vector2?size) { this.NormalIcon = handSprite.IdelIcon; this.handSprite = handSprite; handIcon = gameObject.GetComponent <Image>() ?? gameObject.AddComponent <Image>(); this.Size = size != null ? size.Value : handIcon.rectTransform.sizeDelta; if (NormalIcon == null) { handIcon.enabled = false; } else { handIcon.sprite = NormalIcon; } handIcon.rectTransform.sizeDelta = Size; }