public static void AddObject(ILevelEditorObject value)
        {
            LevelEditorLogger.Log($"Add object to world: {value}");
            Assert.IsFalse(objects.Contains(value), "This object has already been added to the world.");

            objects.Add(value);
        }
Exemplo n.º 2
0
        public IEnumerator ResetReferenceOnSpawn()
        {
            cube.AddComponent <TransformReferenceScript>();
            cube.AddComponent <GameObjectReferenceScript>();

            yield return(null);

            ILevelEditorObject newCube = objectManager.CreateObject("cube");
            var ref1 = newCube.MyGameObject.GetComponent <TransformReferenceScript>();
            var ref2 = newCube.MyGameObject.GetComponent <GameObjectReferenceScript>();

            ref1.value = sphere.transform;
            ref2.value = capsule.gameObject;

            yield return(null);

            objectManager.DeleteObject(newCube);

            yield return(null);

            newCube = objectManager.CreateObject("cube");

            ref1 = newCube.MyGameObject.GetComponent <TransformReferenceScript>();
            ref2 = newCube.MyGameObject.GetComponent <GameObjectReferenceScript>();

            Assert.AreEqual(ref1.value, null);
            Assert.AreEqual(ref2.value, null);
        }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        private IEnumerator UndoRedoDeleteObject()
        {
            ILevelEditorObject newCube = objectManager.CreateObject("cube");
            uint instanceId            = newCube.InstanceID;

            yield return(WaitFrames(1));

            // Make sure the object exists.
            Assert.IsTrue(LevelEditorWorld.TryGetObject(instanceId, out _));
            objectManager.DeleteObject(newCube);

            yield return(WaitFrames(1));

            // Make sure the object doesn't exist.
            Assert.IsFalse(LevelEditorWorld.TryGetObject(instanceId, out _));

            undo.Undo();

            yield return(WaitFrames(1));

            // Make sure the object exists.
            Assert.IsTrue(LevelEditorWorld.TryGetObject(instanceId, out _));

            undo.Redo();

            yield return(WaitFrames(1));

            // Make sure the object doesn't exist.
            Assert.IsFalse(LevelEditorWorld.TryGetObject(instanceId, out _));
        }
Exemplo n.º 6
0
        // [UnityTest]
        // public IEnumerator SaveTransform()
        // {
        //  ILevelEditorObject newCube = objectManager.CreateObject(resources.GetResource("cube"));
        //  ILevelEditorObject newSphere = objectManager.CreateObject(resources.GetResource("sphere"));
        //
        //  uint newCubeId = newCube.InstanceID;
        //  uint newSphereId = newSphere.InstanceID;
        //
        //  yield return null;
        //
        //  TransformWrapper wrapper = newCube.MyGameObject.GetComponent<TransformWrapper>();
        //  Assert.IsNotNull(wrapper);
        //
        //  newCube.MyGameObject.transform.position = new Vector3(10, 20, 30);
        //  newCube.MyGameObject.transform.eulerAngles = new Vector3(40, 50, 60);
        //  newCube.MyGameObject.transform.localScale = new Vector3(1, 2, 3);
        //
        //  newCube.Parent = newSphere;
        //  newSphere.AddChild(newCube);
        //  newCube.MyGameObject.transform.SetParent(newSphere.MyGameObject.transform);
        //
        //  Save();
        //
        //  yield return null;
        //
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(newCubeId);
        //  newSphere = objectManager.GetObject(newSphereId);
        //
        //  Assert.IsNotNull(newCube.MyGameObject);
        //  Assert.IsNotNull(newSphere.MyGameObject);
        //
        //  AreApproximatelyEqual(new Vector3(10, 20, 30), newCube.MyGameObject.transform.position);
        //  AreApproximatelyEqual(new Vector3(40, 50, 60), newCube.MyGameObject.transform.eulerAngles);
        //  AreApproximatelyEqual(new Vector3(1, 2, 3), newCube.MyGameObject.transform.localScale);
        //  Assert.AreEqual(newSphere.MyGameObject.transform, newCube.MyGameObject.transform.parent);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveRigidbody()
        // {
        //  cube.AddComponent<Rigidbody>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject(resources.GetResource("cube"));
        //
        //  uint newCubeId = newCube.InstanceID;
        //
        //  yield return null;
        //
        //  Rigidbody rb = newCube.MyGameObject.GetComponent<Rigidbody>();
        //  RigidbodyWrapper wrapper = newCube.MyGameObject.GetComponent<RigidbodyWrapper>();
        //  Assert.IsNotNull(rb);
        //  Assert.IsNotNull(wrapper);
        //
        //  rb.mass = 10;
        //  rb.drag = 20;
        //  rb.angularDrag = 30;
        //  rb.useGravity = false;
        //  rb.isKinematic = true;
        //
        //  Save();
        //
        //  yield return null;
        //
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(newCubeId);
        //  rb = newCube.MyGameObject.GetComponent<Rigidbody>();
        //
        //  Assert.IsNotNull(rb);
        //
        //  Assert.AreApproximatelyEqual(10, rb.mass);
        //  Assert.AreApproximatelyEqual(20, rb.drag);
        //  Assert.AreApproximatelyEqual(30, rb.angularDrag);
        //  Assert.AreEqual(false, rb.useGravity);
        //  Assert.AreEqual(true, rb.isKinematic);
        // }

        // [UnityTest]
        // public IEnumerator SaveByte()
        // {
        //  cube.AddComponent<ByteTest1>();
        //  cube.AddComponent<ByteTest2>();
        //  cube.AddComponent<ByteTest3>();
        //  cube.AddComponent<ByteTest4>();
        //  cube.AddComponent<ByteTest5>();
        //  cube.AddComponent<ByteTest6>();
        //  cube.AddComponent<ByteTest7>();
        //  cube.AddComponent<ByteTest8>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject(resources.GetResource("cube"));
        //  uint cubeId = newCube.InstanceID;
        //
        //  ByteTest1 byte1 = newCube.MyGameObject.GetComponent<ByteTest1>();
        //  byte1.value = 5;
        //  ByteTest2 byte2 = newCube.MyGameObject.GetComponent<ByteTest2>();
        //  byte2.value = 6;
        //  ByteTest3 byte3 = newCube.MyGameObject.GetComponent<ByteTest3>();
        //  byte3.value1 = 3;
        //  byte3.value2 = 4;
        //  ByteTest4 byte4 = newCube.MyGameObject.GetComponent<ByteTest4>();
        //  byte4.value1 = 10;
        //  byte4.value2 = 20;
        //  ByteTest5 byte5 = newCube.MyGameObject.GetComponent<ByteTest5>();
        //  byte5.Value = 5;
        //  ByteTest6 byte6 = newCube.MyGameObject.GetComponent<ByteTest6>();
        //  byte6.Value = 6;
        //  ByteTest7 byte7 = newCube.MyGameObject.GetComponent<ByteTest7>();
        //  byte7.Value1 = 3;
        //  byte7.Value2 = 4;
        //  ByteTest8 byte8 = newCube.MyGameObject.GetComponent<ByteTest8>();
        //  byte8.Value1 = 10;
        //  byte8.Value2 = 20;
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  byte1 = newCube.MyGameObject.GetComponent<ByteTest1>();
        //  Assert.AreEqual<byte>(5, byte1.value, "Byte 1 field value failed.");
        //  byte2 = newCube.MyGameObject.GetComponent<ByteTest2>();
        //  Assert.AreEqual<byte>(6, byte2.value, "Byte 2 field value failed.");
        //  byte3 = newCube.MyGameObject.GetComponent<ByteTest3>();
        //  Assert.AreEqual<byte>(3, byte3.value1, "Byte 3 field value 1 failed.");
        //  Assert.AreEqual<byte>(4, byte3.value2, "Byte 3 field value 2 failed.");
        //  byte4 = newCube.MyGameObject.GetComponent<ByteTest4>();
        //  Assert.AreEqual<byte>(10, byte4.value1, "Byte 4 field value 1 failed.");
        //  Assert.AreEqual<byte>(20, byte4.value2, "Byte 4 field value 2 failed.");
        //
        //  byte5 = newCube.MyGameObject.GetComponent<ByteTest5>();
        //  Assert.AreEqual<byte>(5, byte5.Value, "Byte 5 property value failed.");
        //  byte6 = newCube.MyGameObject.GetComponent<ByteTest6>();
        //  Assert.AreEqual<byte>(6, byte6.Value, "Byte 6 property value failed.");
        //  byte7 = newCube.MyGameObject.GetComponent<ByteTest7>();
        //  Assert.AreEqual<byte>(3, byte7.Value1, "Byte 7 property value 1 failed.");
        //  Assert.AreEqual<byte>(4, byte7.Value2, "Byte 7 property value 2 failed.");
        //  byte8 = newCube.MyGameObject.GetComponent<ByteTest8>();
        //  Assert.AreEqual<byte>(10, byte8.Value1, "Byte 8 property value 1 failed.");
        //  Assert.AreEqual<byte>(20, byte8.Value2, "Byte 8 property value 2 failed.");
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveByteList()
        // {
        //  cube.AddComponent<ByteListTest>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  ByteListTest bytes = newCube.MyGameObject.GetComponent<ByteListTest>();
        //  bytes.value = new List<byte> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  bytes = newCube.MyGameObject.GetComponent<ByteListTest>();
        //  Assert.IsTrue(bytes.value.IsSameAs(new List<byte> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
        // }

        // [UnityTest]
        // public IEnumerator SaveTransformReference()
        // {
        //  cube.AddComponent<TransformReferenceScript>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject(resources.GetResource("cube"));
        //  ILevelEditorObject newSphere = objectManager.CreateObject(resources.GetResource("sphere"));
        //  ILevelEditorObject newCapsule = objectManager.CreateObject(resources.GetResource("capsule"));
        //
        //  uint newCubeId = newCube.InstanceID;
        //  uint newSphereId = newSphere.InstanceID;
        //  uint newCapsuleId = newCapsule.InstanceID;
        //
        //  TransformReferenceScript trsRef = newCube.MyGameObject.GetComponent<TransformReferenceScript>();
        //  trsRef.value = newSphere.MyGameObject.transform;
        //  trsRef.Value = newCapsule.MyGameObject.transform;
        //
        //  yield return null;
        //
        //  Save();
        //
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(newCubeId);
        //  newSphere = objectManager.GetObject(newSphereId);
        //  newCapsule = objectManager.GetObject(newCapsuleId);
        //
        //  trsRef = newCube.MyGameObject.GetComponent<TransformReferenceScript>();
        //  Assert.AreEqual(newSphere.MyGameObject.transform, trsRef.value);
        //  Assert.AreEqual(newCapsule.MyGameObject.transform, trsRef.Value);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveTransformReferenceArray()
        // {
        //  cube.AddComponent<TransformReferenceArrayScript>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject(resources.GetResource("cube"));
        //  ILevelEditorObject newSphere = objectManager.CreateObject(resources.GetResource("sphere"));
        //  ILevelEditorObject newCapsule = objectManager.CreateObject(resources.GetResource("capsule"));
        //
        //  uint newCubeId = newCube.InstanceID;
        //  uint newSphereId = newSphere.InstanceID;
        //  uint newCapsuleId = newCapsule.InstanceID;
        //
        //  TransformReferenceArrayScript trsRefArray = newCube.MyGameObject.GetComponent<TransformReferenceArrayScript>();
        //  trsRefArray.value = new[] { newSphere.MyGameObject.transform, newCapsule.MyGameObject.transform };
        //  trsRefArray.Value = new[] { newCapsule.MyGameObject.transform, newSphere.MyGameObject.transform };
        //
        //  yield return null;
        //
        //  Save();
        //
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(newCubeId);
        //  newSphere = objectManager.GetObject(newSphereId);
        //  newCapsule = objectManager.GetObject(newCapsuleId);
        //
        //  trsRefArray = newCube.MyGameObject.GetComponent<TransformReferenceArrayScript>();
        //  Assert.IsTrue(trsRefArray.value.IsSameAs(new[] { newSphere.MyGameObject.transform, newCapsule.MyGameObject.transform }));
        //  Assert.IsTrue(trsRefArray.Value.IsSameAs(new[] { newCapsule.MyGameObject.transform, newSphere.MyGameObject.transform }));
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveTransformReferenceList()
        // {
        //  cube.AddComponent<TransformReferenceListScript>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject(resources.GetResource("cube"));
        //  ILevelEditorObject newSphere = objectManager.CreateObject(resources.GetResource("sphere"));
        //  ILevelEditorObject newCapsule = objectManager.CreateObject(resources.GetResource("capsule"));
        //
        //  uint newCubeId = newCube.InstanceID;
        //  uint newSphereId = newSphere.InstanceID;
        //  uint newCapsuleId = newCapsule.InstanceID;
        //
        //  TransformReferenceListScript trsRefList = newCube.MyGameObject.GetComponent<TransformReferenceListScript>();
        //  trsRefList.value.Add(newSphere.MyGameObject.transform);
        //  trsRefList.value.Add(newCapsule.MyGameObject.transform);
        //  trsRefList.Value.Add(newCapsule.MyGameObject.transform);
        //  trsRefList.Value.Add(newCube.MyGameObject.transform);
        //
        //  yield return null;
        //
        //  Save();
        //
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(newCubeId);
        //  newSphere = objectManager.GetObject(newSphereId);
        //  newCapsule = objectManager.GetObject(newCapsuleId);
        //
        //  trsRefList = newCube.MyGameObject.GetComponent<TransformReferenceListScript>();
        //  Assert.IsTrue(trsRefList.value.IsSameAs(new List<Transform>
        //      { newSphere.MyGameObject.transform, newCapsule.MyGameObject.transform }));
        //
        //  Assert.IsTrue(trsRefList.Value.IsSameAs(new List<Transform>
        //      { newCapsule.MyGameObject.transform, newCube.MyGameObject.transform }));
        // }

        // [UnityTest]
        // public IEnumerator SaveInheritanceParent()
        // {
        //  cube.AddComponent<InheritParent>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  InheritParent parent = newCube.MyGameObject.GetComponent<InheritParent>();
        //  parent.parentValue = 420;
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  parent = newCube.MyGameObject.GetComponent<InheritParent>();
        //  Assert.AreEqual(420, parent.parentValue);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveInheritanceChild()
        // {
        //  cube.AddComponent<InheritChild>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  InheritChild child = newCube.MyGameObject.GetComponent<InheritChild>();
        //  child.childValue = 420;
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  child = newCube.MyGameObject.GetComponent<InheritChild>();
        //  Assert.AreEqual(420, child.childValue);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveInheritanceChildAndParent()
        // {
        //  cube.AddComponent<InheritChild>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  InheritChild child = newCube.MyGameObject.GetComponent<InheritChild>();
        //  child.parentValue = 69;
        //  child.childValue = 420;
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  child = newCube.MyGameObject.GetComponent<InheritChild>();
        //  Assert.AreEqual(69, child.parentValue);
        //  Assert.AreEqual(420, child.childValue);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveCustomStruct()
        // {
        //  cube.AddComponent<CustomStructTest>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  CustomStructTest structTest = newCube.MyGameObject.GetComponent<CustomStructTest>();
        //  structTest.value = new MyStruct
        //      { test1 = 42, test2 = "Hello world" };
        //
        //  structTest.Value = new MyStruct
        //      { test1 = 69, test2 = "Look ma!" };
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  structTest = newCube.MyGameObject.GetComponent<CustomStructTest>();
        //  Assert.AreEqual(structTest.value.test1, 42);
        //  Assert.AreEqual(structTest.value.test2, "Hello world");
        //  Assert.AreEqual(structTest.Value.test1, 69);
        //  Assert.AreEqual(structTest.Value.test2, "Look ma!");
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveNestedStruct()
        // {
        //  cube.AddComponent<NestedStructTest>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  NestedStructTest structTest = newCube.MyGameObject.GetComponent<NestedStructTest>();
        //  structTest.value = new NestedStruct
        //  {
        //      nestedValue = new ChildStruct
        //          { value1 = 42, value2 = false },
        //      value = 69
        //  };
        //
        //  structTest.Value = new NestedStruct
        //  {
        //      nestedValue = new ChildStruct
        //          { value1 = 420, value2 = true },
        //      value = 690
        //  };
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  structTest = newCube.MyGameObject.GetComponent<NestedStructTest>();
        //  Assert.AreEqual(structTest.value.nestedValue.value1, 42);
        //  Assert.AreEqual(structTest.value.nestedValue.value2, false);
        //  Assert.AreEqual(structTest.value.value, 69);
        //  Assert.AreEqual(structTest.Value.nestedValue.value1, 420);
        //  Assert.AreEqual(structTest.Value.nestedValue.value2, true);
        //  Assert.AreEqual(structTest.Value.value, 690);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveIgnoresNonSerialized()
        // {
        //  cube.AddComponent<NonSerializedValueTest>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  NonSerializedValueTest structTest = newCube.MyGameObject.GetComponent<NonSerializedValueTest>();
        //  structTest.value = new StructWithNonSerialized() { value1 = 42, value2 = true };
        //  structTest.Value = new StructWithNonSerialized() { value1 = 69, value2 = true };
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  structTest = newCube.MyGameObject.GetComponent<NonSerializedValueTest>();
        //  Assert.AreEqual(structTest.value.value1, 42);
        //  Assert.AreEqual(structTest.value.value2, false);
        //  Assert.AreEqual(structTest.Value.value1, 69);
        //  Assert.AreEqual(structTest.Value.value2, false);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveNonSerializableStruct()
        // {
        //  cube.AddComponent<NonSerializedStructTest>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  NonSerializedStructTest structTest = newCube.MyGameObject.GetComponent<NonSerializedStructTest>();
        //  structTest.value = new NonSerializedStruct() { value1 = 42, value2 = true };
        //  structTest.Value = new NonSerializedStruct() { value1 = 69, value2 = true };
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  structTest = newCube.MyGameObject.GetComponent<NonSerializedStructTest>();
        //  Assert.AreEqual(structTest.value.value1, 0);
        //  Assert.AreEqual(structTest.value.value2, false);
        //  Assert.AreEqual(structTest.Value.value1, 0);
        //  Assert.AreEqual(structTest.Value.value2, false);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveEnumNormal()
        // {
        //  cube.AddComponent<EnumTest>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  EnumTest enumTest = newCube.MyGameObject.GetComponent<EnumTest>();
        //  enumTest.value = NormalEnum.Value2;
        //  enumTest.Value = NormalEnum.Value4;
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  enumTest = newCube.MyGameObject.GetComponent<EnumTest>();
        //  Assert.AreEqual(enumTest.value, NormalEnum.Value2);
        //  Assert.AreEqual(enumTest.Value, NormalEnum.Value4);
        // }
        //
        // [UnityTest]
        // public IEnumerator SaveEnumByte()
        // {
        //  cube.AddComponent<ByteEnumTest>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  ByteEnumTest enumTest = newCube.MyGameObject.GetComponent<ByteEnumTest>();
        //  enumTest.value = ByteEnum.Value2;
        //  enumTest.Value = ByteEnum.Value4;
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  enumTest = newCube.MyGameObject.GetComponent<ByteEnumTest>();
        //  Assert.AreEqual(enumTest.value, ByteEnum.Value2);
        //  Assert.AreEqual(enumTest.Value, ByteEnum.Value4);
        // }

        // [UnityTest]
        // protected IEnumerator SaveEnumByteFlag()
        // {
        //  cube.AddComponent<ByteFlagsEnumTest>();
        //
        //  ILevelEditorObject newCube = objectManager.CreateObject("cube");
        //  uint cubeId = newCube.InstanceID;
        //
        //  ByteFlagsEnumTest enumTest = newCube.MyGameObject.GetComponent<ByteFlagsEnumTest>();
        //  enumTest.value = ByteFlagsEnum.Value1 | ByteFlagsEnum.Value3;
        //  enumTest.Value = ByteFlagsEnum.Value2 | ByteFlagsEnum.Value4;
        //
        //  yield return null;
        //
        //  Save();
        //  objectManager.DeleteAllObjects();
        //
        //  yield return null;
        //
        //  Load();
        //
        //  yield return null;
        //
        //  newCube = objectManager.GetObject(cubeId);
        //  Assert.IsNotNull(newCube);
        //
        //  enumTest = newCube.MyGameObject.GetComponent<ByteFlagsEnumTest>();
        //  Assert.AreEqual(enumTest.value, ByteFlagsEnum.Value1 | ByteFlagsEnum.Value3);
        //  Assert.AreEqual(enumTest.Value, ByteFlagsEnum.Value2 | ByteFlagsEnum.Value4);
        // }

        protected IEnumerator RunTest <TType, TValue>(TValue newValue) where TType : Component, IValue <TValue>
        {
            cube.AddComponent <TType>();

            ILevelEditorObject newCube = objectManager.CreateObject("cube");
            uint cubeId = newCube.InstanceID;

            TType type = newCube.MyGameObject.GetComponent <TType>();

            type.Value = newValue;

            Assert.AreEqual(newValue, type.Value, "Value was not set.");

            Save();

            objectManager.DeleteAllObjects();

            Load();

            newCube = objectManager.GetObject(cubeId);
            Assert.IsNotNull(newCube, "Object was not loaded.");

            type = newCube.MyGameObject.GetComponent <TType>();

            if (newValue is ICollection newValueCollection && type.Value is ICollection valueCollection)
            {
                Assert.IsTrue(newValueCollection.IsSameAs(valueCollection), $"Collection was not the same.");
            }
        public void CreateObjectsFromSaveData(LevelEditorSaveData data)
        {
            if (data.objects != null && data.objects.Count > 0)
            {
                ILevelEditorObject[] savedObjects = new ILevelEditorObject[data.objects.Count];

                for (int i = 0; i < data.objects.Count; i++)
                {
                    ILevelEditorObject obj = this.CreateObject(data.objects[i]);
                    savedObjects[i] = obj;
                }

                Assert.AreEqual(data.objects.Count, savedObjects.Length);

                for (int i = 0; i < savedObjects.Length; i++)
                {
                    LevelEditorComponentData[] components = data.objects[i].components;

                    if (savedObjects[i] == null)
                    {
                        continue;
                    }

                    savedObjects[i].ApplyExposedData(components);
                    OnCreatedObjectFromSaveData?.Invoke(this, new LevelEditorObjectEvent(savedObjects[i]));
                }
            }
        }
        public IEnumerator ResetReferenceValues()
        {
            cube.AddComponent <TransformReferenceScript>();
            cube.AddComponent <GameObjectReferenceScript>();

            yield return(null);

            ILevelEditorObject        newCube    = objectManager.CreateObject("cube");
            ILevelEditorObject        newSphere  = objectManager.CreateObject("sphere");
            ILevelEditorObject        newCapsule = objectManager.CreateObject("capsule");
            TransformReferenceScript  ref1       = newCube.MyGameObject.GetComponent <TransformReferenceScript>();
            GameObjectReferenceScript ref2       = newCube.MyGameObject.GetComponent <GameObjectReferenceScript>();

            ref1.value = newSphere.MyGameObject.transform;
            ref2.value = newCapsule.MyGameObject;

            yield return(null);

            playMode.StartPlayMode(levelEditor);

            yield return(null);

            ref1.value = null;
            ref2.value = null;

            yield return(null);

            playMode.StopPlayMode(levelEditor);

            yield return(null);

            Assert.AreEqual(ref1.value, newSphere.MyGameObject.transform);
            Assert.AreEqual(ref2.value, newCapsule.MyGameObject);
        }
Exemplo n.º 9
0
 private void OnClickAsset(object sender, AssetClickEventArgs e)
 {
     if (e.Resource.Asset is GameObject)
     {
         ILevelEditorObject obj = ObjectManager.CreateObject(e.Resource);
         Selection.SetSelection(obj);
     }
 }
Exemplo n.º 10
0
        public void RemoveChild(ILevelEditorObject child)
        {
            if (child == null)
            {
                return;
            }

            Children.Remove(child);
        }
 public CreateObjectUndoAction(ILevelEditorResource resource, Vector3 position, Quaternion rotation, Transform parent, uint instanceID, ILevelEditorObject obj)
 {
     this.resource   = resource;
     this.position   = position;
     this.rotation   = rotation;
     this.parent     = parent;
     this.instanceID = instanceID;
     this.obj        = obj;
 }
Exemplo n.º 12
0
        public void AddChild(ILevelEditorObject child)
        {
            if (child == null || Children.Contains(child))
            {
                return;
            }

            Children.Add(child);
            child.MyGameObject.transform.SetParent(transform);
        }
Exemplo n.º 13
0
        public bool TryGetObject(out ILevelEditorObject value)
        {
            if (objects == null || objects.Length == 0)
            {
                value = null;
                return(false);
            }

            return(LevelEditorWorld.TryGetObject(objects[0], out value));
        }
Exemplo n.º 14
0
        public IEnumerator SetValueTransformList()
        {
            ILevelEditorObject newSphere  = objectManager.CreateObject("sphere");
            ILevelEditorObject newCapsule = objectManager.CreateObject("capsule");

            ComponentDataWrapper array1 = new ComponentDataWrapper(new Component[] { newSphere.MyGameObject.transform, newCapsule.MyGameObject.transform });
            ComponentDataWrapper array2 = new ComponentDataWrapper(new Component[] { newCapsule.MyGameObject.transform, newSphere.MyGameObject.transform });

            yield return(SetValueTest <ComponentDataWrapper, TransformList>(array1, array2));
        }
Exemplo n.º 15
0
        public IEnumerator SetValueTransform()
        {
            ILevelEditorObject newSphere  = objectManager.CreateObject("sphere");
            ILevelEditorObject newCapsule = objectManager.CreateObject("capsule");

            ComponentDataWrapper sphereRef  = new ComponentDataWrapper(newSphere.MyGameObject.transform);
            ComponentDataWrapper capsuleRef = new ComponentDataWrapper(newCapsule.MyGameObject.transform);

            yield return(SetValueTest <ComponentDataWrapper, TransformReference>(sphereRef, capsuleRef));
        }
Exemplo n.º 16
0
        public IEnumerator SetValueGameObjectArray()
        {
            ILevelEditorObject newSphere  = objectManager.CreateObject("sphere");
            ILevelEditorObject newCapsule = objectManager.CreateObject("capsule");

            ComponentDataWrapper array1 = new ComponentDataWrapper(new[] { newSphere.MyGameObject, newCapsule.MyGameObject });
            ComponentDataWrapper array2 = new ComponentDataWrapper(new[] { newCapsule.MyGameObject, newSphere.MyGameObject });

            yield return(SetValueTest <ComponentDataWrapper, GameObjectArray>(array1, array2));
        }
Exemplo n.º 17
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);
        }
 public DeleteObjectUndoAction(ILevelEditorObject obj)
 {
     targetId         = obj.ID;
     targetInstanceId = obj.InstanceID;
     IExposedToLevelEditor[] exposed = obj.GetExposedComponents();
     savedValues = new IExposedWrapper[exposed.Length];
     for (int i = 0; i < exposed.Length; i++)
     {
         savedValues[i] = exposed[i].GetWrapper();
     }
 }
        private void DeleteObjectInternal(ILevelEditorObject target, bool registerUndo)
        {
            if (!pooledObjects.ContainsKey(target.ID))
            {
                pooledObjects.Add(target.ID, new Stack <ILevelEditorObject>());
            }

            objectsWithId.Remove(target.InstanceID);

            pooledObjects[target.ID].Push(target);
            activeObjects[target.ID].Remove(target);
            objectCount[target.ID]--;

            target.OnPooled();

            if (target.MyGameObject.TryGetComponent(out ILevelEditorGizmos gizmos))
            {
                LevelEditorGLRenderer.Remove(gizmos);
            }

            if (target.Parent != null)
            {
                target.Parent.RemoveChild(target);
            }

            if (target.HasChildren())
            {
                //TODO: If deleting children, register delete multiple undo.
                for (int i = 0; i < target.Children.Count; i++)
                {
                    DeleteObject(target.Children[i], false);
                }

                target.Children.Clear();
            }

            if (registerUndo && Undo != null)
            {
                undoComp.AddAction(new DeleteObjectUndoAction(target));
            }

            if (poolObjects)
            {
                target.MyGameObject.SetActive(false);
            }
            else
            {
                Destroy(target.MyGameObject);
            }

            OnDeletedObject?.Invoke(this, new LevelEditorObjectEvent(target));
        }
Exemplo n.º 20
0
        public IEnumerator SetValueScriptList()
        {
            sphere.AddComponent <TempTestScript>();
            capsule.AddComponent <TempTestScript>();

            ILevelEditorObject newSphere  = objectManager.CreateObject("sphere");
            ILevelEditorObject newCapsule = objectManager.CreateObject("capsule");

            ComponentDataWrapper array1 = new ComponentDataWrapper(new TempTestScript[] { newSphere.MyGameObject.GetComponent <TempTestScript>(), newCapsule.MyGameObject.GetComponent <TempTestScript>() });
            ComponentDataWrapper array2 = new ComponentDataWrapper(new TempTestScript[] { newCapsule.MyGameObject.GetComponent <TempTestScript>(), newSphere.MyGameObject.GetComponent <TempTestScript>() });

            yield return(SetValueTest <ComponentDataWrapper, ScriptList>(array1, array2));
        }
Exemplo n.º 21
0
        public IEnumerator SetValueScript()
        {
            sphere.AddComponent <TempTestScript>();
            capsule.AddComponent <TempTestScript>();

            ILevelEditorObject newSphere  = objectManager.CreateObject("sphere");
            ILevelEditorObject newCapsule = objectManager.CreateObject("capsule");

            ComponentDataWrapper sphereRef  = new ComponentDataWrapper(newSphere.MyGameObject.GetComponent <TempTestScript>());
            ComponentDataWrapper capsuleRef = new ComponentDataWrapper(newCapsule.MyGameObject.GetComponent <TempTestScript>());

            yield return(SetValueTest <ComponentDataWrapper, ScriptReference>(sphereRef, capsuleRef));
        }
        public void Undo(ILevelEditorUndo undo)
        {
            ILevelEditorObject newObj = undo.LevelEditor.ObjectManager.CreateObject(targetId, targetInstanceId, false);

            IExposedToLevelEditor[] exposed = newObj.GetExposedComponents();

            Assert.AreEqual(exposed.Length, savedValues.Length);

            for (int i = 0; i < exposed.Length; i++)
            {
                exposed[i].ApplyWrapper(savedValues[i], true);
            }
        }
