Esempio n. 1
0
        public static void ClearMat(Material mat)
        {
            shaderValue.Clear();
            ShaderValue.GetShaderValue(mat, shaderValue);
            Material emptyMat = new Material(mat.shader);

            mat.CopyPropertiesFromMaterial(emptyMat);
            UnityEngine.Object.DestroyImmediate(emptyMat);
            for (int i = 0; i < shaderValue.Count; ++i)
            {
                ShaderValue sv = shaderValue[i];
                sv.SetValue(mat);
            }
        }
Esempio n. 2
0
        private static bool _ClearMat(Material mat, string path)
        {
            shaderValue.Clear();
            Shader shader = mat.shader;
            int    count  = ShaderUtil.GetPropertyCount(shader);

            for (int i = 0; i < count; ++i)
            {
                ShaderValue sv   = null;
                string      name = ShaderUtil.GetPropertyName(shader, i);
                ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(shader, i);
                switch (type)
                {
                case ShaderUtil.ShaderPropertyType.Color:
                    sv = new ShaderColorValue(name, type, mat);
                    break;

                case ShaderUtil.ShaderPropertyType.Vector:
                    sv = new ShaderVectorValue(name, type, mat);
                    break;

                case ShaderUtil.ShaderPropertyType.Float:
                    sv = new ShaderFloatValue(name, type, mat);
                    break;

                case ShaderUtil.ShaderPropertyType.Range:
                    sv = new ShaderFloatValue(name, type, mat);
                    break;

                case ShaderUtil.ShaderPropertyType.TexEnv:
                    sv = new ShaderTexValue(name, type, mat);
                    break;
                }
                shaderValue.Add(sv);
            }
            Material emptyMat = new Material(shader);

            mat.CopyPropertiesFromMaterial(emptyMat);
            UnityEngine.Object.DestroyImmediate(emptyMat);
            for (int i = 0; i < shaderValue.Count; ++i)
            {
                ShaderValue sv = shaderValue[i];
                sv.SetValue(mat);
            }
            mat.renderQueue = -1;
            return(true);
        }
Esempio n. 3
0
        internal static bool AddMaterialProperty(
            ref MaterialContext context,
            Material material,
            ShaderValue sv,
            List <ShaderProperty> shaderPropertyKey)
        {
            if (sv.name == "_Cutoff" ||
                sv.name == "_SrcBlend" ||
                sv.name == "_DstBlend" ||
                sv.name == "_ZWrite" ||
                sv.name == "_DebugMode")
            {
                return(false);
            }

            ShaderProperty sp = shaderPropertyKey.Find((x) => { return(x.shaderProperty == sv.name); });

            if (sp != null)
            {
                return(AddMaterialProperty(ref context, material, sp));
            }
            else
            {
                if (shaderNameKeys == null)
                {
                    shaderNameKeys = System.Enum.GetNames(typeof(EShaderKeyID));
                    for (int i = 0; i < shaderNameKeys.Length; ++i)
                    {
                        shaderNameKeys[i] = "_" + shaderNameKeys[i];
                    }
                }
                for (int i = 0; i < shaderNameKeys.Length; ++i)
                {
                    if (shaderNameKeys[i] == sv.name)
                    {
                        shareSp.shaderID       = i;
                        shareSp.isTex          = sv is ShaderTexValue;
                        shareSp.shaderProperty = sv.name;
                        return(AddMaterialProperty(ref context, material, shareSp));
                    }
                }
                Debug.LogErrorFormat("null property:{0} mat:{1}", sv.name, material.name);
                return(false);
            }
        }
Esempio n. 4
0
            public static void GetShaderValue(Material mat, List <ShaderValue> shaderValueLst)
            {
                Shader shader = mat.shader;
                int    count  = ShaderUtil.GetPropertyCount(shader);

                for (int i = 0; i < count; ++i)
                {
                    ShaderValue sv   = null;
                    string      name = ShaderUtil.GetPropertyName(shader, i);
                    ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(shader, i);
                    switch (type)
                    {
                    case ShaderUtil.ShaderPropertyType.Color:
                        sv = new ShaderColorValue(name, type, mat);
                        break;

                    case ShaderUtil.ShaderPropertyType.Vector:
                        sv = new ShaderVectorValue(name, type, mat);
                        break;

                    case ShaderUtil.ShaderPropertyType.Float:
                        sv = new ShaderFloatValue(name, type, mat);
                        break;

                    case ShaderUtil.ShaderPropertyType.Range:
                        sv = new ShaderFloatValue(name, type, mat);
                        break;

                    case ShaderUtil.ShaderPropertyType.TexEnv:
                        sv = new ShaderTexValue(name, type, mat);
                        break;
                    }
                    shaderValueLst.Add(sv);
                }
                ShaderKeyWordValue keyword = new ShaderKeyWordValue(mat);

                shaderValueLst.Add(keyword);
            }
