Пример #1
0
        private void GradientColorZone_OnColorSet(ColorZone zone, Color color, Vector3 point)
        {
            // figure out which side of the gradient to change
            // for simplicity's sake, we only allow 2 color gradients at the moment

            Vector3 localPoint    = transform.InverseTransformPoint(point);
            float   gradientValue = 0;

            if (GradientInfo.Type == GradientType.Horizontal)
            {
                gradientValue = Mathf.InverseLerp(-gradientZoneCollider.size.x * 0.5f, gradientZoneCollider.size.x * 0.5f,
                                                  localPoint.x);
            }
            else if (GradientInfo.Type == GradientType.Vertical)
            {
                gradientValue = Mathf.InverseLerp(-gradientZoneCollider.size.y * 0.5f, gradientZoneCollider.size.y * 0.5f,
                                                  localPoint.y);
            }
            else if (GradientInfo.Type == GradientType.Radial)
            {
                gradientValue = ((Vector2)localPoint).magnitude;
            }

            if (GradientInfo.Invert)
            {
                gradientValue = 1 - gradientValue;
            }

            if (gradientValue > 0.5)
            {
                GradientColorKey[] newKeys = new GradientColorKey[2];
                newKeys[0] = Gradient.colorKeys[0];
                newKeys[1] = new GradientColorKey(color, 1);

                Gradient.colorKeys = newKeys;
            }
            else
            {
                Gradient.colorKeys[0] = new GradientColorKey(color, 0);

                GradientColorKey[] newKeys = new GradientColorKey[2];
                newKeys[0] = new GradientColorKey(color, 0);
                newKeys[1] = Gradient.colorKeys[1];

                Gradient.colorKeys = newKeys;
            }

            if (OnGradientChanged != null)
            {
                OnGradientChanged(this);
            }
        }
Пример #2
0
 public void ClearColorZone()
 {
     currentZone = null;
 }
Пример #3
0
 public void SetColorZone(ColorZone colorZone)
 {
     currentZone = colorZone;
 }
Пример #4
0
        void DoColorZoneUpdate()
        {
            checkTimer -= Time.deltaTime;

            if (checkTimer <= 0)
            {
                int numValid = Physics.OverlapBoxNonAlloc(GetTipPosition(), tipZoneSize,
                                                          colorZoneColliders, transform.rotation, colorZoneLayers, QueryTriggerInteraction.Collide);

                if (numValid == 0)
                {
                    for (int i = 0; i < colorZoneColliders.Length; i++)
                    {
                        colorZoneColliders[i]     = null;
                        colorZoneInfo[i].collider = null;
                        colorZoneInfo[i].isValid  = false;
                        colorZoneInfo[i].zone     = null;
                        colorZoneInfo[i].relay    = null;
                    }
                }

                for (int i = 0; i < colorZoneColliders.Length; i++)
                {
                    if (i < numValid)
                    {
                        colorZoneInfo[i].collider = colorZoneColliders[i];

                        // check to see if collider is a valid colorzone

                        ColorZone[] zones = colorZoneInfo[i].collider.GetComponents <ColorZone>();
                        if (zones.Any(item => item.enabled))
                        {
                            colorZoneInfo[i].zone = zones.First(item => item.enabled);
                        }
                        else
                        {
                            colorZoneInfo[i].zone = null;
                        }
                        colorZoneInfo[i].relay = colorZoneInfo[i].collider.GetComponent <ColorZoneRelay>();

                        colorZoneInfo[i].isValid = colorZoneInfo[i].zone != null || colorZoneInfo[i].relay != null;
                        colorZoneInfo[i].closestPointOnCollider = colorZoneInfo[i].collider.ClosestPointOnBounds(GetTipPosition());
                    }
                    else
                    {
                        colorZoneInfo[i].collider = null;
                        colorZoneInfo[i].isValid  = false;
                        colorZoneInfo[i].zone     = null;
                        colorZoneInfo[i].relay    = null;
                    }
                }

                // if any colliders available, find the best candidate
                int   smallestDistIndx = -1;
                float smallestDist     = float.PositiveInfinity;

                for (int i = 0; i < colorZoneInfo.Length; i++)
                {
                    if (colorZoneInfo[i].isValid)
                    {
                        float dist = Vector3.Distance(GetTipPosition(), colorZoneInfo[i].closestPointOnCollider);
                        if (dist < smallestDist)
                        {
                            smallestDist     = dist;
                            smallestDistIndx = i;
                        }
                    }
                }

                // update the current color zone
                if (smallestDistIndx == -1)
                {
                    currentZone = null;
                }
                else
                {
                    if (colorZoneInfo[smallestDistIndx].zone != null)
                    {
                        currentZone = colorZoneInfo[smallestDistIndx].zone;
                    }
                    else
                    {
                        currentZone = colorZoneInfo[smallestDistIndx].relay.Zone;
                    }
                }

                checkTimer = timeBetweenTipChecks;
            }
        }
Пример #5
0
 private void Awake()
 {
     colorZone = GetComponentInParent <ColorZone>();
 }
Пример #6
0
 private void UniformColorZone_OnColorSet(ColorZone zone, Color color, Vector3 point)
 {
     this.color = color;
 }