Beispiel #1
0
        private static Texture2D GenerateGradient(Rect rect, IList <StyleSheetResolver.Value[]> args)
        {
            long key = (long)rect.width * 30 + (long)rect.height * 8;

            foreach (var arg in args)
            {
                for (int i = 0; i < arg.Length; ++i)
                {
                    key += arg[i].GetHashCode() * i + 1;
                }
            }

            if (s_Gradients.ContainsKey(key) && s_Gradients[key] != null)
            {
                return(s_Gradients[key]);
            }

            if (s_Gradients.Count > 300)
            {
                while (s_Gradients.Count > 250)
                {
                    s_Gradients.Remove(s_Gradients.Keys.ToList().First());
                }
            }

            var      width    = (int)rect.width;
            var      height   = (int)rect.height;
            Gradient gradient = new Gradient();
            var      gt       = new Texture2D(width, height)
            {
                alphaIsTransparency = true
            };

            var colorKeys = new GradientColorKey[args.Count];
            var alphaKeys = new GradientAlphaKey[args.Count];

            float increment = args.Count <= 1 ? 1f : 1f / (args.Count - 1);
            float autoStep  = 0;

            for (int i = 0; i < args.Count; ++i)
            {
                var values = args[i];
                if (values.Length == 1)
                {
                    colorKeys[i].color = values[0].AsColor();
                    colorKeys[i].time  = autoStep;
                }
                else if (values.Length == 2)
                {
                    colorKeys[i].color = values[0].AsColor();
                    colorKeys[i].time  = values[1].AsFloat();
                }
                else
                {
                    Debug.LogError("Invalid gradient value argument");
                }

                alphaKeys[i].time  = colorKeys[i].time;
                alphaKeys[i].alpha = colorKeys[i].color.a;

                autoStep = Mathf.Clamp(autoStep + increment, 0f, 1f);
            }

            gradient.SetKeys(colorKeys, alphaKeys);

            float yStep = 1F / height;

            for (int y = height - 1; y >= 0; --y)
            {
                Color color = gradient.Evaluate(1f - (y * yStep));
                for (int x = width - 1; x >= 0; --x)
                {
                    gt.SetPixel(x, y, color);
                }
            }

            gt.Apply();
            s_Gradients[key] = gt;
            return(gt);
        }
Beispiel #2
0
    public IEnumerator LevelUpdate()
    {
        while (GameManager.Instance.CurrentState() == StateType.PRACTICE || GameManager.Instance.CurrentState() == StateType.ENDPRACTICE)
        {
            switch (State)
            {
            case LevelState.FIRSTLOAD:
            {
                for (int i = 0; i < GameManager.Instance.blackboard.players; i++)
                {
                    InputsHandler ih = default;
                    if (i == 0)
                    {
                        ih = PlayerInput.Instantiate(_PrefabInputPlayer, controlScheme: "WASD", pairWithDevice: Keyboard.current).transform.GetComponent <InputsHandler>();
                    }
                    else if (i == 1)
                    {
                        ih = PlayerInput.Instantiate(_PrefabInputPlayer, controlScheme: "Arrows", pairWithDevice: Keyboard.current).transform.GetComponent <InputsHandler>();
                    }
                    _Inputs.Add(ih);
                }
                State = LevelState.LOADINGDATA;
                break;
            }

            case LevelState.LOADINGDATA:
            {
                Blocks   = new List <BlockController>();
                _Terrain = Instantiate(_PrefabTerrain);

                CurrentData = _Terrain.GetComponent <LevelData>();
                _MatBlock.SetColor("_BaseColor", Color.black);
                _MatBeat.SetColor("_EmissionColor", CurrentData._ScenaryColor);

                if (_Terrain.transform.Find("Blocks"))
                {
                    Blocks.AddRange(_Terrain.transform.Find("Blocks").GetComponentsInChildren <BlockController>());
                    Blocks.Shuffle();
                }

                _Bullets = new GameObject("Bullets");
                GameManager.Instance.blackboard.BulletContainer = _Bullets.transform;
                _Players            = new List <GameObject>();
                _playerInputManager = GetComponent <PlayerInputManager>();

                _PlayerSpawner = _Terrain.GetComponentsInChildren <PlayerSpawner>();
                _BotSpawners   = _Terrain.GetComponentsInChildren <BotSpawner>();

                State = LevelState.UPDATINGBACKGROUND;
                break;
            }

            case LevelState.UPDATINGBACKGROUND:
            {
                Gradient           meshCurrentGradient = _Background.GetComponent <MeshGenerator>()._lineGradient;
                GradientColorKey[] bgck = CurrentData._BackgroundGradient.colorKeys;
                int nextNumKeys         = bgck.Length;

                GradientColorKey[] gck = new GradientColorKey[nextNumKeys];
                GradientAlphaKey[] gak = meshCurrentGradient.alphaKeys;

                FindObjectsOfType <AudioPeer>()[0].SetMatColor(CurrentData._BarsMainColor, CurrentData._BarsSecondColor);

                for (int i = 0; i < nextNumKeys; i++)
                {
                    gck[i] = new GradientColorKey(meshCurrentGradient.Evaluate(bgck[i].time), bgck[i].time);
                    yield return(null);
                }

                meshCurrentGradient.SetKeys(gck, gak);

                while (gck[0].color != bgck[0].color)
                {
                    for (int i = 0; i < nextNumKeys; i++)
                    {
                        Color mcg = gck[i].color;
                        mcg    = Color.Lerp(mcg, bgck[i].color, Time.deltaTime * 35f);
                        gck[i] = new GradientColorKey(mcg, gck[i].time);
                        yield return(null);
                    }

                    meshCurrentGradient.SetKeys(gck, gak);

                    _Background.GetComponent <MeshGenerator>().SetGradient(meshCurrentGradient);

                    yield return(new WaitForSeconds(secondsBetweenBlock * 0.5f));
                }
                _Background.GetComponent <MeshGenerator>().SetGradient(CurrentData._BackgroundGradient);
                State = LevelState.LOADINGLEVEL;
                break;
            }

            case LevelState.LOADINGLEVEL:
            {
                foreach (BlockController bc in Blocks)
                {
                    bc.Move();
                    yield return(new WaitForSeconds(secondsBetweenBlock));
                }

                while (Blocks[Blocks.Count - 1].HasToMove || Blocks[Blocks.Count - 1].IsOut)
                {
                    yield return(null);
                }

                State = LevelState.LOADINGPLAYERS;
                break;
            }

            case LevelState.LOADINGPLAYERS:
            {
                Color tempColor = Color.black;
                while (tempColor != CurrentData._ScenaryColor)
                {
                    tempColor = Color.Lerp(tempColor, CurrentData._ScenaryColor, Time.deltaTime * 10f);
                    _MatBeat.SetColor("_EmissionColor", tempColor * Mathf.Pow(2f, AudioPeer._AmplitudeBuffer));
                    yield return(null);
                }
                int startPlayerSpawner = Random.Range(0, _PlayerSpawner.Length - 1);

                GameObject go = Instantiate(_PrefabPlayer);
                go.transform.position = _PlayerSpawner[startPlayerSpawner].GetPosition();
                PlayerController pc = go.GetComponent <PlayerController>();
                pc.Create(0, _Inputs[0]);
                _Players.Add(go);

                State = LevelState.PLAYING;
                break;
            }

            case LevelState.PLAYING:
            {
                _MatBeat.SetColor("_EmissionColor", CurrentData._ScenaryColor * Mathf.Pow(2f, AudioPeer._AmplitudeBuffer));

                foreach (GameObject pl in _Players)
                {
                    if (pl.GetComponent <PlayerController>())
                    {
                        PlayerController pc = pl.GetComponent <PlayerController>();
                        if (pc.IsDead)
                        {
                            _Players.Remove(pl);
                            Destroy(pl);
                            _UI.RemPoint(0);
                            Reset = true;
                            break;
                        }
                    }
                    yield return(null);
                }

                if (Reset)
                {
                    Reset = false;
                    State = LevelState.LOADINGPLAYERS;
                }

                break;
            }

            case LevelState.REMOVINGLEVEL:
            {
                foreach (GameObject go in _Players)
                {
                    go.SetActive(false);
                }

                for (int i = 0; i < Blocks.Count; i++)
                {
                    Blocks[i].Move();
                    yield return(new WaitForSeconds(secondsBetweenBlock));
                }

                while (Blocks[Blocks.Count - 1].transform.position.y > -3f)
                {
                    yield return(null);
                }

                State = LevelState.RESETINGLEVEL;
                break;
            }

            case LevelState.RESETINGLEVEL:
            {
                foreach (GameObject go in _Players)
                {
                    Destroy(go);
                }
                if (_Terrain)
                {
                    Destroy(_Terrain);
                }
                if (_Bullets)
                {
                    Destroy(_Bullets);
                }
                Blocks.Clear();
                State = LevelState.SEEDING;
                break;
            }

            case LevelState.ENDGAME:
            {
                while (GameManager.Instance.TimeScale > SlowmoMinScale)
                {
                    GameManager.Instance.TimeScale -= Time.deltaTime * SlowmoMultiplier;
                    yield return(null);
                }

                GameManager.Instance.TimeScale = SlowmoMinScale;

                Material winnerBg = _UIEnd.transform.Find("Background").GetComponent <UnityEngine.UI.Image>().material;
                float    blurVal  = 0;
                winnerBg.SetFloat("_BlurValue", blurVal);
                _UIEnd.transform.Find("Background").gameObject.SetActive(true);

                while (winnerBg.GetFloat("_BlurValue") < 0.002f)
                {
                    blurVal += Time.deltaTime * 0.025f;
                    winnerBg.SetFloat("_BlurValue", blurVal);
                    yield return(null);
                }

                winnerBg.SetFloat("_BlurValue", 0.002f);

                string playerWinner = "YOU GOT " + GameManager.Instance.blackboard.Player1Score + " POINT/S\n IN " + GameManager.Instance.blackboard.timerPractice + " SECONDS";
                _UIEnd.transform.Find("Winner").GetComponent <UnityEngine.UI.Text>().text = playerWinner;
                _UIEnd.transform.Find("Winner").gameObject.SetActive(true);

                yield return(new WaitForSeconds(2.5f * SlowmoMinScale));

                while (!Input.anyKey)
                {
                    yield return(null);
                }

                GameManager.Instance.CurrentState(StateType.MENU);
                break;
            }

            case LevelState.WAITING:
            {
                break;
            }
            }

            yield return(null);
        }
        yield return(null);
    }
Beispiel #3
0
    // Update is called once per frame
    protected virtual void FixedUpdate()
    {
        line.SetPosition(0, this.transform.position);
        line.SetPosition(1, transform.position + (transform.forward * 1.0f));

        this.transform.position = new Vector3(leftHand.transform.position.x, leftHand.transform.position.y, leftHand.transform.position.z + .1f);
        this.transform.rotation = leftHand.transform.rotation;

        if (Physics.Raycast(transform.position, transform.forward, out hit, 3.0f))
        {
            //Debug.Log("Hitting: " + hit);
            Debug.DrawRay(transform.position, transform.forward);
            if (hit.collider.CompareTag("InteractableObj"))
            {
                Debug.Log("is hitting");
                isHitting = true;

                if (hit.collider.name == "CartelloneInterno")
                {
                    hit.collider.GetComponentInParent <InteractableObject>().Zoom(true);
                }
                else if (hit.collider.name == "ElicotteroMesh")
                {
                    hit.collider.GetComponentInParent <EnableRenderer>().AbleRenderer(true);
                }
                else if (hit.collider.name == "CosoGiallo")
                {
                    hit.collider.GetComponentInParent <EnableRenderer>().AbleRenderer(true);
                }

                Gradient           temporalGradient = new Gradient();
                GradientColorKey[] colorKey         = new GradientColorKey[2];
                GradientAlphaKey[] alphaKey         = new GradientAlphaKey[2];

                colorKey[0].color = Color.white;
                colorKey[0].time  = 0.0f;
                colorKey[1].color = Color.white;
                colorKey[1].time  = 1.0f;

                alphaKey[0].alpha = .8f;
                alphaKey[0].time  = 0.0f;
                alphaKey[1].alpha = 0.5f;
                alphaKey[1].time  = 1.0f;

                temporalGradient.SetKeys(colorKey, alphaKey);
                line.colorGradient = temporalGradient;
                //line.SetPosition(1, hit.transform.position);
            }
        }
        else
        {
            foreach (EnableRenderer renderer in renderers)
            {
                renderer.AbleRenderer(false);
            }

            obj.Zoom(false);
            line.colorGradient = initialGradient;
            isHitting          = false;
        }
    }
Beispiel #4
0
 public static Gradient BlackToWhite()
 {
     GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_Black, Color1_White };
     GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { Alpha0_1 };
     return(New(colorKeys, alphaKeys));
 }
Beispiel #5
0
 public static Gradient WhiteToBlack()
 {
     GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_White, Color1_Black };
     GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { Alpha0_1 };
     return(New(colorKeys, alphaKeys));
 }
Beispiel #6
0
 public static Gradient BlackToWhite()
 {
     GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_Black, Color1_White };
     return(New(colorKeys, null));
 }
