Hello Guest

Author Topic: Inconsistent firing for UIItem  (Read 5586 times)

happy123

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Inconsistent firing for UIItem
« on: July 22, 2013, 09:29:58 am »
I am having trouble with UIItem and am wondering where the problem originates.   I have a screen with multiple objects that are the same.  They are buttons that allow users to select a level to play.  I found that some of these buttons doesn't respond to being clicked or when clicked fires multiple times.  Below is the script attached to the game object. 

The other components I have attached are tk2dSprite, tk2dButton, tk2dUIItem, and Pool Object (prefactory - > http://www.booncotter.com/unity-prefactory-a-better-pool-manager/).  I am using the tk2dUIManager and tk2dCamera as well.

Is there any reason why this is happening?


using UnityEngine;
using System.Collections;

public class PageItem : MonoBehaviour {
   public GameObject system;
   public tk2dUIItem button;
   int level, index;
   
   void Awake()
   {
      string[] nameArray = name.Split(' ');
      level = int.Parse(nameArray[1]);
      index = int.Parse(nameArray[3]);
   
      system = transform.root.gameObject;
            
      renderer.enabled = true;
   }
   
   void Start()
   {   
      setTransform();   
   }
   
   private void setTransform()
   {
      float posX = 1f / ((float)PageInfo.itemsPerRow + 1), posY = 1f/ ((float)PageInfo.itemsPerColumn + 1);
      
      int row = Mathf.CeilToInt((index + 1)/ (float)PageInfo.itemsPerRow);
      int column = index + 1 - ((row - 1) * PageInfo.itemsPerRow);
      
      transform.localPosition = new Vector3((column * posX) - 0.5f, 0.5f - (row * posY), -1f);   
      transform.localScale = Vector3.one;
   }
   
   // 2Dtoolkit
   void OnEnable()
   {
      button.OnClick += pickTeam;
   }
   
   private void pickTeam()
   {
      system.SendMessage("pickTeam", level);
   }
}

gary-unikronsoftware

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 74
    • View Profile
Re: Inconsistent firing for UIItem
« Reply #1 on: July 22, 2013, 10:41:48 am »
Hi,

If you are using an OnEnable() function on your buttons, you should also have a corresponding OnDisable(), i.e.

void OnDisable()
{
     button.OnClick -= pickTeam;
}

Try that and see if it fixes some of your issues.

happy123

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Inconsistent firing for UIItem
« Reply #2 on: July 22, 2013, 12:32:47 pm »
Hi,

I am not seeing any difference. 

- Lap

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Inconsistent firing for UIItem
« Reply #3 on: July 22, 2013, 12:57:31 pm »
Does it work OK if you Instantiate/Destroy rather than pooling?

happy123

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Inconsistent firing for UIItem
« Reply #4 on: July 22, 2013, 01:34:03 pm »
Hi,

Its the same.  I tried using UIItem for tiles on my game board as well and they aren't responding either.

Update:
I found the problem.  Its the Raycast Layer Mask in the UI Manager.  Instead setting it to "Everything",  I need to specify layers to raycast to.  Otherwise, it doesn't always respond.
« Last Edit: July 22, 2013, 01:48:47 pm by happy123 »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Inconsistent firing for UIItem
« Reply #5 on: July 22, 2013, 01:49:30 pm »
If it doesn't always respond, it usually means something else could be blocking it in world space?

happy123

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Inconsistent firing for UIItem
« Reply #6 on: July 22, 2013, 02:00:19 pm »
I need to look into it.  Right now my screen at stacked on top of each other and I .setActive(false) to screen I don't use.  That might be causing the problem.  On the level picking screen there's only: 1) the background --> 2) the page container --> 3) the level buttons.  I will post an update once I figure it out.