Beispiel #1
0
        public void AssetReferenceDrawer_SetObject_CanSetToNull()
        {
            // Setup Original AssetReference to not be null and property
            var property = SetupForSetObjectTests();

            // Test
            string guid;

            m_AssetReferenceDrawer.SetObject(property, null, out guid);
            Assert.AreEqual(null, m_AssetReferenceDrawer.m_AssetRefObject.SubObjectName);
            Assert.AreEqual(string.Empty, m_AssetReferenceDrawer.m_AssetRefObject.AssetGUID);
        }
Beispiel #2
0
        public SerializedProperty SetupForSetObjectTests()
        {
            // Setup Original AssetReference to not be null
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            var assetPath = ConfigFolder + "/test" + "/test.prefab";

            CreateTestPrefabAddressable(assetPath);
            var            newEntryGuid = AssetDatabase.AssetPathToGUID(assetPath);
            AssetReference ar           = new AssetReference(newEntryGuid);

            Directory.CreateDirectory("Assets/AddressableAssetsData");
            AddressableAssetSettingsDefaultObject.Settings = Settings;

            // Setup property
            TestObjectWithRef obj = ScriptableObject.CreateInstance <TestObjectWithRef>();

            Settings.CreateOrMoveEntry(newEntryGuid, Settings.groups[0]);
            obj.Reference = ar;
            var so       = new SerializedObject(obj);
            var property = so.FindProperty("Reference");

            m_AssetReferenceDrawer.GatherFilters(property);
            Directory.CreateDirectory("Assets/AddressableAssetsData");
            AddressableAssetSettingsDefaultObject.Settings = Settings;
            string sprGuid;

            m_AssetReferenceDrawer.m_AssetRefObject = ar;
            m_AssetReferenceDrawer.SetObject(property, obj, out sprGuid);

            return(property);
        }
Beispiel #3
0
        public void AssetReferenceDrawer_SetObject_CanSetObject()
        {
            // Setup AssetReference
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            AssetReference ar        = new AssetReference();
            var            assetPath = AssetDatabase.GUIDToAssetPath(m_AssetGUID);

            m_AssetReferenceDrawer.m_AssetRefObject = ar;
            m_AssetReferenceDrawer.m_AssetRefObject.SubObjectName = "test";
            var testObject = AssetDatabase.LoadMainAssetAtPath(assetPath);

            // Setup property
            TestObjectWithRef obj = ScriptableObject.CreateInstance <TestObjectWithRef>();
            var so       = new SerializedObject(obj);
            var property = so.FindProperty("Reference");

            m_AssetReferenceDrawer.GatherFilters(property);

            // Test
            string guid;

            Assert.IsTrue(m_AssetReferenceDrawer.SetObject(property, testObject, out guid));
            Assert.AreEqual(m_AssetGUID, m_AssetReferenceDrawer.m_AssetRefObject.AssetGUID);
            Assert.AreEqual(m_AssetGUID, guid);
            Assert.AreEqual(testObject.name, m_AssetReferenceDrawer.m_AssetRefObject.editorAsset.name);
        }
Beispiel #4
0
        public void SetObject_WhenTargetIsSubAsset_IsSetAsSubObject()
        {
            // Prepare test fbx
            m_fbxAssetPath = GetAssetPath("testFBX.fbx");
            if (!File.Exists(m_fbxAssetPath))
            {
                string fbxResourcePath = null;
                var    repoRoot        = Directory.GetParent(Application.dataPath).Parent?.FullName;
                if (!string.IsNullOrEmpty(repoRoot))
                {
                    fbxResourcePath = Path.Combine(repoRoot, "Projects", "TestsResources", "testFBX.fbx");
                }

                if (string.IsNullOrEmpty(fbxResourcePath) || !File.Exists(fbxResourcePath))
                {
                    Assert.Ignore($"Unable to find required FBX file to run this test. Ignoring.");
                }

                File.Copy(fbxResourcePath, m_fbxAssetPath, true);
                AssetDatabase.Refresh();
            }

            Assert.IsTrue(File.Exists(m_fbxAssetPath));
            var fbxAsset     = AssetDatabase.LoadAssetAtPath <Object>(m_fbxAssetPath);
            var meshSubAsset = AssetDatabase.LoadAllAssetRepresentationsAtPath(m_fbxAssetPath).First(o => o is Mesh);

            AssetDatabase.TryGetGUIDAndLocalFileIdentifier(fbxAsset, out string fbxAssetGuid, out long _);
            Assert.IsFalse(string.IsNullOrEmpty(fbxAssetGuid));

            // Setup property
            var ar  = new AssetReferenceT <Mesh>("");
            var obj = ScriptableObject.CreateInstance <TestObjectWithRef>();

            obj.Reference = ar;
            var so       = new SerializedObject(obj);
            var property = so.FindProperty("Reference");

            // Test
            string guid;

            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            m_AssetReferenceDrawer.GatherFilters(property);
            m_AssetReferenceDrawer.m_AssetRefObject = ar;
            var success = m_AssetReferenceDrawer.SetObject(property, meshSubAsset, out guid);

            // Assert
            Assert.IsTrue(success);
            Assert.AreEqual(fbxAssetGuid, guid);
            Assert.AreEqual(fbxAsset.name, m_AssetReferenceDrawer.m_AssetRefObject.editorAsset.name);
            Assert.AreEqual(meshSubAsset.name, m_AssetReferenceDrawer.m_AssetRefObject.SubObjectName);
            Assert.AreEqual(meshSubAsset.GetType(), m_AssetReferenceDrawer.m_AssetRefObject.SubOjbectType);
        }