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 - Zyxil

Pages: 1 [2] 3
16
NGUI 3 Support / Re: Fun with EventDelegates
« on: September 05, 2015, 09:52:09 AM »
No love for the EventDelegate?   :(

17
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

18
For anybody that finds this later:

Instead of going through the hassle of creating a Coroutine, just use Invoke:

  1.     public void DragEnd()
  2.     { Invoke("SetFocus", 0.1f); }
  3.  
  4.     public void SetFocus()
  5.     { gameObject.GetComponent<UIInput>().isSelected = true; }
  6.  

19
NGUI 3 Support / Re: Handles not working
« on: August 27, 2014, 08:48:19 AM »
Thanks for the clarification. This has been driving me nuts.

I don't think NGUI works gracefully with this as when I was testing, one uibutton node reopened caused the whole hierarchy to enable.  So one NGUI element folded low in the hierarchy can disable all parent handles. It would make sense if there's a dependency there, but is quite confusing.

20
NGUI 3 Support / Re: Handles not working
« on: August 26, 2014, 07:30:42 PM »
I started unfolding everything in the inspector and things started working.

Why does this work this way?  It makes no sense.   :o

If it's an NGUI thing can we have this removed?  Folding the components keeps things neat and easy to read.


21
NGUI 3 Support / Re: Handles not working
« on: August 25, 2014, 08:07:04 PM »
Bump.  Any idea on what is happening here?

What can I do to troubleshoot?

22
NGUI 3 Support / Re: Handles not working
« on: August 24, 2014, 08:14:23 PM »
I'll hold off on upgrading to 4.6beta since you're on 4.5.2.

Also, maybe relevant. The prefab toolbar constantly loses its labels. Though it seems to have corrected them since upgrading to 3.7.1.  I stopped using the snapshotter on my prefabs because of this.  I'll try them again now that they seem to be working again.

23
NGUI 3 Support / Re: Handles not working
« on: August 24, 2014, 08:08:51 PM »
Oops.  Meant to put that in the original list.

  • All NGUI options are turned on.  I have turned off and then on each item with no result.  (Except for working features to turn off/on.

24
NGUI 3 Support / Re: Handles not working
« on: August 24, 2014, 08:01:06 PM »
I'm on Unity 4.5.2.  This must be it.  Upgrading to NGUI 3.7.1 just now didn't fix it.

I generally don't do beta software.  But for NGUI, I'll do it.   ;)

I'll report when upgraded.

25
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.

26
NGUI 3 Documentation / Re: UISlider
« on: August 16, 2014, 09:33:31 AM »
Ah, thanks for the clarification.  That make everything much cleaner.

27
NGUI 3 Documentation / Re: UISlider
« on: August 14, 2014, 08:12:24 PM »
Ahh, I found it.  I have some custom logic that sets the scale of the panel to 0,0 on start and tweens it into existence.  When the slider is initialized, it can't calculate the thumb position correctly.

Apologies for the bug suspicion, all of the other controls I tested worked fine with this logic.

28
NGUI 3 Documentation / Re: UISlider
« on: August 13, 2014, 10:22:18 PM »
In 3.6.9

There seems to be a bug where the UISlider Thumb position will have a y value *-1 what it should be on first display.  If the control's y value is 50, the Thumb y will be -50.  If control y is -100, Thumb y will be 100.

It will be fixed in the next ForceUpdate() or value change.

You can easily see this by placing the Control - Simple Progress Bar prefab on a panel.  Make sure its y value is not zero and play the scene.



Bottom progress bar is the NGUI prefab. Top one is my customized one with UI2DSprites.  They both show the same behavior.

29
NGUI 3 Support / Re: Perspective Camera and UIDraggablePanel goofiness
« on: September 19, 2012, 09:07:09 PM »
Success!

This solves the problem.

When copying the "Unlit/Transparent Colored (SoftClip)" shader, these steps need to happen:
- rename the shader to: "Unlit/Transparent Colored Overlay (SoftClip)"
- add "+1" to line 14, result: "Queue" = "Transparent+1"

30
NGUI 3 Support / Re: Perspective Camera and UIDraggablePanel goofiness
« on: September 18, 2012, 09:04:22 PM »
I did that.  I duplicated all of the fantasy assets and made sure they referenced each other properly (fantasy atlas duplicates.png).

I then switched fantasy atlas 1 (material) to different shaders:

Unlit Transparent Colored (original): No change, of course
Unlit Transparent Colored (alpha): No change(makes sense)
Unlit Transparent Colored (hard clip): No change(makes sense)
Unlit Transparent Colored (soft clip): No change (this one should work, I would think)
Unlit Transparent Colored Overlay: While drag in process, all items are visible (no clipping).  When no drag, clipping makes full items invisible, but there is no clip line clipping items on the border of the clip zone (improper clipping.png is Game window).  Note improper clipping 2.png showing the editor window. The left and right visible items cross the clipping zone borders.  I circled the items that disappeared once the drag operation finishes.

All of this can be recreated using the changes I've described in these posts.

Pages: 1 [2] 3