Beispiel #1
0
        public static void DestroyImmediate()
        {
            var source = new Source {
                Property = 0
            };
            var binding    = new Binding("Property", BindingMode.OneWay, null, null, null, source);
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var parent = new Mux.Markup.RectTransform();
                parent.AddTo(gameObject);
                var rect = new Mux.Markup.RectTransform();
                parent.Add(rect);

                SynchronizationContextWaiter.Execute(() =>
                {
                    rect.SetBinding(Mux.Markup.RectTransform.BindingContextProperty, binding);
                    rect.DestroyImmediate();
                    source.Property = 1;
                    Assert.AreEqual(0, rect.BindingContext);
                });

                Assert.AreEqual(0, parent.Body.childCount);
                CollectionAssert.DoesNotContain(parent, rect);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #2
0
        public static void ActiveSelf()
        {
            var rect = new Mux.Markup.RectTransform();

            Assert.IsTrue(rect.ActiveSelf);
            rect.ActiveSelf = false;
            Assert.IsFalse(rect.ActiveSelf);

            var gameObject = new UnityEngine.GameObject();

            try
            {
                rect.AddTo(gameObject);
                Assert.IsFalse(rect.Body.gameObject.activeSelf);

                SynchronizationContextWaiter.Execute(() =>
                {
                    rect.ActiveSelf = true;
                    Assert.IsTrue(rect.ActiveSelf);
                });

                Assert.IsTrue(rect.Body.gameObject.activeSelf);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #3
0
        public static void LocalScale()
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform();

                Assert.AreEqual(UnityEngine.Vector3.one, rect.LocalScale);
                rect.AddTo(gameObject);
                Assert.AreEqual(UnityEngine.Vector3.one, rect.Body.localScale);

                SynchronizationContextWaiter.Execute(() =>
                {
                    rect.LocalScale = new UnityEngine.Vector3(0, 2, 3);
                    Assert.AreEqual(new UnityEngine.Vector3(0, 2, 3), rect.LocalScale);
                });

                Assert.AreEqual(new UnityEngine.Vector3(0, 2, 3), rect.Body.localScale);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #4
0
        public static void LocalRotation()
        {
            var newRotation   = new UnityEngine.Quaternion(0, 0, 1, 0);
            var isNewRotation = Is.EqualTo(newRotation).Using(QuaternionEqualityComparer.Instance);
            var gameObject    = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform();
                Assert.AreEqual(UnityEngine.Quaternion.identity, rect.LocalRotation);
                Assert.AreEqual(UnityEngine.Vector3.zero, rect.LocalEulerAngles);

                rect.AddTo(gameObject);
                Assert.AreEqual(UnityEngine.Quaternion.identity, rect.Body.localRotation);

                SynchronizationContextWaiter.Execute(() =>
                {
                    rect.LocalRotation = newRotation;
                    Assert.That(rect.LocalRotation, isNewRotation);
                    Assert.AreEqual(new UnityEngine.Vector3(0, 0, 180), rect.LocalEulerAngles);
                });

                Assert.That(rect.Body.localRotation, isNewRotation);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #5
0
        public static void PresetLayer()
        {
            var gameObject = new UnityEngine.GameObject {
                layer = 1
            };

            try
            {
                var rect = new Mux.Markup.RectTransform {
                    Layer = 2
                };
                rect.AddTo(gameObject);

                Assert.AreEqual(2, rect.Layer);
                Assert.AreEqual(2, rect.Body.gameObject.layer);

                SynchronizationContextWaiter.Execute(() =>
                {
                    rect.Layer = 3;
                    Assert.AreEqual(3, rect.Layer);
                });

                Assert.AreEqual(3, rect.Body.gameObject.layer);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #6
0
        public static void LocalPositionZ()
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform();

                Assert.AreEqual(0, rect.LocalPositionZ);
                rect.AddTo(gameObject);
                Assert.AreEqual(new UnityEngine.Vector3(0, 0, 0), rect.Body.localPosition);

                SynchronizationContextWaiter.Execute(() =>
                {
                    rect.LocalPositionZ = 1;
                    Assert.AreEqual(1, rect.LocalPositionZ);
                });

                Assert.AreEqual(new UnityEngine.Vector3(0, 0, 1), rect.Body.localPosition);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #7
0
        public static void Name()
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform();
                Assert.AreEqual("Mux.Markup.RectTransform", rect.Name);

                rect.AddTo(gameObject);
                Assert.AreEqual("Mux.Markup.RectTransform", rect.Body.name);

                SynchronizationContextWaiter.Execute(() =>
                {
                    rect.Name = "";
                    Assert.AreEqual("", rect.Name);
                });

                Assert.AreEqual("", rect.Body.name);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #8
0
        public static void MoveTransformsSource(int from, int to)
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect             = new Mux.Markup.RectTransform();
                var transformsSource = new ObservableCollection <int> {
                    2, 3
                };

                rect.TransformsSource  = transformsSource;
                rect.TransformTemplate = new DataTemplate(() => new Mux.Markup.RectTransform());
                rect.AddTo(gameObject);
                var transforms = rect.Cast <Mux.Markup.RectTransform>().ToArray();
                transformsSource.Move(from, to);

                Assert.AreEqual(1, transforms[0].Body.GetSiblingIndex());
                Assert.AreEqual(0, transforms[1].Body.GetSiblingIndex());
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #9
0
        public static void InsertTransformsSourceWithParent()
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform();
                rect.AddTo(gameObject);
                var templated        = new Mux.Markup.RectTransform();
                var transformsSource = new ObservableCollection <int>();

                rect.TransformsSource  = transformsSource;
                rect.TransformTemplate = new DataTemplate(() => templated);

                SynchronizationContextWaiter.Execute(() => transformsSource.Add(2));
                Assert.AreEqual(2, templated.BindingContext);
                Assert.AreEqual(0, templated.Body.GetSiblingIndex());

                templated = new Mux.Markup.RectTransform();
                SynchronizationContextWaiter.Execute(() => transformsSource.Add(3));
                Assert.AreEqual(3, templated.BindingContext);
                Assert.AreEqual(1, templated.Body.GetSiblingIndex());
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #10
0
        public static void ResetBodyWithoutParent()
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform();
                rect.AddTo(gameObject);

                SynchronizationContextWaiter.Execute(() =>
                {
                    var oldBody = rect.Body;

                    rect.ActiveSelf = false;
                    rect.X          = new Mux.Markup.Sized {
                        Anchor = 0
                    };
                    rect.Y = new Mux.Markup.Sized {
                        Anchor = 1
                    };

                    ((IInternalTransform)rect).Clear();

                    Assert.AreNotSame(oldBody, rect.Body);
                });

                Assert.AreEqual(false, rect.Body.gameObject.activeSelf);
                Assert.AreEqual(new UnityEngine.Vector2(0, 1), rect.Body.anchorMin);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #11
0
        public static void AddNotTransformAfterHavingParent()
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform {
                    BindingContext = 0
                };
                rect.AddTo(gameObject);
                var child = new NotTransform();
                SynchronizationContextWaiter.Execute(() => rect.Add(child));

                Assert.AreEqual(0, child.BindingContext);
                Assert.AreEqual(rect.Body.gameObject, child.gameObject);
                Assert.AreEqual(1, child.awakeCount);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }
Beispiel #12
0
        public static void ReloadWithTransformsSource()
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform();
                rect.AddTo(gameObject);
                rect.TransformTemplate = new DataTemplate(() => new Mux.Markup.RectTransform());
                rect.TransformsSource  = new[] { 1 };
                var oldNodes = rect.ToArray();

                ((IInternalTransform)rect).Clear();

                var newNodes = rect.ToArray();
                Assert.AreEqual(oldNodes.Length, newNodes.Length);
                Assert.AreNotSame(oldNodes[0], newNodes[0]);
            }
            finally
            {
                UnityEngine.GameObject.Destroy(gameObject);
            }
        }
Beispiel #13
0
        public static void Tag()
        {
            var gameObject = new UnityEngine.GameObject();

            try
            {
                var rect = new Mux.Markup.RectTransform();
                Assert.AreEqual("Untagged", rect.Tag);
                rect.AddTo(gameObject);
                Assert.AreEqual("Untagged", rect.Body.tag);

                SynchronizationContextWaiter.Execute(() =>
                {
                    rect.Tag = "Finish";
                    Assert.AreEqual("Finish", rect.Tag);
                });

                Assert.AreEqual("Finish", rect.Body.tag);
            }
            finally
            {
                UnityEngine.Object.Destroy(gameObject);
            }
        }