liuzhiwei
2020-12-22 987fd66dc6d6c28e3ed08a08141ddc3dbd772cea
Assets/Scripts/Guide/TestButton.cs
@@ -25,26 +25,132 @@
        // string s="<color=red>范围伤害</color>";
        // t.text=s;
        // Debug.Log(s.Length);
        TestFinalPanel();
        //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);
            SendPost("aaa", 7890, 1);
        // 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("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;
@@ -72,15 +178,26 @@
    /// <param name="nickname"></param>
    /// <param name="score"></param>
    /// <param name="level"></param>
    private void SendPost(string nickname, int score, int level)
    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", imei0);
        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)
@@ -88,6 +205,24 @@
        }, 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)
@@ -100,9 +235,11 @@
        }
        else if (loginData["msg"].ToString() == "OK")
        {
            Debug.Log("成功了");
            SendGet();
            Debug.Log("成功了当前score:" + score);
            //SendGet();
        }
        isSending = false;
    }
    /// <summary>
@@ -110,6 +247,7 @@
    /// </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);
@@ -129,25 +267,40 @@
        int myrank = int.Parse(getData["myrank"].ToString());
        JsonData rank = getData["rank"];
        List<HttpGetInfo> allHttpGetInfoLis = new List<HttpGetInfo>();
        HttpGetInfo info;
        foreach (JsonData item in rank)
        {
            allHttpGetInfoLis.Add(
                new HttpGetInfo
                {
                    id = int.Parse(item["id"].ToString()),
                    username = item["username"].ToString(),
                    nickname = item["nickname"].ToString(),
                    score = int.Parse(item["score"].ToString()),
                    level = int.Parse(item["level"].ToString()),
                    extra = item["extra"],
                    create_time = int.Parse(item["create_time"].ToString()),
                }
            );
            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}");
        }
    }
@@ -155,10 +308,11 @@
    void TestFinalPanel()
    {
        GameObject go = Instantiate(Resources.Load<GameObject>("UI/Final/FinalPanel"), transform);
        GameObject a = Resources.Load<GameObject>("UI/Final/FinalPanel");
        GameObject go = Instantiate(a, transform);
        FinalPanel panelUI = go.GetComponent<FinalPanel>();
        panelUI.SetData("成绩 25关 3波", 789220);
        panelUI.SetPlayEffectAC(null);
        panelUI.SetData("1关 1波", 101);
        //panelUI.SetPlayEffectAC(null);
    }
@@ -285,13 +439,4 @@
}
public class HttpGetInfo
{
    public int id;
    public string username;
    public string nickname;
    public int score;
    public int level;
    public JsonData extra;
    public int create_time;
}