Exemple #1
0
        public void BlendValues(AmplifyColorEffect targetColor, VolumeEffect other, float blendAmount)
        {
            VolumeEffectFlags effectFlags = targetColor.EffectFlags;
            GameObject        go          = targetColor.gameObject;

            for (int comp = 0; comp < effectFlags.components.Count; comp++)
            {
                VolumeEffectComponentFlags compFlags = effectFlags.components[comp];
                if (!compFlags.blendFlag)
                {
                    continue;
                }

                Component             c               = go.GetComponent(compFlags.componentName);
                VolumeEffectComponent effectComp      = FindEffectComponent(compFlags.componentName);
                VolumeEffectComponent effectCompOther = other.FindEffectComponent(compFlags.componentName);
                if (c == null || effectComp == null || effectCompOther == null)
                {
                    continue;
                }

                for (int i = 0; i < compFlags.componentFields.Count; i++)
                {
                    VolumeEffectFieldFlags fieldFlags = compFlags.componentFields[i];
                    if (!fieldFlags.blendFlag)
                    {
                        continue;
                    }

#if !UNITY_EDITOR && UNITY_METRO
                    FieldInfo fi = c.GetType().GetRuntimeField(fieldFlags.fieldName);
#else
                    FieldInfo fi = c.GetType().GetField(fieldFlags.fieldName);
#endif
                    VolumeEffectField effectField      = effectComp.FindEffectField(fieldFlags.fieldName);
                    VolumeEffectField effectFieldOther = effectCompOther.FindEffectField(fieldFlags.fieldName);

                    if (fi == null || effectField == null || effectFieldOther == null)
                    {
                        continue;
                    }

                    switch (fi.FieldType.FullName)
                    {
                    case "System.Single": fi.SetValue(c, Mathf.Lerp(effectField.valueSingle, effectFieldOther.valueSingle, blendAmount)); break;

                    case "System.Boolean": fi.SetValue(c, effectFieldOther.valueBoolean); break;

                    case "UnityEngine.Vector2": fi.SetValue(c, Vector2.Lerp(effectField.valueVector2, effectFieldOther.valueVector2, blendAmount)); break;

                    case "UnityEngine.Vector3": fi.SetValue(c, Vector3.Lerp(effectField.valueVector3, effectFieldOther.valueVector3, blendAmount)); break;

                    case "UnityEngine.Vector4": fi.SetValue(c, Vector4.Lerp(effectField.valueVector4, effectFieldOther.valueVector4, blendAmount)); break;

                    case "UnityEngine.Color": fi.SetValue(c, Color.Lerp(effectField.valueColor, effectFieldOther.valueColor, blendAmount)); break;
                    }
                }
            }
        }
Exemple #2
0
 public void UpdateComponent(Component c, VolumeEffectComponentFlags compFlags)
 {
     using (List <VolumeEffectFieldFlags> .Enumerator enumerator = compFlags.componentFields.GetEnumerator())
     {
         while (enumerator.MoveNext())
         {
             VolumeEffectFieldFlags fieldFlags = enumerator.Current;
             if (fieldFlags.blendFlag && !this.fields.Exists((VolumeEffectField s) => s.fieldName == fieldFlags.fieldName))
             {
                 FieldInfo         field             = c.GetType().GetField(fieldFlags.fieldName);
                 VolumeEffectField volumeEffectField = VolumeEffectField.IsValidType(field.FieldType.FullName) ? new VolumeEffectField(field, c) : null;
                 if (volumeEffectField != null)
                 {
                     this.fields.Add(volumeEffectField);
                 }
             }
         }
     }
 }
Exemple #3
0
        public void BlendValues(AmplifyColorBase targetColor, VolumeEffect other, float blendAmount)
        {
            VolumeEffectFlags effectFlags = targetColor.EffectFlags;
            GameObject        gameObject  = targetColor.gameObject;

            for (int i = 0; i < effectFlags.components.Count; i++)
            {
                VolumeEffectComponentFlags volumeEffectComponentFlags = effectFlags.components[i];
                if (volumeEffectComponentFlags.blendFlag)
                {
                    Component             component              = gameObject.GetComponent(volumeEffectComponentFlags.componentName);
                    VolumeEffectComponent volumeEffectComponent  = this.FindEffectComponent(volumeEffectComponentFlags.componentName);
                    VolumeEffectComponent volumeEffectComponent2 = other.FindEffectComponent(volumeEffectComponentFlags.componentName);
                    if (!(component == null) && volumeEffectComponent != null && volumeEffectComponent2 != null)
                    {
                        for (int j = 0; j < volumeEffectComponentFlags.componentFields.Count; j++)
                        {
                            VolumeEffectFieldFlags volumeEffectFieldFlags = volumeEffectComponentFlags.componentFields[j];
                            if (volumeEffectFieldFlags.blendFlag)
                            {
                                FieldInfo         field              = component.GetType().GetField(volumeEffectFieldFlags.fieldName);
                                VolumeEffectField volumeEffectField  = volumeEffectComponent.FindEffectField(volumeEffectFieldFlags.fieldName);
                                VolumeEffectField volumeEffectField2 = volumeEffectComponent2.FindEffectField(volumeEffectFieldFlags.fieldName);
                                if (field != null && volumeEffectField != null && volumeEffectField2 != null)
                                {
                                    string fullName = field.FieldType.FullName;
                                    if (fullName != null)
                                    {
                                        if (!(fullName == "System.Single"))
                                        {
                                            if (!(fullName == "System.Boolean"))
                                            {
                                                if (!(fullName == "UnityEngine.Vector2"))
                                                {
                                                    if (!(fullName == "UnityEngine.Vector3"))
                                                    {
                                                        if (!(fullName == "UnityEngine.Vector4"))
                                                        {
                                                            if (fullName == "UnityEngine.Color")
                                                            {
                                                                field.SetValue(component, Color.Lerp(volumeEffectField.valueColor, volumeEffectField2.valueColor, blendAmount));
                                                            }
                                                        }
                                                        else
                                                        {
                                                            field.SetValue(component, Vector4.Lerp(volumeEffectField.valueVector4, volumeEffectField2.valueVector4, blendAmount));
                                                        }
                                                    }
                                                    else
                                                    {
                                                        field.SetValue(component, Vector3.Lerp(volumeEffectField.valueVector3, volumeEffectField2.valueVector3, blendAmount));
                                                    }
                                                }
                                                else
                                                {
                                                    field.SetValue(component, Vector2.Lerp(volumeEffectField.valueVector2, volumeEffectField2.valueVector2, blendAmount));
                                                }
                                            }
                                            else
                                            {
                                                field.SetValue(component, volumeEffectField2.valueBoolean);
                                            }
                                        }
                                        else
                                        {
                                            field.SetValue(component, Mathf.Lerp(volumeEffectField.valueSingle, volumeEffectField2.valueSingle, blendAmount));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }