Unity3d Research Institute at the beginning of Learning development editor (i)

Source: Internet
Author: User

Unity has a very rich expansion editor interface, if you downloaded a plugin that someone else has written on the Web, you will find out why its monitor panel view is different from the normal one. In fact, he is drawing through the Code of the Monitoring panel, this blog Momo to take you to learn the editor. As shown, this is the panel view that I expanded through the code.

The next simple script, the bindings hang on the camera.

Using unityengine;using System.Collections; public class test:monobehaviour{public    Rect mrectvalue;p ublic Texture Texture;}

, it is a very common structure in the Monitoring panel view.

Now we need to edit it dynamically in the code. Create an Editor folder in your project view, and do not create it if you have one. Put the script myeditor into the Editor folder.

MyEditor.cs

Using unityeditor;using unityengine; Custom Tset scripts [Customeditor (typeof (Test)]//execute scripts in edit mode, which is not very useful to delete. [executeineditmode]//please inherit Editorpublic class Myeditor:editor {//In this method you can draw the panel. Public    override void Oninspectorgui () {//Get test object        Test test = (test) target;//draw a window Test.mrectvalue = Editorguilayout.rectfield ("window coordinates", test.mrectvalue);//Draw a map slot test.texture =  Editorguilayout.objectfield (" Add a decal ", test.texture,typeof (texture), true) as texture; }}

The use of the editor is very simple, the Oninspectorgui () method can draw controls, Editorgui and Editorguilayout can create editor controls, and the GUI is very similar in usage. , the new panel has been greeted in the panel that returns to test. For the use of other controls, you can go to the API to check it yourself. The principle is similar.

It is worth mentioning that the C # language provides a great way to make your data more secure and to be able to listen to your get and assign operations in the Get Set method, which is recommended. Simply change the Test.cs.

Using unityengine;using System.Collections; public class test:monobehaviour{[Hideininspector][serializefield] Rect prectvalue;    Public Rect mrectvalue {        get{return prectvalue;}        set {            Prectvalue = value;        }    } [Hideininspector] [Serializefield] Texture ptexture;    Public Texture Texture {        get{return ptexture;}        set {            ptexture = value;}}    }

  

for example, [Hideininspector][serializefield] hides the data in the panel, and serializes it. It can help us to save the data permanently, and if not added, the value will be reset. It's like I added a decal first, and the map you just added to the game is null. or take texture as an example, when we use the texture object, it goes into the get plate to get the value of the private variable ptexture quickly. When the editor changes texture, it goes into the set section and saves the values in Ptexture. This will make your data more secure, as it operates on a private variable in the current class. You can also add some special code to the Get/set section.

Finally, the texture object can be used directly in update () or Ongui. Of course, it can be any object you define.

    • This article fixed link: http://www.xuanyusong.com/archives/2202
    • Reprint Please specify: Rain pine Momo April 11, 2013 Yu Yussong Momo Program Research Institute published

Unity3d Research Institute at the beginning of Learning development editor (i)

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.