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.


Topics - Zyxil

Pages: [1]
1
NGUI 3 Support / UIDragScrollView.OnDisable() perf question
« on: July 23, 2017, 08:37:06 PM »
Is this OnDisable() even necessary to have?  It allocs a bunch of junk for the GC to clean up.  With a very large number of elements, I'm seeing 80+ % in 2 second frames when destroying and recreating lists.  :(

2
I just came across an event that has happened to me maybe four times in the last two years.  It's very rare, but is a colossal pain in the butt when it happens.  I'll share my experience and maybe it will help down the road.

Event: may be more causes, but from what I've deduced: if you close Unity when there is a compilation error in your code, on reopening Unity, all NGUI prefabs will have lost their data (all of it!).

The first time this happened to me, I set about manually resetting all the data that was lost.  It took me several days to recover.

Current fix: I just discovered that you can manually walk your tree, go each prefab, click Revert and then immediately Undo (ctrl+z).  This will restore your data to the values that were present before.  UILabels that had NGUI fonts assigned will still say they are Unity fonts, but if you click to another GameObject and then back again, the data will show properly.

Moral: do not close Unity with code that won't compile.

I hope this helps somebody, or perhaps it might spark some further discussion or give Aren an "ah-ha" moment.... :)

3
NGUI 3 Support / Small Bug in UIPopupList
« on: October 22, 2016, 04:27:09 PM »
If your popup list is on a panel that has a changed sorting order, the created panel will appear on sorting order 0.

I added this just after panel creation at ~903:

  1.                 mChild.GetComponent<UIPanel>().sortingOrder = NGUITools.FindInParents<UIPanel>(gameObject).sortingOrder;
  2.  

4
NGUI 3 Support / NGUI and Vectrosity
« on: October 20, 2016, 06:26:05 PM »
If you are working with Vectrosity, the line drawing asset, you can use this to get started:

  1. using UnityEngine;
  2. using Vectrosity;
  3. using System.Collections.Generic;
  4.  
  5. public class LineDrawer : MonoBehaviour
  6. {
  7.     public List<Vector3> points;
  8.     private Vector3[] curvePoints = new Vector3[4];
  9.  
  10.     public GameObject sourceGO;
  11.     public GameObject targetGO;
  12.     public Color lineColor = Color.red;
  13.     private Color _setColor = Color.white;
  14.  
  15.     public Camera unityCamera;
  16.  
  17.     //create and assign a standard material, set smoothness source to "Albedo Alpha", set smoothness to 0
  18.     public Material lineMaterial;
  19.  
  20.     private Vector3 sourcePosition;
  21.     private Vector3 targetPosition;
  22.  
  23.     private VectorLine myLine;
  24.  
  25.     private void Start()
  26.     {
  27.         //set these items before any VectorLine is created
  28.  
  29.         VectorLine.SetCamera3D(unityCamera);
  30.  
  31.         //we need to set the canvas to be at the same location as the NGUI screen area
  32.         VectorLine.canvas.renderMode = RenderMode.WorldSpace;
  33.         VectorLine.canvas.transform.position = Vector3.zero;
  34.         //on UIRoot, set Constrained Scaling Style
  35.         VectorLine.canvas.scaleFactor = NGUITools.FindInParents<UIRoot>(this.gameObject).gameObject.transform.localScale.x;
  36.  
  37.  
  38.  
  39.        
  40.  
  41.         if(sourceGO == null | targetGO == null)
  42.         {
  43.             Debug.LogError("Set your source and target GOs.");
  44.             return;
  45.         }
  46.  
  47.         points =new List<Vector3> { Vector3.zero, Vector3.one };
  48.  
  49.         myLine = new VectorLine("myLine", points, 5f, LineType.Continuous);
  50.         myLine.Resize(50);
  51.  
  52.         //setting renderqueue > 3000 will draw in front of all NGUI objects
  53.         lineMaterial.renderQueue = 4000;
  54.         lineMaterial.SetColor("_Color", Color.red);
  55.         lineMaterial.SetColor("_EmissionColor", Color.red);
  56.  
  57.         myLine.material = lineMaterial;
  58.        
  59.  
  60.         myLine.Draw3DAuto();
  61.  
  62.     }
  63.  
  64.     private void Update()
  65.     {
  66.         if(sourceGO == null | targetGO == null)
  67.             return;
  68.  
  69.         if(sourceGO.transform.localPosition != sourcePosition |
  70.             targetGO.transform.localPosition != targetPosition)
  71.         {
  72.             sourcePosition = sourceGO.transform.position;
  73.             targetPosition = targetGO.transform.position;
  74.  
  75.             Vector3 pos1 = new Vector3(sourcePosition.x, sourcePosition.y, sourcePosition.z);
  76.             Vector3 pos2 = new Vector3(targetPosition.x, targetPosition.y, targetPosition.z);
  77.  
  78.             curvePoints[0] = pos1;// sourcePosition;
  79.             curvePoints[1] = (pos1 + new Vector3(0.3f, 0f, 0f));
  80.             curvePoints[2] = pos2;
  81.             curvePoints[3] = (pos2 + new Vector3(0f, 0.3f, 0f));
  82.  
  83.             myLine.MakeCurve(curvePoints);
  84.  
  85.         }
  86.  
  87.         if(_setColor != lineColor)
  88.         {
  89.             lineMaterial.renderQueue = 4000;
  90.             lineMaterial.SetColor("_Color", lineColor);
  91.             lineMaterial.SetColor("_EmissionColor", lineColor);
  92.  
  93.             myLine.material = lineMaterial;
  94.         }
  95.     }
  96. }
  97.  
  98.  

