private void SetScriptFromComponent(Component[] c) { if (c.Length > 0 && c[0] != null) { puzzleScript = (IActivate)c[0]; } }
// Update is called once per frame void Update() { // activationRay = new Ray (transform.position, transform.forward); RaycastHit hit; try{ if (Physics.Raycast(transform.position, transform.forward, out hit, ActivationDistance)) { if (hit.collider.GetComponent <IActivate> () != null) { IActivate active = hit.collider.GetComponent <IActivate> (); if (Input.GetKeyDown(KeyCode.F)) { active.Activate(this); } else { ActivationToolTipText.text = active.GetToolTip(); } } else { ActivationToolTipText.text = emptyString; } } else { ActivationToolTipText.text = emptyString; } } catch { //idc } }
public NullSourceContext(IDescribeMappableProperty sourceProperty, ICreateValueAssignment valueAssignments, IInvoke invoke, IActivate activate) { this.valueAssignments = valueAssignments; this.invoke = invoke; this.activate = activate; SourceType = sourceProperty.PropertyType; Source = null; }
public DefaultValueConverterContainer(IActivate activate) { this.activate = activate; /*always support null conversion*/ converters.Push(new NullConverter()); converters.Push(new ValueMustMatchDestinationTypeConverter(activate)); }
private void DeactivatePuzzle() { if (puzzleScript != null) { puzzleScript.Deactivate(); puzzleScript = null; puzzleActive = false; } }
/// <summary> /// WhenActivated allows you to register a Func to be called when a ViewModel is Activated. /// </summary> /// <param name="item">Object that supports activation.</param> /// <param name="block"> /// The method to be called when the corresponding ViewModel is activated. /// It returns a list of Disposables that will be cleaned up when the ViewModel is deactivated. /// </param> /// <returns>A Disposable that deactivates this registration.</returns> public static void WhenActivated(this IActivate item, Func <IEnumerable <IDisposable> > block) { if (item == null) { throw new ArgumentNullException(nameof(item)); } item.Activator.AddActivationBlock(block); }
private bool TryActivateScript(IActivate puzzleScript) { if (puzzleScript != null) { puzzleScript.Activate(); return(true); } return(false); }
public StandardMenuItem WithActivator(IActivate activator, bool inverse) { _canExecute = () => inverse ? !activator.IsActive : activator.IsActive; activator.Activated += (sender, args) => NotifyOfPropertyChange(() => CanExecute); var deactivator = activator as IDeactivate; if (deactivator != null) { deactivator.Deactivated += (sender, args) => NotifyOfPropertyChange(() => CanExecute); } return(this); }
static void AttachViewReadyOnActivated(IActivate activatable, object nonGeneratedView) { var viewReference = new WeakReference(nonGeneratedView); EventHandler<ActivationEventArgs> handler = null; handler = (s, e) => { ((IActivate)s).Activated -= handler; var view = viewReference.Target; if (view != null) { PlatformProvider.Current.ExecuteOnLayoutUpdated(view, ((ViewAware)s).OnViewReady); } }; activatable.Activated += handler; }
/// <summary> /// WhenInitialized allows you to register a Func to be called when a ViewModel is Initialized. /// </summary> /// <param name="item">Object that supports activation.</param> /// <param name="block"> /// The method to be called when the corresponding ViewModel is initialized. The Action parameter (usually called 'd') allows /// you to collate all the disposables to be cleaned up when the ViewModel is disposed. /// </param> /// <returns>A Disposable that deactivates this registration.</returns> public static void WhenInitialized(this IActivate item, Action <CompositeDisposable> block) { if (item == null) { throw new ArgumentNullException(nameof(item)); } item.Activator.AddInitializationBlock(() => { var d = new CompositeDisposable(); block(d); return(new[] { d }); }); }
/// <summary> /// WhenInitialized allows you to register a Func to be called when a ViewModel is Initialized. /// </summary> /// <param name="item">Object that supports activation.</param> /// <param name="block"> /// The method to be called when the corresponding ViewModel is initialized. The Action parameter (usually called 'd') allows /// you to register Disposables to be cleaned up when the ViewModel is disposed (i.e. "d(someObservable.Subscribe());"). /// </param> /// <returns>A Disposable that deactivates this registration.</returns> public static void WhenInitialized(this IActivate item, Action <Action <IDisposable> > block) { if (item == null) { throw new ArgumentNullException(nameof(item)); } item.Activator.AddInitializationBlock(() => { var ret = new List <IDisposable>(); block(ret.Add); return(ret); }); }
public void WhenActivated_ItSetsTheLocationText() { gpsLocatorMock.Setup(service => service.GetCurrentLocationAsync()).ReturnsAsync(new GpsLocation(1, 2)); gpsLocatorMock.Setup(service => service.GetCivilAddressAsync()).ReturnsAsync("Cluj Napoca"); IActivate activateableVm = viewModel as IActivate; Assert.IsTrue(viewModel.LocationText.Contains("please wait")); activateableVm.Activate(); Assert.AreEqual("Cluj Napoca", viewModel.LocationText); }
static void AttachViewReadyOnActivated(IActivate activatable, object nonGeneratedView) { var viewReference = new WeakReference(nonGeneratedView); EventHandler <ActivationEventArgs> handler = null; handler = (s, e) => { ((IActivate)s).Activated -= handler; var view = viewReference.Target; if (view != null) { PlatformProvider.Current.ExecuteOnLayoutUpdated(view, ((ReactiveViewAware)s).OnViewReady); } }; activatable.Activated += handler; }
public EntryFieldViewModel(IActivate parent, IEventAggregator events) { if (parent == null) { throw new ArgumentNullException("parent"); } if (events == null) { throw new ArgumentNullException("events"); } _parent = parent; _events = events; _events.Subscribe(this); }
private static void AttachViewReadyOnActivated(IActivate activate, object nonGeneratedView) { WeakReference viewReference = new WeakReference(nonGeneratedView); EventHandler <ActivationEventArgs> handler = null; handler = delegate(object s, ActivationEventArgs e) { ((IActivate)s).Activated -= handler; object target = viewReference.Target; if (target != null) { PlatformProvider.Current.ExecuteOnLayoutUpdated(target, o => (s as QueryViewModelBase <TConfig>).OnViewReady(o)); } }; activate.Activated += handler; }
///<summary> /// Activates a child whenever the specified parent is activated. /// Use with caution, it is better to use explicit <see cref="IConductor"/> implementations. ///</summary> ///<param name="child">The child to (de)activate.</param> ///<param name="parent">The parent whose activation triggers the child's activation.</param> public static void ActivateWith(this IActivate child, IActivate parent) { if (parent == null) { return; } // Note on the disposal, in a hierarchical composition we'll always want to close the child(ren) first. // Eg in a multilevel tree the leaf nodes will be closed first, working our way back to the root. child.Activator.AddDisposable( parent.WhenAnyValue(x => x.IsActive) .Where(isActive => isActive) .Select(_ => child.ActivateAsync(CancellationToken.None)) // Tasks are executed eagerly, fire and forget .Subscribe() ); }
///<summary> /// Activates a child whenever the specified parent is activated. ///</summary> ///<param name="child">The child to activate.</param> ///<param name="parent">The parent whose activation triggers the child's activation.</param> public static void ActivateWith(this IActivate child, IActivate parent) { var childReference = new WeakReference(child); EventHandler <ActivationEventArgs> handler = null; handler = (s, e) => { var activatable = (IActivate)childReference.Target; if (activatable == null) { ((IActivate)s).Activated -= handler; } else { activatable.Activate(); } }; parent.Activated += handler; }
///<summary> /// Activates a child whenever the specified parent is activated. ///</summary> ///<param name="child">The child to activate.</param> ///<param name="parent">The parent whose activation triggers the child's activation.</param> public static void ActivateWith(this IActivate child, IActivate parent) { var childReference = new WeakReference(child); void OnParentActivated(object s, ActivationEventArgs e) { var activatable = (IActivate)childReference.Target; if (activatable == null) { ((IActivate)s).Activated -= OnParentActivated; } else { activatable.ActivateAsync(CancellationToken.None); } } parent.Activated += OnParentActivated; }
void IViewAware.AttachView(object view, object context = null) { this.Views[context ?? ViewAware.DefaultContext] = view; object firstNonGeneratedView = PlatformProvider.Current.GetFirstNonGeneratedView(view); PlatformProvider.Current.ExecuteOnFirstLoad(firstNonGeneratedView, new Action <object>(this.OnViewLoaded)); this.OnViewAttached(firstNonGeneratedView, context); this.ViewAttached(this, new ViewAttachedEventArgs { View = firstNonGeneratedView, Context = context }); IActivate activate = this as IActivate; if (activate == null || activate.IsActive) { PlatformProvider.Current.ExecuteOnLayoutUpdated(firstNonGeneratedView, new Action <object>(this.OnViewReady)); return; } AttachViewReadyOnActivated(activate, firstNonGeneratedView); }
///<summary> /// Activates a child whenever the specified parent is activated. ///</summary> ///<param name="child">The child to activate.</param> ///<param name="parent">The parent whose activation triggers the child's activation.</param> public static void ActivateWith(this IActivate child, IActivate parent) { EventHandler <ActivationEventArgs> handler = (s, e) => child.Activate(); parent.Activated += handler; var deactivator = parent as IDeactivate; if (deactivator != null) { EventHandler <DeactivationEventArgs> handler2 = null; handler2 = (s, e) => { if (e.WasClosed) { parent.Activated -= handler; deactivator.Deactivated -= handler2; } }; deactivator.Deactivated += handler2; } }
void IViewAware.AttachView(object view, object context) { Views[context ?? DefaultContext] = view; object nonGeneratedView = PlatformProvider.Current.GetFirstNonGeneratedView(view); PlatformProvider.Current.ExecuteOnFirstLoad(nonGeneratedView, OnViewLoaded); OnViewAttached(nonGeneratedView, context); ViewAttached(this, new ViewAttachedEventArgs { View = nonGeneratedView, Context = context }); IActivate activatable = this as IActivate; if (activatable == null || activatable.IsActive) { PlatformProvider.Current.ExecuteOnLayoutUpdated(nonGeneratedView, OnViewReady); } else { AttachViewReadyOnActivated(activatable, nonGeneratedView); } }
/// <summary> /// Activates this instance. /// </summary> /// <param name="activate">The instance to activate</param> /// <returns>A task that represents the asynchronous operation.</returns> public static Task ActivateAsync(this IActivate activate) => activate.ActivateAsync(default);
public StandardMenuItem WithActivator(IActivate activator) { return WithActivator(activator, false); }
public DefaultResolverFactory(IActivate activate) { this.activate = activate; }
public StandardMenuItem WithActivator(IActivate activator, bool inverse) { _canExecute = () => inverse ? !activator.IsActive : activator.IsActive; activator.Activated += (sender, args) => NotifyOfPropertyChange(() => CanExecute); var deactivator = activator as IDeactivate; if(deactivator != null) deactivator.Deactivated += (sender, args) => NotifyOfPropertyChange(() => CanExecute); return this; }
public BinderFactory(IActivate activate) { this.activate = activate; Logger = new NullLogFactory(); }
/// <summary> /// Used to avoid race conditions during activation. /// When the item is not active, or the WhenActivated scope is not yet completed, the returned observable will tick the provided fallback value. /// After activation the source observable will be used. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="item"></param> /// <param name="source"></param> /// <param name="fallbackValue"></param> /// <returns>A disposable.</returns> public static IObservable <T> WhenActivatedSwitch <T>(this IActivate item, IObservable <T> source, T fallbackValue) => item.Activator.HasActivated .Select(isActivated => isActivated ? source : Observable.Return(fallbackValue)) .Switch();
public DefaultContextualizer(IActivate activate, ICreateValueAssignment valueAssignments, IInvoke invoke) { this.activate = activate; this.valueAssignments = valueAssignments; this.invoke = invoke; }
public StandardMenuItem WithActivator(IActivate activator) { return(WithActivator(activator, false)); }
public ListResolver(IDescribeMappableProperty sourceProperty, ICreateExecutableMapping executor, IActivate activate) { this.sourceProperty = sourceProperty; this.executor = executor; this.activate = activate; }
public ValueMustMatchDestinationTypeConverter(IActivate activate) { this.activate = activate; }
/// <summary> /// Used to avoid race conditions during initialization. /// Before the WhenInitialized scope is completed, the returned observable will tick the provided initial value. /// After initialization the source observable will be used. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="item"></param> /// <param name="source"></param> /// <param name="initialValue"></param> /// <returns>A disposable.</returns> public static IObservable <T> WhenInitializedSwitch <T>(this IActivate item, IObservable <T> source, T initialValue) => item.Activator.HasInitialized .Select(isInitialized => isInitialized ? source : Observable.Return(initialValue)) .Switch();
void Awake() { target = targetGO.GetComponent <IActivate> (); }