Exemplo n.º 1
0
        /// <summary>
        /// apply the color to the material
        /// </summary>
        private void Update()
        {
            for (int i = 0; i < mData.Count; ++i)
            {
                ColorTransitionData data = mData[i];

                if (data.Count < data.Time)
                {
                    data.Count          = Mathf.Clamp(data.Count + Time.deltaTime, 0, data.Time);
                    data.Material.color = GetColorTransition(data.StartColor, data.EndColor, data.Count / data.Time);
                    mData[i]            = data;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fades the color of a material called by name
        /// </summary>
        /// <param name="color"></param>
        /// <param name="name"></param>
        public void StartTransition(Color color, string name = "")
        {
            for (int i = 0; i < mData.Count; ++i)
            {
                if (mData[i].Name == name || name == "")
                {
                    ColorTransitionData data = mData[i];
                    data.Count      = 0;
                    data.Time       = TransitionTime;
                    data.EndColor   = color;
                    data.StartColor = data.Material.color;

                    mData[i] = data;
                }
            }
        }
Exemplo n.º 3
0
        private void Awake()
        {
            // set the target game object if not set already
            if (TargetObject == null)
            {
                TargetObject = this.gameObject;
            }

            // get the material array
            if (Materials == null)
            {
                Materials = TargetObject.GetComponent <Renderer>().materials;
            }

            // add materials to the ColorTransitionData list
            mData = new List <ColorTransitionData>();

            for (int i = 0; i < Materials.Length; ++i)
            {
                ColorTransitionData data = new ColorTransitionData
                {
                    StartColor = Materials[i].color,
                    Percentage = 0,
                    Time       = TransitionTime,
                    Count      = TransitionTime,
                    Material   = Materials[i],
                    Name       = Materials[i].name
                };

                int SpaceIndex = data.Name.IndexOf(" ");
                if (SpaceIndex > -1)
                {
                    data.Name = data.Name.Substring(0, SpaceIndex);
                }

                mData.Add(data);
            }
        }