Example #1
0
        //public void UpdateGOs()
        //{
        //    Debug.Log("Updating");
        //    UnityEngine.GameObject[] objects = FindObjectsOfType(typeof(GameObject)) as GameObject[];
        //    List<GameObject> rootGos = FindRoots(objects);
        //    _gos.RemoveAll(t => !rootGos.Contains(t.GameObject));
        //    _gos.AddRange(FindNewGos(rootGos));
        //    foreach (GameObject gameObject in rootGos.Where(g => _gos.All(j => j.GameObject != g)))
        //    {
        //        _gos.AddRange(new GameObjectTree(gameObject));
        //    }
        //}
        //private List<GameObject> FindRoots(GameObject[] objects)
        //{
        //    List<GameObject> roots = new List<GameObject>();
        //    foreach (GameObject go in objects)
        //    {
        //        if (go != null && go.transform.parent)
        //        {
        //            roots.Add(go);
        //        }
        //    }
        //    return roots;
        //}
        public IEnumerable<GameObjectTree> SceneRoots()
        {
            UnityEngine.Object[] objects = FindObjectsOfType(typeof(GameObject));

            _gos.Clear();

            foreach (UnityEngine.Object o in objects)
            {
                GameObject go = o as GameObject;

                if (go != null && go.transform.parent == null)
                {
                    GameObjectTree tree = new GameObjectTree(go);

                    FillChildren(tree, go);

                    _gos.Add(tree);
                }
            }

            if (_filterJunk)
                return _filter.FilterJunk(_gos);

            return _gos;
        }
Example #2
0
 /// <summary>
 /// Initialize the game application
 /// </summary>
 private void Init()
 {
     // Set Game State to Initial
     state = new GameInitialState();
     Tree  = new GameObjectTree();
     // Init game board
     Board = GameObject.CreateGameObject <GameBoard>(null);
     // Init cells
     InitCells();
     InitPlayers();
 }
Example #3
0
	/**
	 * Find the children game objects in the scene graph at the addresses from the view model's scene graph.
	 * @param	rootAddress	The root will not be in the graph.  The root's children will be the values of the top-level hash.  
	 */
	public static Dictionary<string, GameObjectTree> FindGraph(Dictionary<string, object> graph, GameObject root)
	{
		Dictionary<string, GameObjectTree> sceneGraph = new Dictionary<string, GameObjectTree>();
		foreach (KeyValuePair<string, object> item in graph) {
			string name = item.Key;
			GameObject child = ViewUtil.GetChild(root, name);
			GameObjectTree node = new GameObjectTree(child);
			sceneGraph[name] = node;
			if (null == child) {
				Debug.Log("Expected child at " + name);
			}
			else if (item.Value is Dictionary<string, object>) {
				Dictionary<string, object> subGraph = (Dictionary<string, object>) item.Value;
				sceneGraph[item.Key].children = FindGraph(subGraph, child);
			}
		}
		return sceneGraph;
	}
Example #4
0
    /**
     * Find the children game objects in the scene graph at the addresses from the view model's scene graph.
     * @param	rootAddress	The root will not be in the graph.  The root's children will be the values of the top-level hash.
     */
    public static Dictionary <string, GameObjectTree> FindGraph(Dictionary <string, object> graph, GameObject root)
    {
        Dictionary <string, GameObjectTree> sceneGraph = new Dictionary <string, GameObjectTree>();

        foreach (KeyValuePair <string, object> item in graph)
        {
            string         name  = item.Key;
            GameObject     child = ViewUtil.GetChild(root, name);
            GameObjectTree node  = new GameObjectTree(child);
            sceneGraph[name] = node;
            if (null == child)
            {
                Debug.Log("Expected child at " + name);
            }
            else if (item.Value is Dictionary <string, object> )
            {
                Dictionary <string, object> subGraph = (Dictionary <string, object>)item.Value;
                sceneGraph[item.Key].children = FindGraph(subGraph, child);
            }
        }
        return(sceneGraph);
    }
Example #5
0
        private void FillChildren(GameObjectTree tree, GameObject go)
        {
            foreach (Transform transform in go.transform)
            {
                tree.AddChild(transform.gameObject);

                FillChildren(tree.GetChild(tree.Count - 1), transform.gameObject);
            }
        }
Example #6
0
        private void DrawObject(GameObjectTree treeGo, int spacing)
        {
            GUILayout.BeginHorizontal();

            GUILayout.Space(spacing);

            if (!open.Contains(treeGo.GameObject))
            {
                if (GUILayout.Button("+", GUILayout.Width(20)))
                {
                    open.Add(treeGo.GameObject);
                }
            }
            else
            {
                if (GUILayout.Button("-", GUILayout.Width(20)))
                {
                    open.Remove(treeGo.GameObject);
                }
            }

            if (GUILayout.Button(treeGo.GameObject.name, GUI.skin.label))
            {
                _selected = treeGo.GameObject;
            }

            GUILayout.EndHorizontal();

            if (open.Contains(treeGo.GameObject))
            {
                foreach (GameObjectTree childTreeGo in treeGo.GetChildren())
                {
                    DrawObject(childTreeGo, spacing + 10);
                }
            }
        }