-
Notifications
You must be signed in to change notification settings - Fork 0
/
BooleanProperty.cs
66 lines (56 loc) · 1.77 KB
/
BooleanProperty.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Cuboid (http://github.com/arjonagelhout/cuboid)
// Copyright (c) 2023 Arjo Nagelhout
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Cuboid.UI
{
[RequireComponent(typeof(Toggle))]
public class BooleanProperty : MonoBehaviour, IProperty<bool>
{
private Toggle _toggle;
public Property<bool> Property { get; private set; }
private void Awake()
{
_toggle = GetComponent<Toggle>();
Property = new BooleanPropertyInternal(_toggle);
}
private void OnDestroy()
{
Property.Dispose();
}
/// <summary>
///
/// </summary>
public class BooleanPropertyInternal : Property<bool>
{
private Toggle _toggle;
private IBinding<bool> _toggleBinding = new Binding<bool>();
public BooleanPropertyInternal(Toggle toggle) : base()
{
_toggle = toggle;
_toggle.SetBinding(_toggleBinding);
_toggle.OnSetValue = (value) => { _sourceBinding.Value = value; ConfirmValue(); };
}
protected override void OnValueChanged(bool value)
{
base.OnValueChanged(value);
_toggleBinding.Value = value;
}
protected override void CalculateIsEditingMultiple()
{
_toggle.IsEditingMultiple = IsEditingMultiple(_targetBindings);
}
protected override void SetBinding(IBinding<bool> binding)
{
base.SetBinding(binding);
if (binding != null)
{
_toggleBinding.Value = binding.Value;
}
}
}
}
}