C
Chocolade1972
Guest
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PrefabReplace : EditorWindow
{
public class Tree<GameObject>
{
public GameObject Data { get; set; }
public IEnumerable<Tree<GameObject>> Childs { get; set; }
public bool Opened { get; set; }
public Tree()
{
Childs = Enumerable.Empty<Tree<GameObject>>();
Opened = true;
}
}
public static class GUIExtension
{
public static void ShowTree(Tree<GameObject> tree)
{
if (tree.Childs.Count() > 0)
{
tree.Opened = EditorGUILayout.Foldout(tree.Opened, tree.Data.ToString());
}
else
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space(8);
EditorGUILayout.LabelField(tree.Data.ToString());
EditorGUILayout.EndHorizontal();
}
EditorGUI.indentLevel++;
if (tree.Opened)
{
foreach (var child in tree.Childs)
{
// 再帰
ShowTree(child);
}
}
EditorGUI.indentLevel--;
}
}
Vector2 scroll;
Tree<GameObject> tree;
void OnGUI()
{
if (tree == null) return;
scroll = EditorGUILayout.BeginScrollView(scroll);
GUIExtension.ShowTree(tree);
EditorGUILayout.EndScrollView();
}
void OnSelectionChange()
{
if (Selection.activeGameObject != null)
tree = GameObjectToTree(Selection.activeGameObject);
Repaint();
}
Tree<GameObject> GameObjectToTree(GameObject obj)
{
var childs = new List<Tree<GameObject>>();
foreach (var i in Enumerable.Range(0, obj.transform.childCount))
{
var child = obj.transform.GetChild(i);
childs.Add(GameObjectToTree(child.gameObject));
}
return new Tree<GameObject>
{
Data = obj.name,
Data = obj.scene.name,
Childs = childs
};
}
[MenuItem("Window/TreeView")]
static void ShowWindow()
{
GetWindow<PrefabReplace>();
}
}
Inside the Tree class I have Data:
public GameObject Data { get; set; }
Then inside the return new tree:
Data = obj.name,
Data = obj.scene.name
But I'm getting two errors on obj.name and obj.scene.name
Cannot implicitly convert type 'string' to 'UnityEngine.GameObject'
I can't type Data.name or Data.scene.name
Continue reading...
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PrefabReplace : EditorWindow
{
public class Tree<GameObject>
{
public GameObject Data { get; set; }
public IEnumerable<Tree<GameObject>> Childs { get; set; }
public bool Opened { get; set; }
public Tree()
{
Childs = Enumerable.Empty<Tree<GameObject>>();
Opened = true;
}
}
public static class GUIExtension
{
public static void ShowTree(Tree<GameObject> tree)
{
if (tree.Childs.Count() > 0)
{
tree.Opened = EditorGUILayout.Foldout(tree.Opened, tree.Data.ToString());
}
else
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space(8);
EditorGUILayout.LabelField(tree.Data.ToString());
EditorGUILayout.EndHorizontal();
}
EditorGUI.indentLevel++;
if (tree.Opened)
{
foreach (var child in tree.Childs)
{
// 再帰
ShowTree(child);
}
}
EditorGUI.indentLevel--;
}
}
Vector2 scroll;
Tree<GameObject> tree;
void OnGUI()
{
if (tree == null) return;
scroll = EditorGUILayout.BeginScrollView(scroll);
GUIExtension.ShowTree(tree);
EditorGUILayout.EndScrollView();
}
void OnSelectionChange()
{
if (Selection.activeGameObject != null)
tree = GameObjectToTree(Selection.activeGameObject);
Repaint();
}
Tree<GameObject> GameObjectToTree(GameObject obj)
{
var childs = new List<Tree<GameObject>>();
foreach (var i in Enumerable.Range(0, obj.transform.childCount))
{
var child = obj.transform.GetChild(i);
childs.Add(GameObjectToTree(child.gameObject));
}
return new Tree<GameObject>
{
Data = obj.name,
Data = obj.scene.name,
Childs = childs
};
}
[MenuItem("Window/TreeView")]
static void ShowWindow()
{
GetWindow<PrefabReplace>();
}
}
Inside the Tree class I have Data:
public GameObject Data { get; set; }
Then inside the return new tree:
Data = obj.name,
Data = obj.scene.name
But I'm getting two errors on obj.name and obj.scene.name
Cannot implicitly convert type 'string' to 'UnityEngine.GameObject'
I can't type Data.name or Data.scene.name
Continue reading...