Beispiel #1
0
        protected override void AssignColorFromCurrentRenderers(Color newColor, TransitionTargets target, ColorModes mixMode)
        {
            if (RenderersTable != null)
            {
                Material[] mats = null;
                foreach (KeyValuePair <Renderer, Color[]> pair in RenderersTable)
                {
                    Renderer r           = pair.Key;
                    Color[]  startColors = pair.Value;

                    mats = UseSharedMaterials ? r.sharedMaterials : r.materials;

                    for (int i = 0; i < mats.Length; i++)
                    {
                        if (mats[i].HasProperty(MaterialPropertyName))
                        {
                            if ((MyColorTransition) && (MyColorTransition.InProgress))
                            {
                                mats[i].SetColor(MaterialPropertyName, ApplyColorMode(mats[i].GetColor(MaterialPropertyName), newColor, target, mixMode));
                            }
                            else
                            {
                                mats[i].SetColor(MaterialPropertyName, ApplyColorMode(startColors[i], newColor, target, mixMode));
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// resets the colors of the game object
        /// </summary>
        /// <param name="target">target to be reset</param>
        public void ResetColors(TransitionTargets target = TransitionTargets.ColorAndAlpha)
        {
            if (GraphicsTable != null)
            {
                foreach (KeyValuePair <UnityEngine.UI.Graphic, Color> pair in GraphicsTable)
                {
                    UnityEngine.UI.Graphic g = pair.Key;
                    Color startColor         = pair.Value;
                    g.color = startColor;
                }
            }

            if (RenderersTable != null)
            {
                Material[] mats = null;
                foreach (KeyValuePair <Renderer, Color[]> pair in RenderersTable)
                {
                    Renderer r           = pair.Key;
                    Color[]  startColors = pair.Value;

                    mats = UseSharedMaterials ? r.sharedMaterials : r.materials;
                    for (int i = 0; i < mats.Length; i++)
                    {
                        if (mats[i].HasProperty(MaterialPropertyName))
                        {
                            mats[i].SetColor(MaterialPropertyName, startColors[i]);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// assigns a color mixing it with the start color of each graphics or renderer component
        /// </summary>
        /// <param name="newColor">color to assign</param>
        /// <param name="target">Color, Alpha or Color and Alpha</param>
        /// <param name="mixMode">mix mode</param>
        public virtual void AssignColor(Color newColor, TransitionTargets target, ColorModes mixMode)
        {
            if (GraphicsTable != null)
            {
                foreach (KeyValuePair <UnityEngine.UI.Graphic, Color> pair in GraphicsTable)
                {
                    UnityEngine.UI.Graphic g = pair.Key;
                    Color startColor         = pair.Value;
                    g.color = ApplyColorMode(startColor, newColor, target, mixMode);
                }
            }

            if (RenderersTable != null)
            {
                Material[] mats = null;
                foreach (KeyValuePair <Renderer, Color[]> pair in RenderersTable)
                {
                    Renderer r           = pair.Key;
                    Color[]  startColors = pair.Value;

                    mats = UseSharedMaterials ? r.sharedMaterials : r.materials;
                    for (int i = 0; i < mats.Length; i++)
                    {
                        if (mats[i].HasProperty(MaterialPropertyName))
                        {
                            mats[i].SetColor(MaterialPropertyName, ApplyColorMode(startColors[i], newColor, target, mixMode));
                        }
                    }
                }
            }
        }
Beispiel #4
0
        public virtual void ChangeTarget()
        {
            TransitionTargets target = ca.Target;
            int targetInt            = (int)target;

            targetInt++;
            targetInt = targetInt % 3;
            ca.Target = (TransitionTargets)targetInt;

            UpdateLabel();
        }
Beispiel #5
0
 protected virtual void AssignColorFromCurrentGraphics(Color newColor, TransitionTargets target, ColorModes mixMode)
 {
     if (GraphicsTable != null)
     {
         foreach (KeyValuePair <UnityEngine.UI.Graphic, Color> pair in GraphicsTable)
         {
             UnityEngine.UI.Graphic g = pair.Key;
             g.color = ApplyColorMode(g.color, newColor, target, mixMode);
         }
     }
 }
Beispiel #6
0
 protected override void AssignColorFromCurrentGraphics(Color newColor, TransitionTargets target, ColorModes mixMode)
 {
     if (GraphicsTable != null)
     {
         foreach (KeyValuePair <Graphic, Color> pair in GraphicsTable)
         {
             Graphic g = pair.Key;
             if (MyColorTransition.InProgress)
             {
                 g.color = ApplyColorMode(g.color, newColor, target, mixMode);
             }
             else
             {
                 g.color = ApplyColorMode(GraphicsTable[g], newColor, target, mixMode);
             }
         }
     }
 }
Beispiel #7
0
        protected Color ApplyColorMode(Color startColor, Color newColor, TransitionTargets target, ColorModes mixMode)
        {
            Color32 s32;
            Color32 n32;

            switch (mixMode)
            {
            case ColorModes.Add:
                newColor  += startColor;
                newColor.r = Mathf.Clamp01(newColor.r);
                newColor.g = Mathf.Clamp01(newColor.g);
                newColor.b = Mathf.Clamp01(newColor.b);
                newColor.a = Mathf.Clamp01(newColor.a);
                break;

            case ColorModes.AddHDR:
                newColor  += startColor;
                newColor.a = Mathf.Clamp01(newColor.a);
                break;

            case ColorModes.Multiply:
                newColor.r *= startColor.r;
                newColor.g *= startColor.g;
                newColor.b *= startColor.b;
                newColor.a *= startColor.a;
                newColor.a  = Mathf.Clamp01(newColor.a);
                break;

            case ColorModes.Subtract:
                newColor   = startColor - newColor;
                newColor.r = Mathf.Clamp01(newColor.r);
                newColor.g = Mathf.Clamp01(newColor.g);
                newColor.b = Mathf.Clamp01(newColor.b);
                newColor.a = Mathf.Clamp01(newColor.a);
                break;

            case ColorModes.Invert:
                ApplyColorMode(startColor, newColor, target, ColorModes.Replace);
                newColor   = new Color(1, 1, 1, 1) - newColor;
                newColor.a = Mathf.Clamp01(newColor.a);
                break;

            case ColorModes.And:
                s32        = startColor;
                n32        = newColor;
                n32.r     &= s32.r;
                n32.g     &= s32.g;
                n32.b     &= s32.b;
                n32.a     &= s32.a;
                newColor   = n32;
                newColor.a = Mathf.Clamp01(newColor.a);
                break;

            case ColorModes.Or:
                s32        = startColor;
                n32        = newColor;
                n32.r     |= s32.r;
                n32.g     |= s32.g;
                n32.b     |= s32.b;
                n32.a     |= s32.a;
                newColor   = n32;
                newColor.a = Mathf.Clamp01(newColor.a);
                break;

            case ColorModes.Xor:
                s32        = startColor;
                n32        = newColor;
                n32.r     ^= s32.r;
                n32.g     ^= s32.g;
                n32.b     ^= s32.b;
                n32.a     ^= s32.a;
                newColor   = n32;
                newColor.a = Mathf.Clamp01(newColor.a);
                break;

            case ColorModes.IfDarker:
                newColor.r = Mathf.Min(startColor.r, newColor.r);
                newColor.g = Mathf.Min(startColor.g, newColor.g);
                newColor.b = Mathf.Min(startColor.b, newColor.b);
                newColor.a = Mathf.Min(startColor.a, newColor.a);
                break;

            case ColorModes.IfLighter:
                newColor.r = Mathf.Max(startColor.r, newColor.r);
                newColor.g = Mathf.Max(startColor.g, newColor.g);
                newColor.b = Mathf.Max(startColor.b, newColor.b);
                newColor.a = Mathf.Max(startColor.a, newColor.a);
                break;

            case ColorModes.Replace:
            default:
                ;
                break;
            }

            switch (target)
            {
            case TransitionTargets.Alpha:
                newColor.r = startColor.r;
                newColor.g = startColor.g;
                newColor.b = startColor.b;
                break;

            case TransitionTargets.Color:
                newColor.a = startColor.a;
                break;

            case TransitionTargets.ColorAndAlpha:
                ;
                break;
            }

            //        NoticeMessage( "start: " + startColor + " - newColor: " + newColor );

            return(newColor);
        }
Beispiel #8
0
 /// <summary>
 /// assigns a color mixing it with the current color of each graphics or renderer component
 /// </summary>
 /// <param name="newColor">color to assign</param>
 /// <param name="target">Color, Alpha or Color and Alpha</param>
 /// <param name="mixMode">mix mode</param>
 public virtual void AssignColorFromCurrent(Color newColor, TransitionTargets target, ColorModes mixMode)
 {
     AssignColorFromCurrentGraphics(newColor, target, mixMode);
     AssignColorFromCurrentRenderers(newColor, target, mixMode);
 }