/// <summary> /// 子を削除する /// </summary> public void RemoveChild(EffectTreeElement child) { if (Children.Contains(child)) { Children.Remove(child); child.Parent = null; } }
/// <summary> /// モデルとItemから再帰的に子Itemを作成・追加する /// </summary> private void AddChildrenRecursive(EffectTreeElement model, TreeViewItem item) { foreach (var childModel in model.Children) { var childItem = CreateTreeViewItem(childModel); item.AddChild(childItem); AddChildrenRecursive(childModel, childItem); } }
/// <summary> /// 子を追加する /// </summary> public void AddChild(EffectTreeElement child) { // 既に親がいたら削除 if (child.Parent != null) { child.Parent.RemoveChild(child); } // 親子関係を設定 Children.Add(child); child.Parent = this; }
/// <summary> /// TreeView更新 /// </summary> private void UpdateTreeView() { _treeViewState = _treeViewState ?? new TreeViewState(); _treeView = _treeView ?? new EffectTreeView(_treeViewState); // 親子関係を構築したモデルを作成 // IDは被らないようにする var currentId = 0; var rootElementList = new List <EffectTreeElement>(); //foreach (var prefabData in prefabDataArray) { // ルートオブジェクト var rootElement = new EffectTreeElement { Id = currentId++, Name = _inputParticleSystem == null ? "" : _inputParticleSystem.name, EffectData = new EffectData { ParticleSystem = _inputParticleSystem }, }; rootElementList.Add(rootElement); if (_inputParticleSystem != null) { foreach (ParticleSystem child in _inputParticleSystem.gameObject.GetComponentsInChildren <ParticleSystem>()) { rootElement.AddChild(new EffectTreeElement { Id = currentId++, Name = child.name, EffectData = new EffectData { ParticleSystem = child }, }); } } } // TreeViewの更新 _treeView.Setup(rootElementList.ToArray()); }
/// <summary> /// ExampleTreeElementからTreeViewItemを作成する /// </summary> private TreeViewItem CreateTreeViewItem(EffectTreeElement model) { return new TreeViewItem {id = model.Id, displayName = model.Name}; }