您的位置:首页 > 移动开发 > Unity3D

Unity 使用自定义资源(.asset) 添加 Assets 菜单按钮二

2017-12-18 11:36 267 查看

Unity 使用自定义资源(.asset) 添加 Assets 菜单按钮二

之前一篇Unity使用自定义资源(.asset)

上篇依然有效,添加一个创建 .asset 的方法,在 Assets 菜单栏添加一个创建按钮,执行创建。

Bullet.cs 代码如下

类上面添加一行

[CreateAssetMenu(fileName = "Bullet", menuName = "New Bullet", order = 1)]


作用在 Assets 文件夹下,鼠标右键,菜单栏中添加一个按钮项,菜单名为 menuName,并执行生成名为 fileName 的脚本,order 为按钮显示顺序

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

// 在 Assets 下添加菜单
// fileName 生成名为 Bullet的脚本
// menuName 菜单按钮名New Bullet
// order    按钮显示顺序
[CreateAssetMenu(fileName = "Bullet", menuName = "New Bullet", order = 1)]
public class Bullet: ScriptableObject {

// Bullet 类直接继承自 ScriptableObject

// 子弹速度
public int speed = 10;

// 伤害数值
public int damage = 5;

// 子弹关联的特效
public GameObject effectObj;

public bool CompareSpeed(float _speed)
{
return speed > _speed;
}

}


在 Assets 下任意文件夹内,鼠标右键, Create -> New Bullet



在鼠标所在目录下,生成 Bullet.asset

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity AssetMenu