/// <summary> /// 布局蓝图的MOD部分 /// </summary> /// <param name="tid">蓝图的TID</param> /// <param name="materialNode">MOD节点</param> private void LayoutBlueprintModList(uint tid, Transform modNode) { CfgEternityProxy cfg = GetConfig(); Produce produce = cfg.GetProduceByKey(tid); Item item = cfg.GetItemByKey((uint)produce.ProductId); Category itemType = ItemTypeUtil.GetItemType(item.Type).MainType; int modCount = 0; if (itemType == Category.Warship) { Warship ship = cfg.GetWarshipByKey(item.Id); ModPosition modPosCfg = cfg.GetModPosition((uint)ship.ModPosition); modCount = modPosCfg.PositionsLength; } else if (itemType == Category.Weapon) { Weapon weapon = cfg.GetWeapon(item.Id); ModPosition modPosCfg = cfg.GetModPosition((uint)weapon.ModPosition); modCount = modPosCfg.PositionsLength; } LayoutModList(new int[modCount], modNode); }
//will be called to choose state public ModPosition ChooseState() { if (modular) { position = (ModPosition)Random.Range(0, 4); } // print(position + " place"); return (position); }
/// <summary> /// 检查mod按钮数量 /// </summary> /// <param name="count">数量</param> /// <param name="modPosId">mod位置标记</param> private void CheckModBtnCount(uint count, uint modPosId) { if (m_ModCellList.Count == count) { SetModBtnListData(); } else if (m_ModCellList.Count < count) { while (m_ModCellList.Count < count) { m_ModCellList.Add(GetCell()); } } else { while (m_ModCellList.Count > count) { WarshipModPanelElement item = m_ModCellList[0]; m_ModCellList.RemoveAt(0); item.gameObject.Recycle(); } } ModPosition modPosCfg = m_CfgEternityProxy.GetModPosition(modPosId); ModPositionAttr modPosAttr; for (int i = 0; i < m_ModCellList.Count; i++) { modPosAttr = modPosCfg.Positions(i).Value; m_ModCellList[i].transform.localPosition = new Vector3(modPosAttr.X, modPosAttr.Y, 0); m_ModCellList[i].GetComponent <Toggle>().isOn = false; m_ModCellList[i].name = i.ToString(); } SetModBtnListData(); }
void ChoosePositions() { modItems = GameObject.FindGameObjectsWithTag("modular"); int modAmount = modItems.Length; //print(modAmount); //cycles while choosings positions while (modAmount > 0) { //cycles through each modular item for (int i = 0; i < (modItems.Length); i++) { //picks a position for an item unless it is already taken //then it will choose again until a new position is chosen chosen = false; while (!chosen) { print("choosing for " + modItems[i].name); //picks a random positions for a modular item in its own object positions = modItems[i].GetComponent<modularPosition>().ChooseState(); if (!left && positions == ModPosition.Left) { left = true; chosen = true; print("LEFT"); } if (!right && positions == ModPosition.Right) { right = true; chosen = true; print("RIGHT"); } if (!topLeft && positions == ModPosition.TopLeft) { topLeft = true; chosen = true; print("TOPLEFT"); } if (!topRight && positions == ModPosition.TopRight) { topRight = true; chosen = true; print("TOPRIGHT"); } } } //for each chosen item it will decrement modAmount untill while loop finishes if (left) { modAmount--; } if (right) { modAmount--; } if (topLeft) { modAmount--; } if (topRight) { modAmount--; } } print("Positions Chosen!"); }