Esempio n. 1
0
 /// <summary>
 /// 指定したGeneを選択状態にする。
 /// </summary>
 /// <param name="gene"></param>
 /// <exception cref="ArgumentException"></exception>
 public void SelectGene(Gene gene)
 {
     if (!CurrentGeneTree)
     {
         return;
     }
     if (!CurrentGeneTree.Genes.Contains(gene))
     {
         throw new ArgumentException("指定したGeneは現在のGeneTreeに含まれていません。");
     }
     if (SelectedGene == gene)
     {
         return;
     }
     SelectedGene = gene;
     onSelectedGeneChanged.OnNext(gene);
 }
Esempio n. 2
0
        public void Initialize(UIGeneTreeView view, Gene targetGene, int depth, int order)
        {
            TargetGene = targetGene;
            ParentView = view;
            Depth      = depth;
            Order      = order;

            Label.text = TargetGene.DisplayName;

            ParentView.OnSelectedGeneChanged.Subscribe(gene =>
            {
                bool isSelected = gene == TargetGene;
                if (IsSelected == isSelected)
                {
                    return;
                }
                IsSelected = isSelected;
                if (isSelected)
                {
                    OnSelected();
                }
                else
                {
                    OnUnselected();
                }
            }).AddTo(this);

            if (TargetGene.IsActivated)
            {
                Image.sprite = selectedSprite;
            }
            else
            {
                GeneSystem.Instance.OnGeneActivated.Subscribe(gene =>
                {
                    if (gene == TargetGene)
                    {
                        Image.sprite = selectedSprite;
                    }
                }).AddTo(this);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 指定した遺伝子を開放する。
        /// <param name="tree">解放するGeneを含むGeneTree</param>
        /// <param name="gene">解放するGene</param>
        /// <returns>解放に成功したかどうか。</returns>
        /// </summary>
        public bool Activate(GeneTree tree, Gene gene)
        {
            if (!Trees.Contains(tree))
            {
                throw new ArgumentException("指定したGeneTreeはGeneSystemに登録されていません。");
            }
            if (!tree.Genes.Contains(gene))
            {
                throw new ArgumentException("指定したGeneはGeneTreeに含まれていません。");
            }

            if (gene.ParentGene != null && !Data.ActivatedGenes.Contains(gene.ParentGene.Guid))
            {
                //親ノードの遺伝子が解放されていなければ、解放できない
                return(false);
            }

            var entry = treeEntries.FirstOrDefault(e => e.GeneTreeAsset == tree);

            if (entry != null && entry.ReleaseGeneDefinition != null)
            {
                if (!entry.ReleaseGeneDefinition.Release(gene.Id))
                {
                    return(false);
                }
            }
            else
            {
                Debug.LogWarning("GeneSystem: 指定されたGeneに対応するGeneTreeActionが登録されていません。");
            }

            Data.ActivatedGenes.Add(gene.Guid);
            onGeneActivated.OnNext(gene);
            return(true);

            //TODO: スキルポイント的なやつの消費
        }
Esempio n. 4
0
        /// <summary>
        /// 指定したGeneTreeをもとにツリーのUIを構築します。
        /// </summary>
        /// <param name="geneTree"></param>
        public void Build(GeneTree geneTree)
        {
            foreach (var node in treeNodes)
            {
                Destroy(node.gameObject);
            }

            treeNodes.Clear();

            foreach (var edge in treeEdges)
            {
                Destroy(edge.gameObject);
            }

            treeEdges.Clear();

            CurrentGeneTree = geneTree;
            SelectedGene    = null;

            var rootNodes = geneTree.Genes.Where(g => g.IsRootGene);
            //Depth, Orderを計算
            List <int>            orders = new List <int>();
            List <UIGeneTreeNode> ends   = new List <UIGeneTreeNode>();

            foreach (var gene in rootNodes)
            {
                var n = SetupGeneNodeKernel(orders, ends, 0, gene);
                PlaceGeneNodeKernel(ends, n, 0);
            }

            float boundWidth  = (orders.Count - 1) * horizontalSpacing + padding * 2f;
            float boundHeight = (ends.Count - 1) * verticalSpacing + padding * 2f;


            contentContainer.sizeDelta = new Vector2(boundWidth, boundHeight);
        }
Esempio n. 5
0
        private UIGeneTreeNode SetupGeneNodeKernel(List <int> orders, List <UIGeneTreeNode> ends, int depth, Gene gene)
        {
            if (orders.Count <= depth)
            {
                orders.Add(0);
            }

            UIGeneTreeNode n = Instantiate(geneTreeNodePrefab, elementsRoot).GetComponent <UIGeneTreeNode>();

            n.Initialize(this, gene, depth, orders[depth]);
            treeNodes.Add(n);

            orders[depth]++;
            if (gene.ChildGenes.Count == 0)
            {
                ends.Add(n);
            }
            else
            {
                foreach (var child in gene.ChildGenes)
                {
                    var childNode = SetupGeneNodeKernel(orders, ends, depth + 1, child);
                    n.ChildGeneNodes.Add(childNode);
                }
            }

            return(n);
        }