Пример #1
0
        /// <summary>
        /// Tries to apply the given binding to the transform (parenting it with the corresponding Tracked PCF if specified and setting its local position, rotation and scale).
        /// Returns true if applied succesfully.
        /// </summary>
        private bool TryApplyBinding(MLULandscapeBinding binding)
        {
            if (!binding.IsValid)
            {
                return(false);
            }

            BindingInfo bindingInfo;

            // try to retrieve binding information (at least one current PCF must be binded to successfully restore the object binding)
            if (binding.TryGetBindingInfo(out bindingInfo))
            {
                // only apply binding if its actually different from current one
                if (bindingInfo != CurrentBindingInfo)
                {
                    Transform currentParent = transform.parent;
                    // apply binding transformation
                    transform.parent        = bindingInfo.trackedPCF.transform;
                    transform.localPosition = bindingInfo.binding.Position;
                    transform.localRotation = bindingInfo.binding.Rotation;
                    transform.localScale    = bindingInfo.binding.Scale;
                    // restore previus parent if not parenting with tracked PCF is desired
                    if (!parentToBindedPCF)
                    {
                        transform.parent = currentParent;
                    }

                    CurrentBindingInfo = bindingInfo;        // only succesfully applied bindings are saved
                    transformStatus.RegisterState();
                    isRestoring = false;                     // we are for sure not restoring any more if we succesfully apply a binding
                    if (OnBindingStateChanged != null)
                    {
                        OnBindingStateChanged(this);
                    }
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }