少年修仙传客户端代码仓库
client_linchunjie
2018-09-20 36a67fa54ddfa8638c3488d00bbcd2d87a076041
System/Skill/TalentTreeBehaviour.cs
@@ -2,33 +2,97 @@
using System.Collections.Generic;
using UnityEngine;
using System;
using TableConfig;
using UnityEngine.UI;
namespace Snxxz.UI
{
    public class TalentTreeBehaviour : MonoBehaviour
    {
        [SerializeField] TalentTree[] talentTrees;
        [SerializeField] TalentTree m_TalentTree;
        [SerializeField] TalentSkillBehaviour[] m_TalentSkills;
        [SerializeField] ScrollRect m_Scroller;
        TalentModel model
        {
            get { return ModelCenter.Instance.GetModel<TalentModel>(); }
        }
        public int series { get; private set; }
        public int talentType { get; private set; }
        public virtual void Display(int series, int type)
        {
            this.series = series;
            talentType = type;
            DisplaySkills();
            m_Scroller.verticalNormalizedPosition = 1;
        }
        void DisplaySkills()
        {
            var job = PlayerDatas.Instance.baseData.Job;
            List<int> talentSkills;
            model.TryGetTalents(job, series, talentType, out talentSkills);
            for (int i = 0; i < m_TalentSkills.Length; i++)
            {
                m_TalentSkills[i].Dispose();
                if (talentSkills != null && i < talentSkills.Count)
                {
                    m_TalentSkills[i].gameObject.SetActive(true);
                    m_TalentSkills[i].Display(talentSkills[i]);
                }
                else
                {
                    m_TalentSkills[i].gameObject.SetActive(false);
                }
            }
            model.selectSkill = talentSkills != null ? talentSkills[0] : 0;
        }
        public virtual void Dispose()
        {
        }
        public bool BelongToTalentTree(int job, int series, int type)
        {
            for (int i = 0; i < talentTrees.Length; i++)
            {
                var talentTree = talentTrees[i];
                if (talentTree.job == job && talentTree.series == series
                    && talentTree.type == type)
                {
                    return true;
                }
            }
            return false;
            return m_TalentTree.BelongToTalentTree(job, series, type);
        }
    }
    [Serializable]
    public struct TalentTree
    {
        public int job;
        public int series;
        public int type;
        public int[] jobs;
        public int[] series;
        public int[] types;
        public bool BelongToTalentTree(int job, int series, int type)
        {
            for (int i = 0; i < jobs.Length; i++)
            {
                if (jobs[i] != job)
                {
                    continue;
                }
                for (int k = 0; k < this.series.Length; k++)
                {
                    if (this.series[k] != series)
                    {
                        continue;
                    }
                    for (int q = 0; q < types.Length; q++)
                    {
                        if (types[q] == type)
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }
    }
}