Ejemplo n.º 1
0
    public void addItem(GameObject nitem)
    {
        itemProperties itemProperties = nitem.GetComponentInChildren <itemProperties>();

        if (items.Contains(nitem))
        {
            foreach (Transform child in slotManager.GetComponent <Transform>())
            {
                if (child.transform.GetChild(3).GetComponent <Text>().text == itemProperties.itemName)
                {
                    var value = child.transform.GetChild(0).GetComponent <Text>().text;
                    child.transform.GetChild(0).GetComponent <Text>().text = (Int32.Parse(value) + 1).ToString();
                }
            }
        }
        else
        {
            items.Add(nitem);
            GameObject slot = (GameObject)Instantiate(slotPrefab, slotManager.transform);

            //quantity text
            slot.transform.GetChild(0).GetComponent <Text>().text = "1";
            //description text
            slot.transform.GetChild(1).GetComponent <Text>().text = itemProperties.description;
            //value text
            slot.transform.GetChild(2).GetComponent <Text>().text = itemProperties.value.ToString();
            //name text
            slot.transform.GetChild(3).GetComponent <Text>().text = itemProperties.itemName;
            //raw image
            slot.transform.GetChild(4).GetComponent <RawImage>().texture = Resources.Load(itemProperties.path) as Texture2D;
            Vector2 smSize   = slotManager.GetComponent <RectTransform>().sizeDelta;
            Vector2 slotSize = slot.GetComponent <RectTransform>().sizeDelta;
            slotManager.GetComponent <RectTransform>().sizeDelta = new Vector2(smSize.x, smSize.y + slotSize.y + 5);
        }
    }
Ejemplo n.º 2
0
 // For now a new instance of a ship can always start off with a full fuel tank
 public Ship(itemProperties ip, int fuelCapacity, int igx, int igy, GameObject ship, int currentPlanet, FuelType ft = FuelType.ok) : base(ip.pn, ip.sn, ip.cond, ip.name, ip.hasComponents, ip.components)
 {
     _fuelCapacity  = fuelCapacity;
     _fuelCurrent   = _fuelCapacity;
     _fuelType      = ft;
     _inventory     = new InvGrid(igx, igy);
     _currentPlanet = currentPlanet;
     _gObject       = ship;
 }
Ejemplo n.º 3
0
    public void addItem(GameObject nitem)
    {
        itemProperties itemProperties = nitem.GetComponentInChildren <itemProperties>();

        Debug.Log("adding item");
        GameObject slot = (GameObject)Instantiate(slotPrefab, slotManager.transform);

        slot.transform.GetChild(0).GetComponent <RawImage>().texture = Resources.Load(itemProperties.path) as Texture2D;
        slot.transform.GetChild(1).GetComponent <Text>().text        = itemProperties.itemName;
        Vector2 smSize   = slotManager.GetComponent <RectTransform>().sizeDelta;
        Vector2 slotSize = slot.GetComponent <RectTransform>().sizeDelta;

        slotManager.GetComponent <RectTransform>().sizeDelta = new Vector2(smSize.x, smSize.y + slotSize.y + 5);
        items.Add(nitem);
        if (items.Capacity == 0)
        {
            slot.GetComponent <slotSelectEvent>().slot = 0;
        }
        else
        {
            slot.GetComponent <slotSelectEvent>().slot = items.Count - 1;
        }
    }
 /// <summary>
 /// Start is called on the frame when a script is enabled just before
 /// any of the Update methods is called the first time.
 /// </summary>
 void Start()
 {
     Instance = this;
     thisBody = GetComponent <Rigidbody2D>();
 }
 public void Awake()
 {
     throwState = false;
     item       = new itemProperties(durabilityValue, itemName);
 }