5
NGUI 3 Support / Fun with EventDelegates
« on: August 30, 2015, 09:16:28 PM »
I just want to share some of the fun that can be had with the extremely powerful EventDelegate system in NGUI and propose a few tweaks to help it along.

The power of EventDelegate events in NGUI comes from the ease created by simply wiring events in the editor versus having to handle them via code.  I heartily recommend using the various events exposed on the NGUI stock controls. 

I find that I create many simple public void MethodName() {...} methods that can be the target of these events.  Simple additions, like SetUnchecked() and SetChecked() can then be easy to wire up to events.  What would make this more powerful would be a way to put static parameter values in the editor (see the EventDelegate Wireup.png attached image).  PlayMaker does something similar with the ability to add references and static values.

The next level was reached when I started creating my own List<EventDelegate> events from my own classes.  This then opens up a very easy method to add my own events to my game and even extend NGUI's base classes.

EDIT: The below already exists as EventDelegate.Execute(List<EventDelegate>).
My first recommendation is to add to EventDelegate.cs a static Process() function.  I created my own pseudo-extension method for the same and it means not writing the processing code for events ever again.

EventDelegateProcessor.cs

using System.Collections.Generic;

public static class EventDelegateProcessor
{
    public static void Process(List<EventDelegate> eventDelegate)
    {
        List<EventDelegate> mTemp = null;

        if (eventDelegate != null)
        {
            mTemp = eventDelegate;
            eventDelegate = new List<EventDelegate>();

            // Notify the listener delegates
            EventDelegate.Execute(mTemp);

            // Re-add the previous persistent delegates
            for (int i = 0; i < mTemp.Count; ++i)
            {
                EventDelegate ed = mTemp;
                if (ed != null && !ed.oneShot) EventDelegate.Add(eventDelegate, ed, ed.oneShot);
            }
            mTemp = null;
        }
    }
}

As an example that illustrates the above, here are some simple classes of mine that decorate UIToggle with both types of extra functionality: granular void event target methods and custom events.  (Freyja is the dev name for my project.)

