Unity封裝dll教程整理


///作者Unity3d師兄---LeroyYang

   通過網上大神們的資料以及自己的整理,學習一下用vs2013簡單的封裝dll文件,方便接口模式下開發,使得邏輯層更為清晰。

操作步驟

1、打開vs2013,新建項目 -新建類庫 (注意最上面.NET Framework選擇3.5版本以下的,因為Unity3D(當前的Unity3D版本是3.5版) 支持的 .Net 是3.5版。 

如果選擇的是4.0版會出現 

Internal compiler error. See the console log for more information. output was:Unhandled Exception: System.TypeLoadException: Could not load type 'System.Runtime.Versioning. 

錯誤。  
 

2、項目新建完成之后,編寫簡單的測試代碼

using System;

namespace yanglei {

      public class Yl

    {    

         public static int Attack(int hp)

           {  

             return hp;     

        }    

    }

}

3、生成解決方案,找到vs項目工程文件夾目錄在E:\ProjectYang\bin\Debug下的dll文件

4、導入dll到Unity中,在Unity中Asset文件夾下新建文件夾名為Plugins目錄

5、在Unity新建腳本

using UnityEngine;

using System.Collections;

using yanglei;

public class actionscript : MonoBehaviour {

 void Start () {

        int hp = Yl.Attack(100);

        Debug.Log(hp);  

  }

}

運行結果

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM