Reference Types : Class, interface, array, delegate, object, string (object is the root class for all types in C #, including all value types and reference types, and the string type is a direct relay from the object class. Sealed type (can no longer be inherited), and its instance represents a Unicode string)
If there is a return in the finally,try behind a try, will the code in finally run? If it is running, it will be run after return or return, and run after return.
public static const int a=1; Is this code wrong? What is it? -- const members are static, so you should remove the static
Talk about the difference between final,finally,finalize
Prevent rewriting,
try{}catch{}
Attempts to free resources and perform other cleanup operations before garbage collection
What is the difference between const and static readonly?
Compile constant quantity
Running constant quantity
What classes in net cannot be inherited? A: If you precede the class with the sealed keyword, it means that the class is sealed and the sealed class cannot be inherited. Sealed can be applied to instance methods and properties in addition to classes. A sealed method overrides a method in a base class, but it cannot be overridden in any derived class itself. The sealed modifier must always be used with override when applied to a method or property
Does C # support multiple inheritance? --not supported. Can be implemented using interfaces.
Will private members be inherited? --will, but cannot be accessed. So it seems that they cannot be inherited, but they are indeed inherited.
The method of virtual modification can be overridden by the quilt class.
Is it possible to allow a class to be inherited, but not allow one of the methods to overwrite it? --Yes, Mark this class as public, and mark this method as sealed.
Why can't I specify a modifier for a method in an interface? --the method in the interface is used to define the contract for communication between objects, and it is meaningless to specify that the method in the interface is private or protected. They default to public methods. All methods in an interface must be abstract, and the access modifiers of the method cannot be specified. You can have an implementation of a method in an abstract class, or you can specify the access modifier for a method.
Similarities and differences of String/stringbuilder
A string is an immutable data type that cannot be changed once the string object has been initialized. Ways to modify the contents of a string
And the operator is actually creating a new string.
StringBuilder allocates memory, and the modification of the string is done in the storage unit that is given to the StringBuilder instance. Str=null, declared without memory space, str= "" Declaration of Memory space
string s = new string ("XYZ"), and several string Object are created? --Two objects, one is "XyX", and the other is a reference to "XyX" like s
The cooperative program, that is, while the main program is running, open another logic processing to coordinate the execution of the current program. In other words, opening a co-worker is a thread that opens.
In Unity3d, you can use the Monobehaviour.startcoroutine method to open a synergistic program, which means that the method must be called in a monobehaviour or class that inherits from Monobehaviour.
In Unity3d, a thread can be opened using Startcoroutine (String methodName) and Startcoroutine (IEnumerator routine). The difference is that using a string as a parameter allows the thread to be opened and terminated before the thread ends, whereas using IEnumerator as a parameter can only wait for the end of the thread to terminate at any time (unless the Stopallcoroutines () method is used), and when the string is used as a parameter. Only one parameter can be passed at most when the thread is turned on, and the performance consumption is a bit larger, while using IEnumerator as a parameter does not have this limitation.
In Unity3d, use Stopcoroutine (string methodName) to terminate a synergistic program, using Stopallcoroutines () to terminate all the cooperating programs that can be terminated. However, both of these methods can only terminate the Monobehaviour in this program. The return type of the synergistic program is the Coroutine type. In Unity3d, the Coroutine class inherits from Yieldinstruction, so the return type of the co-program can only be null, the number of frames waiting (frame), and the waiting time.
Unity does not support multithreading, which means we have to manipulate it in the main thread, but unity can create many scripts at the same time, and can be tied to different game objects individually.
Each script awake, Update, Lateupdate, Fixedupdate, and so on, the method in the background has a summary.
Awake in the background ()
{
Awake () in script 0;
Awake () in script 1;
Awake () in script 2;
}
Backstage methods Awake, update, Lateupdate, Fixedupdate, and so on are in order, and so on all sub-scripts in the awake after the execution of the Start, update, Lateupdate and so on. So here's an explanation of unity's lack of multi-threading concepts.
Create a cube object in the Awake method of script 2. in the Awake method of script 0, get the cube object. If the execution order of the script is to execute SCRIPT2 first and then awake in the execution Script0 then Script0 can get to the cube object, but if the script is executed first Script0 then Script2, Then the SCRIPT0 will certainly report a null pointer error.
So the script in the actual project will be very, very much, in their order we don't know anyone. So my advice generally creates a game object or a Resources.load (Prefab) object in the Awake method. Go to the Start method to get the game object, or the game component, so you can be sure of the foolproof.
if you want to control the execution order of the script, it's not totally impossible! Unity can set the order in which the scripts are executed. As shown, select any script in the Inspector View and click Execution Order. Button. Clicking on the "+" in the lower right corner will bring up the drop-down window, including all the scripts in the game. When you finish adding a script, the smaller the number below the default time, the earlier the script will take the lead, if the script that is not set will be executed in the default order.
The life cycle of Unity scripts
update--Normal update for the update logic, which is automatically called by the system once per frame
lateupdate--defer the update, which is called after the Update method has finished executing, and every frame is called
awake--script Wakeup, the first method executed for the system, used for initialization of the script, only once in the life cycle of the script
fixedupdate--fixed update, setting update frequency
start--after the Awake method, the Update method executes before executing and executes only once
ondestroy--used when the current script is destroyed
Call the game object with a script-bind the script to a game object, or you can dynamically bind the script and delete the script in the code. Any one game object can bind multiple game scripts at the same time, and these scripts do not interfere with each other, each completes their own life cycle
gameobject.createprimitive--is used to create a primitive game object whose parameters can be set to the game object provided by the system by default, such as cubes, spheres, cylinders, etc.
addcomponet--for adding components to game objects
renderer.material.color--setting the color or texture of the rendered material
transform.position--Setting the location of the game object
Get the Game object:
Get objects by object name--use the Find method to pass in the full path name of an object to get the game object in code
Get a single Game object by tag--Enter the tag name directly to the right of the Element 0 option in the "Add tag" to add a new label Findwithtag () The--findwithtag method can only get a game object, if more than one object in the program has the same label added, then This method only gets the first object to add this tag
You can return an array of game objects by getting multiple game Object--findgameobjectswithtag () methods through a tag and passing the corresponding tag name as a parameter.
Adding components and modifying components
When adding a game component, you can use the AddComponent () method, because the component itself does not have a corresponding Delete method, you need to use the parent class to execute Object.destroy ()
Render.material references the material of the current script binding object, assigning it directly to modify the object material
A game object can bind multiple scripts, enabling the interaction between these scripts to use the broadcast mechanism
Broadcast and messages sent between game objects are broadly divided into:
1, sent to the child object, will be sent to the object's siblings or descendant objects;
Gameobject.broadcastmessage ("Receivebroadcastmessage", "A0---broadcastmessage ()");
Accept messages sent by the parent class:
function Receivebroadcastmessage (str:string)
{Debug.Log ();}
2, send to themselves, send to their own objects;
Gameobect.sendmessage ();
3, sent to the parent object, sent to the sibling of the object or to the Ancestor object
Gameobject.sendmessageupwards ();
Clone Game Object Instantiate ()
Dynamically add a Script Component--addcomponent () to a game object, passing the name of the script as a parameter to complete the Script component additions
The obj.transform.position reference gets the position of the obj game object in the three-dimensional coordinate system, stored in the Vector3 container (the coordinates that hold the XYZ axis)
Transform. Rotate ()--for setting the rotation of the model around itself, the speed of rotation and the direction of rotation
Transform. Rotatearound ()--used to set the model to rotate around a point
time.deltatime--used to record the time spent on the previous frame, as a speed factor for model rotation
Vector3.right--x axis Direction
Vector3.up--y axis Direction
Vector3.forward--z axis Direction
Transform. Translate () The only parameter is the direction of the translational model obj.transform.Translate (Vector3.forward * time.deltatime)
naming rules--must correspond to the name of the script in the project resource view, otherwise it cannot be successfully bound to the game object
Unity3d Tool Class
time--getting the current system time
time.time--starts from the start of the game, indicating the game time as of now.
time.deltatime--gets the time spent in the update () method to complete the previous frame
The sum of the fixed consumed time in the Time.fixedtime--fixedupdate () method
Use the Waitforseconds () method to allow the program to wait for a period of time in seconds, which directly causes the main thread of the game to enter a wait state. The return value of the method is the IEnumerator type, and the yield return new Waitforseconds (2) is called where it needs to wait.
All the models used in unity are rotated, and the bottom layer is implemented by a four-dollar number, which accurately calculates the angle of rotation of the model.
Unity3d's C # script