Exemplo n.º 23
0
        public LevelEditorObjectData(ILevelEditorObject obj)
        {
            name       = obj.MyGameObject.name;
            active     = obj.MyGameObject.activeSelf;
            id         = obj.ID;
            instanceId = obj.InstanceID;

            IExposedToLevelEditor[] objComps = obj.GetExposedComponents();
            components = new LevelEditorComponentData[objComps.Length];
            for (int i = 0; i < objComps.Length; i++)
            {
                components[i] = new LevelEditorComponentData(objComps[i]);
            }
        }
        public static bool TryGetObject(uint instanceId, out ILevelEditorObject value)
        {
            bool result = TryGetObjects(new uint[1] {
                instanceId
            }, out ILevelEditorObject[] values);

            if (values != null && values.Length == 1)
            {
                value = values[0];
            }
            else
            {
                value = null;
            }

            return(result);
        }
        public void SetSelection(ILevelEditorObject target, bool registerUndo = true)
        {
            if (Selection == target)
            {
                return;
            }

            ILevelEditorObject old = Selection;

            Selection = target;
            OnSelectionChanged?.Invoke(this, new SelectionEventArgs(old, target));

            if (registerUndo && realUndo != null)
            {
                realUndo.AddAction(new SelectObjectUndoAction(old, target));
            }
        }
        public static bool HasExposedProperties(this ILevelEditorObject obj)
        {
            IExposedToLevelEditor[] components = obj.GetExposedComponents();
            if (components == null || components.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < components.Length; i++)
            {
                if (components[i].HasVisibleFields)
                {
                    return(true);
                }
            }

            return(false);
        }
        public static ILevelEditorObject CreateObject(this ILevelEditorObjectManager x, LevelEditorObjectData data, bool registerUndo = false)
        {
            ILevelEditorResource resource = x.GetResource(data.id);

            if (resource == null)
            {
                return(null);
            }
            ILevelEditorObject obj = x.CreateObject(resource, Vector3.zero, Quaternion.identity, null, data.instanceId, registerUndo);

            if (obj == null)
            {
                return(null);
            }
            obj.MyGameObject.name = data.name;
            obj.MyGameObject.SetActive(data.active);

            return(obj);
        }
Exemplo n.º 28
0
        public IEnumerator ResetTransformOnSpawn()
        {
            ILevelEditorObject newCube = objectManager.CreateObject("cube");

            newCube.MyGameObject.transform.position    = new Vector3(10, 20, 30);
            newCube.MyGameObject.transform.eulerAngles = new Vector3(10, 20, 30);
            newCube.MyGameObject.transform.localScale  = new Vector3(10, 20, 30);

            yield return(null);

            objectManager.DeleteObject(newCube);

            yield return(null);

            newCube = objectManager.CreateObject("cube");

            Assert.AreEqual(newCube.MyGameObject.transform.position, Vector3.zero);
            Assert.AreEqual(newCube.MyGameObject.transform.eulerAngles, Vector3.zero);
            Assert.AreEqual(newCube.MyGameObject.transform.localScale, Vector3.one);
        }
Exemplo n.º 29
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;
        }
        public bool DeleteObject(ILevelEditorObject target, bool registerUndo = true)
        {
            if (target == null)
            {
                return(false);
            }

            LevelEditorObjectEventDeletingEvent args = new LevelEditorObjectEventDeletingEvent(target);

            OnDeletingObject?.Invoke(this, args);

            if (args.Cancel)
            {
                LevelEditorLogger.Log("DeleteObject canceled.");
                return(false);
            }

            DeleteObjectInternal(target, registerUndo);

            allObjects.Remove(target);

            return(true);
        }