- Home /
Question by
quantumarchi · Nov 28, 2011 at 10:19 PM ·
gui-buttontooltipdragwindow
scripts not working properly drag doesnt work after its used once.
when i use drag so i can move my inventory it doesnt work more then once (i move it once) then it doesnt reset so i can drag again
using UnityEngine; using System.Collections; using System.Collections.Generic;
public class UI : MonoBehaviour { public GUISkin Skin;
public float lootWindowHeight = 100;
public float buttonWidth = 40;
public float buttonHeight = 40;
public float closeButtonWidth = 20;
public float closeButtonHeight = 20;
private bool _displayLootWindow = false;
private float _offset = 10;
private const int Loot_window_ID = 0;
private Rect _lootWindowRect = new Rect (0, 0, 0, 0);
private Vector2 _lootWindowSlider = Vector2.zero;
public static Interaction interaction;
private bool _displayInvWindow = false;
private const int Inv_window_ID = 1;
private Rect _invWindowRect = new Rect(10, 10, 170, 265);
private int _invRows = 5;
private int _invCols= 5;
private string _tooltip = "";
// Use this for initialization
void Start () {
}
public void OnEnable() {
Messenger.AddListener("DisplayLoot", DisplayLoot);
Messenger.AddListener("CloseIntereaction", ClearWindow);
Messenger.AddListener("ToggleInv", ToggleInvWindow);
}
public void OnDisable() {
Messenger.RemoveListener("DisplayLoot", DisplayLoot);
Messenger.RemoveListener("CloseIntereaction", ClearWindow);
Messenger.RemoveListener("ToggleInv", ToggleInvWindow);
}
void OnGUI() {
GUI.skin = Skin;
if(_displayInvWindow)
_invWindowRect = GUI.Window(Inv_window_ID, _invWindowRect, InvWindow, "Inventory");
if(_displayLootWindow)
_lootWindowRect = GUI.Window(Loot_window_ID, new Rect(_offset, Screen.height - (_offset + lootWindowHeight), Screen.width - (_offset * 2), lootWindowHeight), LootWindow, "Loot window");
DisplayTooltip();
}
private void LootWindow(int id) {
GUI.skin = Skin;
if(GUI.Button(new Rect(_lootWindowRect.width - _offset * 2, 0, closeButtonWidth, closeButtonHeight), "x", " close Window Button"))
ClearWindow();
if(interaction == null)
return;
if(interaction.loot.Count == 0) {
ClearWindow();
return;
}
_lootWindowSlider = GUI.BeginScrollView(new Rect(_offset * .5f, 15, _lootWindowRect.width - _offset, 70), _lootWindowSlider, new Rect(0, 0, (interaction.loot.Count * buttonWidth) + _offset, buttonHeight + _offset));
for(int cnt = 0; cnt < interaction.loot.Count; cnt++) {
if(GUI.Button(new Rect(_offset * .5f + (buttonWidth * cnt), _offset, buttonWidth, buttonHeight), new GUIContent(interaction.loot[cnt].Icon, interaction.loot[cnt].ToolTip()))) {
PlayerCharacter.Inventory.Add(interaction.loot[cnt]);
interaction.loot.RemoveAt(cnt);
}
}
GUI.EndScrollView();
SetToolTip();
}
private void DisplayLoot() {
_displayLootWindow = true;
}
private void ClearWindow() {
_displayLootWindow = false;
interaction.OnMouseUp();
interaction = null;
}
public void InvWindow(int id) {
GUI.skin = Skin;
int cnt = 0;
for(int y = 0; y < _invRows; y++) {
for(int x = 0; x < _invCols; x++) {
if(cnt < PlayerCharacter.Inventory.Count) {
GUI.Button(new Rect(5 + (x * buttonWidth), 20 + (y * buttonHeight), buttonWidth, buttonHeight), new GUIContent(PlayerCharacter.Inventory[cnt].Icon, PlayerCharacter.Inventory[cnt].ToolTip()), "InvSlotUsed");
}
else {
GUI.Label(new Rect(5 + (x * buttonWidth), 20 + (y * buttonHeight), buttonWidth, buttonHeight), (x + y * _invCols).ToString());
}
cnt++;
}
}
SetToolTip();
GUI.DragWindow();
}
public void ToggleInvWindow() {
_displayInvWindow = !_displayInvWindow;
}
private void SetToolTip() {
if(Event.current.type == EventType.Repaint && GUI.tooltip != _tooltip) {
if(_tooltip != "")
_tooltip = "";
if(GUI.tooltip != "")
_tooltip = GUI.tooltip;
}
}
private void DisplayTooltip() {
if(_tooltip != "");
GUI.Box(new Rect(Screen.width / 2 - 100, 10, 200, 100), GUI.tooltip);
}
}
Comment
Your answer
Follow this Question
Related Questions
display hints while mouse is over a text field using tooltip 3 Answers
Checking for idle hover using tooltips 0 Answers
Creating a pause menu (problem using Time.timeScale) 3 Answers
how made GUIButton for car game 2 Answers
IPhone gui jump button 0 Answers