Esempio n. 1
0
        public VolumeEffect GenerateEffectData(AmplifyColorBase go)
        {
            VolumeEffect volumeEffect = new VolumeEffect(go);

            foreach (VolumeEffectComponentFlags volumeEffectComponentFlags in this.components)
            {
                if (volumeEffectComponentFlags.blendFlag)
                {
                    Component component = go.GetComponent(volumeEffectComponentFlags.componentName);
                    if (component != null)
                    {
                        volumeEffect.AddComponent(component, volumeEffectComponentFlags);
                    }
                }
            }
            return(volumeEffect);
        }
        public VolumeEffect GenerateEffectData(AmplifyColorBase go)
        {
            VolumeEffect result = new VolumeEffect(go);

            foreach (VolumeEffectComponentFlags compFlags in components)
            {
                if (!compFlags.blendFlag)
                {
                    continue;
                }

                Component c = go.GetComponent(compFlags.componentName);
                if (c != null)
                {
                    result.AddComponent(c, compFlags);
                }
            }
            return(result);
        }
        public void UpdateVolume()
        {
            if (gameObject == null)
            {
                return;
            }

            VolumeEffectFlags effectFlags = gameObject.EffectFlags;

            foreach (VolumeEffectComponentFlags compFlags in effectFlags.components)
            {
                if (!compFlags.blendFlag)
                {
                    continue;
                }

                Component c = gameObject.GetComponent(compFlags.componentName);
                if (c != null)
                {
                    AddComponent(c, compFlags);
                }
            }
        }
    void DrawVolumeEffectFields(AmplifyColorVolume volume)
    {
        List <VolumeEffect> effectsToDelete = new List <VolumeEffect>();
        float removeButtonSize = 16;

        List <NewLineContainer> volumeLines = null;

        if (!(newLines.TryGetValue(volume, out volumeLines)))
        {
            volumeLines = newLines[volume] = new List <NewLineContainer>();
        }

        GUIStyle minusStyle = new GUIStyle(( GUIStyle )"OL Minus");
        GUIStyle plusStyle  = new GUIStyle(( GUIStyle )"OL Plus");

        minusStyle.margin.top = 2;
        plusStyle.margin.top  = 2;

        #region CurrentEffectFields
        int fieldPosition = 0;
        foreach (VolumeEffect effectVol in volume.EffectContainer.volumes)
        {
            if (effectVol.gameObject == null)
            {
                continue;
            }

            AmplifyColorBase             effect        = effectVol.gameObject;
            List <VolumeEffectComponent> compsToDelete = new List <VolumeEffectComponent>();

            foreach (VolumeEffectComponent comp in effectVol.components)
            {
                Component c = effect.GetComponent(comp.componentName);
                if (c == null)
                {
                    continue;
                }

                List <VolumeEffectField>           fieldsToDelete = new List <VolumeEffectField>();
                List <KeyValuePair <string, int> > fieldsToAdd    = new List <KeyValuePair <string, int> >();

                foreach (VolumeEffectField field in comp.fields)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("", GUILayout.MinWidth(minIndentWidth), GUILayout.MaxWidth(maxIndentWidth));
                    GUILayout.Space(0);

                    if (GUILayout.Button("", minusStyle, GUILayout.MinWidth(18), GUILayout.MaxWidth(18), GUILayout.Height(20)))
                    {
                        fieldsToDelete.Add(field);
                    }

                    AmplifyColorBase[]      effectArray = Resources.FindObjectsOfTypeAll(typeof(AmplifyColorBase)) as AmplifyColorBase[];
                    List <AmplifyColorBase> effectList  = effectArray.ToList();
                    int selectedEffect = -1;

                    if (effectArray.Count() > 0)
                    {
                        int popupSelected = effectList.IndexOf(effect);
                        selectedEffect = EditorGUILayout.Popup(popupSelected, (from e in effectList select e.gameObject.name).ToArray(), GUILayout.MinWidth(minColumnWidth), GUILayout.MaxWidth(maxColumnWidth));
                        if (selectedEffect != popupSelected)
                        {
                            fieldsToDelete.Add(field);
                            dirtyVolumeFlags = true;
                            volumeLines.Add(new NewLineContainer(effectList.ElementAtOrDefault(selectedEffect)));
                        }
                    }

                    Component[]   compArray      = VolumeEffect.ListAcceptableComponents(effectVol.gameObject);
                    List <string> compFlagsArray = compArray.Select(s => s.GetType().Name).ToList();
                    compFlagsArray.Remove(comp.componentName);
                    string[] compNamesArray = new string[] { comp.componentName }.Concat(compFlagsArray).ToArray();
                    int      selectedComponent = 0;
                    selectedComponent = EditorGUILayout.Popup(selectedComponent, compNamesArray, GUILayout.MinWidth(minColumnWidth), GUILayout.MaxWidth(maxColumnWidth));
                    if (selectedComponent != 0)
                    {
                        volumeLines.Add(new NewLineContainer(effect, compNamesArray[selectedComponent]));
                        fieldsToDelete.Add(field);
                        dirtyVolumeFlags = true;
                    }

                    FieldInfo[] fieldArray      = VolumeEffectComponent.ListAcceptableFields(c);
                    string[]    fieldFlagsArray = fieldArray.Select(s => s.Name).ToArray();
                    string[]    fieldNamesArray = comp.GetFieldNames();
                    fieldFlagsArray = fieldFlagsArray.Except(fieldNamesArray).ToArray();

                    List <string> names = new List <string>();
                    names.Add(field.fieldName);
                    names.AddRange(fieldFlagsArray);
                    for (int i = 0; i < names.Count; i++)
                    {
                        if (i == 0)
                        {
                            continue;
                        }

                        FieldInfo fi = Array.Find(fieldArray, s => (names[i] == s.Name));
                        if (fi != null)
                        {
                            names[i] += " : " + fi.FieldType.Name;
                        }
                    }

                    int selectedField = 0;
                    selectedField = EditorGUILayout.Popup(selectedField, names.ToArray(), GUILayout.MinWidth(minColumnWidth), GUILayout.MaxWidth(maxColumnWidth));
                    if (selectedField != 0)
                    {
                        fieldsToAdd.Add(new KeyValuePair <string, int>(fieldFlagsArray[selectedField - 1], fieldPosition));
                        fieldsToDelete.Add(field);
                        dirtyVolumeFlags = true;
                    }
                    fieldPosition++;

                    switch (field.fieldType)
                    {
                    case "System.Single": field.valueSingle = EditorGUILayout.FloatField(field.valueSingle, GUILayout.MinWidth(minValueWidth), GUILayout.MaxWidth(maxValueWidth)); break;

                    case "System.Boolean": field.valueBoolean = EditorGUILayout.Toggle("", field.valueBoolean, GUILayout.MinWidth(minValueWidth), GUILayout.MaxWidth(maxValueWidth)); break;

                    case "UnityEngine.Vector2": field.valueVector2 = EditorGUILayout.Vector2Field("", field.valueVector2, GUILayout.MinWidth(minValueWidth), GUILayout.MaxWidth(maxValueWidth), GUILayout.MaxHeight(16)); break;

                    case "UnityEngine.Vector3": field.valueVector3 = EditorGUILayout.Vector3Field("", field.valueVector3, GUILayout.MinWidth(minValueWidth), GUILayout.MaxWidth(maxValueWidth), GUILayout.MaxHeight(16)); break;

                    case "UnityEngine.Vector4": field.valueVector4 = DrawFixedVector4Field(field.valueVector4); break;

                    case "UnityEngine.Color": field.valueColor = EditorGUILayout.ColorField(field.valueColor, GUILayout.MinWidth(minValueWidth), GUILayout.MaxWidth(maxValueWidth)); break;

                    default: EditorGUILayout.LabelField(field.fieldType, GUILayout.MinWidth(minValueWidth), GUILayout.MaxWidth(maxValueWidth)); break;
                    }

                    // COPY TO CLIPBOARD
                    string luid   = NewLineContainer.GenerateUniqueID(effect, comp.componentName, field.fieldName);
                    bool   copied = copyLines.ContainsKey(luid);
                    bool   keep   = GUILayout.Toggle(copied, "c", removeButtonStyle, GUILayout.Width(removeButtonSize), GUILayout.Height(removeButtonSize));
                    if (keep != copied)
                    {
                        if (keep)
                        {
                            object valueCopy = null;
                            switch (field.fieldType)
                            {
                            case "System.Single": valueCopy = field.valueSingle; break;

                            case "System.Boolean": valueCopy = field.valueBoolean; break;

                            case "UnityEngine.Vector2": valueCopy = field.valueVector2; break;

                            case "UnityEngine.Vector3": valueCopy = field.valueVector3; break;

                            case "UnityEngine.Vector4": valueCopy = field.valueVector4; break;

                            case "UnityEngine.Color": valueCopy = field.valueColor; break;
                            }
                            copyLines.Add(luid, new NewLineContainer(effect, comp.componentName, field.fieldName, field.fieldType, valueCopy));
                        }
                        else
                        {
                            copyLines.Remove(luid);
                        }

                        //Debug.Log( "CopyComplete: " + luid + ", " + keep + ", " + volume.name );
                    }

                    EditorGUILayout.EndHorizontal();
                    GUILayout.Space(2);
                }

                bool fieldRemoved = false;
                foreach (VolumeEffectField field in fieldsToDelete)
                {
                    comp.RemoveEffectField(field);
                    fieldRemoved = true;
                }

                foreach (KeyValuePair <string, int> pair in fieldsToAdd)
                {
                    FieldInfo pi = c.GetType().GetField(pair.Key);
                    if (pi != null)
                    {
                        comp.AddField(pi, c, pair.Value);
                    }
                }

                if (fieldRemoved && comp.fields.Count <= 0)
                {
                    compsToDelete.Add(comp);
                }
            }

            bool compRemoved = false;
            foreach (VolumeEffectComponent comp in compsToDelete)
            {
                effectVol.RemoveEffectComponent(comp);
                compRemoved = true;
            }

            if (compRemoved && effectVol.components.Count <= 0)
            {
                effectsToDelete.Add(effectVol);
            }
        }

        foreach (VolumeEffect effectVol in effectsToDelete)
        {
            volume.EffectContainer.RemoveVolumeEffect(effectVol);
        }
        #endregion

        #region NewLines
        List <NewLineContainer> linesToDelete = new List <NewLineContainer>();
        foreach (NewLineContainer line in volumeLines)
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.MinWidth(minIndentWidth), GUILayout.MaxWidth(maxIndentWidth));
            GUILayout.Space(0);

            if (GUILayout.Button("", minusStyle, GUILayout.MinWidth(18), GUILayout.MaxWidth(18), GUILayout.Height(20)))
            {
                linesToDelete.Add(line);
            }

            AmplifyColorBase[]      colorEffectArray = Resources.FindObjectsOfTypeAll(typeof(AmplifyColorBase)) as AmplifyColorBase[];
            List <AmplifyColorBase> colorEffectList  = colorEffectArray.ToList();

            if (colorEffectArray.Count() > 0)
            {
                int           popupSelected  = (line.camera != null) ? colorEffectList.IndexOf(line.camera) + 1 : 0;
                int           selectedEffect = popupSelected;
                List <string> names          = (from e in colorEffectList select e.gameObject.name).ToList <string>();
                names.Insert(0, "<Camera>");
                selectedEffect = EditorGUILayout.Popup(selectedEffect, names.ToArray(), GUILayout.MinWidth(minColumnWidth), GUILayout.MaxWidth(maxColumnWidth));
                if (selectedEffect != popupSelected && selectedEffect > 0)
                {
                    line.SetCamera(colorEffectArray[selectedEffect - 1]);
                }
            }

            VolumeEffect effectVol = null;
            if (line.camera != null)
            {
                effectVol = volume.EffectContainer.GetVolumeEffect(line.camera);
            }

            if (line.camera != null)
            {
                Component[]   compArray     = VolumeEffect.ListAcceptableComponents(line.camera);
                List <string> names         = compArray.Select(s => s.GetType().Name).ToList <string>();
                int           popupSelected = names.IndexOf(line.component) + 1;
                names.Insert(0, "<Component>");
                int selectedComponent = popupSelected;
                selectedComponent = EditorGUILayout.Popup(selectedComponent, names.ToArray(), GUILayout.MinWidth(minColumnWidth), GUILayout.MaxWidth(maxColumnWidth));
                if (selectedComponent != popupSelected)
                {
                    line.SetComponent(selectedComponent == 0 ? null : names[selectedComponent]);
                }
            }
            else
            {
                GUI.enabled = false;
                EditorGUILayout.Popup(0, new string[] { "<Component>" }, GUILayout.MaxWidth(maxColumnWidth));
                GUI.enabled = true;
            }

            Component c = (line.camera == null) ? null : line.camera.GetComponent(line.component);

            VolumeEffectComponent comp = null;
            if (effectVol != null)
            {
                comp = effectVol.GetEffectComponent(line.component);
            }

            if (c != null)
            {
                FieldInfo[] fieldArray      = VolumeEffectComponent.ListAcceptableFields(c);
                string[]    fieldFlagsArray = fieldArray.Select(s => s.Name).ToArray();
                if (comp != null)
                {
                    string[] fieldNamesArray = comp.GetFieldNames();
                    fieldFlagsArray = fieldFlagsArray.Except(fieldNamesArray).ToArray();
                }

                List <string> names = fieldFlagsArray.ToList();
                for (int i = 0; i < names.Count; i++)
                {
                    FieldInfo fi = Array.Find(fieldArray, s => (names[i] == s.Name));
                    if (fi != null)
                    {
                        names[i] += " : " + fi.FieldType.Name;
                    }
                }
                names.Insert(0, "<Field>");

                int selectedField = 0;
                selectedField = EditorGUILayout.Popup(selectedField, names.ToArray(), GUILayout.MinWidth(minColumnWidth), GUILayout.MaxWidth(maxColumnWidth));
                if (selectedField > 0)
                {
                    FieldInfo pi = c.GetType().GetField(fieldFlagsArray[selectedField - 1]);
                    if (pi != null)
                    {
                        if (effectVol == null)
                        {
                            effectVol = volume.EffectContainer.AddJustColorEffect(line.camera);
                        }

                        if (comp == null)
                        {
                            comp = effectVol.AddComponent(c, null);
                        }

                        comp.AddField(pi, c);
                        linesToDelete.Add(line);
                        dirtyVolumeFlags = true;
                    }
                }

                EditorGUILayout.LabelField("", GUILayout.MinWidth(minValueWidth), GUILayout.MaxWidth(maxValueWidth));
            }
            else
            {
                GUI.enabled = false;
                EditorGUILayout.Popup(0, new string[] { "<Field>" }, GUILayout.MaxWidth(maxColumnWidth));
                EditorGUILayout.TextField("", GUILayout.MinWidth(minValueWidth), GUILayout.MaxWidth(maxValueWidth));
                GUI.enabled = true;
            }

            if (line.camera != null)
            {
                string luid   = NewLineContainer.GenerateUniqueID(line.camera, line.component, line.fieldName);
                bool   copied = copyLines.ContainsKey(luid);
                bool   keep   = GUILayout.Toggle(copied, "c", removeButtonStyle, GUILayout.Width(removeButtonSize), GUILayout.Height(removeButtonSize));
                if (keep != copied)
                {
                    if (keep)
                    {
                        copyLines.Add(luid, new NewLineContainer(line.camera, line.component, line.fieldName, line.fieldType, line.value));
                    }
                    else
                    {
                        copyLines.Remove(luid);
                    }

                    //Debug.Log( "CopyIncomplete: " + luid + ", " + keep + ", " + volume.name );
                }
            }
            else
            {
                GUI.enabled = false;
                GUILayout.Button("c", removeButtonStyle, GUILayout.Width(removeButtonSize), GUILayout.Height(removeButtonSize));
                GUI.enabled = true;
            }

            EditorGUILayout.EndHorizontal();
            GUILayout.Space(2);
        }

        foreach (NewLineContainer line in linesToDelete)
        {
            copyLines.Remove(line.GenerateUniqueID());
            //Debug.Log( "Removed " + line.GenerateUniqueID() );
            volumeLines.Remove(line);
        }
        #endregion

        #region AddPaste
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("", GUILayout.MinWidth(minIndentWidth), GUILayout.MaxWidth(maxIndentWidth));
        GUILayout.Space(0);

        bool add = GUILayout.Button("", plusStyle, GUILayout.MinWidth(18), GUILayout.MaxWidth(18), GUILayout.Height(20));
        if (add || GUILayout.Button("Add New", GUILayout.MinWidth(minColumnWidth), GUILayout.MaxWidth(maxColumnWidth), GUILayout.Height(20)))
        {
            volumeLines.Add(new NewLineContainer());
        }

        GUI.enabled = (copyLines.Count > 0);
        if (GUILayout.Button("Paste", GUILayout.MinWidth(minColumnWidth), GUILayout.MaxWidth(maxColumnWidth), GUILayout.Height(20)))
        {
            foreach (var pair in copyLines)
            {
                NewLineContainer line = pair.Value;
                Component        c    = (line.camera == null) ? null : line.camera.GetComponent(line.component);
                FieldInfo        pi   = (c != null) ? c.GetType().GetField(line.fieldName) : null;

                if (pi == null)
                {
                    volumeLines.Add(new NewLineContainer(line.camera, line.component, line.fieldName, line.fieldType, line.value));
                }
                else
                {
                    VolumeEffect effectVol = volume.EffectContainer.GetVolumeEffect(line.camera);
                    if (effectVol == null)
                    {
                        effectVol = volume.EffectContainer.AddJustColorEffect(line.camera);
                    }

                    VolumeEffectComponent comp = effectVol.GetEffectComponent(line.component);
                    if (comp == null)
                    {
                        comp = effectVol.AddComponent(c, null);
                    }

                    VolumeEffectField field = comp.GetEffectField(line.fieldName);
                    if (field == null)
                    {
                        field = comp.AddField(pi, c);
                    }
                    else
                    {
                        Debug.LogWarning("[AmplifyColor] Blend Effect field already added to Volume " + volume.name + ".");
                    }

                    field.UpdateValue(line.value);
                }
            }

            dirtyVolumeFlags = true;
        }
        GUI.enabled = true;

        EditorGUILayout.EndHorizontal();
        GUILayout.Space(5);
        #endregion
    }
	public VolumeEffect GenerateEffectData( AmplifyColorBase go )
	{
		VolumeEffect result = new VolumeEffect( go );
		foreach ( VolumeEffectComponentFlags compFlags in components )
		{
			if ( !compFlags.blendFlag )
				continue;

			Component c = go.GetComponent( compFlags.componentName );
			if ( c != null )
				result.AddComponent( c, compFlags );
		}
		return result;
	}