123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System.Security.AccessControl;
- using UnityEngine;
- using System.Collections;
- public class NGUICostumeItemScript : MonoBehaviour {
-
- //the characters material used by costumes menu
- //to change the skin
- public Material characterMaterial;
- public Texture characterCostume;//the character costumes
- public int costumeCost;
-
- private GameObject goBuyEquipButton;
- private UILabel uilBuyEquipButton;
- private UILabel uilCostDescription;
-
- //state of the costume (false = not owned; true = owned)
- private bool costumeOwned;
-
- //script references
- private InGameScriptCS hInGameScriptCS;
- private NGUIMenuScript hNGUIMenuScript;
- public Finances.Costumes Costume;
-
-
- void Start ()
- {
- hInGameScriptCS = (InGameScriptCS)GameObject.Find("Player").GetComponent(typeof(InGameScriptCS));
- hNGUIMenuScript = (NGUIMenuScript)GameObject.Find("UI Root (2D)").GetComponent(typeof(NGUIMenuScript));
-
- goBuyEquipButton = (GameObject)this.transform.Find("Button_BuyEquip").gameObject;
- uilBuyEquipButton = (UILabel)this.transform.Find("Button_BuyEquip/Label").GetComponent(typeof(UILabel));
- uilCostDescription = (UILabel)this.transform.Find("Text_Cost").GetComponent(typeof(UILabel));
-
- //check if a meterial, texture and cost has been assigned to exposed variables
- if (characterMaterial == null)
- Debug.Log("EXCEPTION: Character material not assigned to costume shop element. Check the user documentation.");
- else if (characterCostume == null)
- Debug.Log("EXCEPTION: Character texture not assigned to costume shop element. Check the user documentation.");
- else if (costumeCost <= 0)
- Debug.Log("EXCEPTION: No cost assigned to the costume shop element. Check the user documentation.");
-
- //is this the currently applied texture?
- if (characterMaterial.GetTexture("_MainTex") == characterCostume)
- {
- costumeOwned = true;
- uilBuyEquipButton.text = "EQUIP";
- }
- else//not the currently equiped texture
- {
- costumeOwned = false;
- uilBuyEquipButton.text = "BUY";
- }
-
- //set the price on the label
- uilCostDescription.text = costumeCost.ToString();
- }//end of Start
- void Update()
- {
- if (Finances.HasCostume(Costume))
- {
- costumeOwned = true;
- uilBuyEquipButton.text = "EQUIP";
- uilCostDescription.text = "";
- }
- else
- {
- costumeOwned = false;
- uilBuyEquipButton.text = "BUY";
- uilCostDescription.text = Finances.GetCostumeCost(Costume).ToString();
- }
- }
- void OnClick()
- {
- if (!costumeOwned)//buy button tapped
- {
- Finances.BuyCostume(Costume);
- /*if (hInGameScriptCS.getCurrencyCount() >= costumeCost)//check if user has enough currency
- {
- //deduct the cost of costume
- hInGameScriptCS.alterCurrencyCount(-costumeCost);
-
- //change the texture of the character
- characterMaterial.SetTexture("_MainTex", characterCostume);
-
- //turn off buy and show equip button
- uilBuyEquipButton.text = "EQUIP";
-
- //change the costumeOwned
- costumeOwned = true;
-
- //take the user to the main menu
- hNGUIMenuScript.ShowMenu(NGUIMenuScript.NGUIMenus.MainMenu);
- hNGUIMenuScript.CloseMenu(NGUIMenuScript.NGUIMenus.ShopCostumes);
- }//end of if cost == cash */
- }
- else //equip button tapped
- {
- //change the texture of the character
- //characterMaterial.SetTexture("_MainTex", characterCostume);
- Costumes.Equip(Costume);
- //take the user to the main menu
- hNGUIMenuScript.ShowMenu(NGUIMenuScript.NGUIMenus.MainMenuNew);
- hNGUIMenuScript.CloseMenu(NGUIMenuScript.NGUIMenus.ShopCostumes);
- }
- }//end of On Click function
- }
|