Unity small function, knowledge point two

Source: Internet
Author: User
Tags transparent color

The opening and termination of a synergistic program:
In Unity3d, a synergistic program can be opened using the Monobehaviour.startcoroutine method, which means that the method must beMonobehaviour or inherited from MonobehaviourCalled in the class.
In Unity3d, a thread can be opened using Startcoroutine (String methodName) and Startcoroutine (IEnumerator routine).The difference isUsing a string as a parameter allows you to open a thread and terminate the thread before it ends, instead using IEnumerator as a parameter to wait for the thread to end without stopping at any time (unless you use the Stopallcoroutines () method), or by using a string 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.
There is also a way to terminate the co-program, set the active property of the Gameobject where the program is located to False, and when you set the active to Ture again, the co-program will no longer open It will not take effect if you set the enabled script for the collaboration program to false. This is because the co-operation is turned on as a thread, and Monobehaviour is a thread, they become non-interfering modules, unless the code is called, they work on the same object, only if the object is not visible to terminate the two threads at the same time. However, in order to manage our extra open threads, Unity3d put the call of the cooperative program in Monobehaviour, so that we can easily invoke the cooperative program in the specified script when we are programming, instead of being unable to manage it. In particular, it is easy to make mistakes in multi-person development by simply judging the thread based on the method name, which ensures that the object, the script is managed methodically, and the duplicate name is prevented.

Calculate the width of a font (for example, I am a programmer is a process need to insert an arrow, the length of the arrows, you need to calculate the number of spaces between the process)

 private  float  gettextwhide (int  fontsize, font font, string   str) {font. Requestcharactersintexture (str, fontsize, fontstyle.normal); Characterinfo Characterinfo;  float  width = 0f;  for  (int  i = 0 ; i < str. Length; I++ out   Characterinfo, fontsize); width  += characterinfo.advance;}  return   width;}  

Where fontsize is the font size for this text, font is the font used, str is the string you want to calculate the length of, and the function returns a width that indicates when the string is rendered on the specified text.

Ugui whitespace causes line wrapping: Converts spaces to full-width spaces, and half-width spaces cause text to wrap.


Implementation text display different colors of words, such as I am a programmer small white, where the programmer is red, the rest is black. Use the transparent Color label <color= #0000ff00 >111</color>, where 111 does not appear on the text but will occupy the grid, acting like a space, through the color value of this tag can change the corresponding font color.

Color Label Link: http://blog.csdn.net/ynn0705/article/details/7012516

Pause in Unity Edit state:

1.debug.break (); or UnityEditor.EditorApplication.isPaused = false;

2. Use the Editor class: Editorapplication.executemenuitem ("Edit/play");
3.unityeditor.editorapplication.isplaying = false;

Problem:
Application.datapath + "/resources/config/xxx" in unity works correctly on the editor when the path to the file is to be read, but does not read the file correctly after it is packaged
Solve:
This is because different platform Application.datapath specify the path is not the same, the editor mode represents the asset, after packaging the corresponding path is the folder generated when packaging "Xxx_data", it is necessary to copy the corresponding files to the "Xxx_data" folder, for example, after packaging the file path "E:\Unity\TowerDefense\Build\ Tower anti-_data\resources\config" corresponding to the editor "E:\Unity\TowerDefense\Assets\ Resources\config ".

Problem:
UNITY cannot import Video solutions
Solve
1.unity Import Video can not be converted to movietexture, when unity will prompt the movie import failure, this time need to switch to QuickTime Player, this software can convert unity's film into unity can use the material.
2.QuickTime does not run correctly and prompts "Please install Apple application Support", open the downloaded QuickTime installation package and select Install "Apple application Support.msi ", install select" Repair ".
The 3.unity supported movie formats are. mov. mpg. mpeg. mp4. avi. asf.
4. Successfully imported movie will generate a corresponding movie audio, this file is the movie's sound file.

Issue: Sliding events in Scroll rect are eventtrigger responses, so when item also responds to a click event by EventTrigger, it obscures the sliding event of the Scroll rect behind.
The Scrollrect component of the Ugui will have an event response conflict with the button or toggle component placed on it, which is manifested as the above component will block the response below, and on the button or toggle components, the effect can only be clicked and not sliding. You have to click Next to Slide.
Solve:
(1). Button:Button.onClick.AddListener (Delegate () {Buttononclick (button.gameobject);}); The onclick callback function is inherited from the UnityEngine.Events.UnityAction. Delegate. Because the same click event responds through different event modules, it is good to handle the issue of item blocking scroll Rect event. The delegate format is a function without any arguments and returns.
The button here is the one you want to press, and the Buttononclick is the event to be triggered when the button is pressed.
The second solution is: no buttons, 1. Create a script that inherits the Monobehaviour and Ipointerclickhandler interfaces (for example, Clickobject), 2. This script implements public void Onpointerclick ( Pointereventdata eventData) Method: 3. Create an empty object named Panel_ipointer, which is your button. and attach the Clickobject script to the object. Clicking on this object will call the Onpointerclick method.
The third type: Create an image (for example, named BTN), add the EventTrigger component to the Btn object, and select "Add New", "Pointerclick". Drag the Btn object to the trigger position. Then click "No Function" to select the Ontestclick event we want to trigger.
(2) Toggle: A method using ISON, such as if (Toggle.ison) {debug.log ("click")};

Unity small function, knowledge point two

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.