alors le truc c'est en gros de pouvoir referencer un scriptable object dans un monobehaviour , et de faire savoir aux autre qui reference ce meme scriptable object que il a ete modifier.
scenario simple , vous avez un scriptable object qui gere une seule valeure ( int, bool etc..)
un example de scriptable object
Code : Tout sélectionner
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
[CreateAssetMenu(fileName = "NewIntAttribute", menuName = "CustomSO/Attribute/IntAttribute")]
public class IntAttribute : ScriptableObject
{
public int Value;
[Header("Value that will set on calling reset method")]
public int InitialValue;
public void ResetToInitialValue()
{
Value = InitialValue;
}
public UnityAction OnValueChanged;
public void NotifyValueChanged()
{
OnValueChanged?.Invoke();
}
}
la variable Value sera certainememt modifier durant le jeu et , vous voulez le signifier au autre gameobject qui ont besoin de cette valeur.
Dans le script qui va utiliser cette valeure vous pouvez faire ca :
Code : Tout sélectionner
public IntAttribute IntegerUpdatable;
public bool NotifyPropertyChange = true;
public string Label = "Value";
private Text m_Text;
private void Start()
{
m_Text = GetComponent<Text>();
if (IntegerUpdatable != null && NotifyPropertyChange)
{
IntegerUpdatable.OnValueChanged = UpdateText;
}
}
public void UpdateText()
{
m_Text.text = Label +" "+ IntegerUpdatable.Value.ToString();
}
Code : Tout sélectionner
public IntAttribute UpdatableLiveCount;
public void Increase()
{
UpdatableLiveCount.Value += 1;
UpdatableLiveCount.NotifyValueChanged();
}
avantage pas de reference direct dans une scene, si vous voulez modifier la valeur, vous le faite depuis le scriptable objet.
bref , bon je sais je suis pas pedagogue pour 2 rond haha , si question il y a , question vous pouvez poser