Esempio n. 5
0
    private void SetShaderValueInternal(ShaderValue value)
    {
        ShaderDefaultValue defaultValue;

        if (_processingValues.Any(bundle => bundle.Value.ShaderType == value.ShaderType))
        {
            defaultValue = _processingValues.First(bundle => bundle.Value.ShaderType == value.ShaderType).DefaultValue;
        }
        else
        {
            float defaultFloat = 0f;
            Color defaultColor = Color.black;

            if (value.ShaderType == ShaderType.ColorGrading_Filter)
            {
                defaultColor = _shaderColorGrading.colorFilter.value;
            }
            else if (value.ShaderType == ShaderType.DepthOfField_Distance)
            {
                defaultFloat = _shaderDepthOfField.focusDistance.value;
            }
            else if (value.ShaderType == ShaderType.ChromaticAberration_Intensity)
            {
                defaultFloat = _shaderChromaticAberration.intensity.value;
            }

            defaultValue = new ShaderDefaultValue {
                DefaultFloat = defaultFloat,
                DefaultColor = defaultColor
            };
        }

        _processingValues.Add(new ShaderValueBundle {
            StartTime    = Time.time,
            Value        = value,
            DefaultValue = defaultValue
        });
    }
Esempio n. 6
0
    private void Update()
    {
        if (Intro)
        {
            if (_introStart.Equals(0f))
            {
                _introStart = Time.time;
            }

            float perc = (Time.time - _introStart) / 5f;
            if (perc <= .5f)
            {
                _imageY = perc / .5f;
                _bgA    = 1f;
                _imageA = 1f;
            }
            else
            {
                _imageY = 1f;
                _bgA    = 1f - (perc - .5f) / .5f;
                _imageA = _bgA;
            }

            if (perc >= 1f)
            {
                Intro       = false;
                _introStart = 0f;
            }
        }

        float desiredHealthOnion = GameManager.Instance.StatusHuntersHealth / (float)GameManager.Instance.StatusHuntersMaxHealth;

        if (_huntersHealthOnion > desiredHealthOnion)
        {
            _huntersHealthOnion = Mathf.MoveTowards(_huntersHealthOnion, desiredHealthOnion, Time.deltaTime * .5f);
        }
        else
        {
            _huntersHealthOnion = desiredHealthOnion;
        }

        desiredHealthOnion = GameManager.Instance.StatusVictimsHealth / (float)GameManager.Instance.StatusVictimsMaxHealth;
        if (_victimsHealthOnion > desiredHealthOnion)
        {
            _victimsHealthOnion = Mathf.MoveTowards(_victimsHealthOnion, desiredHealthOnion, Time.deltaTime * .5f);
        }
        else
        {
            _victimsHealthOnion = desiredHealthOnion;
        }

        for (var i = 0; i < _processingValues.Count; i++)
        {
            ShaderValueBundle  valueBundle  = _processingValues[i];
            ShaderValue        value        = valueBundle.Value;
            ShaderDefaultValue defaultValue = valueBundle.DefaultValue;

            if (Time.time >= valueBundle.StartTime && Time.time <= valueBundle.StartTime + value.TimeFull)
            {
                float time       = Time.time - valueBundle.StartTime;
                float transition = time <= value.TimeIn ? time / value.TimeIn : time >= value.TimeFull - value.TimeOut ? 1f - (time - (value.TimeFull - value.TimeOut)) / value.TimeOut : 1f;
                Debug.Log(transition);
                if (value.ShaderType == ShaderType.ColorGrading_Filter)
                {
                    _shaderColorGrading.colorFilter.value = ColorTransition(defaultValue.DefaultColor, value.ColorValue, transition);
                }
                else if (value.ShaderType == ShaderType.DepthOfField_Distance)
                {
                    _shaderDepthOfField.focusDistance.value = FloatTransition(defaultValue.DefaultFloat, value.FloatValue, transition);
                }
                else if (value.ShaderType == ShaderType.ChromaticAberration_Intensity)
                {
                    _shaderChromaticAberration.intensity.value = FloatTransition(defaultValue.DefaultFloat, value.FloatValue, transition);
                }
            }
            else
            {
                if (value.ShaderType == ShaderType.ColorGrading_Filter)
                {
                    _shaderColorGrading.colorFilter.value = defaultValue.DefaultColor;
                }
                else if (value.ShaderType == ShaderType.DepthOfField_Distance)
                {
                    _shaderDepthOfField.focusDistance.value = defaultValue.DefaultFloat;
                }
                else if (value.ShaderType == ShaderType.ChromaticAberration_Intensity)
                {
                    _shaderChromaticAberration.intensity.value = defaultValue.DefaultFloat;
                }

                _processingValues.RemoveAt(i);
                i--;
            }
        }
    }
Esempio n. 7
0
 public static void SetShaderValue(ShaderValue value)
 {
     Instance.SetShaderValueInternal(value);
 }