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

雨谈老师塔防Editor 路点

2015-09-01 14:28 363 查看
Edetor详细解释

Editor文件夹可以在根目录下,也可以在子目录里,只要名子叫Editor就可以。比如目录:/xxx/xxx/Editor  和 /Editor 是一样的,无论多少个叫Editor的文件夹都可以。Editor下面放的所有资源文件或者脚本文件都不会被打进发布包中,并且脚本也只能在编辑时使用。一般呢会把一些工具类的脚本放在这里,或者是一些编辑时用的DLL。 比如我们现在要做类似技能编辑器,那么编辑器的代码放在这里是再好不过了,因为实际运行时我们只需要编辑器生成的文件,而不需要编辑器的核心代码。

2.Editor Default Resources

Editor Default Resources注意中间是有空格的,它必须放在Project视图的根目录下,如果你想放在/xxx/xxx/Editor Default Resources 这样是不行的。你可以把编辑器用到的一些资源放在这里,比如图片、文本文件、等等。它和Editor文件夹一样都不会被打到最终发布包里,仅仅用于开发时使用。你可以直接通过EditorGUIUtility.Load去读取该文件夹下的资源。

using UnityEngine;

using System.Collections;

public class PathNode : MonoBehaviour {

//父路点
public PathNode m_parent;
//子路点
public PathNode m_next;
// Use this for initialization
//设置当前路点的子路点函数
public void SetNext(PathNode node){
if(m_next!=null){m_next.m_parent=null;}
m_next = node;
node.m_parent = this;

}

//  绘制一个辅助图标,只在编辑界面显示,这个图标要放在根目录Gizmos文件夹下面

void OnDrawGizmos(){
Gizmos.DrawIcon (this.transform.position,"hbs01tif.tif");
}

}

——————————————————————————————————————————————————

using UnityEngine;

using UnityEditor;

using System.Collections;

public class PathTool : ScriptableObject {

//存放路点
static PathNode tool_parent=null;
//在编辑器中添加菜单PathTool
//设置父路点菜单  快捷键 Ctrl+q;
[MenuItem("PathTool/Set Parent %q")]
static void SetParent(){
//如果没有选择如何物体,或选择物体大于1,返回
if(!Selection.activeGameObject || Selection.GetTransforms(SelectionMode.Unfiltered).Length>1){return;}
if(Selection.activeGameObject.tag=="pathnode")
{tool_parent=Selection.activeGameObject.GetComponent<PathNode>();}

}

// 如果什么都没有选择将禁用菜单功能

[MenuItem ("PathTool/Set Parent %q", true)]
static bool ValidateSelection() {
if (Selection.activeGameObject == null || Selection.activeGameObject.tag != "pathnode" )
{ return false;
} else {return true;}

}

//设置子路点菜单  快捷键 Ctrl+w;
[MenuItem("PathTool/Set next %w")]
static void SetNextChild(){
if(!Selection.activeGameObject || tool_parent==null || Selection.GetTransforms(SelectionMode.Unfiltered).Length>1 )
{return;}
if (Selection.activeGameObject.tag == "pathnode") {
tool_parent.SetNext(Selection.activeGameObject.GetComponent<PathNode>());
tool_parent=null;
}
}
//选择的物体不是路点时禁用
[MenuItem ("PathTool/Set next %w", true)]
static bool ValidateSelection1() {
if (Selection.activeGameObject == null || Selection.activeGameObject.tag != "pathnode" ||tool_parent==null)
{ return false;
} else {return true;}

}

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