chenxin
2020-12-25 adb0dae8a82a7eabb4e686bc0e83c8859bf6445f
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using KTGMGemClient;
using LitJson;
using UnityEngine.Networking;
using System.Net;
using System.IO;
using System.Collections.Generic;
 
public class TestButton : MonoBehaviour
{
    //public Text t;
    // Start is called before the first frame update
    void Start()
    {
 
        // transform.Find("TowerBuyBtn").GetComponent<Button>().onClick.AddListener(OnClickTowerBuyBtn);
 
        // transform.Find("GuidePanel/Image_TowerPos2").GetComponent<Button>().onClick.AddListener(GetOneTowerPos);
 
        // int guide = PlayerPrefs.GetInt("GemBattleGuide");
 
        // string s="<color=red>范围伤害</color>";
        // t.text=s;
        // Debug.Log(s.Length);
        //TestFinalPanel();
        // isSending = false;
        // score = 0;
 
        // TestHttp();
 
    }
    public DoubleHitImg OneTimeKillObj;
 
    /// <summary>
    /// 显示一次性击杀飘字
    /// </summary>
    /// <param name="count"></param>
    private void ShowOneTimeKill()
    {
        OneTimeKillObj.SetkillCount();
    }
 
 
    int score;
    private void OnGUI()
    {
        GUILayout.BeginArea(new Rect(5, 330, 150, 300));
        // if (GUILayout.Button("SendRequest", GUILayout.Width(150), GUILayout.Height(70)))
        // {
        //     //SendRequest("aa", 4700, 28);
        //     score += 10;
        //     SendPost(score.ToString(), score, 1, "25关 3波");
        // }
 
        // if (GUILayout.Button("SendGet", GUILayout.Width(150), GUILayout.Height(70)))
        // {
        //     SendGet();
 
        // }
 
        // if (GUILayout.Button("清理本地存储", GUILayout.Width(150), GUILayout.Height(70)))
        // {
        //     PlayerPrefs.DeleteAll();
        //     Debug.Log("清理本地存储");
 
        // }
 
        // if (GUILayout.Button("生成Nick", GUILayout.Width(150), GUILayout.Height(70)))
        // {
 
        //     CreateNick();
        // }
        if (GUILayout.Button("击杀10", GUILayout.Width(150), GUILayout.Height(50)))
        {
            ShowOneTimeKill();
        }
 
        GUILayout.EndArea();
 
    }
 
    int killCoun1t = 0;
    private void CreateNick()
    {
        TimeSpan timeStamp = new TimeSpan(DateTime.Now.Ticks);
        Debug.Log(timeStamp.TotalMilliseconds);
 
        DateTime dt = DateTime.Now;
        Debug.Log(dt.ToString("fffff"));
 
 
        return;
 
        //--DateTime各种ToString("")//https://www.cnblogs.com/wangyuelang0526/archive/2012/06/27/2565289.html
        Debug.Log("DateTime");
        Debug.Log("MaxValue     " + DateTime.MaxValue.ToString());
        Debug.Log("MinValue     " + DateTime.MinValue.ToString());
        Debug.Log("Now      " + DateTime.Now.ToString());
        Debug.Log("Today        " + DateTime.Today.ToString());
        Debug.Log("UtcNow       " + DateTime.UtcNow.ToString());
        Debug.Log("Now.Date     " + DateTime.Now.Date.ToString());
        Debug.Log("Now.Day      " + DateTime.Now.Day.ToString());
        Debug.Log("Now.DayOfWeek    " + DateTime.Now.DayOfWeek.ToString());
        Debug.Log("Now.DayOfYear        " + DateTime.Now.DayOfYear.ToString());
        // string[] TimeFormats = DateTime.Now.GetDateTimeFormats();
        // for (int i = 0; i < TimeFormats.Length; i++)
        // {
        //     Debug.Log("Now.GetDateTimeFormats()     " + i.ToString() + "     " + TimeFormats[i]);
        // }
        Debug.Log("Now.Hour     " + DateTime.Now.Hour.ToString());
        Debug.Log("Now.IsDaylightSavingTime()       " + DateTime.Now.IsDaylightSavingTime());
        Debug.Log("Now.Kind     " + DateTime.Now.Kind.ToString());
        Debug.Log("Now.Millisecond      " + DateTime.Now.Millisecond.ToString());
        Debug.Log("Now.Minute       " + DateTime.Now.Minute.ToString());
        Debug.Log("Now.Month        " + DateTime.Now.Month.ToString());
        Debug.Log("Now.Second       " + DateTime.Now.Second.ToString());
 
        Debug.Log("Now.Subtract(DateTime)       " + DateTime.Now.Subtract(new DateTime(1970, 1, 1)).Ticks.ToString());
        Debug.Log("Now.Ticks        " + DateTime.Now.Ticks.ToString());
        Debug.Log("DateTime(1970, 1, 1).Ticks     " + new DateTime(1970, 1, 1).Ticks.ToString());
        Debug.Log("Now.TimeOfDay        " + DateTime.Now.TimeOfDay.ToString());
        Debug.Log("Now.ToBinary()       " + DateTime.Now.ToBinary().ToString());
        Debug.Log("Now.ToFileTime()     " + DateTime.Now.ToFileTime().ToString());
        Debug.Log("Now.ToFileTimeUtc()      " + DateTime.Now.ToFileTimeUtc().ToString());
        Debug.Log("Now.ToLocalTime()        " + DateTime.Now.ToLocalTime().ToString());
        Debug.Log("Now.ToLongDateString()       " + DateTime.Now.ToLongDateString());
        Debug.Log("Now.ToLongTimeString()       " + DateTime.Now.ToLongTimeString());
        Debug.Log("Now.ToOADate()       " + DateTime.Now.ToOADate().ToString());
        Debug.Log("Now.ToShortDateString()      " + DateTime.Now.ToShortDateString());
        Debug.Log("Now.ToShortTimeString()      " + DateTime.Now.ToShortTimeString());
        Debug.Log("Now.ToUniversalTime()        " + DateTime.Now.ToUniversalTime().ToString());
 
        Debug.Log("TimeSpan");
        TimeSpan timeSpan = DateTime.Now.TimeOfDay;
        Debug.Log("Days     " + timeSpan.Days.ToString());
        Debug.Log("Duration()       " + timeSpan.Duration().ToString());
        Debug.Log("Hours        " + timeSpan.Hours.ToString());
        Debug.Log("Milliseconds     " + timeSpan.Milliseconds.ToString());
        Debug.Log("Minutes      " + timeSpan.Minutes.ToString());
        Debug.Log("Negate()     " + timeSpan.Negate().ToString());
        Debug.Log("Seconds      " + timeSpan.Seconds.ToString());
        Debug.Log("Subtract(timeSpan)       " + timeSpan.Subtract(timeSpan).ToString());
        Debug.Log("Ticks        " + timeSpan.Ticks.ToString());
        Debug.Log(new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddTicks(timeSpan.Ticks).Ticks.ToString());
        Debug.Log("TotalDays        " + timeSpan.TotalDays.ToString());
        Debug.Log("TotalHours       " + timeSpan.TotalHours.ToString());
        Debug.Log("TotalMilliseconds        " + timeSpan.TotalMilliseconds.ToString());
        Debug.Log("TotalMinutes     " + timeSpan.TotalMinutes.ToString());
        Debug.Log("TotalSeconds     " + timeSpan.TotalSeconds.ToString());
        Debug.Log(timeSpan.ToString(@"hh\:mm\:ss"));
 
    }
    private JsonData loginData;
 
    public string imei0 = "";//设备信息唯一ID
    private bool isSending = false;
    void TestHttp()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            //GetetDeviceIMEI();//获取安卓手机IMEI
            imei0 = TDAA_SDKManager.Ins.GetDeviceId();//使用设备ID
        }
        else if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            imei0 = "MyTestGemBattle123";
        }
        Debug.Log("设置imei0:" + imei0);
    }
 
 
    /// <summary>
    /// 
    /// </summary>
    /// <param name="nickname"></param>
    /// <param name="score"></param>
    /// <param name="level"></param>
    private void SendPost(string nickname, int score, int level, string waveInfo)
    {
        Debug.Log("开始Post");
        if (isSending) return;
        isSending = true;
        string url = "http://9377-big-data.sbk-h5.com:8600/users/addrank";
 
        Dictionary<string, object> keyValues = new Dictionary<string, object>();
        keyValues.Add("username", nickname);
        keyValues.Add("nickname", nickname);
        keyValues.Add("score", score);
        keyValues.Add("level", level);
        keyValues.Add("extra", waveInfo);
 
        //string v = PostWebRequest(url, data.ToJson());
        //LoadPostTxt(v);
        //Debug.Log(v);
        //byte[] postBytes = System.Text.Encoding.Default.GetBytes(data.ToJson());
        //StartCoroutine(Post(url, postBytes));
 
        HttpHelper.Request(this, url, HttpHelper.MethodType.POST, keyValues, delegate (object value)
        {
            if (value != null)
                LoadPostTxt(value.ToString());
 
        }, HttpHelper.DownloadHanlderType.kHttpTEXT);
 
    }
 
    IEnumerator Post(string url, byte[] postBytes)
    {
        UnityWebRequest request = UnityWebRequest.Post(url, "POST");
        request.uploadHandler = new UploadHandlerRaw(postBytes);
        request.downloadHandler = new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");
        yield return request.SendWebRequest();
 
        if (request.isDone)
        {
            LoadPostTxt(request.downloadHandler.text);
        }
        else
        {
 
        }
    }
 
    private void LoadPostTxt(string value)
    {
        Debug.Log(value);
        loginData = JsonMapper.ToObject(value);
        if (loginData["error"].ToString() != "0")
        {
            Debug.Log("失败了");
        }
        else if (loginData["msg"].ToString() == "OK")
        {
            Debug.Log("成功了当前score:" + score);
            //SendGet();
        }
 
        isSending = false;
    }
 
    /// <summary>
    /// 下载排行榜
    /// </summary>
    private void SendGet()
    {
        Debug.Log("开始下载排行榜");
        string url = "http://9377-big-data.sbk-h5.com:8600/users/getrank";//9377-big-data.sbk-h5.com:8600/users/getrank?username=0001&limit=100
        Dictionary<string, object> keyValues = new Dictionary<string, object>();
        keyValues.Add("username", imei0);
        keyValues.Add("limit", 100);
 
        HttpHelper.Request(this, url, HttpHelper.MethodType.GET, keyValues, delegate (object value)
        {
            if (value != null)
                LoadGetTxt(value.ToString());
        }, HttpHelper.DownloadHanlderType.kHttpTEXT);
 
    }
 
    private void LoadGetTxt(string value)
    {
        JsonData getData = JsonMapper.ToObject(value);
        int myrank = int.Parse(getData["myrank"].ToString());
 
        JsonData rank = getData["rank"];
 
        List<HttpGetInfo> allHttpGetInfoLis = new List<HttpGetInfo>();
        HttpGetInfo info;
        foreach (JsonData item in rank)
        {
            info = new HttpGetInfo(item);
            allHttpGetInfoLis.Add(info);
        }
 
        foreach (HttpGetInfo item in allHttpGetInfoLis)
        {
 
            Debug.LogError(item.extra);
            Debug.LogError(item.nickname);
            Debug.LogError(item.waveInfo);
 
            // if (item.extra.ContainsKey("waveInfo"))
            // {
            //     Debug.LogError(item.extra["waveInfo"]);
            // }
            // string a = item.extra.ToJson();
            // Debug.LogError(a);
            // JsonData tmpData = JsonMapper.ToObject(a);
            // Debug.LogError(tmpData);
 
            // JsonData tmpData = item.extra;
            // if (tmpData != null)
            // {
            //     if (tmpData.Count > 0)
            // }
            // if (item.extra.ContainsKey("waveInfo"))
            // {
            //     Debug.LogError(item.extra["waveInfo"].ToString());
            // }
            Debug.Log($"item.username:{item.username}  item.nickname:{item.nickname} item.score:{item.score}  item.create_time:{item.create_time}");
        }
    }
 
 
    void TestFinalPanel()
    {
        GameObject a = Resources.Load<GameObject>("UI/Final/FinalPanel");
        GameObject go = Instantiate(a, transform);
        FinalPanel panelUI = go.GetComponent<FinalPanel>();
        panelUI.SetData("1关 1波", 101);
        //panelUI.SetPlayEffectAC(null);
    }
 
 
    private void OnEnable()
    {
        //EventCenter.Ins.Add((int)KTGMGemClient.EventType.AddCard, AddCard);
        // EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateFireLv2, CreateFireLv2);
        // EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateFirstWave, CreateFirstWave);
        // EventCenter.Ins.Add((int)KTGMGemClient.EventType.RestartWave, RestartWave);
        // EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.AddGold, AddGold);
        // EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateWaterLv1, CreateWaterLv1);
        // EventCenter.Ins.Add((int)KTGMGemClient.EventType.CreateSecondWave, CreateSecondWave);
        // EventCenter.Ins.Add((int)KTGMGemClient.EventType.SkillRelease, SkillRelease);
        // EventCenter.Ins.Add((int)KTGMGemClient.EventType.GuideFinish, GuideFinish);
 
    }
 
    //购买宝石
    private void OnClickTowerBuyBtn()
    {
        Debug.Log("点击了TowerBuyBtn");
    }
 
    private void AddCard()
    {
        Debug.Log("这里需要生成一个二级宝石");
    }
 
 
    private void CreateFireLv2()
    {
        Debug.Log("生成一个2级的火焰塔");
 
    }
 
    private void CreateFirstWave()
    {
        Debug.Log("第一关小怪出木元素小怪");
        StartCoroutine(CreateWave());
    }
 
    IEnumerator CreateWave()
    {
        yield return new WaitForSeconds(1f);
        Debug.Log("出怪完毕,等待火元素完成第一次充能");
        yield return new WaitForSeconds(1f);
        Debug.Log("火元素充能效果结束,暂停出怪");
        //EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.ChargingEnd);
 
    }
 
 
    private void RestartWave()
    {
        Debug.Log("恢复出怪");
        StartCoroutine(RestartWaveCoroutine());
    }
 
    IEnumerator RestartWaveCoroutine()
    {
        yield return new WaitForSeconds(1f);
        Debug.Log("出怪完毕");
        yield return new WaitForSeconds(1f);
        Debug.Log("怪物被杀光,这里需要停止出下一波怪物");
        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.KillDone);
 
    }
 
    private void AddGold(int gold)
    {
        Debug.Log("增加金钱:" + gold);
 
    }
 
    private void GetOneTowerPos()
    {
        Debug.Log("解锁了第一排第二个塔位");
        //EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.GetOneTowerPos);
 
    }
 
    private void CreateWaterLv1()
    {
        Debug.Log("生成一个1级的水元素塔");
    }
 
    private void CreateSecondWave()
    {
        Debug.Log("第二关小怪出火属性小怪");
        StartCoroutine(CreateSecondWaveCoroutine());
 
    }
    IEnumerator CreateSecondWaveCoroutine()
    {
        yield return new WaitForSeconds(1f);
        Debug.Log("当第二关第8波怪物生成后或玩家塔位收到第一次伤害后,这里需要暂停时间");
 
        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.SkillStep);
 
    }
 
    private void SkillRelease()
    {
        Debug.Log("释放技能");
 
        StartCoroutine(SkillReleaseDone());
 
    }
 
    IEnumerator SkillReleaseDone()
    {
        yield return new WaitForSeconds(1f);
        Debug.Log("技能效果播放完毕秒杀小怪后,暂停事件");
 
        EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.SkillReleaseDone);
 
    }
 
    private void GuideFinish()
    {
 
        Debug.Log("新手引导流程结束");
    }
 
}