欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

unity學(xué)習(xí)教程之定制腳本模板示例代碼

1、unity的腳本模板

新建網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),新建網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為新建上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個(gè)售后服務(wù)好的新建做網(wǎng)站的公司定做!

新版本unity中的C#腳本有三類,第一類是我們平時(shí)開發(fā)用的C# Script;第二類是Testing,用來做單元測試;第三類是Playables,用作TimeLine中管理時(shí)間線上每一幀的動畫、聲音等。我們點(diǎn)擊創(chuàng)建腳本時(shí),會自動生成unity內(nèi)置的一套模板:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour {

 // Use this for initialization
 void Start () {
  
 }
 
 // Update is called once per frame
 void Update () {
  
 }
}

如果我們開發(fā)時(shí)使用的框架有明顯的一套基礎(chǔ)模板, 那為項(xiàng)目框架定制一套模板會很有意義,這樣可以為我們省去編寫重復(fù)代碼的時(shí)間。這里介紹兩種方法。

2、修改默認(rèn)腳本模板

打開unity安裝目錄,比如D:\unity2018\Editor\Data\Resources\ScriptTemplates,unity內(nèi)置的模板腳本都在這里,那么可以直接修改這里的cs文件,比如我們將81-C# Script-NewBehaviourScript.cs.txt文件修改為如下,那下次創(chuàng)建C# Script時(shí)模板就會變成這樣:

////////////////////////////////////////////////////////////////////
//       _ooOoo_        //
//       o8888888o        //
//       88" . "88        //
//       (| ^_^ |)        //
//       O\ = /O        //
//      ____/`---'\____       //
//     .' \\|  |// `.       //
//     / \\||| : |||// \      //
//     / _||||| -:- |||||- \      //
//     | | \\\ - /// | |      //
//     | \_| ''\---/'' | |      //
//     \ .-\__ `-` ___/-. /      //
//    ___`. .' /--.--\ `. . ___      //
//    ."" '< `.___\_<|>_/___.' >'"".     //
//   | | : `- \`.;`\ _ /`;.`/ - ` : | |     //
//   \ \ `-. \_ __\ /__ _/ .-` / /     //
//  ========`-.____`-.___\_____/___.-`____.-'========   //
//       `=---='        //
//  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  //
//   佛祖保佑  永不宕機(jī)  永無BUG     //
////////////////////////////////////////////////////////////////////



using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class #SCRIPTNAME# : MonoBehaviour {

 // Use this for initialization
 void Start () {
  #NOTRIM#
 }
 
 // Update is called once per frame
 void Update () {
  #NOTRIM#
 }
}

3、拓展腳本模板

上面講的第一種方法直接修改了unity的默認(rèn)配置,這并不適應(yīng)于所有項(xiàng)目,這里第二種方法會更有效,可以針對不同的項(xiàng)目和框架創(chuàng)建合適的腳本模板。

首先,先創(chuàng)建一個(gè)文本文件MyTemplateScript.cs.txt作為腳本模板,并將其放入unity project的Editor文件夾下,模板代碼為:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyNewBehaviourScript : MonoBase {

 //添加事件監(jiān)聽
 protected override void AddMsgListener()
 {

 }
 
 //處理消息
 protected override void HandleMsg(MsgBase msg)
 {
  switch (msg.id)
  {
   default:
    break;
  }
 }

}

我們使用時(shí),需要在Project視圖中右擊->Create->C# FrameScript 創(chuàng)建腳本模板,因此首先要?jiǎng)?chuàng)建路徑為Assets/Create/C# FrameScript的MenuItem,點(diǎn)擊創(chuàng)建腳本后,需要修改腳本名字,因此需要在拓展編輯器腳本中繼承EndNameEditAction來監(jiān)聽回調(diào),最終實(shí)現(xiàn)輸入腳本名字后自動創(chuàng)建相應(yīng)的腳本模板。

unity學(xué)習(xí)教程之定制腳本模板示例代碼

代碼如下,將這個(gè)腳本放入Editor文件夾中:

using UnityEditor;
using UnityEngine;
using System;
using System.IO;
using UnityEditor.ProjectWindowCallback;
using System.Text;
using System.Text.RegularExpressions;

public class CreateTemplateScript {

  //腳本模板路徑
  private const string TemplateScriptPath = "Assets/Editor/MyTemplateScript.cs.txt";

  //菜單項(xiàng)
  [MenuItem("Assets/Create/C# FrameScript", false, 1)]
  static void CreateScript()
  {
    string path = "Assets";
    foreach (UnityEngine.Object item in Selection.GetFiltered(typeof(UnityEngine.Object),SelectionMode.Assets))
    {
      path = AssetDatabase.GetAssetPath(item);
      if (!string.IsNullOrEmpty(path) && File.Exists(path))
      {
        path = Path.GetDirectoryName(path);
        break;
      }
    }
    ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<CreateScriptAsset>(),
    path + "/MyNewBehaviourScript.cs",
    null, TemplateScriptPath);

  }
  
}


class CreateScriptAsset : EndNameEditAction
{
  public override void Action(int instanceId, string newScriptPath, string templatePath)
  {
    UnityEngine.Object obj= CreateTemplateScriptAsset(newScriptPath, templatePath);
    ProjectWindowUtil.ShowCreatedAsset(obj);
  }

  public static UnityEngine.Object CreateTemplateScriptAsset(string newScriptPath, string templatePath)
  {
    string fullPath = Path.GetFullPath(newScriptPath);
    StreamReader streamReader = new StreamReader(templatePath);
    string text = streamReader.ReadToEnd();
    streamReader.Close();
    string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(newScriptPath);
    //替換模板的文件名
    text = Regex.Replace(text, "MyTemplateScript", fileNameWithoutExtension);
    bool encoderShouldEmitUTF8Identifier = true;
    bool throwOnInvalidBytes = false;
    UTF8Encoding encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier, throwOnInvalidBytes);
    bool append = false;
    StreamWriter streamWriter = new StreamWriter(fullPath, append, encoding);
    streamWriter.Write(text);
    streamWriter.Close();
    AssetDatabase.ImportAsset(newScriptPath);
    return AssetDatabase.LoadAssetAtPath(newScriptPath, typeof(UnityEngine.Object));
  }

}

然后,在project中,點(diǎn)擊創(chuàng)建C# FrameScript,輸入腳本名字,對應(yīng)的腳本就已經(jīng)創(chuàng)建好了

unity學(xué)習(xí)教程之定制腳本模板示例代碼

4、總結(jié)

上面介紹了兩種方案,第一種適合玩玩,第二種方法顯然逼格高一些,為不同的項(xiàng)目和框架定制一套腳本模板,可以讓我們少寫一些重復(fù)代碼。按照上面介紹的方法,我們同樣可以修改和拓展Testing、Playables的腳本模板,甚至shader,我們也可以定制模板。

好了,以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對創(chuàng)新互聯(lián)的支持。

網(wǎng)頁題目:unity學(xué)習(xí)教程之定制腳本模板示例代碼
當(dāng)前地址:http://aaarwkj.com/article0/isghio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司企業(yè)建站、微信公眾號、、網(wǎng)站導(dǎo)航網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
中文字幕五月久久婷热| 一区二区三区不卡中文字幕| 天天干天天干夜夜操| 久久亚洲综合精品少妇| 欧美生活一区二区三区| 亚洲一区二区三区精品乱码| 在线观看不卡的黄色地址| 亚洲成人久久久久久久| 国产成人短视频在线播放| 欧美精品中出一区二区三区 | 亚洲黄色av网址在线观看| 92午夜福利在线视频| 精品国产一区二区三区大| av在线播放网址网站| 日韩国产欧美一区二区三区| 亚洲欧美午夜福利视频| 日韩欧美一级性生活片| 精品日韩av一区二区三区| 国产在线不卡中文字幕| 一区二区不卡日韩av| av色狠狠一区二区三区| 在线观看91高清视频| 婷婷久久五月综合激情| 欧美日韩另类激情免费| 小黄片免费在线播放观看| 色悠悠色综合视频在线| 亚洲中文字幕乱码丝袜在线精品| 人妻巨乳一区二区三区| 中文字幕伦理一区二区| 国内精品人妻中文字幕| 久久一二三四区中文字幕| 欧美黄色一级在线免费观看| 国产传媒在线播放一区| 外国男人搞亚洲女人在线| 亚洲欧美日韩在线第三页| 韩国三级在线视频网站| 日本熟妇中文字幕三级久久| 高清国产在线播放91| 91午夜精品在线观看| 亚洲美女高清一区二区三区| 亚洲天堂av在线播放|