- Home /
Question by
norman1234 · Feb 06, 2014 at 03:32 PM ·
javascriptinventoryinventory system
How to optimize this script and add items imediately without grids
How can i optimize this inventory script. And also pick up items and drop them. The items are in c#. i Tried converting this script but to no avail.
#pragma strict
//Private Variables
private var InventoryOn = false;
private var scrollBarChopGrid : Vector2 = Vector2.zero;
private var GridValue : float = -1;
var myskin : GUISkin;
//GUI Pos/Size
var ClosePosition : Vector2 = new Vector2(312,5);
var CloseSize : Vector2 = new Vector2(35,35);
var NamePosition : Vector2 = new Vector2(13,13);
var NameSize : Vector2 = new Vector2(250,250);
var TooltipSize : Vector2 = new Vector2(140,40);
var GridPosition : Vector2 = new Vector2(10,2);
var GridSize : Vector2 = new Vector2(323,410);
var ScrollPosition : Vector2 = new Vector2(0,95);
var ScrollSize : Vector2 = new Vector2(353,257);
var WindowPosition : Vector2 = new Vector2(0,0);
var WindowSize : Vector2 = new Vector2(360,360);
var DragWindowPosition : Rect = Rect(0, 0, WindowSize.x, WindowSize.y);
//Textures
var InventoryWindow : Texture;
var CloseIcon : Texture;
var Grids : GUIContent[];
function Update () {
//On or Off
if (Input.GetKeyUp("i"))
{
if (InventoryOn == false)
{
InventoryOn = true;
}
else if (InventoryOn == true)
{
InventoryOn = false;
scrollBarChopGrid.y= 0;
}
}
//Window Drag fix
if (Input.GetKeyDown("left shift"))
{
if (Input.GetKeyDown("i"))
{
DragWindowPosition.x = 10;
DragWindowPosition.y = 10;
}
}
}
function OnGUI()
{
GUI.skin = myskin;
if (InventoryOn == true)
{
DragWindowPosition = GUI.Window(0, DragWindowPosition, DoMyWindow, "");
if (GridValue != 0 && GUI.tooltip != ""){
{
GUI.Box(Rect (Event.current.mousePosition.x, Screen.height - Input.mousePosition.y + 15, TooltipSize.x,TooltipSize.y), Grids[GridValue].tooltip);
}
}
}
}
function DoMyWindow(windowID : int){
if (InventoryOn == true)
{
GUI.BeginGroup(new Rect(WindowPosition.x, WindowPosition.y, WindowSize.x, WindowSize.y), InventoryWindow);
//Name
GUI.Label (Rect (NamePosition.x, NamePosition.y,NameSize.x, NameSize.y),"Your Inventory");
//Close Button
if (GUI.Button(Rect(ClosePosition.x, ClosePosition.y, CloseSize.x, CloseSize.y), CloseIcon))
{
InventoryOn = false;
}
//Scroll Bar
scrollBarChopGrid = GUI.BeginScrollView(Rect (ScrollPosition.x, ScrollPosition.y, ScrollSize.x, ScrollSize.y), scrollBarChopGrid, Rect(0,0,0,420));
// Grid
GridValue = GUI.SelectionGrid(Rect(GridPosition.x, GridPosition.y, GridSize.x, GridSize.y), GridValue, Grids, 5);
GUI.EndScrollView();
//Dragable Window
GUI.DragWindow (Rect (WindowPosition.x, WindowPosition.y, 10000, 40));
GUI.EndGroup();
}
}
Comment
Your answer
Follow this Question
Related Questions
Inventory code not working [JS] 0 Answers
Having scripts interact 1 Answer
Is this considered bad coding 1 Answer
Locked door and key to open it script 1 Answer
How to simplify my Equipment method? 1 Answer