Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges