public void AddPersonnel(CSUIMyNpc npc)//增加一个npc { if (npc == null) { Debug.LogWarning("The giving npc is null."); } if (!npc.IsRandom) { return; } // Trainee Npc if (!npc.HasOccupation) { CSUI_MyNpcItem npcGrid = CreateNPCGird(npc, m_TraineeRootUI.transform); m_TraineeRootUI.repositionNow = true; m_TraineeGrids.Add(npcGrid); } // Instructor Npc else { CSUI_MyNpcItem npcGrid = CreateNPCGird(npc, m_InstructorRootUI.transform); m_InstructorRootUI.repositionNow = true; m_InstructorGrids.Add(npcGrid); } }
private CSUI_MyNpcItem CreateNPCGird(CSUIMyNpc npc, Transform root)//生成一个npc { CSUI_MyNpcItem npcGrid = Instantiate(m_NpcGridPrefab) as CSUI_MyNpcItem; npcGrid.transform.parent = root; CSUtils.ResetLoacalTransform(npcGrid.transform); npcGrid.m_UseDeletebutton = true; npcGrid.m_Npc = npc; UICheckbox cb = npcGrid.gameObject.GetComponent <UICheckbox>(); cb.radioButtonRoot = root; UIEventListener.Get(npcGrid.gameObject).onActivate = OnNPCGridActive; return(npcGrid); }
private void UpdateNPCRef(CSUIMyNpc npc) { if (npc != null) { m_RefNpc = npc; } if (m_RefNpc != null && !m_RefNpc.HasOccupation) { UpdateSkills(); } if (m_RefNpc != null && m_RefNpc.HasOccupation) { GetInstructorSkill(m_RefNpc.OwnSkills); } }
void CreatRandomNpcs(int numbers) { if (numbers <= 5) { return; } //技能 List <CSUIMySkill> skillLis = new List <CSUIMySkill>(); //for (int i = 0; i < 4; i++) //{ // CSUIMySkill ms = new CSUIMySkill(); // ms.name = "npc_big_GerdyHooke"; // ms.iconImg = "npc_big_GerdyHooke"; // skillLis.Add(ms); //} CSUIMySkill ms1 = new CSUIMySkill(); ms1.name = "skill1"; ms1.iconImg = "npc_big_GerdyHooke"; skillLis.Add(ms1); CSUIMySkill ms2 = new CSUIMySkill(); ms2.name = "skill2"; ms2.iconImg = "npc_big_AgnesCopperfield"; skillLis.Add(ms2); CSUIMySkill ms3 = new CSUIMySkill(); ms3.name = "skill3"; ms3.iconImg = "npc_big_BenYin"; skillLis.Add(ms3); CSUIMySkill ms4 = new CSUIMySkill(); ms4.name = "skill4"; ms4.iconImg = "npc_big_AvaAzniv"; skillLis.Add(ms4); for (int i = 0; i < numbers - 6; i++)//学员 { CSUIMyNpc randomNpc = new CSUIMyNpc(); randomNpc.OwnSkills = skillLis; randomNpc.IsRandom = true; randomNpc.HasOccupation = false; randomNpc.Health = 90; randomNpc.HealthMax = 100; randomNpc.Name = "xueyuan"; randomNpc.RandomNpcFace = linshiyong[i]; randomNpc.Sex = PeSex.Female; if (i == 3) { randomNpc.State = 10; } allRandomNpcs.Add(randomNpc); } for (int i = 4; i < numbers; i++)//教练 { CSUIMyNpc randomNpc = new CSUIMyNpc(); randomNpc.OwnSkills = skillLis; randomNpc.IsRandom = true; randomNpc.HasOccupation = true; randomNpc.AddHealth = "6~10"; randomNpc.AddHunger = "3~5"; randomNpc.Name = "jiaolian"; randomNpc.RandomNpcFace = linshiyong[i]; randomNpc.Sex = PeSex.Male; allRandomNpcs.Add(randomNpc); } Debug.Log("生成的allRandomNpcs:" + allRandomNpcs.Count); }
void Update() { #region 临时用测试 if (Input.GetKeyDown(KeyCode.P)) { uip.items.Clear(); uip.items = new List <string>() { "White" + kk.ToString(), "Red" + kk.ToString(), "Green" + kk.ToString(), "Grey" + kk.ToString() }; kk++; } if (Input.GetKeyDown(KeyCode.H)) { CreatSkill1(); GetInstructorSkill(skilllistTest); } if (Input.GetKeyDown(KeyCode.J)) { CreatSkill2(); GetInstructorSkill(skilllistTest); } if (Input.GetKeyDown(KeyCode.K)) { //uip.items.Clear(); uip.selection = ""; } if (Input.GetKeyDown(KeyCode.V)) { uip.items.Add("1234"); Debug.Log(uip.items.Count.ToString()); } #endregion #region 学员信息 if (m_RefNpc == null) { SetServantInfo("--", PeSex.Male, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); mInstructorFace_Stats.mainTexture = null; mInstructorFace_Stats.enabled = false; mInstructorFace_Skill.mainTexture = null; mInstructorFace_Skill.enabled = false; mTraineeFace_Stats.mainTexture = null; mTraineeFace_Stats.enabled = false; mTraineeFace_Skill.mainTexture = null; mTraineeFace_Skill.enabled = false; SetInstructorInfo("", "", "", "", ""); SetTraineeInfo(0, 0, 0, 0, 0); } else { if (!m_RefNpc.HasOccupation)//学员 { SetServantInfo(m_RefNpc.Name, m_RefNpc.Sex, m_RefNpc.Health, m_RefNpc.HealthMax, m_RefNpc.Stamina, m_RefNpc.Stamina_max, m_RefNpc.Hunger, m_RefNpc.Hunger_max, m_RefNpc.Comfort, m_RefNpc.Comfort_max, m_RefNpc.Oxygen, m_RefNpc.Oxygen_max, m_RefNpc.Shield, m_RefNpc.Shield_max, m_RefNpc.Energy, m_RefNpc.Energy_max, m_RefNpc.Attack, m_RefNpc.Defense); } } #endregion #region 技能和属性 if (m_RefNpc != null) { if (m_RefNpc.HasOccupation) //教练 { if (m_UpgradePage.activeSelf) //属性提升 { if (m_RefNpc.State == 10) //假设这个状态是在教学 { mInstructorStats = null; mInstructorFace_Stats.mainTexture = null; mInstructorFace_Stats.enabled = false; SetInstructorInfo("", "", "", "", ""); } else if (m_RefNpc.State != 10) { if (mInstructorStats != m_RefNpc) { mInstructorStats = m_RefNpc; } mInstructorFace_Stats.mainTexture = m_RefNpc.RandomNpcFace; mInstructorFace_Stats.enabled = true; SetInstructorInfo(m_RefNpc.AddHealth, m_RefNpc.AddStrength, m_RefNpc.AddHunger, m_RefNpc.AddStamina, m_RefNpc.AddOxygen); } } else if (m_LearnSkillPage.activeSelf)//技能学习 { mInstructorFace_Skill.mainTexture = m_RefNpc.RandomNpcFace; mInstructorFace_Skill.enabled = true; } } else if (!m_RefNpc.HasOccupation) //学员 { if (m_UpgradePage.activeSelf) //属性提升 { if (m_RefNpc.State == 10) //假设这个状态是在学习 { mTraineeStats = null; mTraineeFace_Stats.mainTexture = null; mTraineeFace_Stats.enabled = false; SetTraineeInfo(0, 0, 0, 0, 0); } else if (m_RefNpc.State != 10) { if (mTraineeStats != m_RefNpc) { mTraineeStats = m_RefNpc; } mTraineeFace_Stats.mainTexture = m_RefNpc.RandomNpcFace; mTraineeFace_Stats.enabled = true; SetTraineeInfo(m_RefNpc.HealthMax, m_RefNpc.Strength_max, m_RefNpc.Hunger_max, m_RefNpc.Stamina_max, m_RefNpc.Oxygen_max); } } else if (m_LearnSkillPage.activeSelf) //技能学习 { if (m_RefNpc.OwnSkills.Count != 5) //还没学满5个技能 { if (mTraineeSkill != m_RefNpc) { mTraineeSkill = m_RefNpc; } Debug.Log("学员技能学习的头像该有"); mTraineeFace_Skill.mainTexture = m_RefNpc.RandomNpcFace; mTraineeFace_Skill.enabled = true; Debug.Log(mTraineeFace_Skill.mainTexture); } } } } #endregion }
public void RemovePersonnel(CSUIMyNpc npc)//减少一个npc { if (npc == null) { Debug.LogWarning("The giving npc is null"); } if (!npc.IsRandom) { return; } //学员 if (!npc.HasOccupation) { int index = m_TraineeGrids.FindIndex(item0 => item0.m_Npc == npc); if (index != -1) { // If this icon is checked if (m_TraineeGrids[index].gameObject.GetComponent <UICheckbox>().isChecked) { if (m_TraineeGrids.Count == 1) { ActiveNpcGrid = null; } else { int newIndex = index == 0 ? 1 : index - 1; m_TraineeGrids[newIndex].gameObject.GetComponent <UICheckbox>().isChecked = true; } } DestroyImmediate(m_TraineeGrids[index].gameObject); m_TraineeGrids.RemoveAt(index); m_TraineeRootUI.repositionNow = true; } else { Debug.LogWarning("The giving npc is not a Settler"); } } // 教练 else { int index = m_InstructorGrids.FindIndex(item0 => item0.m_Npc == npc); if (index != -1) { // If this icon is checked if (m_InstructorGrids[index].gameObject.GetComponent <UICheckbox>().isChecked) { if (m_InstructorGrids.Count == 1) { ActiveNpcGrid = null; } else { int newIndex = index == 0 ? 1 : index - 1; m_InstructorGrids[newIndex].gameObject.GetComponent <UICheckbox>().isChecked = true; } } DestroyImmediate(m_InstructorGrids[index].gameObject); m_InstructorGrids.RemoveAt(index); m_InstructorRootUI.repositionNow = true; } else { Debug.LogWarning("The giving npc is not a Settler"); } } }