Ejemplo 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);
        }
Ejemplo n.º 2
0
        public void AssetReferenceDrawer_IsAssetPathInAddressableDirectory_PathNotInAddressableFolder()
        {
            // Asset setup
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            string     assetName    = "";
            var        newEntryPath = ConfigFolder + "/test" + "/test.prefab";
            GameObject testObject   = new GameObject("TestObject");

            Directory.CreateDirectory(ConfigFolder + "/test");
            PrefabUtility.SaveAsPrefabAsset(testObject, newEntryPath);
            var folderGuid = AssetDatabase.AssetPathToGUID(ConfigFolder + "/test");

            // Test
            Assert.IsFalse(Settings.IsAssetPathInAddressableDirectory(newEntryPath, out assetName));
            Assert.AreEqual(assetName, "");

            // Cleanup
            Settings.RemoveAssetEntry(AssetDatabase.AssetPathToGUID(newEntryPath));
            Settings.RemoveAssetEntry(folderGuid);
            if (Directory.Exists(ConfigFolder + "/test"))
            {
                AssetDatabase.DeleteAsset(ConfigFolder + "/test");
            }
            m_AssetReferenceDrawer = null;
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        public void AssetReferenceDrawer_IsAssetPathInAddressableDirectory_PathEmptyString()
        {
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            string assetName = "";

            Assert.IsFalse(Settings.IsAssetPathInAddressableDirectory("", out assetName));
            Assert.AreEqual(assetName, "");
        }
Ejemplo n.º 5
0
        public void AssetReferenceDrawer_IsAssetPathInAddressableDirectory_PathPointToNonexistentAsset()
        {
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            string assetName = "";

            Assert.IsFalse(Settings.IsAssetPathInAddressableDirectory(ConfigFolder + "/test.prefab", out assetName));
            Assert.AreEqual(assetName, "");
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void CanRestrictLabel()
        {
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            TestObjectWithRestrictedRef obj = ScriptableObject.CreateInstance <TestObjectWithRestrictedRef>();
            var so       = new SerializedObject(obj);
            var property = so.FindProperty("Reference");

            m_AssetReferenceDrawer.GatherFilters(property);
            Assert.AreEqual(m_AssetReferenceDrawer.Restrictions.Count, 1);
            List <AssetReferenceUIRestrictionSurrogate> restrictions = m_AssetReferenceDrawer.Restrictions;

            Assert.True(restrictions.First().ToString().Contains("HD"));
        }
Ejemplo n.º 8
0
        public void SetUpForSubassetPerformanceTests(int numAtlasObjects, int numReferences, int selectedId)
        {
            // Drawer Setup
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            _subAssets             = new List <Object>();
            var atlas = SetUpSpriteAtlas(numAtlasObjects, out _subAssets);

            _property = SetupForSetSubAssets(atlas, numReferences, true);
            m_AssetReferenceDrawer.m_label          = new GUIContent("testSpriteReference");
            m_AssetReferenceDrawer.m_AssetRefObject = m_AssetReferenceDrawer.m_AssetRefObject;
            FieldInfo propertyFieldInfo = typeof(TestSubObjectsSpriteAtlas).GetField("testSpriteReference", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            m_AssetReferenceDrawer.SetSubAssets(_property, _subAssets[selectedId], propertyFieldInfo);
            m_AssetReferenceDrawer.GatherFilters(_property);
        }
Ejemplo n.º 9
0
        public void CanRestrictInNestedClass()
        {
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            TestObjectWithRestrictedRefInNestedClass obj = ScriptableObject.CreateInstance <TestObjectWithRestrictedRefInNestedClass>();
            var so           = new SerializedObject(obj);
            var oneLevelProp = so.FindProperty("OneLevelNested.ReferenceInNestedClass");

            m_AssetReferenceDrawer.GatherFilters(oneLevelProp);
            Assert.True(m_AssetReferenceDrawer.Restrictions.First().ToString().Contains("HD"));

            var twoLevelProp = so.FindProperty("TwoLevelNested.OneLevelNested.ReferenceInNestedClass");

            m_AssetReferenceDrawer.GatherFilters(twoLevelProp);
            Assert.True(m_AssetReferenceDrawer.Restrictions.First().ToString().Contains("HD"));
        }
Ejemplo n.º 10
0
        public void CanRestrictMultipleLabels()
        {
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            TestObjectWithRestrictedRefByMultipleLabels obj = ScriptableObject.CreateInstance <TestObjectWithRestrictedRefByMultipleLabels>();
            var so       = new SerializedObject(obj);
            var property = so.FindProperty("ReferenceMultiple");

            m_AssetReferenceDrawer.GatherFilters(property);
            List <AssetReferenceUIRestrictionSurrogate> restrictions = m_AssetReferenceDrawer.Restrictions;
            string restriction = restrictions.First().ToString();

            Assert.True(restriction.Contains("HDR"));
            Assert.True(restriction.Contains("test"));
            Assert.True(restriction.Contains("default"));
        }
Ejemplo n.º 11
0
        public SerializedProperty SetupForSetSubAssetsList(SpriteAtlas spriteAtlas,
                                                           int numReferences,
                                                           int selectedElement,
                                                           int numElements    = 1,
                                                           bool setReferences = true,
                                                           int numToSet       = -1)
        {
            // Setup AssetReference selected
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            var assetPath            = AssetDatabase.GetAssetOrScenePath(spriteAtlas);
            var atlasGuid            = AssetDatabase.AssetPathToGUID(assetPath);
            AssetReferenceSprite sar = new AssetReferenceSprite(atlasGuid);

            // Default to preset all references
            if (setReferences && numToSet == -1)
            {
                numToSet = numReferences - 1;
            }

            // Select one element per reference array as a targetObject
            var targetObjects = new Object[numElements];

            for (int refIdx = 0; refIdx < numReferences; refIdx++)
            {
                var testScriptable = TestSubObjectsSpriteAtlasList.CreateInstance <TestSubObjectsSpriteAtlasList>();
                testScriptable.testSpriteReference = new AssetReferenceSprite[numElements];

                // Preset reference array elements for certain tests
                if (setReferences && refIdx <= numToSet)
                {
                    for (int i = 0; i < numElements; i++)
                    {
                        AssetReferenceSprite ar = new AssetReferenceSprite(atlasGuid);
                        testScriptable.testSpriteReference[i] = ar;
                        testScriptable.testSpriteReference[i].SubObjectName = "test";
                    }
                }

                var serialObj = new SerializedObject(testScriptable);
                var serProp   = serialObj.FindProperty("testSpriteReference.Array.data[" + selectedElement + "]");
                targetObjects[refIdx] = serProp.serializedObject.targetObject;
            }

            // Get main property to pass to AssetReferenceDrawer
            var property = SetupPropertyDrawerSetListTests(targetObjects, sar, selectedElement);

            return(property);
        }
Ejemplo n.º 12
0
        public void AssetReferenceDrawer_HandleDragAndDrop_CanRecognizeNonAddressableInAddressableFolder()
        {
            // ScriptableObject property and Drawer setup
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            m_AssetReferenceDrawer.m_AssetRefObject = new AssetReference();
            TestObjectWithRestrictedRef obj = ScriptableObject.CreateInstance <TestObjectWithRestrictedRef>();
            var so           = new SerializedObject(obj);
            var propertyName = "Reference";
            var property     = so.FindProperty(propertyName);

            // Group setup
            string groupName = "TestGroup";

            Settings.CreateGroup(groupName, false, false, false, null);

            // Asset setup
            var newEntryPath = ConfigFolder + "/test" + "/test.prefab";
            var folderGuid   = CreateTestPrefabAddressable(newEntryPath);
            var newAssetGuid = AssetDatabase.AssetPathToGUID(newEntryPath);

            Settings.CreateOrMoveEntry(folderGuid, Settings.groups[2]);
            Directory.CreateDirectory("Assets/AddressableAssetsData");
            AddressableAssetSettingsDefaultObject.Settings = Settings;

            // Test
            m_AssetReferenceDrawer.DragAndDropNotFromAddressableGroupWindow(newEntryPath, newAssetGuid, property, Settings);
            var newentry = Settings.FindAssetEntry(newAssetGuid);

            Assert.IsNull(newentry);
            Assert.AreEqual(m_AssetReferenceDrawer.m_AssetRefObject.AssetGUID, newAssetGuid);

            // Cleanup
            Settings.RemoveAssetEntry(AssetDatabase.AssetPathToGUID(newEntryPath));
            Settings.RemoveAssetEntry(folderGuid);
            Settings.RemoveGroup(Settings.groups[2]);
            if (Directory.Exists(ConfigFolder + "/test"))
            {
                AssetDatabase.DeleteAsset(ConfigFolder + "/test");
            }
            m_AssetReferenceDrawer = null;
        }
Ejemplo n.º 13
0
        public void AssetReferenceDrawer_IsAssetPathInAddressableDirectory_PathInAddressableFolder()
        {
            // Asset setup
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            string assetName    = "";
            var    newEntryPath = ConfigFolder + "/test" + "/test.prefab";
            var    folderGuid   = CreateTestPrefabAddressable(newEntryPath);

            // Test
            Assert.IsTrue(Settings.IsAssetPathInAddressableDirectory(newEntryPath, out assetName));
            Assert.AreEqual(assetName, newEntryPath);

            // Cleanup
            Settings.RemoveAssetEntry(AssetDatabase.AssetPathToGUID(newEntryPath));
            Settings.RemoveAssetEntry(folderGuid);
            if (Directory.Exists(ConfigFolder + "/test"))
            {
                AssetDatabase.DeleteAsset(ConfigFolder + "/test");
            }
            m_AssetReferenceDrawer = null;
        }
Ejemplo n.º 14
0
        public SerializedProperty SetupForSetSubAssets(SpriteAtlas spriteAtlas, int numReferences, bool setReferences = true, int numToSet = -1)
        {
            // Setup AssetReference selected
            m_AssetReferenceDrawer = new AssetReferenceDrawer();
            var assetPath           = AssetDatabase.GetAssetOrScenePath(spriteAtlas);
            var atlasGuid           = AssetDatabase.AssetPathToGUID(assetPath);
            AssetReferenceSprite ar = new AssetReferenceSprite(atlasGuid);

            // Setup property
            if (numToSet == -1)
            {
                numToSet = numReferences - 1;
            }
            var targetObjects = new Object[numReferences];

            for (int i = 0; i < numReferences; i++)
            {
                var testScriptable = TestSubObjectsSpriteAtlas.CreateInstance <TestSubObjectsSpriteAtlas>();

                // Preset references for certain tests
                if (setReferences && i <= numToSet)
                {
                    testScriptable.testSpriteReference = ar;
                }
                targetObjects[i] = testScriptable;
            }
            var so       = new SerializedObject(targetObjects);
            var property = so.FindProperty("testSpriteReference");

            m_AssetReferenceDrawer.GatherFilters(property);
            Directory.CreateDirectory("Assets/AddressableAssetsData");
            AddressableAssetSettingsDefaultObject.Settings = Settings;
            m_AssetReferenceDrawer.m_AssetRefObject        = ar;
            m_AssetReferenceDrawer.m_label = new GUIContent("testSpriteReference");
            return(property);
        }
Ejemplo n.º 15
0
 internal TestAssetReferencePopup(AssetReferenceDrawer drawer, string guid, string nonAddressedAsset)
     : base(drawer, guid, nonAddressedAsset)
 {
 }
Ejemplo n.º 16
0
 internal void TreeSetup(TreeViewState treeState, AssetReferenceDrawer testARD, AssetReferencePopup popup)
 {
     _testTree = new TestSelectionTree(treeState, testARD, popup, "testtree", "");
     _testTree.Reload();
 }
Ejemplo n.º 17
0
 internal TestSelectionTree(TreeViewState state, AssetReferenceDrawer drawer,
                            AssetReferencePopup popup, string guid, string nonAddressedAsset)
     : base(state, drawer, popup, guid, nonAddressedAsset)
 {
 }