zoukankan      html  css  js  c++  java
  • UnityAsseet-FieldScriptWriter‘s instruction

     Introduction

      We always like to define the protection level of the field as private when writing a script, but it is often wrong because of the spelling or case of the path and other reasons. And every time there is a lot of repetitive code that we need to write, FieldScriptWriter's just to optimize the problem.

      We often need to write code in this form when making UI Script:

      

      FieldScriptWriter can help us automatically generate this form of code.

      instruction

        1.AutoWriteVariablesWindow

      Open the menu "Tools/AutoWriterVariablesWindox"then you can open a unity editor window

      I create a demo ui panel for teach.First of all,we selected a protection level of the field,the selection can decide your field be public or private(Auto Wirte Findpath).We choose private.

      Then, we drag the gameobject that we want to make our script attch to Attach Object field.It will be on the basis of the variables transform path.In this instraction,we drag the LoginPanelDemo to it. 

      

      and then we need to input a classname for our script.such as LoginPanelDemoContainer.

      next step, we can choose one or many gameobjects that we want to get it or their compoent  in our script and click the button"Please Selected The GameObject Then Click Me"

      and then we can edit every variables type name and note.If the you want to define your custom type that you want to get,open the customType toggle.popon provide frequently-used type, and you can input the variables's name(default value is the gameobject'name to lower) and note,then click the button"Create"

    Then you can select a path to save your script ,and generate it, Let's check the script!!!

     That's pefect! you nerver worry about input wrong path and nerver write these repetitive code!

      2.GetPrivateCode And Get The Transform Path.

      Sometimes,we want to modify our code ,such as add new variables or change the path.In this case, we don't need to generate a new script file. Now we can use the GetPath function directly to get the code for this component or to get its path in the Hierarchy panel (to the root path).

      We only added the feature directly to find the get code for some common components. Other components or a custom scripting component can use our access path function.

      1.Copy FindPathCode To Clipboard

      All we need to do is select a gameobject and then expand the menu of the components you want to get and select "CopyPrivateGetCode"

      At this point, our code is written to the clipboard, so as long as we use Ctrl+V to paste this line of code:

    transform.Find("Canvas/LoginPanelDemo").GetComponent<RectTransform>();

    Note: the code path here starts with rootpath.Please make appropriate modifications to the path!!!

      2.Get The Path From Root Only

      For some components, such as user-defined scripts, there are no  "CopyPrivateGetCode" options in the menu, so we can simply get the path of the gameobject from rootpath in the Hierarchy.

      Right click on gameobject select FieldScriptWriter/GetPathToRoot to write the path of the gameobject to the clipboard.

      

      We use Ctrl+V to paste this line of path:"Canvas/LoginPanelDemo/BackGround/Title"

    Note: The path here starts with rootpath.Please make appropriate modifications to the path!!!

      So, using this asset allows you to avoid many of the problems of when you get the subobject components in the script. That's what this asset is all about!

  • 相关阅读:
    【Uvalive4960】 Sensor network (苗条树,进化版)
    【UVA 1151】 Buy or Build (有某些特别的东东的最小生成树)
    【UVA 1395】 Slim Span (苗条树)
    【UVA 10600】 ACM Contest and Blackout(最小生成树和次小生成树)
    【UVA 10369】 Arctic Network (最小生成树)
    【UVA 10816】 Travel in Desert (最小瓶颈树+最短路)
    【UVA 11183】 Teen Girl Squad (定根MDST)
    【UVA 11865】 Stream My Contest (二分+MDST最小树形图)
    【UVA 11354】 Bond (最小瓶颈生成树、树上倍增)
    【LA 5713 】 Qin Shi Huang's National Road System (MST)
  • 原文地址:https://www.cnblogs.com/StraussDu/p/7508142.html
Copyright © 2011-2022 走看看