Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
Activar una función cuando se cambian los valores de la matriz

Estoy agregando un conjunto de valores de matriz a través de la ventana del inspector. Estoy tratando de lograr activar una función, cuando cambio los valores de mi matriz. Es decir, mi secuencia de comandos debe verificar si los nuevos valores no son iguales a los valores anteriores y luego llamar a esta función. No quiero usar Actualizar ya que requerirá más memoria y potencia de procesamiento, entonces, ¿cuál podría ser la alternativa?

 public class SetValues : MonoBehaviour { [Serializable] public struct SetValues { public float Position; public float Value; } public SetValues[] setValues; void Function_ValuesChanged() { Debug.Log("The Value is changed"); //Do Something } }
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Prueba MonoBehavior.OnValidate()

Ejemplo:

 public class SetValues : MonoBehaviour { [Serializable] public struct SetValues { public float Position; public float Value; } public SetValues[] setValues; void OnValidate() { Debug.Log("The Value is changed"); //Do Something } }
over 4 years ago · Santiago Trujillo Report

0

Si sucede algo en el juego y desea notificar a otros scripts, use eventos. Los eventos son ligeros y fáciles de implementar.

En la clase que contiene una matriz, cree una propiedad y cambie el valor de la matriz, solo desde la propiedad. Nunca interactúe directamente con el campo de matriz.

 // Create Event Arguments public class OnArrayValueChangedEventArgs : EventArgs { public float Position; public float Value; } // Crate Event public event EventHandler<OnArrayValueChangedEventArgs> OnArrayValueChanged; Array[] myArray; // Change Array value only from this property, so when you change value, event will be called public Array[] MyArray { get { return myArray; } set { myArray = value; OnArrayValueChangedEvent(this, new OnArrayValueChangedEventArgs() { Position = myArray.Position, Value = myArray.Value };} }

Desde la segunda clase, solo debe suscribirse a este evento y hacer las cosas. Llamaré a este evento desde mi clase GameManager Singleton.

 private void Awake() { GameManager.Instance.OnArrayValueChanged += Instance_OnArrayValueChanged; } private void Instance_OnArrayValueChanged(object sender, GameManager.OnArrayValueChangedEventArgs e) { // Do the thing }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!