Пример #1
0
        private void OnColorChange(Color color)
        {
            var haircutObject = avatarViewer.HaircutObject;

            if (haircutObject == null)
            {
                return;
            }

            var hairMeshRenderer = haircutObject.GetComponent <MeshRenderer> ();

            CurrentColor = color;
            CurrentTint  = CoreTools.CalculateTint(color, averageColor);
            hairMeshRenderer.material.SetVector("_ColorTarget", color);
            hairMeshRenderer.material.SetVector("_ColorTint", CurrentTint);
            hairMeshRenderer.material.SetFloat("_TintCoeff", 0.8f);
        }
Пример #2
0
    private static bool MatchTwoMeshTint(SkinnedMeshRenderer meshChanging, SkinnedMeshRenderer meshTarget, float coefficient = 0f, float threshold = 0.55f)
    {
        if (meshChanging == null || meshTarget == null)
        {
            return(false);
        }

        Color   colorChanging = CoreTools.CalculateAverageColor(meshChanging.material.mainTexture as Texture2D);
        Color   colorTarget   = CoreTools.CalculateAverageColor(meshTarget.material.mainTexture as Texture2D);
        Vector4 tint          = CoreTools.CalculateTint(colorTarget, colorChanging);

        meshChanging.material.SetVector("_ColorTarget", colorTarget);
        meshChanging.material.SetVector("_ColorTint", tint);
        meshChanging.material.SetFloat("_TintCoeff", coefficient);
        meshChanging.material.SetFloat("_MultiplicationTintThreshold", threshold);

        return(true);
    }
Пример #3
0
    private static bool ChangeMeshTint(SkinnedMeshRenderer meshRenderer, string hex, float coefficient = 0.8f)
    {
        Color color;
        bool  validColor = ColorUtility.TryParseHtmlString(hex, out color);

        if (meshRenderer == null || !validColor)
        {
            return(false);
        }

        Color   averageColor = CoreTools.CalculateAverageColor(meshRenderer.material.mainTexture as Texture2D);
        Vector4 tint         = CoreTools.CalculateTint(color, averageColor);

        meshRenderer.material.SetVector("_ColorTarget", color);
        meshRenderer.material.SetVector("_ColorTint", tint);
        meshRenderer.material.SetFloat("_TintCoeff", coefficient);

        return(true);
    }