コード例 #1
0
ファイル: NFModelInput.cs プロジェクト: tzw28/NFUnitySDK
    // 获取模型部分数据Http
    private IEnumerator SendHttpRequestForPart(string url, string partName)
    {
        using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
        {
            yield return(webRequest.SendWebRequest());

            if (!string.IsNullOrEmpty(webRequest.error))
            {
                Debug.LogError(webRequest.error);
            }
            string data = UnGZipHttpData(webRequest.downloadHandler.data);
            var    resp = JSON.Parse(data);
            string msg  = resp["msg"].Value;
            string raw  = resp["sync_unit"]["raw"].Value;
            byte[] temp = Convert.FromBase64String(raw);
            raw = Encoding.UTF8.GetString(temp);
            if (raw == null)
            {
                Debug.Log("model ack null");
            }
            GameObject     xModelObject = mSceneModule.GetModelObject();
            NFModelControl modelCtl     = xModelObject.GetComponent <NFModelControl>();
            modelCtl.LoadPartFromRaw(raw, partName);
            modelCtl.UnifyPartScales();

            NFUIMain mainUI = mUIModule.GetUI <NFUIMain>();
            mainUI.SetMessage(0, "读取模型: " + "-1 ms");
            mainUI.SetMessage(1, "网格转换: " + "-1 ms");
            mainUI.SetMessage(2, "网络传输: " + "-1 ms");
            mainUI.SetMessage(3, "模型加载: " + "-1 ms");
            // string data = webRequest.downloadHandler.text;
        }
    }
コード例 #2
0
ファイル: NFModelInput.cs プロジェクト: tzw28/NFUnitySDK
    public IEnumerator RequireModelTargetHttp(int tar, int level)
    {
        string url = "http://" + mNetModule.strGameServerIP + ":9001/model";

        url += "?target=" + tar.ToString() + "&level=" + level.ToString();
        string data = "";

        // StartCoroutine(SendModelRequest(url));
        yield break;
        var    resp = JSON.Parse(data);
        string msg  = resp["msg"].Value;

        byte[] temp = Convert.FromBase64String(msg);
        msg = Encoding.UTF8.GetString(temp);
        string raw = resp["sync_unit"]["raw"].Value;

        temp = Convert.FromBase64String(raw);
        raw  = Encoding.UTF8.GetString(temp);

        System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
        long            timeStamp = (long)(DateTime.Now - startTime).TotalMilliseconds;                    // 相差秒数

        Debug.Log("receive msg " + timeStamp);
        // NFMsg.MsgBase xMsg = NFMsg.MsgBase.Parser.ParseFrom(System.Text.Encoding.Unicode.GetBytes(stream));
        // NFMsg.ReqAckModelTarget xData = NFMsg.ReqAckModelTarget.Parser.ParseFrom(xMsg.MsgData);
        // Debug.Log(xData.Msg.ToStringUtf8());
        // string[] msgs = xData.Msg.ToStringUtf8().Split(' ');
        string[]    msgs  = msg.Split(' ');
        List <long> times = new List <long>();

        times.Add(long.Parse(msgs[1]) - long.Parse(msgs[0]));
        times.Add(long.Parse(msgs[2]) - long.Parse(msgs[1]));
        times.Add(timeStamp - long.Parse(msgs[2]));
        // if (xData.SyncUnit.Raw == null)
        if (raw == null)
        {
            Debug.Log("model ack null");
        }
        GameObject     xModelObject = mSceneModule.GetModelObject();
        NFModelControl modelCtl     = xModelObject.GetComponent <NFModelControl>();
        // string raw = xData.SyncUnit.Raw.ToStringUtf8();
        // System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
        // stopwatch.Start(); //  开始监视代码运行时间

        DateTime beforDT = System.DateTime.Now;

        Debug.Log(String.Format("开始{0}ms.", beforDT.Millisecond));
        modelCtl.LoadTextureFromRaw(raw, ModelRawType.FORMATTED);
        // stopwatch.Stop(); //  停止监视
        // System.TimeSpan timespan = stopwatch.Elapsed;
        // double milliseconds = timespan.TotalMilliseconds;  //  总毫秒数
        DateTime afterDT = System.DateTime.Now;

        Debug.Log(String.Format("结束{0}ms.", afterDT));
        TimeSpan ts = afterDT.Subtract(beforDT);

        Debug.Log(String.Format("总共花费{0}ms.", ts.TotalMilliseconds));
        times.Add((long)ts.TotalMilliseconds);
        // Debug.Log("Recalculate Normals " + milliseconds);
        NFUIMain mainUI = mUIModule.GetUI <NFUIMain>();

        mainUI.SetMessage(0, "读取模型: " + times[0].ToString() + " ms");
        mainUI.SetMessage(1, "网格转换: " + times[1].ToString() + " ms");
        mainUI.SetMessage(2, "网络传输: " + times[2].ToString() + " ms");
        mainUI.SetMessage(3, "模型加载: " + times[3].ToString() + " ms");
    }