wangguan
2020-12-02 d58e991831a3cda2c6d9f1f7bb16e959fc74cbc8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Core.Utilities;
using TowerDefense.Level;
using System;
using Protobuf;
using DG.Tweening;
 
 
/**
 * 无尽模式道具掉落管理器
 * @Author: chenxin
 * @Date: 2020-10-20 15:00:12
 */
namespace KTGMGemClient
{
    public class EndlessDrop
    {
        /// <summary>
        /// 唯一id,用于区分每一个掉落,获得掉落时EndlessDropManager会为id分配值
        /// </summary>
        public int Id;
 
        /// <summary>
        /// 配置数据
        /// </summary>
        public reward Reward;
 
        /// <summary>
        /// 自动拾取时间
        /// </summary>
        public float AutoPickupTime;
 
        /// <summary>
        /// 未拾取经历时间 > 自动拾取时间,自动获得
        /// </summary>
        public float ElapsedTime;
 
        /// <summary>
        /// 是否拾取完成,自动拾取/玩家手动点击拾取完成,拾取完成意味着真正的获得了掉落,清理场景时也要获得所有还未拾取的掉落
        /// </summary>
        public bool IsPickupCompleted;
    }
 
    public class EndlessDropReward : MonoBehaviour
    {
        /// <summary>
        /// 发光粒子特效
        /// </summary>
        public ParticleSystem LightParticle;
 
        /// <summary>
        /// item图标
        /// </summary>
        public Image Icon;
 
        /// <summary>
        /// 自动拾取时间
        /// </summary>
        public float AutoPickupTime { get; set; } = 5f;
 
        public EndlessDrop DropData;
 
        private string path = "UI/Props/";
 
        public event Action<EndlessDrop> ClickDropEvent;
 
        private bool isBox;//是否是宝箱
        private GameObject propBtn;
 
        // Start is called before the first frame update
        private void Start()
        {
            ClickDropEvent += EndlessDropManager.instance.OnClickDrop;
            propBtn = GameObject.Find("BottomUI/PropsObtained/PropButton");
        }
 
        public GameObject drapIcon;
        public void OnClick()
        {
            // if (isBox)
            // {
            //     EndlessDropManager.instance.FlyIcon(transform.parent, Icon.sprite, transform.position, (propBtn.transform as RectTransform).position, true);
            // }
            // else
            // {
            //     FlyImage fly = EndlessDropManager.instance.CreateIcon(transform.parent);
            //     fly.SetDestination(Icon.sprite, transform.position, (propBtn.transform as RectTransform).position, false);
            // }
            // if (ClickDropEvent != null)
            //     ClickDropEvent(DropData);
 
        }
 
        public void SetIcon()
        {
            string resId = "";
            Vector3 scale = Icon.rectTransform.localScale;
 
            if (DropData.Reward.id == 0)
            {
                resId = $"{path}{(int)DropData.Reward.type}";
                isBox = true;
            }
            else
            {
                resId = $"{path}{(int)DropData.Reward.type}_{DropData.Reward.id}";
                scale *= 1.5f;
                isBox = false;
 
            }
            Icon.sprite = Resources.Load<Sprite>(resId);
            Icon.SetNativeSize();
 
            //Debug.Log("开始缩放");
            Icon.rectTransform.localScale = scale * 0.5f;
            Icon.rectTransform.DOScale(scale, 0.5f);
 
        }
 
        /// <summary>
        /// 播放发光的粒子特效
        /// </summary>
        public void PlayParticle()
        {
            LightParticle.Play();
        }
 
 
    }
}