Example #1
0
        public IEnumerator SetValueParentAndChild()
        {
            cube.AddComponent <InheritChild>();
            ILevelEditorObject    newCube = objectManager.CreateObject("cube");
            IExposedToLevelEditor exposed = newCube.MyGameObject.GetComponent <InheritChild>() as IExposedToLevelEditor;

            Assert.IsNotNull(exposed);

            var parentValue = (int)exposed.GetValue(0);
            var childValue  = (int)exposed.GetValue(1);

            Assert.AreEqual(0, parentValue);
            Assert.AreEqual(0, childValue);

            exposed.SetValue(0, 10, true);
            exposed.SetValue(1, 20, true);

            parentValue = (int)exposed.GetValue(0);
            childValue  = (int)exposed.GetValue(1);

            Assert.AreEqual(10, parentValue);
            Assert.AreEqual(20, childValue);

            yield break;
        }
Example #2
0
        private IEnumerator SetValueTest <TValue, TScript1, TScript2>(TValue value1, TValue value2) where TScript1 : Component where TScript2 : Component
        {
            cube.AddComponent <TScript1>();
            if (typeof(TScript1) != typeof(TScript2))
            {
                cube.AddComponent <TScript2>();
            }

            ILevelEditorObject    newCube  = objectManager.CreateObject("cube");
            IExposedToLevelEditor exposed1 = newCube.MyGameObject.GetComponent <TScript1>() as IExposedToLevelEditor;
            IExposedToLevelEditor exposed2 = null;

            if (typeof(TScript1) != typeof(TScript2))
            {
                exposed2 = newCube.MyGameObject.GetComponent <TScript2>() as IExposedToLevelEditor;
            }

            Assert.IsNotNull(exposed1);
            if (exposed2 != null)
            {
                Assert.IsNotNull(exposed2);
            }

            exposed1.SetValue(0, value1, true);
            if (exposed2 != null)
            {
                exposed2.SetValue(512, value2, true);
            }
            else
            {
                exposed1.SetValue(512, value2, true);
            }

            yield return(null);

            TValue newValue1 = (TValue)exposed1.GetValue(0);
            TValue newValue2;

            if (exposed2 != null)
            {
                newValue2 = (TValue)exposed2.GetValue(512);
            }
            else
            {
                newValue2 = (TValue)exposed1.GetValue(512);
            }

            Assert.AreEqual(typeof(TValue), value1.GetType());
            Assert.AreEqual(typeof(TValue), value2.GetType());

            Assert.AreEqual(newValue1, value1);
            Assert.AreEqual(newValue2, value2);

            yield return(null);
        }
Example #3
0
        private IEnumerator EventTest <T>(int id, Action <IExposedToLevelEditor, Action <int, object> > subscribeToEvent) where T : Component
        {
            cube.AddComponent <T>();
            ILevelEditorObject    newCube = objectManager.CreateObject("cube");
            IExposedToLevelEditor exposed = newCube.MyGameObject.GetComponent <T>() as IExposedToLevelEditor;

            sceneObjects.Add(newCube.MyGameObject);

            Assert.IsNotNull(exposed);

            int    changedId    = -1;
            object changedValue = null;
            bool   eventCalled  = false;

            subscribeToEvent.Invoke(exposed, (id, value) =>
            {
                eventCalled  = true;
                changedId    = id;
                changedValue = value;
            });

            exposed.SetValue(0, 10, true);

            Assert.AreEqual(true, eventCalled);
            Assert.AreEqual(0, changedId);
            Assert.AreEqual(10, changedValue);

            yield return(null);
        }
Example #4
0
        public IEnumerator SetValueParentOnly()
        {
            cube.AddComponent <InheritParent>();
            ILevelEditorObject    newCube = objectManager.CreateObject("cube");
            IExposedToLevelEditor exposed = newCube.MyGameObject.GetComponent <InheritParent>() as IExposedToLevelEditor;

            Assert.IsNotNull(exposed);

            var value = (int)exposed.GetValue(0);

            Assert.AreEqual(0, value);

            exposed.SetValue(0, 10, true);

            value = (int)exposed.GetValue(0);

            Assert.AreEqual(10, value);

            yield break;
        }
 /// <summary>
 /// Sets a value WITHOUT registering undo.
 /// </summary>
 /// <param name="exposed"></param>
 /// <param name="id"></param>
 /// <param name="value"></param>
 /// <param name="notify"></param>
 public static void SetValue(this IExposedToLevelEditor exposed, int id, object value, bool notify)
 {
     exposed.SetValue(id, value, notify, null);
 }
 public void Redo(ILevelEditorUndo undo)
 {
     exposed.SetValue(propertyId, newValue, true);
 }