Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void AssetReferenceDrawer_SelectionChanged_CanSelectSameNameAssetsInDifferentGroups()
        {
            // Drawer Setup
            var testAssetReferenceDrawer = new TestAssetReferenceDrawer();

            testAssetReferenceDrawer.SetAssetReference(new AssetReference());
            TestObjectWithRef obj = ScriptableObject.CreateInstance <TestObjectWithRef>();
            var so       = new SerializedObject(obj);
            var property = so.FindProperty("Reference");

            testAssetReferenceDrawer.GatherFilters(property);

            // Entries setup
            var        newEntryPath = ConfigFolder + "/test" + "/test.prefab";
            var        testEntry    = Settings.CreateOrMoveEntry(m_AssetGUID, Settings.groups[0]);
            GameObject testObject   = new GameObject("TestObject");

            Directory.CreateDirectory(ConfigFolder + "/test");
            PrefabUtility.SaveAsPrefabAsset(testObject, newEntryPath);
            var newEntryGuid    = AssetDatabase.AssetPathToGUID(newEntryPath);
            var secondTestEntry = Settings.CreateOrMoveEntry(newEntryGuid, Settings.groups[1]);

            // Tree setup
            var        testId      = testEntry.AssetPath.GetHashCode();
            List <int> selectedIds = new List <int>()
            {
                testId
            };
            var treeState = new TreeViewState();

            treeState.selectedIDs = selectedIds;
            Directory.CreateDirectory("Assets/AddressableAssetsData");
            AddressableAssetSettingsDefaultObject.Settings = Settings;
            testAssetReferenceDrawer.TreeSetup(treeState);


            // Test
            testAssetReferenceDrawer.TreeSelectionChangedHelper(selectedIds);
            Assert.AreEqual(m_AssetGUID, testAssetReferenceDrawer.newGuid);
            selectedIds[0] = secondTestEntry.AssetPath.GetHashCode();
            testAssetReferenceDrawer.TreeSelectionChangedHelper(selectedIds);
            Assert.AreEqual(AssetDatabase.AssetPathToGUID(newEntryPath), testAssetReferenceDrawer.newGuid);

            // Cleanup
            if (Directory.Exists("Assets/AddressableAssetsData"))
            {
                AssetDatabase.DeleteAsset("Assets/AddressableAssetsData");
            }
            EditorBuildSettings.RemoveConfigObject("Assets/AddressableAssetsData");
            Settings.RemoveAssetEntry(AssetDatabase.AssetPathToGUID(newEntryPath));
            Settings.RemoveAssetEntry(m_AssetGUID);
        }