Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - weltraumaffe

Pages: [1]
1
Thank you very much! Looks very promising for what we need :)

2
menu is a GameObject that holds all the buttons for the menu.
It's just some buttons..

Thanks for the remarks about lasthit and lastTouchPosition!

A bit bummed that hover doesn't work while mouse down... Is there a way to work around this limitation?

3
NGUI 3 Support / Context Menu Show/hide with LeftClick Press/Release
« on: April 30, 2013, 01:32:48 PM »
Hi,

I'm currently working on a context menu that appears if the player presses a button for a certain amount of time. After the player releases the button the Menu disappears.
It's already working that it shows on click and disappears on release of the mouse button.
However the effects like coloring, resizing and so on don't work.
This is my OnPress function:
  1. void OnPress(bool pressed) {
  2.                 if (pressed) {
  3.                         if (UICamera.currentTouchID == (int)menuButton) {
  4.                                 RaycastHit hit;
  5.                                 if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity)) {
  6.  
  7.                                         ShipComponent hitComponenent = hit.transform.GetComponent<ShipComponent>();
  8.  
  9.                                         if (hitComponenent) {
  10.                                                 if (hitComponenent == _selectShipComponent.selectedComponent) {
  11.                                                         EnableCountdownForMenu();
  12.                                                         _menuPos = Input.mousePosition;
  13.                                                 }
  14.                                         }
  15.                                 }
  16.                         }
  17.  
  18.                 } else {
  19.                         DisableCountdownForMenu();
  20.                         DestroyMenu();
  21.                 }
  22.         }
  23.  

And this code is responsible for showing the menu:
  1. NGUITools.SetActive(menu, true);
  2. menu.transform.localPosition = _menuPos;
  3.  
I hide the menu with
  1. NGUITools.SetActive(menu, false);

If I disable the hiding the button works as expected (scaling and coloring...)

The Menu is a simple gameobject with some buttons and a sprite as children
Any idea what I do wrong?

4
NGUI 3 Support / UIGridPlus (Grid + LayoutSelection)
« on: April 23, 2013, 06:58:46 AM »
I needed a grid where you can choose in which direction the children are layed out (select a pivot point).
I didn't find anything that suited me so I programmed my own... I used UIGrid as a base and changed what I needed, I hope thats ok.
Here is the code:
  1.  
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4.  
  5. [ExecuteInEditMode]
  6. public class UIGridPlus : MonoBehaviour {
  7.         public enum Pivot {
  8.                 TopLeft,
  9.                 TopCenter,
  10.                 TopRight,
  11.                 MiddleLeft,
  12.                 MiddleCenter,
  13.                 MiddleRight,
  14.                 BottomLeft,
  15.                 BottomCenter,
  16.                 BottomRight
  17.         }
  18.         public Pivot pivot;
  19.         public int maxPerLine = 0;
  20.         public float cellWidth = 200f;
  21.         public float cellHeight = 200f;
  22.         public bool repositionNow = false;
  23.         public bool sorted = false;
  24.         public bool hideInactive = true;
  25.  
  26.         bool mStarted = false;
  27.  
  28.         void Start() {
  29.                 mStarted = true;
  30.                 Reposition();
  31.         }
  32.  
  33.         void Update() {
  34.                 if (repositionNow) {
  35.                         repositionNow = false;
  36.                         Reposition();
  37.                 }
  38.         }
  39.  
  40.         static public int SortByName(Transform a, Transform b) { return string.Compare(a.name, b.name); }
  41.  
  42.         /// <summary>
  43.         /// Recalculate the position of all elements within the grid, sorting them alphabetically if necessary.
  44.         /// </summary>
  45.  
  46.         public void Reposition() {
  47.                 if (!mStarted) {
  48.                         repositionNow = true;
  49.                         return;
  50.                 }
  51.  
  52.                 Transform myTrans = transform;
  53.  
  54.                 int x = 0;
  55.                 int y = 0;
  56.                 List<Transform> list = new List<Transform>();
  57.  
  58.                 for (int i = 0; i < myTrans.childCount; ++i) {
  59.                         Transform t = myTrans.GetChild(i);
  60.                         if (t && (!hideInactive || NGUITools.GetActive(t.gameObject))) list.Add(t);
  61.                 }
  62.                 if (sorted) {
  63.                         list.Sort(SortByName);
  64.                 }
  65.                 int lines = maxPerLine > 0 ? list.Count / maxPerLine - 1 : 0;
  66.                 int columns = maxPerLine > 0 ?
  67.                         (list.Count > maxPerLine ? maxPerLine : list.Count) - 1 :
  68.                         list.Count - 1;
  69.                 Debug.Log(lines + " " + columns);
  70.                 for (int i = 0, imax = list.Count; i < imax; ++i) {
  71.                         Transform t = list[i];
  72.  
  73.                         if (!NGUITools.GetActive(t.gameObject) && hideInactive) continue;
  74.  
  75.                         float depth = t.localPosition.z;
  76.                         Vector3 newPos = new Vector3();
  77.                         switch (pivot) {
  78.                                 case Pivot.TopLeft:
  79.                                 case Pivot.TopCenter:
  80.                                 case Pivot.TopRight:
  81.                                         newPos.y = -cellHeight * y;
  82.                                         break;
  83.                                 case Pivot.MiddleLeft:
  84.                                 case Pivot.MiddleCenter:
  85.                                 case Pivot.MiddleRight:
  86.                                         newPos.y = -cellHeight * (-lines / 2f + y);
  87.                                         break;
  88.                                 case Pivot.BottomLeft:
  89.                                 case Pivot.BottomCenter:
  90.                                 case Pivot.BottomRight:
  91.                                         newPos.y = cellHeight * (lines - y);// -cellHeight * lines + cellHeight * y;
  92.                                         break;
  93.                                 default:
  94.                                         break;
  95.                         }
  96.                         switch (pivot) {
  97.                                 case Pivot.TopLeft:
  98.                                 case Pivot.MiddleLeft:
  99.                                 case Pivot.BottomLeft:
  100.                                         newPos.x = cellWidth * x;
  101.                                         break;
  102.                                 case Pivot.TopCenter:
  103.                                 case Pivot.MiddleCenter:
  104.                                 case Pivot.BottomCenter:
  105.                                         newPos.x = cellWidth * (-columns / 2f + x); // -cellWidth * (columns / 2f) + cellWidth * x;
  106.                                         break;
  107.                                 case Pivot.TopRight:
  108.                                 case Pivot.MiddleRight:
  109.                                 case Pivot.BottomRight:
  110.                                         newPos.x = cellWidth * (-columns + x);
  111.                                         break;
  112.                                 default:
  113.                                         break;
  114.                         }
  115.                         newPos.z = depth;
  116.                         t.localPosition = newPos;
  117.  
  118.                         if (++x >= maxPerLine && maxPerLine > 0) {
  119.                                 x = 0;
  120.                                 ++y;
  121.                         }
  122.                 }
  123.  
  124.  
  125.                 UIDraggablePanel drag = NGUITools.FindInParents<UIDraggablePanel>(gameObject);
  126.                 if (drag != null) drag.UpdateScrollbars(true);
  127.         }
  128. }
  129.  

Pages: [1]