8

#你好Unity3D#Project脚本执行双击资源操作

 3 years ago
source link: https://www.xuanyusong.com/archives/3875
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

#你好Unity3D#Project脚本执行双击资源操作

雨松MOMO 【你好Unity3D】 围观111336 条评论 编辑日期:2016-04-29 字体:

Unity的Project里面放了很多游戏资源,比如脚本或者图片。正常情况下我们可以通过鼠标双击来进行打开。假如我现在不想主动双击打开,我想自动打开某个脚本或者图片再或者别的资源怎么办?

如下代码所示,两种方法都OK 。这里是测试我用的是鼠标主动选择的对象,可以把需要打开的资源对象使用AssetDatabase.LoadAssetAtPath读取进来, 这样就可以打开任意对象了。

using UnityEngine;
using System.Collections;
using UnityEditor;
public class MyPng :Editor {
[MenuItem("Assets/Auto Open")]
static void Run()
var obj = Selection.activeObject;
if (obj != null) {
if (!string.IsNullOrEmpty (AssetDatabase.GetAssetPath (obj.GetInstanceID ()))) {
AssetDatabase.OpenAsset (obj);
[MenuItem("Assets/Auto Open2")]
static void Run1()
var obj = Selection.activeObject;
if (obj != null) {
if (!string.IsNullOrEmpty (AssetDatabase.GetAssetPath (obj.GetInstanceID ()))) {
EditorApplication.ExecuteMenuItem ("Assets/Open");
作者:雨松MOMO
专注移动互联网,Unity3D游戏开发
捐 赠写博客不易,如果您想请我喝一杯星巴克的话?就进来看吧!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK