<commit_before>﻿
// ^
// Experimental Reactive Properties!

// Soon.

// @matnesis
// 2015/12/12 02:40 PM


using UnityEngine;
using System.Collections;
using System;


/// <summary>
/// Reactive properties core.
/// </summary>
[Serializable]
public class ReactiveProp<T>
{
	private T _value = default(T);
	public T Value
	{
		set
		{
			// if (_value != null && _value.Equals(value))
			// return;

			_value = value;

			if (Suscribers != null)
				Suscribers(_value);
		}

		get { return _value; }
	}

	private Action<T> Suscribers;


	/// <summary>
	/// Suscribe an Action that will be called when .Value changes.
	/// </summary>
	public void Suscribe(Action<T> callback)
	{
		Suscribers += callback;
	}
}


// ^
// Specialized properties can be seeing on the Unity inspector.


[Serializable]
public class BoolReactiveProp : ReactiveProp<bool>
{
	[SerializeField]
	private bool boolValue;


	public BoolReactiveProp(bool initialValue)
	{
		Suscribe(x => boolValue = x);
		Value = initialValue;
	}


	public void SyncWithInspector()
	{
		if (Value != boolValue)
			Value = boolValue;
	}
}


[Serializable]
public class StringReactiveProp : ReactiveProp<string>
{
	[SerializeField]
	private string stringValue;


	public StringReactiveProp(string initialValue)
	{
		Suscribe(x => stringValue = x);
		Value = initialValue;
	}


	public void SyncWithInspector()
	{
		if (Value != stringValue)
			Value = stringValue;
	}
}


[Serializable]
public class IntReactiveProp : ReactiveProp<int>
{
	[SerializeField]
	private int intValue;


	public IntReactiveProp(int initialValue)
	{
		Suscribe(x => intValue = x);
		Value = initialValue;
	}

	public void SyncWithInspector()
	{
		if (Value != intValue)
			Value = intValue;
	}
}


[Serializable]
public class FloatReactiveProp : ReactiveProp<float>
{
	[SerializeField]
	private float floatValue;
<commit_msg>The Int in this version works great :D<commit_after>﻿
// ^
// Experimental Reactive Properties!

// Soon.

// @matnesis
// 2015/12/12 02:40 PM


using UnityEngine;
using System.Collections;
using System;


/// <summary>
/// Reactive properties core.
/// </summary>
[Serializable]
public class ReactiveProp<T>
{
	[SerializeField]
	private T _value = default(T);
	public T Value
	{
		get { return _value; }

		set
		{
			if (_value != null && _value.Equals(value))
				return;

			_value = value;

			CallSuscribers();
		}
	}

	private Action<T> Suscribers;
	private T _valueSent = default(T);


	/// <summary>
	/// Suscribe an Action that will be called when .Value changes.
	/// </summary>
	public void Suscribe(Action<T> callback)
	{
		Suscribers += callback;

		if (_valueSent != null)
			callback(Value);
	}

	public void CallSuscribers()
	{
		if (_valueSent != null && _valueSent.Equals(_value))
			return;

		_valueSent = _value;
		if (Suscribers != null)
			Suscribers(_value);
	}
}


// ^
// Specialized properties can be seeing on the Unity inspector.


[Serializable]
public class BoolReactiveProp : ReactiveProp<bool>
{
	[SerializeField]
	private bool boolValue;


	public BoolReactiveProp(bool initialValue)
	{
		Suscribe(x => boolValue = x);
		Value = initialValue;
	}


	public void SyncWithInspector()
	{
		if (Value != boolValue)
			Value = boolValue;
	}
}


[Serializable]
public class StringReactiveProp : ReactiveProp<string>
{
	[SerializeField]
	private string stringValue;


	public StringReactiveProp(string initialValue)
	{
		Suscribe(x => stringValue = x);
		Value = initialValue;
	}


	public void SyncWithInspector()
	{
		if (Value != stringValue)
			Value = stringValue;
	}
}


[Serializable]
public class IntReactiveProp : ReactiveProp<int>
{
	public IntReactiveProp(int initialValue)
	{
		Value = initialValue;
	}
}


[Serializable]
public class FloatReactiveProp : ReactiveProp<float>
{
	[SerializeField]
	private float floatValue;

{'fraction_non_alphanumeric': 0.11743119266055047, 'fraction_numerical': 0.006290956749672346, 'mean_word_length': 3.665036674816626, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2202654', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1276, 'n_words': 332}