protected virtual void Start() { var btns = GetComponentsInChildren <ISelectAble>(true); var bSelectFirst = false; //根据父UI节点类型,拿到默认选项 var parentUi = GetComponentInParent <UiInstance>(); int defaultIdx = 0; if (parentUi != null) { _parentUIType = parentUi.GetType(); SelectStatus.TryGetValue(_parentUIType, out defaultIdx); } //初始化 for (int i = 0; i < btns.Length; i++) { var btn = btns[i]; btn.SetSelect(false); ItemList.Add(btn); } //自动选中 for (int i = 0; i < btns.Length; i++) { var btn = btns[i]; if (!bSelectFirst) { if (btn.IsEnable && i == defaultIdx) { btn.SetSelect(true, true); CurrSelectIdx = i; bSelectFirst = true; } } else { btn.SetSelect(false); } } OnInitOver?.Invoke(); GameEventCenter.AddListener(GameEvent.UI_Sure, OnClickSure); }
void Start() { ID = ++MaxID; RealCamp = Camp; HP = StartHP; ColliderSelf = gameObject.GetComponent <Collider>(); if (!ColliderSelf) { ColliderSelf = gameObject.AddComponent <BoxCollider>(); } IsTrigger = ColliderSelf.isTrigger; Role = gameObject.GetComponentInChildren <Asset_Role>(); if (Role) { Role.Init(this); } else if (this != WorldInteractObj.Instance) { Debug.LogError(gameObject.name + "下没有找到Asset_Role!"); } dicSkillEnergy.Clear(); SearchEnemyBase[] searchEnemies = GetComponentsInChildren <SearchEnemyBase>(true); for (int i = 0, length = searchEnemies.Length; i < length; ++i) { SearchEnemyBase single = searchEnemies[i]; single.Init(this); listSearchEnemy.Add(single); } SkillEnergy[] skillResources = GetComponentsInChildren <SkillEnergy>(true); for (int i = 0, length = skillResources.Length; i < length; ++i) { SkillEnergy single = skillResources[i]; single.Init(this); dicSkillEnergy[single.E_type] = single; } ResumeEnergy[] resumeSkillResources = GetComponentsInChildren <ResumeEnergy>(true); for (int i = 0, length = resumeSkillResources.Length; i < length; ++i) { ResumeEnergy single = resumeSkillResources[i]; single.Init(this); listResumeSkillEnergy.Add(single); } SkillBase[] skills = GetComponentsInChildren <SkillBase>(true); for (int i = 0, length = skills.Length; i < length; ++i) { SkillBase single = skills[i]; single.Init(this); listSkills.Add(single); } listSkills.Sort((a, b) => { return(b.CastOrder - a.CastOrder); }); fAttackMinRange = AttackMinRange; OutBattleRange = Mathf.Max(fAttackMaxRange = AttackMaxRange, OutBattleRange); Init(); InitBloodUI(); BattleManager.Instance.RegisterInteractiveObj(this); InteractiveObjExt[] exts = GetComponentsInChildren <InteractiveObjExt>(true); for (int i = 0, length = exts.Length; i < length; ++i) { InteractiveObjExt single = exts[i]; single.Init(this); listExtModules.Add(single); } OnInitOver.Invoke(); }