19
|
1 using System.Collections;
|
|
2 using System.Collections.Generic;
|
|
3 using UnityEngine;
|
|
4
|
|
5 public class SceneNode : MonoBehaviour {
|
|
6
|
|
7 public GameObject obj;
|
|
8
|
|
9 public SceneNode m_parent;
|
|
10 public System.Collections.Generic.List<SceneNode> m_childs;
|
|
11
|
|
12 public SceneNode(GameObject obj, SceneNode parent=null){
|
|
13 this.obj = obj;
|
|
14 m_parent = parent;
|
|
15 m_childs = new System.Collections.Generic.List<SceneNode>();
|
|
16 }
|
|
17
|
|
18 public void OnAdded () {}
|
|
19
|
|
20 public void OnRemoved () {}
|
|
21
|
|
22 public bool AddChild (SceneNode toAdd){
|
|
23 toAdd.m_parent = this;
|
|
24 m_childs.Add(toAdd);
|
|
25 toAdd.OnAdded();
|
|
26 return true;
|
|
27 }
|
|
28
|
|
29 public bool RemoveChild (SceneNode toRemove) {
|
|
30 toRemove.OnRemoved();
|
|
31 return m_childs.Remove(toRemove);
|
|
32 }
|
|
33
|
|
34 public void RemoveAllChildren () {
|
|
35 int childcount = m_childs.Count;
|
|
36 for(int i = 0; i < childcount ;++i){
|
|
37 m_childs[i].RemoveAllChildren();
|
|
38 }
|
|
39
|
|
40 for(int i = 0; i < childcount ;++i){
|
|
41 m_childs[i].OnRemoved();
|
|
42 }
|
|
43 m_childs.Clear();
|
|
44 }
|
|
45 }
|