Ejemplo n.º 1
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.º 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);
        }
Ejemplo n.º 3
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.º 4
0
        internal SerializedProperty SetupPropertyDrawerSetListTests(Object[] targetObjects, AssetReference ar, int selectedElement)
        {
            var so       = new SerializedObject(targetObjects);
            var property = so.FindProperty("testSpriteReference.Array.data[" + selectedElement + "]");

            m_AssetReferenceDrawer.GatherFilters(property);
            Directory.CreateDirectory("Assets/AddressableAssetsData");
            AddressableAssetSettingsDefaultObject.Settings = Settings;
            m_AssetReferenceDrawer.m_AssetRefObject        = ar;
            return(property);
        }
Ejemplo n.º 5
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.º 6
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.º 7
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.º 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 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);
        }