雨谈老师塔防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;}
}
}
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;}
}
}
相关文章推荐
- Kinect结合Unity3D引擎开发体感游戏(一)
- Unity3D中脚本的执行顺序和编译顺序
- Unity3D动态对象优化代码分享
- unity3d发布apk在android虚拟机中运行的详细步骤(unity3d导出android apk)
- Unity3D游戏引擎实现在Android中打开WebView的实例
- unity3d调用手机或电脑摄像头
- 分享一个开源的网络游戏服务器架构—HouHai
- Unity3D插件详细评测及教学下载
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关
- Unity3d TransformPoint 函数研究
- Unity3d 动态加载fbx模型文件
- unity3d地形系统总结