public void Save(TrailEffect effect)
 {
     active                         = effect.active;
     ignoreFrames                   = effect.ignoreFrames;
     duration                       = effect.duration;
     continuous                     = effect.continuous;
     smooth                         = effect.smooth;
     checkWorldPosition             = effect.checkWorldPosition;
     minDistance                    = effect.minDistance;
     worldPositionRelativeOption    = effect.worldPositionRelativeOption;
     worldPositionRelativeTransform = effect.worldPositionRelativeTransform;
     checkScreenPosition            = effect.checkScreenPosition;
     minPixelDistance               = effect.minPixelDistance;
     maxStepsPerFrame               = effect.maxStepsPerFrame;
     checkTime                      = effect.checkTime;
     timeInterval                   = effect.timeInterval;
     checkCollisions                = effect.checkCollisions;
     orientToSurface                = effect.orientToSurface;
     ground                         = effect.ground;
     surfaceOffset                  = effect.surfaceOffset;
     collisionLayerMask             = effect.collisionLayerMask;
     drawBehind                     = effect.drawBehind;
     cullMode                       = effect.cullMode;
     subMeshMask                    = effect.subMeshMask;
     colorOverTime                  = effect.colorOverTime;
     color                  = effect.color;
     colorSequence          = effect.colorSequence;
     colorCycleDuration     = effect.colorCycleDuration;
     colorStartPalette      = effect.colorStartPalette;
     pingPongSpeed          = effect.pingPongSpeed;
     this.effect            = effect.effect;
     texture                = effect.texture;
     scale                  = effect.scale;
     scaleStartRandomMin    = effect.scaleStartRandomMin;
     scaleStartRandomMax    = effect.scaleStartRandomMax;
     scaleOverTime          = effect.scaleOverTime;
     scaleUniform           = effect.scaleUniform;
     localPositionRandomMin = effect.localPositionRandomMin;
     localPositionRandomMax = effect.localPositionRandomMax;
     laserBandWidth         = effect.laserBandWidth;
     laserIntensity         = effect.laserIntensity;
     laserFlash             = effect.laserFlash;
     lookTarget             = effect.lookTarget;
     lookToCamera           = effect.lookToCamera;
     textureCutOff          = effect.textureCutOff;
     normalThreshold        = effect.normalThreshold;
     useLastAnimationState  = effect.useLastAnimationState;
     maxBatches             = effect.maxBatches;
     meshPoolSize           = effect.meshPoolSize;
     animationStates        = effect.animationStates;
 }
