Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- [System.Serializable]
- [AddComponentMenu("NGUI/NData/NguiLocalScaleBinding Binding")]
- public class NguiLocalScaleBinding : NguiBinding
- {
- private EZData.Property<Vector3> _property;
- private Vector3 _prevValue = new Vector3();
- private bool _ignoreChanges = false;
- private Vector3 _transformReceiver;
- public override void Awake()
- {
- base.Awake();
- _transformReceiver = gameObject.transform.localScale;
- }
- public override void UpdateBinding()
- {
- _property = null;
- var context = GetContext();
- if (context == null)
- {
- Debug.LogWarning("NguiLocalScaleBinding.UpdateBinding - context is null");
- return;
- }
- _property = context.FindProperty<Vector3>(Path, this);
- if (_property != null)
- {
- _property.OnChange += OnChange;
- }
- OnChange();
- }
- void Update()
- {
- if (_transformReceiver != null && _property != null)
- {
- if (_prevValue != _transformReceiver)
- {
- _prevValue = _transformReceiver;
- _ignoreChanges = true;
- _property.SetValue(_transformReceiver);
- _ignoreChanges = false;
- }
- }
- }
- public void OnChange()
- {
- if (_ignoreChanges)
- return;
- if (_property == null || _transformReceiver == null)
- return;
- _transformReceiver = _property.GetValue();
- gameObject.transform.localScale = _transformReceiver;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement