void GradientEditorSetter(string GradientName, string GradientLabel, MaterialColorSetter MaterialSetter)
    {
        VisualElement root = rootVisualElement;
        VisualElement gradientVisualElement = root.Q <VisualElement>(name: GradientName);

        if (gradientVisualElement != null)
        {
            GradientField    gradientField             = gradientVisualElement.Q <GradientField>();
            SerializedObject serialized_MaterialSetter = new SerializedObject(MaterialSetter);
            gradientField.bindingPath = "gradient";
            gradientField.Bind(serialized_MaterialSetter);
            gradientVisualElement.Q <Label>().text = GradientLabel;
        }
    }
Пример #2
0
    void FindElementsToEdit()
    {
        if (GameObject.Find("Lights Controller"))
        {
            TimeController = GameObject.Find("Lights Controller").GetComponent <LightColorController>();
        }

        if (GameObject.Find("Light - Sky") != null)
        {
            skyColorSetter = GameObject.Find("Light - Sky").GetComponent <MaterialColorSetter>();
        }

        if (GameObject.Find("Light - Ruin") != null)
        {
            RuinsColorSetter = GameObject.Find("Light - Ruin").GetComponent <MaterialColorSetter>();
        }

        if (GameObject.Find("Light Group - Tree Tops") != null)
        {
            TreesColorSetter = GameObject.Find("Light Group - Tree Tops").GetComponent <LightColorSetter>();
        }
        if (GameObject.Find("Vegetation Setter - Rim Color") != null)
        {
            RimColorSetter = GameObject.Find("Vegetation Setter - Rim Color").GetComponent <MaterialColorSetter>();
        }
        if (GameObject.Find("Light Group - Sun Spots - 1") != null)
        {
            SunSpot_Group = GameObject.Find("Light Group - Sun Spots - 1").GetComponent <LightColorSetter>();
            if (SunSpot_Group.gameObject.GetComponentsInChildren <Light2D>() != null)
            {
                SunSpots = SunSpot_Group.gameObject.GetComponentsInChildren <Light2D>();
            }
        }

        if (GameObject.Find("Light Group - Grass") != null)
        {
            GrassLight_Group = GameObject.Find("Light Group - Grass").GetComponent <LightColorSetter>();
            if (GrassLight_Group.gameObject.GetComponentInChildren <Light2D>() != null)
            {
                GrassLight = GrassLight_Group.gameObject.GetComponentInChildren <Light2D>();
            }
        }

        if (GameObject.Find("Light - Cave Hole - 1") != null)
        {
            CaveHoleLight = GameObject.Find("Light - Cave Hole - 1").GetComponent <Light2D>();
        }

        if (GameObject.Find("Light Group - Sun Spots - 1") != null)
        {
            GameObject SunSpotsHolder = GameObject.Find("Light Group - Sun Spots - 1");
            if (SunSpotsHolder.GetComponentsInChildren <Light2D>() != null)
            {
                SunSpots = SunSpotsHolder.GetComponentsInChildren <Light2D>();
            }
        }
        WindMaterials = Resources.Load <ScriptableWindMaterial>("WindMaterials").WindMaterials;

        if (GameObject.Find("Volume - Global") != null)
        {
            postprocessingVolume = GameObject.Find("Volume - Global").GetComponent <Volume>();

            postprocessingVolume.sharedProfile.TryGet(out whiteBalanceProperty);
            postprocessingVolume.sharedProfile.TryGet(out BloomProperty);
        }
        if (GameObject.Find("Particles_Glow") != null)
        {
            GlowParticleSystem = GameObject.Find("Particles_Glow").GetComponent <ParticleSystem>();
        }
    }
Пример #3
0
    void SetArtistTool()
    {
        VisualElement root = rootVisualElement;

        root.Clear();
        VisualTreeAsset ArtistToolVisualTree = Resources.Load <VisualTreeAsset>("ArtistTool");

        ArtistToolVisualTree.CloneTree(root);
        root.styleSheets.Add(Resources.Load <StyleSheet>("ArtistTool"));

        SerializedObject Tso        = new SerializedObject(TimeController);
        Slider           timeSlider = root.Q <Slider>(name: "Time");

        timeSlider.Bind(Tso);


        #region SkyColor
        VisualElement gradientVisualElement = root.Q <VisualElement>(name: "SkyGradient");

        if (gradientVisualElement != null)
        {
            GradientField gradientField = gradientVisualElement.Q <GradientField>();

            if (gradientField != null)
            {
                skyColorSetter = GameObject.Find("Light - Sky").GetComponent <MaterialColorSetter>();
                SerializedObject serialized_MaterialSetter = new SerializedObject(skyColorSetter);
                gradientField.bindingPath = "gradient";
                gradientField.Bind(serialized_MaterialSetter);
                gradientVisualElement.Q <Label>().text = "Sky Gradient";
            }
        }

        #endregion

        #region Ruins
        GradientEditorSetter("RuinsGradient", "Ruins Gradient", RuinsColorSetter);
        #endregion

        #region Trees
        GradientEditorSetter("TreesGradient", "Trees Gradient", TreesColorSetter);
        #endregion

        #region Rim
        GradientEditorSetter("RimColor", "Rim Gradient", RimColorSetter);
        #endregion



        #region Lights

        #region SunLights
        SerializedObject serialized_SunSpot = new SerializedObject(SunSpot_Group);

        VisualElement sunLightVisualElement = root.Q <VisualElement>(name: "Sunlight");
        if (sunLightVisualElement.Q <VisualElement>(name: "LightGradient") != null)
        {
            GradientField sunLightGradient  = sunLightVisualElement.Q <VisualElement>(name: "LightGradient").Q <GradientField>();
            FloatField    sunLightIntensity = root.Q <FloatField>(name: "Intensity");
            if (sunLightGradient != null)
            {
                sunLightGradient.bindingPath = "gradient";
                sunLightGradient.Bind(serialized_SunSpot);
                sunLightGradient.label = "Gradient";
            }

            sunLightIntensity.value = GetSpotLightIntensity();
            sunLightIntensity.RegisterCallback <ChangeEvent <float> >(ChangeIntensitySpotLightsEvent);
        }

        #endregion

        #region GrassLight
        SerializedObject serialized_GrassLight_Group = new SerializedObject(GrassLight_Group);

        VisualElement grassLightVisualElement = root.Q <VisualElement>(name: "GrassLight");
        if (grassLightVisualElement.Q <VisualElement>(name: "LightGradient") != null)
        {
            GradientField grassLightGradient  = grassLightVisualElement.Q <VisualElement>(name: "LightGradient").Q <GradientField>();
            FloatField    grassLightIntensity = grassLightVisualElement.Q <FloatField>(name: "Intensity");

            if (grassLightGradient != null)
            {
                grassLightGradient.bindingPath = "gradient";
                grassLightGradient.Bind(serialized_GrassLight_Group);
                grassLightGradient.label = "Gradient";
            }

            grassLightIntensity.value = GrassLight.intensity;

            SerializedObject serialized_GrassLight = new SerializedObject(GrassLight);
            grassLightIntensity.Bind(serialized_GrassLight);
        }
        #endregion

        #region cave Light
        SerializedObject serialized_CaveHoleLight = new SerializedObject(CaveHoleLight);

        VisualElement caveLightVisualElement = root.Q <VisualElement>(name: "CaveHoleLight");
        caveLightVisualElement.Q <FloatField>(name: "Falloff").Bind(serialized_CaveHoleLight);

        Slider     fallOffSlider = caveLightVisualElement.Q <Slider>(name: "FalloffIntencity");
        FloatField fallOffField  = fallOffSlider.Q <FloatField>(name: "CurrentValue");
        fallOffSlider.Bind(serialized_CaveHoleLight);

        fallOffField.SetValueWithoutNotify(CaveHoleLight.falloffIntensity);

        fallOffField.RegisterCallback <ChangeEvent <float> >((evt) => fallOffSlider.value = evt.newValue);

        fallOffSlider.RegisterCallback <ChangeEvent <float> >((evt) => fallOffField.SetValueWithoutNotify(evt.newValue));

        #endregion

        #region Visualisers
        var AllGradientElements = root.Query <GradientField>();
        AllGradientElements.ForEach((element) =>
        {
            //registerCallback for Gradient to apply changes on scene
            element.RegisterCallback <ChangeEvent <Gradient> >(ChangeGradientEvent);

            VisualElement visualiser = element.Q <VisualElement>(name: "VisualisationColor");

            //Init color of visualisation cube
            float currentTime = TimeController.timeValue;
            visualiser.style.backgroundColor = element.value.Evaluate(currentTime);

            //register Callback for each visualisation cube when gradient Changes
            element.RegisterCallback <ChangeEvent <Gradient> >((evt) =>
            {
                float timeOfChange = TimeController.timeValue;
                visualiser.style.backgroundColor = evt.newValue.Evaluate(currentTime);
            });

            //register Callback for each visualisation cube when Time Changes
            timeSlider.RegisterCallback <ChangeEvent <float> >((evt) =>
            {
                visualiser.style.backgroundColor = element.value.Evaluate(evt.newValue);
            });
        });
        #endregion

        #endregion

        #region Wind Shader
        // Set Initial Values
        VisualElement windComponent = root.Q <VisualElement>(name: "Wind");
        if (windComponent != null)
        {
            Vector4Field windDirectionQuaternion = windComponent.Q <Vector4Field>(name: "WindDirection");
            windDirectionQuaternion.value = GetWindDirection();

            FloatField windScaleFloat = windComponent.Q <FloatField>(name: "WindScale");
            windScaleFloat.value = GetWindScale();

            MinMaxValue minMaxStrength = GetWindStrength();

            VisualElement windStrengthHolder = windComponent.Q <VisualElement>(name: "WinStrengthHolder");

            MinMaxSlider windStrengthSlider = windStrengthHolder.Q <MinMaxSlider>(name: "WindStrength");
            windStrengthSlider.highLimit = minMaxStrength.HighLimit;
            windStrengthSlider.lowLimit  = minMaxStrength.LowLimit;
            windStrengthSlider.value     = new Vector2(minMaxStrength.minValue, minMaxStrength.maxValue);

            windStrengthHolder.Q <Label>(name: "MinValue").text = "Min Value :" + minMaxStrength.minValue;
            windStrengthHolder.Q <Label>(name: "MaxValue").text = "Max Value :" + minMaxStrength.maxValue;

            FloatField windSpeedFloat = windComponent.Q <FloatField>(name: "WindSpeed");
            windSpeedFloat.value = GetWindSpeed();

            //Set Callbacks values
            windDirectionQuaternion.RegisterCallback <ChangeEvent <Vector4> >(ChangeWindDirection);
            windScaleFloat.RegisterCallback <ChangeEvent <float> >(ChangeWindScale);
            windStrengthSlider.RegisterCallback <ChangeEvent <Vector2> >(ChangeWindStrength);
            windSpeedFloat.RegisterCallback <ChangeEvent <float> >(ChangeWindSpeed);
        }

        #endregion

        #region Postprocessing
        #region WhiteBalance
        //serialize White balance property
        SerializedObject serialized_whiteBalanceProperty = new SerializedObject(whiteBalanceProperty);
        //Get White balance Visual Element
        VisualElement whiteBalanceVisualElement = root.Q <VisualElement>(name: "WhiteBalance");

        #region Temperature
        //Get White Balance temperature Visual Element
        VisualElement whiteBalanceTemperatureVE = whiteBalanceVisualElement.Q <VisualElement>(name: "Temperature");

        //Get White Balance temperature Slider
        Slider whiteBalanceTemperatureSlider = whiteBalanceTemperatureVE.Q <Slider>(name: "SliderValue");

        //Bind Slider to value
        whiteBalanceTemperatureSlider.bindingPath = "temperature.m_Value";
        whiteBalanceTemperatureSlider.Bind(serialized_whiteBalanceProperty);

        //Get White Balance temperature Float Field
        FloatField whiteBalanceTemperatureFloat = whiteBalanceTemperatureVE.Q <FloatField>(name: "CurrentValue");
        //Set default Temperature
        whiteBalanceTemperatureFloat.SetValueWithoutNotify(whiteBalanceProperty.temperature.value);

        //Register change callback for the float field to change the slider value. Changing slider value will change the values bound with it.
        whiteBalanceTemperatureFloat.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTemperatureSlider.value = evt.newValue);

        //Register change Callback for the slider, to change the float fiel Without notification (to avoid triggering Float field callback)
        whiteBalanceTemperatureSlider.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTemperatureFloat.SetValueWithoutNotify(evt.newValue));
        #endregion

        #region Tint

        //Get White Balance Tint Visual Element
        VisualElement whiteBalanceTintVE = whiteBalanceVisualElement.Q <VisualElement>(name: "Tint");

        //Get White Balance Tint Slider
        Slider whiteBalanceTintSlider = whiteBalanceTintVE.Q <Slider>(name: "SliderValue");

        //Bind Slider to value
        whiteBalanceTintSlider.bindingPath = "tint.m_Value";
        whiteBalanceTintSlider.Bind(serialized_whiteBalanceProperty);

        //Get White Balance Tint Float Field
        FloatField whiteBalanceTintFloat = whiteBalanceTintVE.Q <FloatField>(name: "CurrentValue");
        //Set default Tint
        whiteBalanceTintFloat.SetValueWithoutNotify(whiteBalanceProperty.tint.value);

        //Register change callback for the float field to change the slider value. Changing slider value will change the values bound with it.
        whiteBalanceTintFloat.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTintSlider.value = evt.newValue);

        //Register change Callback for the slider, to change the float fiel Without notification (to avoid triggering Float field callback)
        whiteBalanceTintSlider.RegisterCallback <ChangeEvent <float> >((evt) => whiteBalanceTintFloat.SetValueWithoutNotify(evt.newValue));
        #endregion

        #endregion

        #region Bloom

        //serialize bloom property
        SerializedObject serialized_BloomProperty = new SerializedObject(BloomProperty);
        //Get Bloom Visual Element
        VisualElement bloomVisualElement = root.Q <VisualElement>(name: "Bloom");

        //Get Bloom Tint Color
        ColorField bloomTint = bloomVisualElement.Q <ColorField>(name: "Tint");

        //Bind color to value
        bloomTint.bindingPath = "tint.m_Value";
        bloomTint.Bind(serialized_BloomProperty);

        //Get Bloom Intensity
        FloatField bloomIntensity = bloomVisualElement.Q <FloatField>(name: "Intensity");

        //Bind Intensity to value
        bloomIntensity.Bind(serialized_BloomProperty);

        #endregion
        #endregion


        #region VFX

        SerializedObject serialized_GlowParticleSystem = new SerializedObject(GlowParticleSystem);

        VisualElement VFXVisualElement = root.Q <VisualElement>(name: "VFX");


        VFXVisualElement.Q <FloatField>(name: "Emission").bindingPath = "EmissionModule.rateOverTime.scalar";
        VFXVisualElement.Q <FloatField>(name: "Emission").Bind(serialized_GlowParticleSystem);

        VFXVisualElement.Q <EnumField>(name: "RenderMode").Init(GlowParticleSystem.GetComponent <ParticleSystemRenderer>().renderMode);
        VFXVisualElement.Q <EnumField>(name: "RenderMode").RegisterCallback <ChangeEvent <string> >(ChangeRenderMode);

        VFXVisualElement.Q <ObjectField>(name: "Material").objectType = typeof(Material);
        VFXVisualElement.Q <ObjectField>(name: "Material").RegisterCallback <ChangeEvent <string> >(ChangeRenderMaterial);
        #endregion

        root.Q <Button>(name: "SaveButton").clicked  += SaveButton;
        root.Q <Button>(name: "ResetButton").clicked += ResetToInitialSceneValues;
    }