Example #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        void GeometryTypeCH(List <MaterialProperty> allProps, STCGeometryType[] geomTypes)
        {
            //--------------

            STCGeometryType setGeomType = (STCGeometryType)EditorGUILayout.EnumPopup("Geometry Type", geomTypes[0]);

            if (EditorGUI.EndChangeCheck())
            {
                bool shouldEnableAlphaTest = ShouldEnableAlphaTest(setGeomType);
                UnityEngine.Rendering.CullMode cullMode = shouldEnableAlphaTest ? UnityEngine.Rendering.CullMode.Off : UnityEngine.Rendering.CullMode.Back;

                foreach (Material m in targets.Cast <Material>())
                {
                    if (shouldEnableAlphaTest)
                    {
                        m.SetOverrideTag("RenderType", "treeTransparentCutout");
                    }
                    for (int i = 0; i < STCGTypeString.Length; ++i)
                    {
                        m.DisableKeyword(STCGTypeString[i]);
                    }
                    m.EnableKeyword(STCGTypeString[(int)setGeomType]);
                    m.renderQueue = shouldEnableAlphaTest ? (int)UnityEngine.Rendering.RenderQueue.AlphaTest : (int)UnityEngine.Rendering.RenderQueue.Geometry;
                    m.SetInt("_Cull", (int)cullMode);
                }
            }
            EditorGUI.showMixedValue = false;

            MaterialProperty culling = allProps.Find(prop => prop.name == "_Cull");

            if (culling != null)
            {
                allProps.Remove(culling);
                ShaderProperty(culling, culling.displayName);
            }

            //--------------
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            var theShader = serializedObject.FindProperty("m_Shader");

            // if we are not visible... return
            if (!isVisible || theShader.hasMultipleDifferentValues || theShader.objectReferenceValue == null)
            {
                return;
            }

            List <MaterialProperty> props = new List <MaterialProperty>(GetMaterialProperties(targets));

            SetDefaultGUIWidths();

            // Geometry type choice
            //---------------------------------------------------------------
            var geomTypes = new SpeedTreeGeometryType[targets.Length];

            for (int i = 0; i < targets.Length; ++i)
            {
                geomTypes[i] = SpeedTreeGeometryType.Branch;
                for (int j = 0; j < speedTreeGeometryTypeString.Length; ++j)
                {
                    if (((Material)targets[i]).shaderKeywords.Contains(speedTreeGeometryTypeString[j]))
                    {
                        geomTypes[i] = (SpeedTreeGeometryType)j;
                        break;
                    }
                }
            }
            EditorGUI.showMixedValue = geomTypes.Distinct().Count() > 1;
            EditorGUI.BeginChangeCheck();
            var setGeomType = (SpeedTreeGeometryType)EditorGUILayout.EnumPopup("Geometry Type", geomTypes[0]);

            if (EditorGUI.EndChangeCheck())
            {
                bool shouldEnableAlphaTest = ShouldEnableAlphaTest(setGeomType);
                UnityEngine.Rendering.CullMode cullMode = shouldEnableAlphaTest ? UnityEngine.Rendering.CullMode.Off : UnityEngine.Rendering.CullMode.Back;

                foreach (var m in targets.Cast <Material>())
                {
                    if (shouldEnableAlphaTest)
                    {
                        m.SetOverrideTag("RenderType", "treeTransparentCutout");
                    }
                    for (int i = 0; i < speedTreeGeometryTypeString.Length; ++i)
                    {
                        m.DisableKeyword(speedTreeGeometryTypeString[i]);
                    }
                    m.EnableKeyword(speedTreeGeometryTypeString[(int)setGeomType]);
                    m.renderQueue = shouldEnableAlphaTest ? (int)UnityEngine.Rendering.RenderQueue.AlphaTest : (int)UnityEngine.Rendering.RenderQueue.Geometry;
                    m.SetInt("_Cull", (int)cullMode);
                }
            }
            EditorGUI.showMixedValue = false;

            //---------------------------------------------------------------
            var mainTex = props.Find(prop => prop.name == "_MainTex");

            if (mainTex != null)
            {
                props.Remove(mainTex);
                ShaderProperty(mainTex, mainTex.displayName);
            }

            //---------------------------------------------------------------
            var bumpMap = props.Find(prop => prop.name == "_BumpMap");

            if (bumpMap != null)
            {
                props.Remove(bumpMap);

                var  enableBump = targets.Select(t => ((Material)t).shaderKeywords.Contains("EFFECT_BUMP"));
                bool?enable     = ToggleShaderProperty(bumpMap, enableBump.First(), enableBump.Distinct().Count() > 1);
                if (enable != null)
                {
                    foreach (var m in targets.Cast <Material>())
                    {
                        if (enable.Value)
                        {
                            m.EnableKeyword("EFFECT_BUMP");
                        }
                        else
                        {
                            m.DisableKeyword("EFFECT_BUMP");
                        }
                    }
                }
            }

            //---------------------------------------------------------------
            var detailTex = props.Find(prop => prop.name == "_DetailTex");

            if (detailTex != null)
            {
                props.Remove(detailTex);
                if (geomTypes.Contains(SpeedTreeGeometryType.BranchDetail))
                {
                    ShaderProperty(detailTex, detailTex.displayName);
                }
            }

            //---------------------------------------------------------------
            var enableHueVariation = targets.Select(t => ((Material)t).shaderKeywords.Contains("EFFECT_HUE_VARIATION"));
            var hueVariation       = props.Find(prop => prop.name == "_HueVariation");

            if (enableHueVariation != null && hueVariation != null)
            {
                props.Remove(hueVariation);
                bool?enable = ToggleShaderProperty(hueVariation, enableHueVariation.First(), enableHueVariation.Distinct().Count() > 1);
                if (enable != null)
                {
                    foreach (var m in targets.Cast <Material>())
                    {
                        if (enable.Value)
                        {
                            m.EnableKeyword("EFFECT_HUE_VARIATION");
                        }
                        else
                        {
                            m.DisableKeyword("EFFECT_HUE_VARIATION");
                        }
                    }
                }
            }

            //---------------------------------------------------------------
            var alphaCutoff = props.Find(prop => prop.name == "_Cutoff");

            if (alphaCutoff != null)
            {
                props.Remove(alphaCutoff);
                if (geomTypes.Any(t => ShouldEnableAlphaTest(t)))
                {
                    ShaderProperty(alphaCutoff, alphaCutoff.displayName);
                }
            }

            //---------------------------------------------------------------
            foreach (var prop in props)
            {
                if ((prop.flags & MaterialProperty.PropFlags.HideInInspector) != 0)
                {
                    continue;
                }
                ShaderProperty(prop, prop.displayName);
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            RenderQueueField();
            EnableInstancingField();
            DoubleSidedGIField();
        }
    public static void DrawMaterialEditor(Material mat)
    {
        //Just set these directly, why not. It's a custom inspector already, no need to bog this down even more
        Undo.RecordObject(mat, "Changed Super Text Mesh Material");
        //name changer
        EditorGUI.BeginChangeCheck();
        mat.name = EditorGUILayout.TextField("Material Name", mat.name);
        if (EditorGUI.EndChangeCheck())
        {
            AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(mat), mat.name);
            //Undo.RecordObject (myObject, "Change Asset Name");
            AssetDatabase.Refresh();
            //stm.data = null;
        }

        int originalQueue = mat.renderQueue;

        mat.shader = (Shader)EditorGUILayout.ObjectField("Shader", mat.shader, typeof(Shader), false);

        //set to correct value
        if (mat.HasProperty("_Cutoff"))
        {
            mat.SetFloat("_Cutoff", 0.0001f);
        }
        //set to correct value
        if (mat.HasProperty("_ShadowCutoff"))
        {
            mat.SetFloat("_ShadowCutoff", 0.5f);
        }

        //culling mode
        if (mat.HasProperty("_CullMode"))
        {
            UnityEngine.Rendering.CullMode cullMode = (UnityEngine.Rendering.CullMode)mat.GetInt("_CullMode");
            cullMode = (UnityEngine.Rendering.CullMode)EditorGUILayout.EnumPopup("Cull Mode", cullMode);
            mat.SetInt("_CullMode", (int)cullMode);
        }
        //draw on top?
        if (mat.HasProperty("_ZTestMode"))
        {
            int  zTestMode = mat.GetInt("_ZTestMode");
            bool onTop     = zTestMode == 6;
            onTop = EditorGUILayout.Toggle("Render On Top", onTop);
            //Always or LEqual
            mat.SetInt("_ZTestMode", onTop ? 6 : 2);
        }
        //masking
        if (mat.HasProperty("_MaskMode"))
        {
            int maskMode = mat.GetInt("_MaskMode");
            //bool masked = maskMode == 1;
            //masked = EditorGUILayout.Toggle("Masked", masked);
            maskMode = EditorGUILayout.Popup("Mask Mode", maskMode, new string[] { "Outside", "Inside" });
            //Always or LEqual
            mat.SetInt("_MaskMode", maskMode);
        }

        //if this is the multishader
        if (mat.GetTag("STMUberShader", true, "Null") == "Yes")
        {
            //toggle SDF
            bool sdfMode = mat.IsKeywordEnabled("SDF_MODE");
            EditorGUI.BeginChangeCheck();
            sdfMode = EditorGUILayout.Toggle("SDF Mode", sdfMode);            //show the toggle
            if (EditorGUI.EndChangeCheck())
            {
                if (sdfMode)
                {
                    mat.EnableKeyword("SDF_MODE");
                }
                else
                {
                    mat.DisableKeyword("SDF_MODE");
                }
                //EditorUtility.SetDirty(mat);
            }
            if (sdfMode)
            {            //draw SDF-related properties
                if (mat.HasProperty("_Blend"))
                {
                    //EditorGUILayout.PropertyField(shaderBlend);
                    mat.SetFloat("_Blend", EditorGUILayout.Slider("Blend", mat.GetFloat("_Blend"), 0.0001f, 1f));
                }
                if (mat.HasProperty("_SDFCutoff"))
                {
                    mat.SetFloat("_SDFCutoff", EditorGUILayout.Slider("SDF Cutoff", mat.GetFloat("_SDFCutoff"), 0f, 1f));
                }
            }

            //toggle Pixel Snap
            bool pixelSnap = mat.IsKeywordEnabled("PIXELSNAP_ON");
            EditorGUI.BeginChangeCheck();
            pixelSnap = EditorGUILayout.Toggle("Pixel Snap", pixelSnap);            //show the toggle
            if (EditorGUI.EndChangeCheck())
            {
                if (pixelSnap)
                {
                    mat.EnableKeyword("PIXELSNAP_ON");
                }
                else
                {
                    mat.DisableKeyword("PIXELSNAP_ON");
                }
                //EditorUtility.SetDirty(mat);
            }
        }
        else
        {
            if (mat.HasProperty("_Blend"))
            {
                //EditorGUILayout.PropertyField(shaderBlend);
                mat.SetFloat("_Blend", EditorGUILayout.Slider("Blend", mat.GetFloat("_Blend"), 0f, 1f));
            }
            if (mat.HasProperty("_SDFCutoff"))
            {
                mat.SetFloat("_SDFCutoff", EditorGUILayout.Slider("SDF Cutoff", mat.GetFloat("_SDFCutoff"), 0f, 1f));
            }
        }

        if (mat.HasProperty("_ShadowColor"))
        {
            //EditorGUILayout.PropertyField(shadowColor);
            mat.SetColor("_ShadowColor", EditorGUILayout.ColorField("Shadow Color", mat.GetColor("_ShadowColor")));
        }
        if (mat.HasProperty("_ShadowDistance"))
        {
            //EditorGUILayout.PropertyField(shadowDistance);
            mat.SetFloat("_ShadowDistance", EditorGUILayout.FloatField("Shadow Distance", mat.GetFloat("_ShadowDistance")));
        }
        if (mat.HasProperty("_ShadowAngle"))
        {
            //EditorGUILayout.PropertyField(shadowAngle);
            mat.SetFloat("_ShadowAngle", EditorGUILayout.Slider("Shadow Angle", mat.GetFloat("_ShadowAngle"), 0f, 360f));
        }
        if (mat.HasProperty("_OutlineColor"))
        {
            //EditorGUILayout.PropertyField(outlineColor);
            mat.SetColor("_OutlineColor", EditorGUILayout.ColorField("Outline Color", mat.GetColor("_OutlineColor")));
        }
        if (mat.HasProperty("_OutlineWidth"))
        {
            //EditorGUILayout.PropertyField(outlineWidth);
            mat.SetFloat("_OutlineWidth", EditorGUILayout.FloatField("Outline Width", mat.GetFloat("_OutlineWidth")));
        }

        EditorGUILayout.BeginHorizontal();
        mat.renderQueue = EditorGUILayout.IntField("Render Queue", originalQueue);
        if (GUILayout.Button("Reset"))
        {
            mat.renderQueue = mat.shader.renderQueue;
        }
        EditorGUILayout.EndHorizontal();
    }
 public static void SetCullMode(Material material, UnityEngine.Rendering.CullMode cull)
 {
     material.SetFloat(PropertyNames.CULL_MODE, (int)cull);
 }