Ejemplo n.º 1
0
        public void TryGetValueWorks_ForMultipleIdenticalValues()
        {
            var decl   = ScriptableObject.CreateInstance <ValueDeclaration>();
            var usages = new[]
            {
                ScriptableObject.CreateInstance <ValueUsage>(),
                ScriptableObject.CreateInstance <ValueUsage>(),
            };
            var soDecl  = new SerializedObject(decl);
            var serDecl = new SerializedScalableSetting(soDecl.FindProperty(nameof(ValueDeclaration.intValue)));

            var soUsage  = new SerializedObject(usages);
            var serUsage = new SerializedScalableSettingValue(soUsage.FindProperty(nameof(ValueUsage.intValue)));

            // Same level values
            usages[0].intValue.useOverride = false;
            usages[0].intValue.level       = 1;
            usages[1].intValue.useOverride = false;
            usages[1].intValue.level       = 1;
            soUsage.SetIsDifferentCacheDirty();
            soUsage.Update();

            Assert.False(serUsage.hasMultipleValues);
            Assert.True(serUsage.TryGetValue(serDecl, out int v));
            Assert.AreEqual(2, v);

            Assert.True(serUsage.TryGetValue(decl.intValue, out v));
            Assert.AreEqual(2, v);

            // Same override value
            usages[0].intValue.useOverride = true;
            usages[0].intValue.@override   = 5;
            usages[0].intValue.level       = 1;
            usages[1].intValue.useOverride = true;
            usages[1].intValue.@override   = 5;
            // Explicitly have a different level here
            // It must not matter
            usages[1].intValue.level = 2;
            soUsage.SetIsDifferentCacheDirty();
            soUsage.Update();

            Assert.False(serUsage.hasMultipleValues);
            Assert.True(serUsage.TryGetValue(serDecl, out v));
            Assert.AreEqual(5, v);

            Assert.True(serUsage.TryGetValue(decl.intValue, out v));
            Assert.AreEqual(5, v);
        }
        public void TryGetValueWorks_ForMissingLevelValue()
        {
            var decl  = ScriptableObject.CreateInstance <ValueDeclaration>();
            var usage = ScriptableObject.CreateInstance <ValueUsage>();

            usage.intValue.useOverride = false;
            usage.intValue.level       = 10;

            var soDecl  = new SerializedObject(decl);
            var serDecl = new SerializedScalableSetting(soDecl.FindProperty(nameof(ValueDeclaration.intValue)));

            var soUsage  = new SerializedObject(usage);
            var serUsage = new SerializedScalableSettingValue(soUsage.FindProperty(nameof(ValueUsage.intValue)));

            Assert.False(serUsage.TryGetValue(serDecl, out int v));
            Assert.AreEqual(default(int), v);

            Assert.False(serUsage.TryGetValue(decl.intValue, out v));
            Assert.AreEqual(default(int), v);
        }
        public void TryGetValueWorks_ForOverrideValue()
        {
            var decl  = ScriptableObject.CreateInstance <ValueDeclaration>();
            var usage = ScriptableObject.CreateInstance <ValueUsage>();

            usage.intValue.useOverride = true;
            usage.intValue.@override   = 5;

            var soDecl  = new SerializedObject(decl);
            var serDecl = new SerializedScalableSetting(soDecl.FindProperty(nameof(ValueDeclaration.intValue)));

            var soUsage  = new SerializedObject(usage);
            var serUsage = new SerializedScalableSettingValue(soUsage.FindProperty(nameof(ValueUsage.intValue)));

            Assert.True(serUsage.TryGetValue(serDecl, out int v));
            Assert.AreEqual(5, v);

            Assert.True(serUsage.TryGetValue(decl.intValue, out v));
            Assert.AreEqual(5, v);
        }