| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | namespace vnxbqy.UI |
| | | { |
| | | public class ItemBaseEffect : MonoBehaviour |
| | | { |
| | | [SerializeField] UIEffect m_SuitEffect; |
| | | // using System.Collections; |
| | | // using System.Collections.Generic; |
| | | // using UnityEngine; |
| | | // namespace vnxbqy.UI |
| | | // { |
| | | // public class ItemBaseEffect : MonoBehaviour |
| | | // { |
| | | // [SerializeField] UIEffect m_SuitEffect; |
| | | |
| | | int itemId = 0; |
| | | // int itemId = 0; |
| | | |
| | | private void OnEnable() |
| | | { |
| | | Display(itemId); |
| | | } |
| | | // private void OnEnable() |
| | | // { |
| | | // Display(itemId); |
| | | // } |
| | | |
| | | public void Display(int itemId, bool dirty = false) |
| | | { |
| | | this.itemId = itemId; |
| | | var curItem = ItemConfig.Get(this.itemId); |
| | | bool isPlay = true; |
| | | if (curItem == null) |
| | | { |
| | | isPlay = false; |
| | | return; |
| | | } |
| | | // public void Display(int itemId, bool dirty = false) |
| | | // { |
| | | // this.itemId = itemId; |
| | | // var curItem = ItemConfig.Get(this.itemId); |
| | | // bool isPlay = true; |
| | | // if (curItem == null) |
| | | // { |
| | | // isPlay = false; |
| | | // return; |
| | | // } |
| | | |
| | | int effectId = 0; |
| | | switch (curItem.ItemColor) |
| | | { |
| | | case 4: |
| | | effectId = 7119; |
| | | break; |
| | | case 5: |
| | | effectId = 7120; |
| | | break; |
| | | case 6: |
| | | case 7: |
| | | case 8: |
| | | effectId = 7121; |
| | | break; |
| | | } |
| | | // int effectId = 0; |
| | | // switch (curItem.ItemColor) |
| | | // { |
| | | // case 4: |
| | | // effectId = 7119; |
| | | // break; |
| | | // case 5: |
| | | // effectId = 7120; |
| | | // break; |
| | | // case 6: |
| | | // case 7: |
| | | // case 8: |
| | | // effectId = 7121; |
| | | // break; |
| | | // } |
| | | |
| | | if (curItem.BaseEffectID != 0) |
| | | { |
| | | effectId = curItem.BaseEffectID; |
| | | } |
| | | // if (curItem.BaseEffectID != 0) |
| | | // { |
| | | // effectId = curItem.BaseEffectID; |
| | | // } |
| | | |
| | | if (m_SuitEffect.effect != effectId) |
| | | { |
| | | //同一个位置替换特效需要先释放 |
| | | m_SuitEffect.StopImediatly(); |
| | | } |
| | | m_SuitEffect.effect = effectId; |
| | | // if (m_SuitEffect.effect != effectId) |
| | | // { |
| | | // //同一个位置替换特效需要先释放 |
| | | // m_SuitEffect.StopImediatly(); |
| | | // } |
| | | // m_SuitEffect.effect = effectId; |
| | | |
| | | if (m_SuitEffect.effect == 0) |
| | | { |
| | | isPlay = false; |
| | | } |
| | | if (isPlay) |
| | | { |
| | | m_SuitEffect.Play(); |
| | | } |
| | | else |
| | | { |
| | | m_SuitEffect.StopImediatly(); |
| | | } |
| | | // if (m_SuitEffect.effect == 0) |
| | | // { |
| | | // isPlay = false; |
| | | // } |
| | | // if (isPlay) |
| | | // { |
| | | // m_SuitEffect.Play(); |
| | | // } |
| | | // else |
| | | // { |
| | | // m_SuitEffect.StopImediatly(); |
| | | // } |
| | | |
| | | if (dirty) |
| | | { |
| | | SnxxzGame.Instance.StartCoroutine(Co_SetOrder(this, transform as RectTransform)); |
| | | } |
| | | } |
| | | // if (dirty) |
| | | // { |
| | | // SnxxzGame.Instance.StartCoroutine(Co_SetOrder(this, transform as RectTransform)); |
| | | // } |
| | | // } |
| | | |
| | | public static ItemBaseEffect Create(RectTransform transform) |
| | | { |
| | | var go = UIUtility.CreateWidget("ItemBaseEffect", "ItemBaseEffect"); |
| | | var behaviour = go.GetComponent<ItemBaseEffect>(); |
| | | // public static ItemBaseEffect Create(RectTransform transform) |
| | | // { |
| | | // var go = UIUtility.CreateWidget("ItemBaseEffect", "ItemBaseEffect"); |
| | | // var behaviour = go.GetComponent<ItemBaseEffect>(); |
| | | |
| | | SnxxzGame.Instance.StartCoroutine(Co_SetOrder(behaviour, transform)); |
| | | // SnxxzGame.Instance.StartCoroutine(Co_SetOrder(behaviour, transform)); |
| | | |
| | | var scale = 1f; |
| | | var itemBasic = transform.GetComponentInParent<CommonItemBaisc>(); |
| | | if (itemBasic == null) |
| | | itemBasic = transform.GetComponentInParent<ItemCell>(); |
| | | if (itemBasic != null) |
| | | { |
| | | scale = GetEffectScale(itemBasic.format); |
| | | } |
| | | else |
| | | { |
| | | var itemBehaviour = transform.GetComponentInParent<ItemBehaviour>(); |
| | | if (itemBehaviour != null) |
| | | { |
| | | if (itemBehaviour.backGround != null) |
| | | { |
| | | var size = itemBehaviour.backGround.rectTransform.rect.width; |
| | | scale = size / 84; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | var findPreciousItemBehaviour = transform.GetComponentInParent<FindPreciousItemBehaviour>(); |
| | | if (findPreciousItemBehaviour != null) |
| | | { |
| | | scale = 0.86f; //暂且写死 |
| | | } |
| | | } |
| | | } |
| | | // var scale = 1f; |
| | | // var itemBasic = transform.GetComponentInParent<CommonItemBaisc>(); |
| | | // if (itemBasic == null) |
| | | // itemBasic = transform.GetComponentInParent<ItemCell>(); |
| | | // if (itemBasic != null) |
| | | // { |
| | | // scale = GetEffectScale(itemBasic.format); |
| | | // } |
| | | // else |
| | | // { |
| | | // var itemBehaviour = transform.GetComponentInParent<ItemBehaviour>(); |
| | | // if (itemBehaviour != null) |
| | | // { |
| | | // if (itemBehaviour.backGround != null) |
| | | // { |
| | | // var size = itemBehaviour.backGround.rectTransform.rect.width; |
| | | // scale = size / 84; |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // var findPreciousItemBehaviour = transform.GetComponentInParent<FindPreciousItemBehaviour>(); |
| | | // if (findPreciousItemBehaviour != null) |
| | | // { |
| | | // scale = 0.86f; //暂且写死 |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | var rect = go.transform as RectTransform; |
| | | go.transform.SetParentEx(transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | rect.MatchWhith(transform); |
| | | go.transform.localScale = Vector3.one * scale; |
| | | go.transform.SetAsLastSibling(); |
| | | // var rect = go.transform as RectTransform; |
| | | // go.transform.SetParentEx(transform, Vector3.zero, Quaternion.identity, Vector3.one); |
| | | // rect.MatchWhith(transform); |
| | | // go.transform.localScale = Vector3.one * scale; |
| | | // go.transform.SetAsLastSibling(); |
| | | |
| | | return behaviour; |
| | | } |
| | | // return behaviour; |
| | | // } |
| | | |
| | | static IEnumerator Co_SetOrder(ItemBaseEffect behaviour, RectTransform transform) |
| | | { |
| | | yield return null; |
| | | // static IEnumerator Co_SetOrder(ItemBaseEffect behaviour, RectTransform transform) |
| | | // { |
| | | // yield return null; |
| | | |
| | | if (transform == null || behaviour == null) |
| | | { |
| | | yield break; |
| | | } |
| | | // if (transform == null || behaviour == null) |
| | | // { |
| | | // yield break; |
| | | // } |
| | | |
| | | Canvas canva = transform.GetComponentInParent<Canvas>(); |
| | | if (canva != null) |
| | | { |
| | | behaviour.m_SuitEffect.ResetOrder(canva.sortingOrder + 1); |
| | | } |
| | | // Canvas canva = transform.GetComponentInParent<Canvas>(); |
| | | // if (canva != null) |
| | | // { |
| | | // behaviour.m_SuitEffect.ResetOrder(canva.sortingOrder + 1); |
| | | // } |
| | | |
| | | if (behaviour.m_SuitEffect.maskArea == null) |
| | | { |
| | | behaviour.m_SuitEffect.SetMask(); |
| | | } |
| | | } |
| | | // if (behaviour.m_SuitEffect.maskArea == null) |
| | | // { |
| | | // behaviour.m_SuitEffect.SetMask(); |
| | | // } |
| | | // } |
| | | |
| | | static float GetEffectScale(ItemCellformat format) |
| | | { |
| | | switch (format) |
| | | { |
| | | case ItemCellformat.Format_80x80: |
| | | return 0.95f; |
| | | case ItemCellformat.Format_70x70: |
| | | return 0.83f; |
| | | case ItemCellformat.Format_64x64: |
| | | return 0.76f; |
| | | default: |
| | | return 1f; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // static float GetEffectScale(ItemCellformat format) |
| | | // { |
| | | // switch (format) |
| | | // { |
| | | // case ItemCellformat.Format_80x80: |
| | | // return 0.95f; |
| | | // case ItemCellformat.Format_70x70: |
| | | // return 0.83f; |
| | | // case ItemCellformat.Format_64x64: |
| | | // return 0.76f; |
| | | // default: |
| | | // return 1f; |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | |