/// <summary> /// Tries to restore the given binding (It tries once and returns true if succeeded). If no binding is provided it will try to retrieve it from the current binding library. /// The binding may be a valid binding but fail to restore the transform if the current landscape is not recognized, in that case false will be returned. /// </summary> public bool TryRestoreOnce(MLULandscapeBinding?tryBinding = null) { MLULandscapeBinding binding = tryBinding ?? default(MLULandscapeBinding); // either use the given binding if its valid or try to retrieve it from the binding library if (binding.IsValid || (BindingLibrary.TryGetLandscapeBinding(UniqueID, out binding) && binding.IsValid)) { // if a saved binding was found try to apply it on the object transform if (TryApplyBinding(binding)) { BindingInfo bindingInfo = CurrentBindingInfo ?? default(BindingInfo); Debug.Log(LogHeader + "Binding restored succesfully! Binded to PCF: " + bindingInfo.trackedPCF.PCF.CFUID); if (OnRestored != null) { OnRestored(this); } return(true); } else { Debug.Log(LogHeader + "Restore try failed! No binded PCFs were found on current landscape."); } } else { Debug.Log(LogHeader + "Restore try failed! binding data is not valid."); } return(false); }
/// <summary> /// If the object is binded it will save the binding to the currently used library. /// </summary> public void SaveBindingToLibrary() { if (IsBinded) { BindingInfo bindingInfo = CurrentBindingInfo ?? default(BindingInfo); BindingLibrary.SetLandscapeBinding(UniqueID, bindingInfo.landscapeBinding); } }
/// <summary> /// It will start a coroutine that tries to restore the given binding or look for a saved one in the current binding library (if a custom binding is given /// but it's not valid it will look on the library). AutoBindAndSave functionallity will be paused during restoration process. If GameObject transform is changed or /// TryBind() is called the restoration coroutine will stop. /// </summary> public void TryRestore(MLULandscapeBinding?tryBinding = null) { MLULandscapeBinding binding = tryBinding ?? default(MLULandscapeBinding); if (restoringCoroutine != null) { StopCoroutine(restoringCoroutine); } isRestoring = false; // just in case it was true because of the stopped coroutine if (binding.IsValid || BindingLibrary.TryGetLandscapeBinding(UniqueID, out binding)) { restoringCoroutine = StartCoroutine(C_TryRestore(binding)); } else { Debug.Log(LogHeader + "Restore coroutine did not start. Couldn't find valid binding data for this object."); restoringCoroutine = null; } }
/// <summary> /// If currently used binding library contains a binding for this object it will be deleted (even if the object is not currently binded). /// Note that if the object is currently binded it will stay binded (only binding data from the library will be removed). /// </summary> public void DeleteBindingFromLibrary() { BindingLibrary.RemoveLandscapeBinding(UniqueID); }