void DisplayInventory()
    {
        float   sw = Screen.width;
        float   sh = Screen.height;
        Texture buttonTexture;
        Texture t;
        int     totalCellsToDisplay = inventoryItems.Count;

        for (int i = 0; i < totalCellsToDisplay; i++)
        {
            InventoryItem ii              = inventoryItems [i];
            int           quantity        = ii.quantity;
            float         totalCellLength = sw - (numCells * width);
            float         xcoord          = totalCellLength - .5f * totalCellLength + width * i;
            GameObject    go              = ii.item;

            CustomGameObj     cgoi = go.GetComponent <CustomGameObj> ();
            ObjectInteraction oi   = go.GetComponent <ObjectInteraction> ();
            buttonTexture = oi.texture;

            Rect r = new Rect(xcoord, yPosition * sh, width, height);
            if (GUI.Button(r, buttonTexture))
            {
                Debug.Log("in GUI.Button.xcoord: " + xcoord);
            }
            string   s     = quantity.ToString();
            Rect     r2    = new Rect(xcoord, yPosition * sh, width / 2, height / 2);
            GUIStyle style = new GUIStyle();

            GUI.Label(r2, s, "<font bgcolor=yellow color=red></font>");
        }
    }
예제 #2
0
 // Use this for initialization
 void Start()
 {
     gameObjectInfo = this.gameObject.GetComponent<CustomGameObj>();
     if (gameObjectInfo) {
         gameObjectInfo.validate();
     }
 }
 // Use this for initialization
 void Start()
 {
     customGameObj = this.GetComponent <CustomGameObj> ();
     if (customGameObj != null)
     {
         customGameObj.validate();
     }
 }
    public void Add(InteractiveObj iObj)
    {
        ObjectInteraction oi = iObj.OnCloseEnough;

        switch (oi.interactionType)
        {
        case ObjectInteraction.InteractionType.Unique:
            Insert(iObj);
            break;

        case ObjectInteraction.InteractionType.Accumulate:
        {
            bool          inserted             = false;
            CustomGameObj cgo                  = iObj.gameObject.GetComponent <CustomGameObj> ();
            CustomGameObj.CustomObjectType cot = CustomGameObj.CustomObjectType.Invalid;
            if (cgo != null)
            {
                cot = cgo.objectType;                         // type
            }
            for (int i = 0; i < inventoryItems.Count; i++)
            {
                CustomGameObj cgoi = inventoryItems[i].item.GetComponent <CustomGameObj> ();
                CustomGameObj.CustomObjectType coti = CustomGameObj.CustomObjectType.Invalid;
                if (cgoi != null)
                {
                    coti = cgoi.objectType;               // type
                }
                if (cot == coti)                          //accumulate
                {
                    inventoryItems [i].quantity++;
                    //deal with mission token
                    MissionToken mt = iObj.gameObject.GetComponent <MissionToken> ();
                    if (mt != null)
                    {
                        missionMgr.Add(mt);
                        iObj.gameObject.SetActive(false);
                        inserted = true;
                        break;
                    }
                }                //if(cot == coti)
            }                    //for (

            if (!inserted)
            {
                Insert(iObj);
            }
        }        //accumulate
        break;
        }        //switch
    }