Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Inv {
  2.     public var item : MicrowaveItem;
  3.     public var name : String;
  4.     public var description : String;
  5.     public var quantity : int;
  6.     public var siz : int;
  7.     public var rh : boolean; // restore health
  8.     public var rmh : boolean; // restore microwave health
  9.     public var texture : Texture2D;
  10. }
  11. var inv : Inv[];
  12. private var scrollPosition : Vector2;
  13. private var scrollPosition2 : Vector2;
  14. private var srh : boolean = false;
  15. private var srmh : boolean = false;
  16. private var show : boolean = false;
  17. private var item : int;
  18. private var nam : String;
  19. private var micitems : int[];
  20. private var msize : int = 10;
  21. private var temparr = Array();
  22. function OnGUI () {
  23.     if (Camera.main.transform.GetComponent("main").ms==1) {
  24.         if (GUI.Button(Rect(0,0,150,30),"Return to main menu")) {
  25.             Camera.main.transform.GetComponent("main").ms=0;
  26.         }
  27.         GUI.Box(Rect(Screen.width-300,40,300,Screen.height-80),"");
  28.         GUI.Box(Rect(0,40,Screen.width-310,((Screen.height-80)/2)-5),"");
  29.         GUI.Box(Rect(0,((Screen.height-80)/2)+45,Screen.width-310,((Screen.height-80)/2)-5),"");
  30.         // inventory list---------------------------------------------------------------------------------------
  31.         GUILayout.BeginArea (Rect (Screen.width-300,40,300,Screen.height-80));
  32.         scrollPosition = GUILayout.BeginScrollView (scrollPosition, GUILayout.Width (300), GUILayout.Height (Screen.height-80));
  33.         GUILayout.BeginVertical ("");
  34.         for (var i = 0;i<inv.length;i++) {
  35.             if (inv[i].quantity>0) {
  36.                 GUILayout.BeginHorizontal("");
  37.                 if (GUILayout.Button(inv[i].texture,GUILayout.Width(75))) {
  38.                     //inv[i].quantity=inv[i].quantity-1;
  39.                     show = true;
  40.                     item = i;
  41.                     nam = inv[i].name;
  42.                 }
  43.                 GUILayout.BeginVertical ("");
  44.                 GUILayout.Label(inv[i].name);
  45.                 GUILayout.Label(""+inv[i].quantity);
  46.                 GUILayout.EndVertical();
  47.                 GUILayout.EndHorizontal();
  48.             }
  49.         }
  50.         GUILayout.EndVertical();
  51.         GUILayout.EndScrollView ();
  52.         GUILayout.EndArea ();
  53.         if (show && inv[item].quantity>0) {
  54.             // item description------------------------------------------------------------------------------
  55.             GUILayout.BeginArea (Rect(0,40,Screen.width-310,((Screen.height-80)/2)-5));
  56.             GUILayout.BeginVertical ("");
  57.             GUILayout.BeginHorizontal("");
  58.             GUILayout.Label(inv[item].texture,GUILayout.Width (64));
  59.             GUILayout.BeginVertical ("");
  60.             GUILayout.Label(inv[item].name);
  61.             GUILayout.Label("number in inventory = "+inv[item].quantity+", item size = "+inv[item].siz);
  62.             GUILayout.EndVertical();
  63.             GUILayout.EndHorizontal();
  64.             GUILayout.Label(inv[item].description);
  65.             GUILayout.EndVertical();
  66.             GUILayout.EndArea ();
  67.             if (inv[item].siz>msize) {
  68.                 GUI.enabled = false;
  69.             }
  70.             if (GUI.Button(Rect(0,((Screen.height-80)/2)+5,Screen.width-310,30),"Add "+nam+" to microwave")) {
  71.                 //show=false;
  72.                 AddToMicrowave(item);
  73.             }
  74.             GUI.enabled = true;
  75.         }
  76.         // microwave item list--------------------------------------------------------------------------------
  77.         GUILayout.BeginArea (Rect(0,((Screen.height-80)/2)+45,Screen.width-310,((Screen.height-80)/2)-5));
  78.         scrollPosition2 = GUILayout.BeginScrollView (scrollPosition2, GUILayout.Width (Screen.width-310), GUILayout.Height (((Screen.height-80)/2)-5));
  79.         GUILayout.BeginVertical ("");
  80.         GUILayout.BeginHorizontal("");
  81.         if (Screen.width-310>360) {
  82.             GUILayout.Space((Screen.width-310-360)/2);
  83.         }
  84.         if (micitems != null && micitems.length>0) {
  85.             for (k=0;k<micitems.length&&k!=5;k++) {
  86.                 GUILayout.BeginVertical ("",GUILayout.Width(50));
  87.                 GUILayout.Label(inv[micitems[k]].texture);
  88.                 if (GUILayout.Button("remove")) {
  89.                     RemoveFromMicrowave(k);
  90.                 }
  91.                 GUILayout.EndVertical();
  92.             }
  93.         }
  94.         GUILayout.EndHorizontal();
  95.         if (micitems != null && micitems.length>5) {
  96.             GUILayout.BeginHorizontal("");
  97.             if (Screen.width-310>360) {
  98.                 GUILayout.Space((Screen.width-310-360)/2);
  99.             }
  100.             if (micitems != null && micitems.length>0) {
  101.                 for (k=5;k<micitems.length;k++) {
  102.                     GUILayout.BeginVertical ("",GUILayout.Width(50));
  103.                     GUILayout.Label(inv[micitems[k]].texture);
  104.                     if (GUILayout.Button("remove")) {
  105.                         RemoveFromMicrowave(k);
  106.                     }
  107.                     GUILayout.EndVertical();
  108.                 }
  109.             }
  110.             GUILayout.EndHorizontal();
  111.         }
  112.         GUILayout.EndVertical();
  113.         GUILayout.EndScrollView ();
  114.         GUILayout.EndArea ();
  115.         //Rect(0,Screen.height-30,Screen.width,30),"add "+nam+" to microwave")
  116.     }
  117. }
  118. function RemoveFromMicrowave(ite:int) {
  119.     inv[micitems[ite]].quantity = inv[micitems[ite]].quantity + 1;
  120.     msize = msize + inv[micitems[ite]].siz;
  121.     temparr = new Array (micitems);
  122.     temparr.RemoveAt(ite);
  123.     micitems = temparr.ToBuiltin(int);
  124. }
  125. function AddToMicrowave (it : int) {
  126.     inv[it].quantity = inv[it].quantity - 1;
  127.     msize = msize - inv[it].siz;
  128.     if (micitems!=null)
  129.     temparr = new Array (micitems);
  130.     temparr.Push(it);
  131.     micitems = temparr.ToBuiltin(int);
  132.    
  133.     //Debug.Log("works");
  134.     //Camera.main.transform.GetComponent("main").ms=0;
  135. }
  136.  
  137. function Update() {
  138.     if (Camera.main.transform.GetComponent("main").ms==0) {
  139.         show=false;
  140.         scrollPosition = Vector2.zero;
  141.         scrollPosition2 = Vector2.zero;
  142.     }
  143.     /*msize = 10;
  144.     if (micitems != null && micitems.length>0) {
  145.         for (j=0;j<micitems.length;j++) {
  146.             msize = msize - inv[micitems[j]].siz;
  147.         }
  148.     }*/
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement