예제 #1
0
 private bool StartAnimatingPropertyVector3Int(object component, string strProp, Vector3Int src, Vector3Int targ, float durTime,
                                               PropertyUpdater <T> .GetValAtUpdate getValAtUpdate,
                                               List <UnityAction> callbacksStart,
                                               List <UnityAction> callbacksPause,
                                               List <UnityAction> callbacksResume,
                                               List <UnityAction> callbacksEnd)
 {
     return(StartAnimatingPeoperty <Vector3Int>(updatersVector3Int, component, strProp, src, targ, durTime, PropertyUpdater <Vector3Int> .GetValAtUpdateVector3Int, callbacksStart, callbacksPause, callbacksResume, callbacksEnd));
 }
예제 #2
0
        /// <summary>
        /// Refresh this cached object with a custom delegate.
        /// </summary>
        /// <param name="providedDelegate"></param>
        public T Refresh(PropertyUpdater <T> providedDelegate)
        {
            if (isStale)
            {
                updateDelegate = updateDelegate ?? providedDelegate;
                Refresh();
            }

            return(value);
        }
예제 #3
0
        /// <summary>
        /// Create a new cached property.
        /// </summary>
        /// <param name="updateDelegate">The delegate method which will perform future updates to this property.</param>
        /// <param name="refreshInterval">How often we should refresh this property.</param>
        /// <param name="backgroundRefresh">Whether we should continuously refresh this property in the background (on a background thread)</param>
        public CachedProperty(PropertyUpdater <T> updateDelegate, int refreshInterval = 1000, bool backgroundRefresh = false)
        {
            RefreshInterval     = refreshInterval;
            this.updateDelegate = updateDelegate;

            Refresh();

            if (backgroundRefresh)
            {
                scheduledDelegate = GameBase.BackgroundScheduler.AddDelayed(Refresh, refreshInterval, true);
            }
        }
예제 #4
0
        protected void UpdateProperty <TValue, TEntity>(TEntity entity, Func <Expression <Func <TEntity, TValue> > > expressionGetter, TValue newValue)
        {
            var c = PropertyUpdater <TEntity, TValue> .GetPropertyUpdater(expressionGetter);

            var oldValue = c.UpdateValue(entity, newValue);

            if (!Equals(oldValue, newValue))
            {
                PropertyChanging?.Invoke(ModelChangedEventArgs.PropertyChange(this, c.Name, oldValue, newValue));
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(c.Name));
            }
        }
예제 #5
0
    private bool StartAnimatingPeoperty <T>(List <PropertyUpdater <T> > updaters, object component, string strProp, T src, T targ, float durTime, PropertyUpdater <T> .GetValAtUpdate getValAtUpdate)
    {
        if (FindAnimatingProperty <T>(updaters, component, strProp) != null)
        {
            Debug.LogWarning("Property is already in animating.");
            return(false);
        }
        PropertyWrapper <T> wrapper = new PropertyWrapper <T>(component, strProp);
        PropertyUpdater <T> updater = new PropertyUpdater <T>(wrapper, src, targ, durTime, getValAtUpdate);

        updaters.Add(updater);
        updater.Start();
        return(true);
    }
예제 #6
0
    private bool EndAnimatingProperty <T>(List <PropertyUpdater <T> > updaters, object component, string strProp, EndPropertyState endState)
    {
        PropertyUpdater <T> updater = FindAnimatingProperty <T>(updaters, component, strProp);

        if (updater == null)
        {
            return(false);
        }
        switch (endState)
        {
        case EndPropertyState.Src:
            updater.Pause();
            updater.SetStartVal();
            break;

        case EndPropertyState.Targ:
            updater.End();
            break;

        case EndPropertyState.Keep:
            updater.Pause();
            break;
        }
        updaters.Remove(updater);

        UnityEvent             uevent;
        Tuple <object, string> key = new Tuple <object, string>(component, strProp);

        // Remove pausing event
        eventsDicPause.Remove(key);
        // Remove resuming event
        eventsDicResume.Remove(key);
        // Invoke endineventsDicPauseg event
        uevent = FindPropertyEvent <T>(eventsDicEnd, component, strProp);
        if (uevent != null)
        {
            uevent.Invoke();
        }
        // Remove resuming event
        eventsDicEnd.Remove(key);

        return(true);
    }
예제 #7
0
    private bool ResumeAnimatingProperty <T>(List <PropertyUpdater <T> > updaters, object component, string strProp)
    {
        PropertyUpdater <T> updater = FindAnimatingProperty <T>(updaters, component, strProp);

        if (updater == null)
        {
            return(false);
        }
        updater.Resume();

        // Invoke resuming event
        UnityEvent uevent = FindPropertyEvent <T>(eventsDicResume, component, strProp);

        if (uevent != null)
        {
            uevent.Invoke();
        }
        return(true);
    }
예제 #8
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void ReadLocalProperty ()
		{
			PropertyUpdater data = new PropertyUpdater ();
			Rectangle rectangle = new Rectangle { Opacity = 0f };
			Binding binding = new Binding {
				Path = new PropertyPath ("Opacity"),
				Mode = BindingMode.OneWay,
				Source = data
			};
			Assert.AreEqual (0.0, (double) rectangle.ReadLocalValue (Rectangle.OpacityProperty), "#1");
			
			rectangle.SetBinding (Rectangle.OpacityProperty, binding);
			
			Assert.IsTrue(rectangle.ReadLocalValue (Rectangle.OpacityProperty) is BindingExpressionBase, "#2");
		}
예제 #9
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void TestOneWayBinding3 ()
		{
			PropertyUpdater data = new PropertyUpdater { Opacity = 0.5f };
			Rectangle rectangle = new Rectangle { Opacity = 1f , DataContext = data };
			Binding binding = new Binding
			{
				Path = new PropertyPath ("Opacity"),
				Mode = BindingMode.OneWay,
			};

			rectangle.SetBinding (Rectangle.OpacityProperty, binding);
			rectangle.DataContext = null;
			data.Opacity = 0.5f;
			Assert.AreEqual (1.0f, rectangle.Opacity, "#1");
			rectangle.DataContext = data;
			Assert.AreEqual (0.5f, rectangle.Opacity, "#2");
		}
예제 #10
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void TestOneWayBinding2 ()
		{
			PropertyUpdater data = new PropertyUpdater { Opacity = 0.5f };
			Rectangle rectangle = new Rectangle { Opacity = 0f };
			Binding binding = new Binding {
				Path = new PropertyPath ("Opacity"),
				Mode = BindingMode.OneWay,
				Source = data
			};

			rectangle.SetBinding (Rectangle.OpacityProperty, binding);
			Assert.AreEqual (data.Opacity, rectangle.Opacity);
			data.Opacity = 0.0f;
			Assert.AreEqual (data.Opacity, rectangle.Opacity);
		}
예제 #11
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void TestTwoWayBinding5 ()
		{
			PropertyUpdater data = new PropertyUpdater { Opacity = 0.5f };
			data.Reset ();
			TextBlock block = new TextBlock { Text = "Ted" };
			block.SetBinding (TextBlock.TextProperty, new Binding {
				Path = new PropertyPath ("Opacity"),
				Source = data,
				Mode = BindingMode.TwoWay
			});
			Assert.AreEqual ("0.5", block.Text, "#1");
			Assert.IsTrue (data.Get, "#a");
			Assert.IsFalse (data.Set, "#b");
			data.Reset ();

			block.Text = "1";
			Assert.AreEqual (1, data.Opacity, "#2");
			Assert.IsTrue (data.Get, "#c");
			Assert.IsTrue (data.Set, "#d");
			data.Reset ();

			block.Text = "1";
			Assert.IsFalse (data.Get, "#e");
			Assert.IsFalse (data.Set, "#f");
		}
예제 #12
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void TestTwoWayBinding4 ()
		{
			PropertyUpdater data = new PropertyUpdater { Opacity = 0.5f };
			TextBlock block = new TextBlock { Text = "Ted" };
			block.SetBinding (TextBlock.TextProperty, new Binding {
				Path = new PropertyPath ("Opacity"),
				Source = data,
				Mode = BindingMode.TwoWay
			});
			Assert.AreEqual ("0.5", block.Text, "#1");
			block.Text = "1";
			Assert.AreEqual (1, data.Opacity, "#2");
			block.Text = "100";
			Assert.AreEqual (100, data.Opacity, "#3");
			block.Text = "";
			Assert.AreEqual (100, data.Opacity, "#4");
		}
예제 #13
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void TestTwoWayBinding3 ()
		{
			PropertyUpdater data = new PropertyUpdater { Opacity = 0.5f };
			Rectangle r = new Rectangle { Opacity = 0 };
			r.SetBinding (Rectangle.OpacityProperty, new Binding {
				Path = new PropertyPath ("OpacityASDF"),
				Source = data,
				Mode = BindingMode.TwoWay
			});
			Assert.AreEqual (1, r.Opacity, "#1");
			Assert.AreEqual (0.5, data.Opacity, "#2");
			data.Opacity = 0;
			Assert.AreEqual (1, r.Opacity, "#3");
			r.Opacity = 0.5f;
			Assert.AreEqual (0, data.Opacity);
		}
예제 #14
0
 public static PropertyUpdater <T> Update <T>(T objectToUpdate)
 {
     return(PropertyUpdater <T> .Update(objectToUpdate));
 }
예제 #15
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void DataContext_ChangeParentOneWay ()
		{
			Canvas canvas = new Canvas ();
			PropertyUpdater updater = new PropertyUpdater { Opacity = 0 };
			Binding binding = new Binding ("Opacity");
			Rectangle rectangle = new Rectangle { Name = "TED" };

			canvas.DataContext = updater;
			canvas.Children.Add (rectangle);
			rectangle.SetBinding (Rectangle.OpacityProperty, binding);

			Assert.AreSame (rectangle.DataContext, canvas.DataContext, "#1");
			updater.Opacity = 0;
			Assert.AreEqual (0, rectangle.Opacity, "#2");

			canvas.DataContext = null;
			Assert.AreEqual (1, rectangle.Opacity, "#3");
			updater.Opacity = 0.5f;
			Assert.AreEqual (1, rectangle.Opacity, "#4");
		}
