Problems Encountered in Digital Twin Project 2.0

Problems encountered:

1. The problem of class reference failure occurs when using other people's code (UnityEngine can be referenced normally)

insert image description here
Solution:

  • Delete the .sln in the project root directory
  • insert image description here
    It should be different configurations of different computers, which lead to different sln files, which may interfere.

2. Moving Logs/AssetImportWorker 1.log to Logs/AssetImportWorker 1-prev.log: Another program is using this file and the process cannot access it.

[Solution] Moving Logs/AssetImportWorker 1.log to Logs/AssetImportWorker 1-prev.log: Another program is using this file, and the process cannot access it.

3. Unity can't see things that are too far away, but will see the sky box.

Solution: adjust Clipping Planesthe parameters of the camera
insert image description here

4. Undetectable by radiation

Solution: Add a collision body (but there may be false touch problems).
Ray detection requires a collision body (can be checked as Trigger)

5. When writing to Excel, there are always inexplicable error reports. Some files are OK and some are not.

It seems that because Excel has hyperlinks, there will be no problem reading, but writing will not find the corresponding table

6. When importing the library, download the dll file and put it in uinty and then use unity without reporting an error, but vs reports an error

Because unity adds references but vs does not add references, I don't know why unity depends on vs but not completely.

Solution:
select this first
insert image description here
, then click this to open that reference and that option.
insert image description here
After opening, add a reference
insert image description here
and add it according to the path of the dll file you imported.
insert image description here

7. When using Lambda expressions to add click events, the bound loop variables are all the maximum values ​​(propertyTypeList.Count)

insert image description here
The reason should be that the variable corresponding to the implicit function is the position of the loop variable, and when triggered, the loop variable is already the maximum value of the array + 1 (although the temporary variable is destroyed, it should be the variable that calls the address that causes the problem)

Solution: Use a global reference type or turn the value type into an application type

//-------------1.
       foreach (Toggle toggle in toggles)
            toggle.onValueChanged.AddListener( ()=> {
    
     VideoChange(toggle); });
//-------------2.
		//因为匿名函数不可以有值类型变量 要换成引用变量
		for(int i=0;i< toggles.Count; i++)
        {
    
    
			Toggle item = toggles[i];
			//添加点击事件
			toggles[i].onValueChanged.AddListener((isOn) => {
    
     print(item); });
		}

Learned knowledge:

  • The TextAsset class can be used to read the text content in txt format in the project, and use .text to get the string of the text content

  • yield return WWW: Wait for a network request to complete and continue execution from the current location ( usage of C# coroutine. )

  • The as operator is similar to the cast operation; however, if the conversion is not possible, as returns null instead of throwing an exception.

  • typeofThe System.Type object used to get the type. Cooperate with Resources.Load(“路径”,Type) file path and Type type

  • ToString( string format )format is an optional format code string. ( [C#] ToString() parameter format analysis complete collection )

  • Some simple click events in the UI can be directly written in the form of anonymous functions with code additions (a bool parameter passed is his SetActive, should it be?)

  • Mathf.Clamp public static float Clamp(float value, float min, float max);
    returns the value if the value is between min and max, returns the min value if it is less than min, and returns the max value if it is greater than max

  • ref和out

    In a function, if outor is used refas a keyword before a formal parameter, as long as the formal parameter is modified in the function body, the value assigned to the actual parameter of the corresponding formal parameter when the function is called before will also be modified. Its mechanism is that the formal parameters used outand modified are reference types (similar to pointers in C language), rather than value types, which means that the information they store is an address , not a value type.ref

    ref out
    the difference It is required that the variable must be initialized (assigned with an initial value) before being passed, but you can do nothing to it when calling; while out does not need to assign an initial value to the variable of this formal parameter before calling. Can only be used to pass values ​​out of methods. No matter what the external value is, using out is to clear the parameter, and then it must be assigned a value in the function body. That is to say, the variable modified by out must be assigned in the function body at the time of calling.

    Simply put, ref has both in and out (or no out), and out has no in and out.

    Example: What does the keyword out in c# mean? what does ref mean? What's the difference?

  • The difference between Image and RawImage: Unity - UGUI: Image and RawImage

  • You can quickly configure components through the Reset function written by yourself. The use of Unity's own function Reset()

  • Common properties of UI interactive components (can be used to implement some simple animations): [Unity study notes] Common properties of interactive components: Interactable, Transition, Navigation

  • To interact with objects in the scene, you need to add a Physics Raycaster to the camera (in the case of EventSystemIPointerClickHandler ), then inherit the interface , implement the method OnPointerClick, and write the clicked event in it

  • Switching in different states can use conflicting points as trigger conditions, which can make the switching of states smoother.

Guess you like

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