Unity3D expand hierachry by code
2015-07-07 11:33
405 查看
public static void SetExpandedRecursive(GameObject go, bool expand)
{
var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow");
var methodInfo = type.GetMethod("SetExpandedRecursive");
EditorApplication.ExecuteMenuItem("Window/Hierarchy");
var window = EditorWindow.focusedWindow;
methodInfo.Invoke(window, new object[] { go.GetInstanceID(), expand });
//Selection.activeObject = go;
}
public static void Collapse(GameObject go, bool collapse)
{
// bail out immediately if the go doesn't have children
if (go.transform.childCount == 0) return;
// get a reference to the hierarchy window
var hierarchy = GetFocusedWindow("Hierarchy");
// select our go
SelectObject(go);
// create a new key event (RightArrow for collapsing, LeftArrow for folding)
var key = new Event { keyCode = collapse ? KeyCode.RightArrow : KeyCode.LeftArrow, type = EventType.keyDown };
// finally, send the window the event
hierarchy.SendEvent(key);
}
public static void SelectObject(Object obj)
{
Selection.activeObject = obj;
}
public static EditorWindow GetFocusedWindow(string window)
{
FocusOnWindow(window);
return EditorWindow.focusedWindow;
}
public static void FocusOnWindow(string window)
{
EditorApplication.ExecuteMenuItem("Window/" + window);
}
from: http://answers.unity3d.com/questions/656869/foldunfold-gameobject-from-code.html
相关文章推荐
- Unity3D调用自己封装的dll
- Unity中的mvc框架_StrangeIoC(之四)
- Unity中的mvc框架_StrangeIoC(之三)
- Unity中的mvc框架_StrangeIoC(之二)
- Unity中的mvc框架_StrangeIoC(之一)
- C#开发Unity游戏教程之Scene视图与脚本的使用
- C#开发Unity游戏教程之Scene视图与脚本的使用
- Unity 3D知识体系结构
- 【Unity3D游戏开发】NGUI之渐变加载到100%的Loading场景进度条 (一)
- Unity对象池的实现
- [游戏安全] Unity3D游戏无意中的发现
- unity3d开源Ultimate MMORPG插件技术文档菜鸟翻译第6页
- C#开发Unity游戏教程之Scene视图与脚本的使用
- unity3d开源Ultimate MMORPG插件技术文档渣翻译第5页
- unity3d开源Ultimate MMORPG插件技术文档渣翻译第4页
- Unity 泛型T的用法
- unity3d对象池的使用
- unity3d Panel之间的转换
- unity5.0利用自带UI制作滚动条
- Unity3D研究院之Time.timeScale、游戏暂停(七十四)