예제 #16
0
파일: BindingTest.cs 프로젝트: shana/moon
			public ContainsPropertyUpdater ()
			{
				Updater = new PropertyUpdater ();
			}
예제 #17
0
    private bool StartAnimatingPeoperty <T>(List <PropertyUpdater <T> > updaters, object component, string strProp, T src, T targ, float durTime,
                                            PropertyUpdater <T> .GetValAtUpdate getValAtUpdate,
                                            List <UnityAction> callbacksStart,
                                            List <UnityAction> callbacksPause,
                                            List <UnityAction> callbacksResume,
                                            List <UnityAction> callbacksEnd)
    {
        if (!StartAnimatingPeoperty <T>(updaters, component, strProp, src, targ, durTime, getValAtUpdate))
        {
            return(false);
        }

        Tuple <object, string> key = new Tuple <object, string>(component, strProp);
        UnityEvent             uevent;

        //if (callbacksStart!=null && callbacksStart.Count > 0)
        //{
        //    uevent = new UnityEvent();
        //    foreach (var callback in callbacksStart)
        //    {
        //        uevent.AddListener(callback);
        //    }
        //    eventsDicStart.Add(key, uevent);
        //}
        if (callbacksPause != null && callbacksPause.Count > 0)
        {
            uevent = new UnityEvent();
            foreach (var callback in callbacksPause)
            {
                uevent.AddListener(callback);
            }
            eventsDicPause.Add(key, uevent);
        }
        if (callbacksResume != null && callbacksResume.Count > 0)
        {
            uevent = new UnityEvent();
            foreach (var callback in callbacksResume)
            {
                uevent.AddListener(callback);
            }
            eventsDicResume.Add(key, uevent);
        }
        if (callbacksEnd != null && callbacksEnd.Count > 0)
        {
            uevent = new UnityEvent();
            foreach (var callback in callbacksEnd)
            {
                uevent.AddListener(callback);
            }
            eventsDicEnd.Add(key, uevent);
        }

        UnityEvent ueventStart = new UnityEvent();

        foreach (var callback in callbacksStart)
        {
            ueventStart.AddListener(callback);
        }
        ueventStart.Invoke();

        return(true);
    }
예제 #18
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void BindToText2 ()
		{
			PropertyUpdater data = new PropertyUpdater { Opacity = 0 };
			Binding binding = new Binding ("Opacity");
			
			TextBox box = new TextBox ();
			box.DataContext = data;
			box.SetBinding (TextBox.TextProperty, binding);

			data.Opacity = 0.5f;
			Assert.AreEqual ("0.5", box.Text, "#1");
			data.Opacity = 0.0f;
			Assert.AreEqual ("0", box.Text, "#2");
		}
예제 #19
0
 /// <summary>
 /// Create a new cached property.
 /// </summary>
 /// <param name="updateDelegate">The delegate method which will perform future updates to this property.</param>
 /// <param name="clock">The clock which will be used to decide whether we need a refresh.</param>
 /// <param name="refreshInterval">How often we should refresh this property. Set to -1 to never update. Set to 0 for once per frame.</param>
 public Cached(PropertyUpdater updateDelegate = null, IClock clock = null, int refreshInterval = -1)
 {
     RefreshInterval     = refreshInterval;
     this.updateDelegate = updateDelegate;
     this.clock          = clock;
 }
예제 #20
0
 /// <summary>
 /// Refresh this cached object with a custom delegate.
 /// </summary>
 /// <param name="providedDelegate"></param>
 public T Refresh(PropertyUpdater providedDelegate)
 {
     updateDelegate = updateDelegate ?? providedDelegate;
     return(MakeValidOrDefault());
 }
예제 #21
0
파일: BindingTest.cs 프로젝트: shana/moon
		public void TestTwoWayBinding2()
		{
			PropertyUpdater data = new PropertyUpdater { Opacity = 0.5f };
			Rectangle r = new Rectangle();
			r.SetBinding(Rectangle.OpacityProperty, new Binding
			{
				Path = new PropertyPath("Opacity"),
				Source = data,
				Mode = BindingMode.TwoWay
			});
			Assert.AreEqual(0.5, r.Opacity, "#1");
			Assert.AreEqual(0.5, data.Opacity, "#2");
			data.Opacity = 0;
			Assert.AreEqual(0.0, r.Opacity, "#3");
			r.Opacity = 1;
			Assert.IsTrue(r.ReadLocalValue(Rectangle.OpacityProperty) is BindingExpressionBase, "#4");
			Assert.AreEqual(1, r.Opacity, "#5");
			Assert.AreEqual(1, data.Opacity, "#6");

			r.ClearValue(Rectangle.OpacityProperty);
			r.Opacity = 0.5;
			Assert.AreEqual(1, data.Opacity, "#7");
		}