void CheckMovementSide() { //这个函数用来检测平台上是否至少有一个左/右的腿部组件 //由于这个函数需要get组件,尽量不要每帧调用,只在可能发生改变的时候调用 have_L_movement_part = false; have_R_movement_part = false; if (all_leg_parts.Count > 0) { foreach (var lp in all_leg_parts) { LegPart llpp = lp.GetComponent <LegPart>(); if (llpp.self_side == -1) { have_L_movement_part = true; } else { have_R_movement_part = true; } } } else { have_L_movement_part = false; have_R_movement_part = false; } }
//public void DeleteSelf() //{ // if (unit_blueprint.menu_open) return; // if ((Input.GetKeyDown(KeyCode.Delete) && (be_picked || hover)) || mandatory_delete) // { // be_picked = false; // hover = false; // energy_supply = false; // //清理蓝图的信息: // unit_blueprint.mouse_picking_a_part = false; // unit_blueprint.RemovePartFromUnit(this); // //整理相关的零件的碰撞信息列表: // foreach (Part OP in overlaped_parts) // { // //从所有与本零件重叠的零件的碰撞列表中移除本零件 // Debug.Log("*****" + OP.overlaped_parts.Contains(this)); // OP.overlaped_parts.Remove(this); // } // //重置与这个零件连接的所有节点信息、清空父级零件信息 // foreach (var MP in mount_points) // { // MP.UnLink2MountPoint(); // } // //销毁自身的UI组件 // foreach (var UI in all_UI) // { // Destroy(UI.gameObject); // } // //销毁自身 // Destroy(gameObject); // } //} void ChangeSelfOrientation() { if (unit_blueprint.menu_open) { return; } if (Input.GetKeyDown(KeyCode.C) && be_picked && symmetry) { LegPart temp_leg_part = (Instantiate(Resources.Load <GameObject>("Part/MovementPart/LegPart/" + brother_part_name))).GetComponent <LegPart>(); temp_leg_part.enabled = true; temp_leg_part.Init();//手动初始化,因为Start执行顺序有问题 temp_leg_part.CreatFromButton(); temp_leg_part.be_creat_from_button = true; mandatory_delete = true; DeleteSelf(); } }
// Use this for initialization void Awake() { myCamera = GetComponentInChildren <CameraController>(); inventory = GetComponent <Inventory>(); armPart = GetComponentInChildren <ArmPart>(); torsoPart = GetComponentInChildren <TorsoPart>(); legPart = GetComponentInChildren <LegPart>(); AddInitialItems(new GameObject[3] { armPart.gameObject, torsoPart.gameObject, legPart.gameObject }); currHp = torsoPart.maxHp; currStamina = torsoPart.maxStamina; uiBars = GetComponent <HandleUIBars>(); uiBars.UpdateBarMaxValue(0, torsoPart.maxHp); uiBars.UpdateBarMaxValue(1, torsoPart.maxStamina); uiBars.UpdateBarValue(0, currHp); uiBars.UpdateBarValue(1, currStamina); startRegeningStamina = false; timerRestDelay = 0; armPart.ArmsAddedToBody(this); CanAttack = true; }
public void Init() { part_pos_default = new Vector3(-2.5f, 1.3f, -1f); UIpart_camera = GameObject.Find("UIPartCamera").GetComponent <Camera>(); UI_camera = GameObject.Find("UICamera").GetComponent <Camera>(); canvas = GameObject.Find("UICanvasBase").transform as RectTransform; UIpart_group = GameObject.Find("UIPart").transform; UIpart_offset = new Vector3(0, 0, -0.2f); unit_blueprint = GameObject.Find("DesignPlatform/Unit").GetComponent <UnitBlueprint>(); UI_canvas_top = GameObject.Find("UICanvasTop").transform as RectTransform; self_screen_pos = Camera.main.WorldToScreenPoint(transform.position); foreach (Transform t in GetComponentsInChildren <Transform>()) { if (t.name == "HoverImage") { hover_image = t.GetComponent <Image>(); } else if (t.name == "BanImage") { ban_image = t.GetComponent <Image>(); } else if (t.name == "PartName") { name_text = t.GetComponent <Text>(); } else if (t.name == "iIcon") { self_i_icon = t.GetComponent <iIcon>(); self_i_icon.parent_button = this; } } switch ((int)part_type) { case 0: UIpart_prefab = Instantiate(Resources.Load <GameObject>("UIPart/PowerUIPart/" + UIpart_name), UIpart_group); part_particulars_UI = Instantiate(Resources.Load <GameObject>("UI/PartParticulars/PowerPartParticulars"), UI_canvas_top); temp_part_prefab = Instantiate(Resources.Load <GameObject>("Part/PowerPart/" + part_name)); PowerPart temp_powerpart = temp_part_prefab.GetComponent <PowerPart>(); name_text.text = temp_powerpart.self_name; foreach (RectTransform rt in part_particulars_UI.GetComponentsInChildren <RectTransform>()) { if (rt.name == "Name") { rt.GetComponent <Text>().text = temp_powerpart.self_name; } else if (rt.name == "Power") { rt.GetComponent <Text>().text = "能量 +" + temp_powerpart.power_value.ToString(); } else if (rt.name == "Weight") { rt.GetComponent <Text>().text = "重量 " + temp_powerpart.weight_value.ToString(); } else if (rt.name == "Durability") { rt.GetComponent <Text>().text = "耐久 " + temp_powerpart.durability_value.ToString(); } else if (rt.name == "Specialty") { //rt.GetComponent<Text>().text = "特性 " + temp_powerpart.durability_value.ToString(); } else if (rt.name == "NormalDEF") { rt.GetComponent <Text>().text = temp_powerpart.normalDEF_value.ToString(); } else if (rt.name == "BlastDEF") { rt.GetComponent <Text>().text = temp_powerpart.blastDEF_value.ToString(); } else if (rt.name == "EnergyDEF") { rt.GetComponent <Text>().text = temp_powerpart.energyDEF_value.ToString(); } else if (rt.name == "Cost") { rt.GetComponent <Text>().text = temp_powerpart.cost.ToString(); } } break; case 1: UIpart_prefab = Instantiate(Resources.Load <GameObject>("UIPart/MovementUIPart/" + UIpart_name), UIpart_group); part_particulars_UI = Instantiate(Resources.Load <GameObject>("UI/PartParticulars/LegPartParticulars"), UI_canvas_top); temp_part_prefab = Instantiate(Resources.Load <GameObject>("Part/MovementPart/LegPart/" + part_name)); LegPart temp_legpart = temp_part_prefab.GetComponent <LegPart>(); name_text.text = temp_legpart.self_name; foreach (RectTransform rt in part_particulars_UI.GetComponentsInChildren <RectTransform>()) { if (rt.name == "Name") { rt.GetComponent <Text>().text = temp_legpart.self_name; } else if (rt.name == "UsePower") { rt.GetComponent <Text>().text = "持续耗能 " + temp_legpart.usepower_value.ToString(); } else if (rt.name == "Load") { rt.GetComponent <Text>().text = "最大载重 " + temp_legpart.load_value.ToString(); } else if (rt.name == "Move") { rt.GetComponent <Text>().text = "移动力 " + temp_legpart.move_value.ToString(); } else if (rt.name == "Dodge") { rt.GetComponent <Text>().text = "灵活性 " + temp_legpart.dodge_value.ToString(); } else if (rt.name == "Durability") { rt.GetComponent <Text>().text = "耐久 " + temp_legpart.durability_value.ToString(); } else if (rt.name == "Specialty") { if (temp_legpart.specialty.Count == 0) { rt.GetComponent <Text>().text = ""; } else { string spec = ""; foreach (int sp in temp_legpart.specialty) { switch (sp) { case 0: spec += "闪避叠加 "; break; case 1: spec += "反应装甲 "; break; } } rt.GetComponent <Text>().text = "特性 " + spec; } } else if (rt.name == "NormalDEF") { rt.GetComponent <Text>().text = temp_legpart.normalDEF_value.ToString(); } else if (rt.name == "BlastDEF") { rt.GetComponent <Text>().text = temp_legpart.blastDEF_value.ToString(); } else if (rt.name == "EnergyDEF") { rt.GetComponent <Text>().text = temp_legpart.energyDEF_value.ToString(); } else if (rt.name == "Cost") { rt.GetComponent <Text>().text = temp_legpart.cost.ToString(); } } break; case 2: UIpart_prefab = Instantiate(Resources.Load <GameObject>("UIPart/ControlUIPart/" + UIpart_name), UIpart_group); part_particulars_UI = Instantiate(Resources.Load <GameObject>("UI/PartParticulars/ControlPartParticulars"), UI_canvas_top); temp_part_prefab = Instantiate(Resources.Load <GameObject>("Part/ControlPart/" + part_name)); ControlPart temp_controlpart = temp_part_prefab.GetComponent <ControlPart>(); name_text.text = temp_controlpart.self_name; foreach (RectTransform rt in part_particulars_UI.GetComponentsInChildren <RectTransform>()) { if (rt.name == "Name") { rt.GetComponent <Text>().text = temp_controlpart.self_name; } else if (rt.name == "UsePower") { rt.GetComponent <Text>().text = "持续耗能 " + temp_controlpart.usepower_value.ToString(); } else if (rt.name == "Weight") { rt.GetComponent <Text>().text = "重量 " + temp_controlpart.weight_value.ToString(); } else if (rt.name == "Modules") { rt.GetComponent <Text>().text = "模块 " + temp_controlpart.modules_value.ToString(); } else if (rt.name == "Durability") { rt.GetComponent <Text>().text = "耐久 " + temp_controlpart.durability_value.ToString(); } else if (rt.name == "NormalDEF") { rt.GetComponent <Text>().text = temp_controlpart.normalDEF_value.ToString(); } else if (rt.name == "BlastDEF") { rt.GetComponent <Text>().text = temp_controlpart.blastDEF_value.ToString(); } else if (rt.name == "EnergyDEF") { rt.GetComponent <Text>().text = temp_controlpart.energyDEF_value.ToString(); } else if (rt.name == "Cost") { rt.GetComponent <Text>().text = temp_controlpart.cost.ToString(); } } break; case 3: UIpart_prefab = Instantiate(Resources.Load <GameObject>("UIPart/EquipmentUIPart/" + UIpart_name), UIpart_group); part_particulars_UI = Instantiate(Resources.Load <GameObject>("UI/PartParticulars/EquipmentPartParticulars"), UI_canvas_top); temp_part_prefab = Instantiate(Resources.Load <GameObject>("Part/EquipmentPart/" + part_name)); EquipmentPart temp_equippart = temp_part_prefab.GetComponent <EquipmentPart>(); name_text.text = temp_equippart.self_name; foreach (RectTransform rt in part_particulars_UI.GetComponentsInChildren <RectTransform>()) { if (rt.name == "Name") { rt.GetComponent <Text>().text = temp_equippart.self_name; } else if (rt.name == "PartType") { string s1 = ""; string s2 = ""; switch ((int)temp_equippart.damage_type) { case 0: //normal s1 = "常规武器"; break; case 1: //blast s1 = "爆炸武器"; break; case 2: //energy s1 = "能量武器"; break; } switch ((int)temp_equippart.atk_pattern) { case 0: s2 = "射击"; break; case 1: s2 = "飞弹"; break; } rt.GetComponent <Text>().text = "装备·" + s1 + "·" + s2; } else if (rt.name == "UsePower") { rt.GetComponent <Text>().text = "持续耗能 " + temp_equippart.usepower_value.ToString(); } else if (rt.name == "EachUsePower") { rt.GetComponent <Text>().text = "使用耗能 " + temp_equippart.eachusepower_value.ToString(); } else if (rt.name == "Damage") { rt.GetComponent <Text>().text = "伤害 " + temp_equippart.damage.ToString() + " * " + temp_equippart.attack_number.ToString(); } else if (rt.name == "DamageTypeIcon") { switch ((int)temp_equippart.damage_type) { case 0: //normal rt.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Icon/DamageTypeIcons")[0]; break; case 1: //blast rt.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Icon/DamageTypeIcons")[1]; break; case 2: //energy rt.GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("Icon/DamageTypeIcons")[2]; break; } } else if (rt.name == "Range") { rt.GetComponent <Text>().text = "射程 " + temp_equippart.range_value.ToString(); } else if (rt.name == "Ammo") { string one; string two; if (temp_equippart.ammo_value == -999) { one = "∞"; } else { one = temp_equippart.ammo_value.ToString(); } if (temp_equippart.magazine_value == -999) { two = "∞"; } else { two = temp_equippart.magazine_value.ToString(); } rt.GetComponent <Text>().text = "弹药 " + one + "/" + two; } else if (rt.name == "Specialty") { if (temp_equippart.specialty.Count == 0) { rt.GetComponent <Text>().text = ""; } else { string spec = ""; foreach (int sp in temp_equippart.specialty) { switch (sp) { case 0: spec += "连射 "; break; case 1: spec += " "; break; } } rt.GetComponent <Text>().text = "特性 " + spec; } } else if (rt.name == "Weight") { rt.GetComponent <Text>().text = "重量 " + temp_equippart.weight_value.ToString(); } else if (rt.name == "Durability") { rt.GetComponent <Text>().text = "耐久 " + temp_equippart.durability_value.ToString(); } else if (rt.name == "Tag") { if (temp_equippart.symmetry) { rt.GetComponentInChildren <Text>().text = "对称"; } else { rt.GetComponentInChildren <Text>().text = "多方向"; } } else if (rt.name == "NormalDEF") { rt.GetComponent <Text>().text = temp_equippart.normalDEF_value.ToString(); } else if (rt.name == "BlastDEF") { rt.GetComponent <Text>().text = temp_equippart.blastDEF_value.ToString(); } else if (rt.name == "EnergyDEF") { rt.GetComponent <Text>().text = temp_equippart.energyDEF_value.ToString(); } else if (rt.name == "Cost") { rt.GetComponent <Text>().text = temp_equippart.cost.ToString(); } } break; } Destroy(temp_part_prefab); //销毁临时零件 part_particulars_UI.GetComponent <PartParticulars>().parent_button = this; part_particulars_UI.SetActive(false); //关闭零件详情页 }
public GameObject BuildCharacter(GameObject characterContainer, PartsManager caller = null) { SetEquippedUsingIndex(equip.equippedParts); if (currentTorsoPrefab == null) { return(null); } GameObject ad = Instantiate(currentTorsoPrefab, characterContainer.transform, false); ad.transform.localPosition = Vector3.zero; if (caller != null) { caller.TorsoEquipped = ad.GetComponent <TorsoPart>(); } TorsoPart parent = ad.GetComponent <TorsoPart>(); if (currentHeadPrefab != null) { GameObject adding = Instantiate(currentHeadPrefab, parent.neckForHead.transform, false); adding.transform.localPosition = Vector3.zero; if (caller != null) { caller.headEquipped = adding.GetComponent <ItemPart>(); } } if (currentLeftArmPrefab != null) { GameObject adding = Instantiate(currentLeftArmPrefab, parent.LeftArmUpper.transform, false); ArmPart armPart = adding.GetComponent <ArmPart>(); armPart.EquipArm(parent, parent.LeftArmUpper, parent.LeftArmFore, parent.LeftArmHand); if (caller != null) { caller.leftArmEquipped = armPart; } } if (currentRightArmPrefab != null) { GameObject adding = Instantiate(currentRightArmPrefab, parent.RightArmUpper.transform, false); ArmPart armPart = adding.GetComponent <ArmPart>(); armPart.EquipArm(parent, parent.RightArmUpper, parent.RightArmFore, parent.RightArmHand); if (caller != null) { caller.rightArmEquipped = armPart; } } if (currentLeftLegPrefab != null) { GameObject adding = Instantiate(currentLeftLegPrefab, parent.LeftUpperThigh.transform, false); LegPart legPart = adding.GetComponent <LegPart>(); legPart.EquipLeg(parent.LeftUpperThigh, parent.Leftshin, parent.LefttAnkle, parent.LeftFoot); if (caller != null) { caller.leftLegEquipped = legPart; } } if (currentRightLegPrefab != null) { GameObject adding = Instantiate(currentRightLegPrefab, parent.RightUpperThigh.transform, false); LegPart legPart = adding.GetComponent <LegPart>(); legPart.EquipLeg(parent.RightUpperThigh, parent.Rightshin, parent.RightAnkle, parent.RightFoot); if (caller != null) { caller.rightLegEquipped = legPart; } } if (parent.bodyType == BodyType.FourArm) { Debug.Log("Four"); if (currentRightArmPrefab != null) { GameObject adding = Instantiate(currentRightArmPrefab, parent.LowerRightArmUpper.transform, false); ArmPart armPart = adding.GetComponent <ArmPart>(); armPart.EquipArm(parent, parent.LowerRightArmUpper, parent.LowerRightArmFore, parent.LowerRightArmHand); } if (currentLeftArmPrefab != null) { GameObject adding = Instantiate(currentLeftArmPrefab, parent.LowerLeftArmUpper.transform, false); ArmPart armPart = adding.GetComponent <ArmPart>(); armPart.EquipArm(parent, parent.LowerLeftArmUpper, parent.LowerLeftArmFore, parent.LowerLeftArmHand); } } return(ad); }
public void CheckLegal() { //Debug.LogError("111111111111111111all_power_parts.Count = " + all_power_parts.Count); //这个函数每帧检测零件的合法性变化情况及时更改各个列表中储存的零件 //清空缓存列表: if (remove_those_from_all_legal_parts.Count != 0) { remove_those_from_all_legal_parts.Clear(); } foreach (var p in all_parts) { if (p.legal) { //如果检测零件合法但是合法零件列表中没有这个零件,就添加 if (!all_legal_parts.Contains(p)) { all_legal_parts.Add(p); //然后再向分类的合法零件列表中添加 if (p.part_type == PartType.PowerPart && !all_power_parts.Contains(p)) { Debug.LogError("这里添加" + all_power_parts.Count); //如果是动力组件并且分类列表中没有这个组件才添加 PowerPart temp = p.GetComponent <PowerPart>(); button_controller.BanPowerPartButton(); all_power_parts.Add(temp); have_power_part = true; Debug.LogError("这里添加" + all_power_parts.Count); } else if (p.part_type == PartType.LegPart && !all_leg_parts.Contains(p)) { LegPart temp = p.GetComponent <LegPart>(); all_leg_parts.Add(temp); //执行移动组件检测重新确定左右是否都有合法的移动组件 CheckMovementSide(); } else if (p.part_type == PartType.ControlPart && !all_ctrl_parts.Contains(p)) { ControlPart temp = p.GetComponent <ControlPart>(); all_ctrl_parts.Add(temp); } else if (p.part_type == PartType.Equipment && !all_equip_parts.Contains(p)) { EquipmentPart temp = p.GetComponent <EquipmentPart>(); all_equip_parts.Add(temp); } } } else { //如果检测零件不合法,先添加到移除的缓存列表中 //一个零件由合法转为不合法的时,此时 all_legal_parts 里存在这个零件,但 p.legal = false; if (all_legal_parts.Contains(p) && !p.legal) { remove_those_from_all_legal_parts.Add(p); //Debug.LogError("零件已经进入移除缓存区"); //再处理其他合法零件列表 if (p.part_type == PartType.PowerPart && all_power_parts.Contains(p)) { PowerPart temp = p.GetComponent <PowerPart>(); button_controller.ReleasePowerPartButton(); all_power_parts.Remove(temp); have_power_part = false; //Debug.LogError(all_power_parts.Contains(p)); //Debug.LogError("这里" + all_power_parts.Count); } else if (p.part_type == PartType.LegPart && all_leg_parts.Contains(p)) { LegPart temp = p.GetComponent <LegPart>(); all_leg_parts.Remove(temp); //执行移动组件检测重新确定左右是否都有合法的移动组件 CheckMovementSide(); } else if (p.part_type == PartType.ControlPart && all_ctrl_parts.Contains(p)) { ControlPart temp = p.GetComponent <ControlPart>(); all_ctrl_parts.Remove(temp); } else if (p.part_type == PartType.Equipment && all_equip_parts.Contains(p)) { EquipmentPart temp = p.GetComponent <EquipmentPart>(); all_equip_parts.Remove(temp); } } } } //Debug.LogError("all_legal_parts = " + all_legal_parts.Count); foreach (var p in remove_those_from_all_legal_parts) { all_legal_parts.Remove(p); Debug.LogError(p.name + "零件已从合法零件列表中移除"); } }
void RemoveFromList(Part p) { //移除的话不用管零件当前是否合法,如果能从列表里找到就移除,找不到说明零件不合法根本就没在列表里 //但是这里的判断条件用了两个,实际上只要一个为true另一个理论上也应该为true,这么写是为了验证代码逻辑有没有漏洞 if (all_legal_parts.Contains(p) && p.legal) { all_legal_parts.Remove(p); Debug.Log("零件已从合法零件列表中删除"); } if (p.part_type == PartType.PowerPart) { //如果移除的是动力组件,还要重新打开所有动力组件的按钮并且从动力零件列表中删除 PowerPart temp = p.GetComponent <PowerPart>(); have_power_part = false; button_controller.ReleasePowerPartButton(); if (all_power_parts.Contains(temp) && temp.legal) { all_power_parts.Remove(temp); Debug.Log("动力组件已经移除!"); } else { Debug.Log("动力组件不合法已经直接移除!"); } } else if (p.part_type == PartType.LegPart) { LegPart temp = p.GetComponent <LegPart>(); switch (temp.self_side) { case -1: have_L_movement_part = false; break; case 1: have_R_movement_part = false; break; } if (all_leg_parts.Contains(temp) && temp.legal) { all_leg_parts.Remove(temp); Debug.Log("一个合法的腿部组件已经移除!"); } else { Debug.Log("腿部组件不合法已经直接移除!"); } //执行移动组件检测重新确定左右是否都有合法的移动组件 CheckMovementSide(); } else if (p.part_type == PartType.ControlPart) { ControlPart temp = p.GetComponent <ControlPart>(); if (all_ctrl_parts.Contains(temp) && temp.legal) { all_ctrl_parts.Remove(temp); Debug.Log("一个合法的控制组件已经移除!"); } else { Debug.Log("控制组件不合法已经直接移除!"); } } else if (p.part_type == PartType.Equipment) { EquipmentPart temp = p.GetComponent <EquipmentPart>(); if (all_equip_parts.Contains(temp) && temp.legal) { all_equip_parts.Remove(temp); Debug.Log("一个合法的控制组件已经移除!"); } else { Debug.Log("控制组件不合法已经直接移除!"); } } }
void AllotList(Part p) { //这个函数不管零件当前是否合法,直接加到相应的合法的零件列表中,然后再通过每帧的合法性检测移除那些不合法的零件; if (all_legal_parts.Contains(p)) { Debug.LogError("严重错误 :AllotList 列表中已经存在这个 Part 的实例"); } else { all_legal_parts.Add(p); Debug.LogError("all_legal_parts = " + all_legal_parts.Count); } if (p.part_type == PartType.PowerPart) { //have_power_part = true; //button_controller.BanPowerPartButton(); //all_power_parts.Add(p.GetComponent<PowerPart>()); Debug.LogError("111111111111111111111111111all_power_parts = " + all_power_parts.Count); } else if (p.part_type == PartType.LegPart) { LegPart temp = p.GetComponent <LegPart>(); if (temp.legal) { //如果是合法的 } switch (temp.self_side) { case -1: have_L_movement_part = true; break; case 1: have_R_movement_part = true; break; } all_leg_parts.Add(temp); //执行移动组件检测重新确定左右是否都有合法的移动组件 CheckMovementSide(); } else if (p.part_type == PartType.ControlPart) { ControlPart temp = p.GetComponent <ControlPart>(); if (temp.legal) { //如果是合法的 } have_ctrl_part = true; all_ctrl_parts.Add(temp); } else if (p.part_type == PartType.Equipment) { EquipmentPart temp = p.GetComponent <EquipmentPart>(); if (temp.legal) { //如果是合法的 } all_equip_parts.Add(temp); } }
public void ClickPartButton(PartButton click_this_button) { //计算零件出生位置: ////Vector3 start_pos = SetPosWhenPartCreat(); switch ((int)click_this_button.part_type) { case 0: if (unit_blueprint.have_power_part) { Debug.LogError("设计平台上已经存在一个动力组件!"); self_AS.clip = all_ACs["Error"]; self_AS.Play(); return; } part_prefab = Instantiate(Resources.Load <GameObject>("Part/PowerPart/" + click_this_button.part_name)); PowerPart temp_power_part = part_prefab.GetComponent <PowerPart>(); temp_power_part.enabled = true; temp_power_part.Init(); //手动初始化,因为Start执行顺序有问题 temp_power_part.CreatFromButton(); temp_power_part.be_creat_from_button = true; break; case 1: GameObject temp_go = Resources.Load <GameObject>("Part/MovementPart/LegPart/" + click_this_button.part_name); part_prefab = Instantiate(temp_go); //part_prefab.transform.position = start_pos; LegPart temp_leg_part = part_prefab.GetComponent <LegPart>(); temp_leg_part.enabled = true; temp_leg_part.Init(); //手动初始化,因为Start执行顺序有问题 temp_leg_part.CreatFromButton(); temp_leg_part.be_creat_from_button = true; break; case 2: if (unit_blueprint.have_ctrl_part) { Debug.Log("注意:设计平台上已经存在一个控制组件!"); //break; } part_prefab = Instantiate(Resources.Load <GameObject>("Part/ControlPart/" + click_this_button.part_name)); ControlPart temp_control_part = part_prefab.GetComponent <ControlPart>(); temp_control_part.enabled = true; temp_control_part.Init(); //手动初始化,因为Start执行顺序有问题 temp_control_part.CreatFromButton(); temp_control_part.be_creat_from_button = true; break; case 3: part_prefab = Instantiate(Resources.Load <GameObject>("Part/EquipmentPart/" + click_this_button.part_name)); EquipmentPart temp_equip_part = part_prefab.GetComponent <EquipmentPart>(); temp_equip_part.enabled = true; temp_equip_part.Init(); //手动初始化,因为Start执行顺序有问题 temp_equip_part.CreatFromButton(); temp_equip_part.be_creat_from_button = true; break; } //播放创建零件的音效: creat_part_audio.Play(); //关闭悬停高亮Ui: click_this_button.hover_image.enabled = false; foreach (var lb in all_layer_button) { lb.self_image.sprite = lb.sp[0]; lb.pressed = false; } ToolClosePartInterface(); unit_blueprint.menu_open = false; }
public void addLimb() { combinedShop.Refresh = true; changed = true; GameObject adding; GameObject currentPart = combinedShop.currentPart; //The object, found at the index inside the list. int currentIndex = combinedShop.currentIndex; partType currentType = combinedShop.currentType; if (currentPart == null) { return; } if (currentType == partType.Torso) { addingTorso(); return; } if (TorsoEquipped == null) { return; } switch (currentType) { case partType.Head: if (headEquipped != null && currentPart.name == headEquipped.gameObject.name) { return; } if (headEquipped != null) { Destroy(headEquipped.gameObject); } adding = Instantiate(currentPart, TorsoEquipped.neckForHead.transform, false); headEquipped = adding.GetComponent <ItemPart>(); list.ChangeEquip(currentPart, partType.Head, currentIndex); adding.name = currentPart.name; break; case partType.LeftArm: if (leftArmEquipped != null && currentPart.name == leftArmEquipped.gameObject.name) { return; } if (leftArmEquipped != null) { leftArmEquipped.deleteArm(); } adding = Instantiate(currentPart, TorsoEquipped.LeftArmUpper.transform, false); leftArmEquipped = adding.GetComponent <ArmPart>(); leftArmEquipped.EquipArm(TorsoEquipped, TorsoEquipped.LeftArmUpper, TorsoEquipped.LeftArmFore, TorsoEquipped.LeftArmHand); adding.name = currentPart.name; list.ChangeEquip(currentPart, partType.LeftArm, currentIndex); adding = null; break; case partType.RightArm: if (rightArmEquipped != null && currentPart.name == rightArmEquipped.gameObject.name) { return; } if (rightArmEquipped != null) { rightArmEquipped.deleteArm(); } adding = Instantiate(currentPart, TorsoEquipped.RightArmUpper.transform, false); rightArmEquipped = adding.GetComponent <ArmPart>(); rightArmEquipped.EquipArm(TorsoEquipped, TorsoEquipped.RightArmUpper, TorsoEquipped.RightArmFore, TorsoEquipped.RightArmHand); adding.name = currentPart.name; list.ChangeEquip(currentPart, partType.RightArm, currentIndex); adding = null; break; case partType.LeftLeg: if (leftLegEquipped != null && currentPart.name == leftLegEquipped.gameObject.name) { return; } if (leftLegEquipped != null) { leftLegEquipped.DeleteLeg(); } adding = Instantiate(currentPart, TorsoEquipped.RightUpperThigh.transform, false); leftLegEquipped = adding.GetComponent <LegPart>(); leftLegEquipped.EquipLeg(TorsoEquipped.LeftUpperThigh, TorsoEquipped.Leftshin, TorsoEquipped.LefttAnkle, TorsoEquipped.LeftFoot); list.ChangeEquip(currentPart, partType.LeftLeg, currentIndex); adding.name = currentPart.name; adding = null; break; case partType.RightLeg: if (rightLegEquipped != null && currentPart.name == rightLegEquipped.gameObject.name) { } if (rightLegEquipped != null) { rightLegEquipped.DeleteLeg(); } adding = Instantiate(currentPart, TorsoEquipped.RightUpperThigh.transform, false); rightLegEquipped = adding.GetComponent <LegPart>(); rightLegEquipped.EquipLeg(TorsoEquipped.RightUpperThigh, TorsoEquipped.Rightshin, TorsoEquipped.RightAnkle, TorsoEquipped.RightFoot); list.ChangeEquip(currentPart, partType.RightLeg, currentIndex); adding.name = currentPart.name; adding = null; break; default: break; } if (TorsoEquipped.bodyType == BodyType.FourArm) { Destroy(TorsoEquipped.gameObject); list.BuildCharacter(parentOfTorso, this); return; } }