Problems Encountered in the Small Semester Project

1. Problems encountered

Question 1: The project requires scene rendering

I searched online for scene rendering, which should mean making the scene more natural by adding different materials and adjusting some lights.

Production and rendering of this unity scene seen at station B

Question 2: The SelectIcon of the scene is too small to see clearly

By adjusting this property
insert image description here

Question 3: When the project is running, it is found that other windows are missing, there is only one Game window and it is maximized, resulting in UI deformation

Because the Maximize On Play on the right is turned on, the display is maximized when it is turned on,
and it is best to choose the ratio of the resolution on the left at the beginning so that the scene UI can maintain the ratio and is not easy to deform
insert image description here

Question 4: Problems with initial attempts at network requests

Because I used an unreferenced class, I went to the official website
insert image description here
to download it according to the article. After downloading, I still reported an error. I found that there was no reference added.
insert image description here
insert image description here
After confirming the download, I deleted it and downloaded it again. I found that there was one in vs. Reference, but there is no reference in Unity, and an error is still reported.
Re-download the file with dll from the official website, put it into Unity again, and it succeeds later

	// 定义回调函数 其实就是委托
    delegate void SendRequestCallback(JObject returnData);

    //佛山 101280800
    //两种写法
    private void CallBack(JObject returnData)
    {
    
    

    }

    private void Start()
    {
    
    
        //SendRequestCallback sendRequestCallback = new SendRequestCallback(CallBack); 
        SendRequestCallback sendRequestCallback = delegate (JObject returnData)
        {
    
    
            JObject data = (JObject)returnData["data"];

            Debug.Log(data);

            WeatherControl instance = WeatherControl.Instance;

            instance.humidity = data["shidu"].ToString();
            instance.temperature = data["wendu"].ToString();
            instance.airQuality = data["quality"].ToString();

            instance.windDirection = data["forecast"][0]["fx"].ToString();
            instance.windPower = data["forecast"][0]["fl"].ToString();
            instance.weatherCondition = data["forecast"][0]["type"].ToString();

        };

        //http://t.weather.sojson.com/api/weather/city/101280800
        //http://www.weather.com.cn/data/cityinfo/101280800.html

        StartCoroutine(SendRequest(new JObject(), "http://t.weather.sojson.com/api/weather/city/101280800", sendRequestCallback, "GET"));
    }




    /// <summary>
    /// 本方法将以Json格式向后端发送请求
    /// </summary>
    /// <param name="originJson">要发送的Json对象</param>
    /// <param name="url"></param>
    /// <param name="call">回调函数,不会处理异常,将信息原样返回</param>
    /// <param name="type">可以是"POST"、"GET"等</param>
    IEnumerator SendRequest(JObject originJson, string url, SendRequestCallback callback, string type)
    {
    
    
        // 将JObject转成json字符串
        string sendData = JsonConvert.SerializeObject(originJson);
        // 将字符串使用UTF-8编码成字节流
        byte[] postBytes = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(sendData);


        // 创建UnityWebRequest对象,用以发送请求。使用type指定请求的类型。
        using (UnityWebRequest webRequest = new UnityWebRequest(url, type))
        {
    
    
            // 设置要上传的数据
            webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(postBytes);

            // 创建后端返回数据的接收端
            webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();

            // 添加请求头。token是我们项目特有的
            //webRequest.SetRequestHeader("xxx", xxx);

            // 必须要添加Content-Type请求头,明确指定以json形式传输
            webRequest.SetRequestHeader("Content-Type", "application/json");

            // 发送请求,并等待后端返回后继续调用。
            yield return webRequest.SendWebRequest();

            // 当后端炸了,可能返回一个空字符串,对空字符串进行json解析会导致错误
            if (string.IsNullOrEmpty(webRequest.downloadHandler.text))
            {
    
    
                callback(null);
            }
            else
            {
    
    
                // 将后端返回的json字符串转换成一个JObject对象,使用callback传递。
                JObject returnData = JObject.Parse(webRequest.downloadHandler.text);
                callback(returnData);
            }

        }
    }

useful knowledge points

1. Put the generated object into an object and set the parent node of the object

people.transform.parent = peopleParent.transform

2. Get time

		DateTime time= DateTime.Now;
        string strNowTime = string.Format("{0:D}-{1:D}-{2:D}  {3:D}:{4:D}:{5:D}", time.Year, time.Month, time.Day, time.Hour, time.Minute, time.Second);

3. Display the playing video on the UI interface

[Unity] Display and play video on the UI interface

4. Use the version manager PlasticSCM that comes with Unity

About the initial use of Unity's version control tool PlasticSCM

5. Use code to change the Lighting property of the scene

		//改变场景中的天空盒
		RenderSettings.skybox = skyBox;
		//改变场景中的lntensity Multiplier  (强度乘数)
        RenderSettings.reflectionIntensity = 0.5f*(index+1);

        //RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Flat;
        RenderSettings.ambientSkyColor = index == 0 ? Color.HSVToRGB(0, 0, 0.2078f) : Color.HSVToRGB(0, 0, 0.9608f);

6. Right-click the Properties of the object in the Hierarchy window to open the locked Inspector window of the object

insert image description here

7. DOTween is a very powerful tween animation plug-in

You can easily realize some animation effects, you don’t need to write the animation controller yourself, you can also realize some camera movement, UI animation, etc.
Details: DOTween Chinese detailed explanation (continuously updated)
easing curve: Dotween SetEase Ease easing function

8. UniStorm is a very useful weather system plug-in

The weather system UniStorm of the Unity plug-

in uses the UniStorm plug-in to dynamically modify the weather effect according to the current city

Some summary of shallow use:
1. When creating, you need to use an object called Player whose tag name is also Player to store the prefab, and the particle effects of rain and snow weather can only be seen near it. 2. The
control panel is a Canvas prefab and UI public should adjust the priority, otherwise it will be overwritten
3. The options of the control panel are in
4. The weather type is obtained through the subscript of the built-in weather comparison table

Guess you like

Origin blog.csdn.net/anxious333/article/details/125579143