FreyjaToggle.cs
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. public class FreyjaToggle : MonoBehaviour
  5. {
  6.     private UIToggle _uiToggle;
  7.  
  8.     [HideInInspector]
  9.     public List<EventDelegate> onToggleTrue = new List<EventDelegate>();
  10.  
  11.     [HideInInspector]
  12.     public List<EventDelegate> onToggleFalse = new List<EventDelegate>();
  13.  
  14.  
  15.     public void Start()
  16.     {
  17.         _uiToggle = gameObject.GetComponent<UIToggle>();
  18.         EventDelegate.Add(_uiToggle.onChange, OnToggleChanged, false);
  19.     }
  20.  
  21.     private void OnToggleChanged()
  22.     {
  23.         if (_uiToggle.value)
  24.             EventDelegateProcessor.Process(onToggleTrue);
  25.         else
  26.             EventDelegateProcessor.Process(onToggleFalse);
  27.     }
  28.  
  29.     public void SetValue(bool isChecked)
  30.     { _uiToggle.value = isChecked; }
  31.  
  32.     public void SetChecked()
  33.     { SetValue(true); }
  34.  
  35.     public void SetUnchecked()
  36.     { SetValue(false); }
  37.  
  38.     public void ToggleState()
  39.     { _uiToggle.value = !_uiToggle.value; }
  40. }
  41.  

FreyjaToggleEditor.cs: located in an \Editor folder
  1. using UnityEngine;
  2. using UnityEditor;
  3.  
  4. [CustomEditor(typeof(FreyjaToggle))]
  5. public class FreyjaToggleEditor : Editor
  6. {
  7.     public override void OnInspectorGUI()
  8.     {
  9.         base.OnInspectorGUI();
  10.  
  11.         FreyjaToggle ft = target as FreyjaToggle;
  12.  
  13.         NGUIEditorTools.DrawEvents("On Toggle True", ft, ft.onToggleTrue);
  14.         NGUIEditorTools.DrawEvents("On Toggle False", ft, ft.onToggleFalse);
  15.     }
  16. }
  17.  

I hope this helps somebody!!   ;D

6
NGUI 3 Support / [Solved] Handles not working
« on: August 24, 2014, 07:29:22 PM »
I can't seem to get the handles to work any more. 

Weird behavior:
  • Restarts of Unity do not affect this.  Nor do scene changes.
  • I can have the handles show up on UILabel GOs, but only if they are clicked twice.
  • Clicking any other NGUI GO does not even select it in the editor window.  They can only be selected via the hierarchy.
  • No errors, warnings or log entries are showing.
  • *Edit: Move (W) tool is selected.

Not sure what else might be relevant.  Ask and I'll answer.

Anybody else have this happening?

*Edit to add move tool comment.

7
NGUI 3 Support / Perspective Camera and UIDraggablePanel goofiness
« on: September 16, 2012, 08:47:30 PM »
I'm using NGUI in perspective mode and have modeled my scrolling panels off of Example 7 - Scroll View (Panel).

When working this way, the draggable panel will not appear properly so you have to "float" it many units in front of the window panel (more than the described -.1f or -1f that makes sense).  What happens is the draggable panel, when it's moving, will think it's behind the window when you are near the beginning or end of the scrolling extent.  Once movement stops the panel will pop to the desired front of the window.

This is a drawing problem. The actual positions of the items do not change.

You can reproduce this easily:

1. Open the Example 7 - Scroll View (Panel)
2. Change the Camera to perspective mode
3. Change the Window Root transform Z value to 600
4. Note that the UIPanel (Clipped View) will not be visible.  You will need to move the clipped view Z to about -7.8 for it to appear in edit mode.
5. Hit Play and use mouse wheel to scroll.  The panel will blink out while moving and appear again when movement stops.

If you pull the panel forward to about -100, you will be able to see that the window is in front of the panel while moving.  You will also see that when you are in the middle of your panel, the effect is lessened (the panel stays visible or less sensitive to movement).  When the scroll position is close to either end, the effect is much greater.

Any idea what's going on here?

8
NGUI 3 Support / UITable: Cell Pivot
« on: September 03, 2012, 09:14:07 PM »
How about a Cell Pivot property on UITable that would position the widgets within each table cell?

9
NGUI 3 Support / UIInput: Colored Caret
« on: September 03, 2012, 08:57:30 PM »
I'd love to make my caret "[ff0000]|[-]".  Setting this now just adds the text to the label.  How about blinking, too?

And what's the status on "input within a string"?  I've seen it mentioned as "in progress" elsewhere on the board.

Thanks!!  Great work as always!
-John

Pages: [1]