Hi!
I’ve created my own selectable with an UnityEvent onValueChange. I programmatically invoke it with parameter but it seems that listeners receive parameter set in inspector rather than the one sent in Invoke call. Is there a way to set which argument should be passed? Or may I somehow get into that value from inspector to change it on the fly?
This is part of my setup:
Functions SetRightLaneCount(int count) are fired with count set to 0 or whatever is set in that field in inspector.
But I fire the event manually:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
using UnityEngine.Events;
public class IncrementalInput : Selectable
{
[SerializeField]
private Text text;
[SerializeField]
private Button PlusButton;
[SerializeField]
private Button MinusButton;
public int MinValue;
public int MaxValue;
private int currentValue = 1;
public int CurrentValue
{
get { return currentValue; }
set { currentValue = value;
if( CurrentValue == MaxValue )
PlusButton.interactable = false;
else if( CurrentValue == MinValue )
MinusButton.interactable = false;
else {
MinusButton.interactable = true;
PlusButton.interactable = true;
}
onValueChanged.Invoke(currentValue); //Event is fired
text.text = value.ToString();
}
}
[System.Serializable]
public class OnValueChanged : UnityEvent<int> { };
public OnValueChanged onValueChanged;
public void Add()
{
if( CurrentValue < MaxValue )
CurrentValue++;
}
public void Substract()
{
if( CurrentValue > MinValue )
CurrentValue--;
}
}
So everything works fine: currentValue changes, events are fired, but don’t use correct variable as an argument.