Beispiel #7
0
 public static Gradient BlackFadeOut()
 {
     GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_Black };
     GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { Alpha0_1, Alpha1_0 };
     return(New(colorKeys, alphaKeys));
 }
        void AssignHeightMapToProvinces(bool colorGroundCells)
        {
            if (heightMapTexture == null)
            {
                return;
            }

            if (currentHeightmapWidth == 0)
            {
                return;
            }
            if (heightGradient == null)
            {
                heightGradientPreset = HeightMapGradientPreset.Colored;
            }

            GradientColorKey[] colorKeys;
            switch (heightGradientPreset)
            {
            case HeightMapGradientPreset.Colored:
                heightGradient           = new Gradient();
                colorKeys                = new GradientColorKey[4];
                colorKeys [0]            = new GradientColorKey(Color.gray, 0f);
                colorKeys [1]            = new GradientColorKey(new Color(0.133f, 0.545f, 0.133f), seaLevel);
                colorKeys [2]            = new GradientColorKey(new Color(0.898f, 0.898f, 0.298f), (seaLevel + 1f) * 0.5f);
                colorKeys [3]            = new GradientColorKey(Color.white, 1f);
                heightGradient.colorKeys = colorKeys;
                break;

            case HeightMapGradientPreset.ColoredLight:
                heightGradient           = new Gradient();
                colorKeys                = new GradientColorKey[4];
                colorKeys [0]            = new GradientColorKey(Color.gray, 0f);
                colorKeys [1]            = new GradientColorKey(new Color(0.333f, 0.745f, 0.333f), seaLevel);
                colorKeys [2]            = new GradientColorKey(new Color(0.998f, 0.998f, 0.498f), (seaLevel + 1f) * 0.5f);
                colorKeys [3]            = new GradientColorKey(Color.white, 1f);
                heightGradient.colorKeys = colorKeys;
                break;

            case HeightMapGradientPreset.Grayscale:
                heightGradient           = new Gradient();
                colorKeys                = new GradientColorKey[3];
                colorKeys [0]            = new GradientColorKey(Color.black, 0f);
                colorKeys [1]            = new GradientColorKey(Color.gray, seaLevel);
                colorKeys [2]            = new GradientColorKey(Color.white, 1f);
                heightGradient.colorKeys = colorKeys;
                break;

            case HeightMapGradientPreset.BlackAndWhite:
                heightGradient           = new Gradient();
                colorKeys                = new GradientColorKey[3];
                colorKeys [0]            = new GradientColorKey(Color.black, 0f);
                colorKeys [1]            = new GradientColorKey(Color.white, seaLevel);
                colorKeys [2]            = new GradientColorKey(Color.white, 1f);
                heightGradient.colorKeys = colorKeys;
                break;
            }

            int provCount = mapProvinces.Count;

            for (int k = 0; k < provCount; k++)
            {
                MapProvince prov = mapProvinces [k];
                int         x    = (int)Mathf.Clamp((prov.center.x + 0.5f) * currentHeightmapWidth, 0, currentHeightmapWidth - 1);
                int         y    = (int)Mathf.Clamp((prov.center.y + 0.5f) * currentHeightmapHeight, 0, currentHeightmapHeight - 1);
                int         j    = y * currentHeightmapWidth + x;
                float       h    = heights [j];
                if (h < seaLevel)
                {
                    prov.visible = false;
                }
                else
                {
                    prov.visible = true;
                    prov.color   = colorGroundCells ? heightGradient.Evaluate(h) : Color.white;
                }
            }
        }
        public static object Load(System.Type type, string text, object oldValue)
        {
            if (type == null)
            {
                return(null);
            }

            if (type.IsPrimitive)
            {
                if (string.IsNullOrEmpty(text))
                {
                    try
                    {
                        return(Activator.CreateInstance(type));
                    }
                    catch (MissingMethodException)
                    {
                        Debug.LogError(type.Name + " Doesn't seem to have a default constructor");

                        throw;
                    }
                }

                return(Convert.ChangeType(text, type, CultureInfo.InvariantCulture));
            }
            else if (typeof(UnityEngine.Object).IsAssignableFrom(type))
            {
                object obj = new ObjectWrapper();
                EditorJsonUtility.FromJsonOverwrite(text, obj);

                return(((ObjectWrapper)obj).obj);
            }
            else if (type.IsAssignableFrom(typeof(AnimationCurve)))
            {
                AnimCurveWrapper sac = new AnimCurveWrapper();

                JsonUtility.FromJsonOverwrite(text, sac);

                AnimationCurve curve = oldValue != null ? (AnimationCurve)oldValue : new AnimationCurve();

                if (sac.frames != null)
                {
                    Keyframe[] keys = new UnityEngine.Keyframe[sac.frames.Length];
                    for (int i = 0; i < sac.frames.Length; ++i)
                    {
                        keys[i].time       = sac.frames[i].time;
                        keys[i].value      = sac.frames[i].value;
                        keys[i].inTangent  = sac.frames[i].inTangent;
                        keys[i].outTangent = sac.frames[i].outTangent;
                        if (sac.version == 1)
                        {
                            AnimationUtility.SetKeyLeftTangentMode(ref keys[i], sac.frames[i].leftTangentMode);
                            AnimationUtility.SetKeyRightTangentMode(ref keys[i], sac.frames[i].rightTangentMode);
                            AnimationUtility.SetKeyBroken(ref keys[i], sac.frames[i].broken);
                        }
                        else
                        {
                            AnimationUtility.SetKeyLeftTangentMode(ref keys[i], (TangentMode)((sac.frames[i].tangentMode & kLeftTangentMask) >> 1));
                            AnimationUtility.SetKeyRightTangentMode(ref keys[i], (TangentMode)((sac.frames[i].tangentMode & kRightTangentMask) >> 5));
                            AnimationUtility.SetKeyBroken(ref keys[i], (sac.frames[i].tangentMode & kBrokenMask) != 0);
                        }
                    }
                    curve.keys         = keys;
                    curve.preWrapMode  = sac.preWrapMode;
                    curve.postWrapMode = sac.postWrapMode;
                }

                return(curve);
            }
            else if (type.IsAssignableFrom(typeof(Gradient)))
            {
                GradientWrapper gw       = new GradientWrapper();
                Gradient        gradient = oldValue != null ? (Gradient)oldValue : new Gradient();

                JsonUtility.FromJsonOverwrite(text, gw);

                gradient.mode = gw.gradientMode;

                GradientColorKey[] colorKeys = null;
                if (gw.colorKeys != null)
                {
                    colorKeys = new GradientColorKey[gw.colorKeys.Length];
                    for (int i = 0; i < gw.colorKeys.Length; ++i)
                    {
                        colorKeys[i].color = gw.colorKeys[i].color;
                        colorKeys[i].time  = gw.colorKeys[i].time;
                    }
                }
                else
                {
                    colorKeys = new GradientColorKey[0];
                }

                GradientAlphaKey[] alphaKeys = null;

                if (gw.alphaKeys != null)
                {
                    alphaKeys = new GradientAlphaKey[gw.alphaKeys.Length];
                    for (int i = 0; i < gw.alphaKeys.Length; ++i)
                    {
                        alphaKeys[i].alpha = gw.alphaKeys[i].alpha;
                        alphaKeys[i].time  = gw.alphaKeys[i].time;
                    }
                }
                else
                {
                    alphaKeys = new GradientAlphaKey[0];
                }

                gradient.SetKeys(colorKeys, alphaKeys);
                return(gradient);
            }
            else if (type == typeof(string))
            {
                return(text.Substring(1, text.Length - 2).Replace("\\\"", "\""));
            }
            else if (type == typeof(SerializableType))
            {
                var obj = new SerializableType(text.Substring(1, text.Length - 2));
                return(obj);
            }
            else if (type.IsArrayOrList())
            {
                List <string> elements = ParseArray(text);

                if (elements == null)
                {
                    return(null);
                }
                if (type.IsArray)
                {
                    int listCount = elements.Count;

                    Array arrayObj = (Array)Activator.CreateInstance(type, new object[] { listCount });

                    for (int index = 0; index < listCount; index++)
                    {
                        arrayObj.SetValue(Load(type.GetElementType(), elements[index], null), index);
                    }

                    return(arrayObj);
                }
                else //List
                {
                    int   listCount = elements.Count;
                    IList listObj   = (Array)Activator.CreateInstance(type, new object[] { listCount });
                    for (int index = 0; index < listCount; index++)
                    {
                        listObj.Add(Load(type.GetElementType(), elements[index], null));
                    }

                    return(listObj);
                }
            }
            else
            {
                try
                {
                    object obj = Activator.CreateInstance(type);
                    EditorJsonUtility.FromJsonOverwrite(text, obj);
                    return(obj);
                }
                catch (MissingMethodException)
                {
                    Debug.LogError(type.Name + " Doesn't seem to have a default constructor");

                    throw;
                }
            }
        }
 public static Vector4 ColorKeyToVector(GradientColorKey key)
 {
     return(new Vector4(key.color.r, key.color.g, key.color.b, key.time));
 }
