示例#1
0
    public void PopulateSlots(Monster monster, string playerName)
    {
        //getting the part infos from the monster
        HeadPartInfo  headInfo     = monster.headPart.partInfo;
        TorsoPartInfo torsoInfo    = monster.torsoPart.partInfo;
        ArmPartInfo   rightArmInfo = monster.rightArmPart.partInfo;
        ArmPartInfo   leftArmInfo  = monster.leftArmPart.partInfo;
        LegPartInfo   legsInfo     = monster.legPart.partInfo;

        //populating the parts in to each slot
        headSlot.ChangePart(headInfo);
        torsoSlot.ChangePart(torsoInfo);
        rightArmSlot.ChangePart(rightArmInfo);
        leftArmSlot.ChangePart(leftArmInfo);
        legsSlot.ChangePart(legsInfo);

        //populating the weapons into each slot, if there are any equipped
        string rightWeapon = rightArmInfo.equippedWeapon;
        string leftWeapon  = leftArmInfo.equippedWeapon;

        if (rightWeapon != "")
        {
            rightWeaponSlot.ChangeWeapon(WeaponFactory.GetWeapon(rightWeapon, null, null, null));
        }
        if (leftWeapon != "")
        {
            leftWeaponSlot.ChangeWeapon(WeaponFactory.GetWeapon(leftWeapon, null, null, null));
        }

        //setting the name field text
        nameField.text = playerName;
    }
示例#2
0
    public void PopulateWeaponPicker()
    {
        var xOffset = 0f;

        if (availableWeapons.Count != 0)
        {
            //iterating through all of the items in the availbleWeapons array
            for (int i = 0; i < availableWeapons.Count; i++)
            {
                if (i == 0)
                {
                    xOffset = 60;
                }
                else
                {
                    xOffset += 120;
                }
                //loading the appropriate WeaponPicker prefab
                var pickerButtonPrefab = new GameObject();
                pickerButtonPrefab = Resources.Load <GameObject>("Prefabs/MonsterMaker/WeaponPickerButton");

                //instantiating the picker button
                var pickerButton = Instantiate(pickerButtonPrefab, Vector2.zero, Quaternion.identity);

                //initializing the pickerButton and also saving the created Weapon
                var weapon = pickerButton.GetComponent <WeaponPickerButton>().InitializePickerButton(availableWeapons[i]);
                //setting the onClick listener to the pickerButton
                pickerButton.GetComponent <Button>().onClick.AddListener(
                    delegate
                {
                    weaponSlot.ChangeWeapon(weapon);
                    weaponName.text = weapon.WeaponName;
                    weaponType.text = weapon.WeaponType;
                    weaponDesc.text = weapon.WeaponDesc;
                });

                //getting the rect transform of the button
                var pickerButtonTransform = pickerButton.GetComponent <RectTransform>();
                pickerButtonTransform.SetParent(weaponScroll.content);
                pickerButtonTransform.anchoredPosition = new Vector2(xOffset, 0);
                pickerButtonTransform.localScale       = new Vector3(0.5f, 0.5f, 0.5f);
                weaponScroll.content.sizeDelta         = new Vector2(weaponScroll.content.sizeDelta.x + 120f, weaponScroll.content.sizeDelta.y);
            }
        }
    }