Beispiel #11
0
    // Shows feedback on whether the balloon is pulling up or down on the cargo.
    IEnumerator ShowPullFeedback(Vector2 pullDirection, float duration = 1f)
    {
        if (isPullAnimating)
        {
            yield break;
        }

        isPullAnimating = true;

        GradientColorKey start       = new GradientColorKey(),
                         backFramer  = new GradientColorKey(),
                         frontFramer = new GradientColorKey();

        // Sets the gradient properties.
        Color pullColor;
        bool  pullUp = pullDirection.y > 0;

        if (pullUp)
        {
            start.color      = pullColor = pullDirectionUI.upColor;
            backFramer.color = frontFramer.color = pullDirectionUI.baseColor;
            start.time       = backFramer.time = 0.999f;
            frontFramer.time = 0.899f;
        }
        else
        {
            start.color      = pullColor = pullDirectionUI.downColor;
            backFramer.color = frontFramer.color = pullDirectionUI.baseColor;
            start.time       = backFramer.time = 0.001f;
            frontFramer.time = 0.101f;
        }

        // Array we are going to modify before injecting into the gradient.
        GradientColorKey[] colorKey = new GradientColorKey[5] {
            new GradientColorKey {
                color = pullDirectionUI.baseColor,
                time  = 0f
            },
            backFramer,
            start,
            frontFramer,
            new GradientColorKey {
                color = pullDirectionUI.baseColor,
                time  = 1f
            }
        };

        // This is the timed loop.
        WaitForEndOfFrame w       = new WaitForEndOfFrame();
        float             elapsed = 0;

        do
        {
            yield return(w);

            elapsed += Time.deltaTime;
            float ratio = elapsed / duration;
            if (pullUp)
            {
                ratio = 1 - ratio;
            }

            // Updates the gradient colors on the line renderer.
            colorKey[1].time           = Mathf.Clamp(ratio - 0.1f, 0, 1);
            colorKey[2].time           = ratio;
            colorKey[3].time           = Mathf.Clamp(ratio + 0.1f, 0, 1);
            lineRenderer.colorGradient = new Gradient()
            {
                colorKeys = colorKey
            };
        } while(elapsed < duration);

        // Undo the shine on the line renderer.
        isPullAnimating            = false;
        lineRenderer.colorGradient = new Gradient {
            colorKeys = new GradientColorKey[1] {
                new GradientColorKey {
                    color = pullDirectionUI.baseColor,
                    time  = 0f
                }
            }
        };
    }
Beispiel #12
0
        private static UnityEngine.Gradient Lerp(this UnityEngine.Gradient a, UnityEngine.Gradient b, float t, bool noAlpha, bool noColor)
        {
            keysTimes.Clear();

            if (a == b || a.Equals(b))
            {
                return(b);
            }

            GradientAlphaKey[] alphaKeys1 = a.alphaKeys;
            GradientColorKey[] colorKeys1 = a.colorKeys;
            GradientAlphaKey[] alphaKeys2 = b.alphaKeys;
            GradientColorKey[] colorKeys2 = b.colorKeys;

            if (alphaKeys1.Length == alphaKeys2.Length && colorKeys1.Length == colorKeys2.Length)
            {
                // full compare of all keys, save allocating memory if both gradients are equal
                bool equal = true;
                for (int i = 0; i < alphaKeys1.Length; i++)
                {
                    if (alphaKeys1[i].alpha != alphaKeys2[i].alpha || alphaKeys1[i].time != alphaKeys2[i].time ||
                        colorKeys1[i].color != colorKeys2[i].color || colorKeys1[i].time != colorKeys2[i].time)
                    {
                        equal = false;
                        break;
                    }
                }
                if (equal)
                {
                    return(b);
                }
                Gradient           gradient = new Gradient();
                GradientColorKey[] clrs     = new GradientColorKey[colorKeys1.Length];
                GradientAlphaKey[] alphas   = new GradientAlphaKey[colorKeys1.Length];
                for (int i = 0; i < colorKeys1.Length; i++)
                {
                    clrs[i]   = new GradientColorKey(Color.Lerp(colorKeys1[i].color, colorKeys2[i].color, t), Mathf.Lerp(colorKeys1[i].time, colorKeys2[i].time, t));
                    alphas[i] = new GradientAlphaKey(Mathf.Lerp(alphaKeys1[i].alpha, alphaKeys2[i].alpha, t), Mathf.Lerp(alphaKeys1[i].time, alphaKeys2[i].time, t));
                }
                gradient.colorKeys = clrs;
                gradient.alphaKeys = alphas;
                return(gradient);
            }
            else
            {
                for (int i = 0; i < colorKeys1.Length; i++)
                {
                    float k = colorKeys1[i].time;
                    if (!keysTimes.Contains(k))
                    {
                        keysTimes.Add(k);
                    }
                }

                for (int i = 0; i < colorKeys2.Length; i++)
                {
                    float k = colorKeys2[i].time;
                    if (!keysTimes.Contains(k))
                    {
                        keysTimes.Add(k);
                    }
                }
                for (int i = 0; i < alphaKeys1.Length; i++)
                {
                    float k = alphaKeys1[i].time;
                    if (!keysTimes.Contains(k))
                    {
                        keysTimes.Add(k);
                    }
                }
                for (int i = 0; i < alphaKeys2.Length; i++)
                {
                    float k = alphaKeys2[i].time;
                    if (!keysTimes.Contains(k))
                    {
                        keysTimes.Add(k);
                    }
                }

                GradientColorKey[] clrs   = new GradientColorKey[keysTimes.Count];
                GradientAlphaKey[] alphas = new GradientAlphaKey[keysTimes.Count];

                for (int i = 0; i < keysTimes.Count; i++)
                {
                    float key = keysTimes[i];
                    var   clr = Color.Lerp(a.Evaluate(key), b.Evaluate(key), t);
                    clrs[i]   = new GradientColorKey(clr, key);
                    alphas[i] = new GradientAlphaKey(clr.a, key);
                }

                Gradient gradient = new Gradient();
                gradient.SetKeys(clrs, alphas);
                return(gradient);
            }
        }
Beispiel #13
0
        public static object ReadFromBinary(DataType dataType, BinaryReader br)
        {
            object value = null;

            if (dataType == DataType.String)
            {
                value = br.ReadString();
            }
            else if (dataType == DataType.Char)
            {
                value = br.ReadChar();
            }
            else if (dataType == DataType.Boolean)
            {
                byte byteValue = br.ReadByte();
                value = (byteValue != 0);
            }
            else if (dataType == DataType.Integer)
            {
                value = br.ReadInt32();
            }
            else if (dataType == DataType.Long)
            {
                value = br.ReadInt64();
            }
            else if (dataType == DataType.Float)
            {
                value = br.ReadSingle();
            }
            else if (dataType == DataType.Double)
            {
                value = br.ReadDouble();
            }
            else if (dataType == DataType.Vector2)
            {
                value = new Vector2(br.ReadSingle(), br.ReadSingle());
            }
            else if (dataType == DataType.Vector3)
            {
                value = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
            }
            else if (dataType == DataType.Vector4)
            {
                value = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
            }
#if UNITY_2017_2_OR_NEWER
            else if (dataType == DataType.Vector2Int)
            {
                value = new Vector2Int(br.ReadInt32(), br.ReadInt32());
            }
            else if (dataType == DataType.Vector3Int)
            {
                value = new Vector3Int(br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
            }
#endif
            else if (dataType == DataType.Bounds)
            {
                value = new Bounds(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
            }
#if UNITY_2017_2_OR_NEWER
            else if (dataType == DataType.BoundsInt)
            {
                value = new BoundsInt(new Vector3Int(br.ReadInt32(), br.ReadInt32(), br.ReadInt32()), new Vector3Int(br.ReadInt32(), br.ReadInt32(), br.ReadInt32()));
            }
#endif
            else if (dataType == DataType.Quaternion)
            {
                value = new Quaternion(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
            }
            else if (dataType == DataType.Rect)
            {
                value = new Rect(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
            }
#if UNITY_2017_2_OR_NEWER
            else if (dataType == DataType.RectInt)
            {
                value = new RectInt(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32());
            }
#endif
            else if (dataType == DataType.Color)
            {
                value = new Color(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
            }
            else if (dataType == DataType.Color32)
            {
                value = new Color32(br.ReadByte(), br.ReadByte(), br.ReadByte(), br.ReadByte());
            }
            else if (dataType == DataType.AnimationCurve)
            {
                int        keyframeCount = br.ReadInt32();
                Keyframe[] keyframes     = new Keyframe[keyframeCount];
                for (int i = 0; i < keyframeCount; i++)
                {
                    keyframes[i] = new Keyframe(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                }
                value = new AnimationCurve(keyframes);
            }
            else if (dataType == DataType.Gradient)
            {
                GradientMode       gradientMode = (GradientMode)br.ReadByte();
                GradientAlphaKey[] alphaKeys    = new GradientAlphaKey[br.ReadInt32()];
                for (int i = 0; i < alphaKeys.Length; i++)
                {
                    alphaKeys[i] = new GradientAlphaKey(br.ReadSingle(), br.ReadSingle());
                }
                GradientColorKey[] colorKeys = new GradientColorKey[br.ReadInt32()];

                for (int i = 0; i < colorKeys.Length; i++)
                {
                    colorKeys[i] = new GradientColorKey(new Color(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), br.ReadSingle());
                }
                value = new Gradient()
                {
                    mode = gradientMode, alphaKeys = alphaKeys, colorKeys = colorKeys
                };
            }
            else if (dataType == DataType.Enum)
            {
                value = br.ReadInt32();
            }
            else if (dataType == DataType.UnityObjectReference)
            {
                string guidString = br.ReadString();
                if (string.IsNullOrEmpty(guidString))
                {
                    value = Guid.Empty;
                }
                else
                {
                    value = new Guid(guidString); // Read guid
                }
            }
            else if (dataType == DataType.Unknown)
            {
                value = br.ReadString(); // Read Type name
            }
            else if (dataType == DataType.Void)
            {
                // No need to read/write a value for a void type
            }
            else
            {
                Debug.LogWarning("Could not read " + dataType);
            }
            return(value);
        }
Beispiel #14
0
 public static Gradient WhiteToBlack()
 {
     GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_White, Color1_Black };
     return(New(colorKeys, null));
 }
Beispiel #15
0
        public static Vector4 ToVector(this GradientColorKey key)
        {
            var c = key.color.linear;

            return(new Vector4(c.r, c.g, c.b, key.time));
        }
Beispiel #16
0
 public static Gradient WhiteFadeIn()
 {
     GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_White };
     GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { Alpha0_0, Alpha1_1 };
     return(New(colorKeys, alphaKeys));
 }
		public void SetKeys(GradientColorKey[] colorKeys, GradientAlphaKey[] alphaKeys){}
    void updateRangefinder(unitScript unit, GridItem position)
    {
        RangedWeapon weapon = (RangedWeapon)unit.getCurrentWeapon();

        // Set line data
        Vector3[] positions = new Vector3[4];
        positions[0] = new Vector3(unit.GetComponent <GridItem>().getX(), 1.0f, unit.GetComponent <GridItem>().getY());
        positions[3] = new Vector3(position.getX(), 1.0f, position.getY());

        float distance = Vector3.Distance(positions[0], positions[3]);

        positions[1] = Vector3.Lerp(positions[0], positions[3], Mathf.Max(0.001f, weapon.minRange / distance));
        positions[2] = Vector3.Lerp(positions[0], positions[3], Mathf.Min(0.9999f, (float)weapon.maxRange / distance));

        rangeRenderer.numPositions = 4;
        rangeRenderer.SetPositions(positions);



        GradientColorKey[] colorKey = new GradientColorKey[4];
        GradientAlphaKey[] alphaKey = new GradientAlphaKey[2];

        //Set ends to red and red
        colorKey[2] = new GradientColorKey(new Color(1, 0, 0), 0.0f);


        Color endColor;

        if (distance < weapon.minRange || distance > weapon.maxRange)
        {
            endColor = new Color(1, 0, 0);
        }
        else
        {
            endColor = new Color(0, 0, 0);
        }

        colorKey[3] = new GradientColorKey(endColor, 1.0f);

        //Set alphaKeys
        alphaKey[0] = new GradientAlphaKey(1.0f, 0.0f);
        alphaKey[1] = new GradientAlphaKey(1.0f, 1.0f);
        //Set color key's two and three according to range

        GradientColorKey minKey, maxKey;

        if (distance > weapon.minRange)
        {
            minKey = new GradientColorKey(new Color(0, 0, 0), (float)weapon.minRange / distance);
        }
        else
        {
            minKey = new GradientColorKey(new Color(1, 0, 0), 0.2f);
        }

        colorKey[0] = minKey;

        if (distance > weapon.minRange)
        {
            maxKey = new GradientColorKey(new Color(0, 0, 0), Mathf.Min(0.99999f, (float)weapon.maxRange / distance));
        }
        else
        {
            maxKey = new GradientColorKey(new Color(1, 0, 0), 0.5f);
        }

        colorKey[1] = maxKey;

        Gradient grad = new Gradient();

        grad.mode = GradientMode.Blend;
        grad.SetKeys(colorKey, alphaKey);

        rangeRenderer.colorGradient = grad;
    }