SetKeys() 개인적인 메소드

private SetKeys ( GradientColorKey colorKeys, GradientAlphaKey alphaKeys ) : void
colorKeys GradientColorKey
alphaKeys GradientAlphaKey
리턴 void
 static public int SetKeys(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         UnityEngine.Gradient           self = (UnityEngine.Gradient)checkSelf(l);
         UnityEngine.GradientColorKey[] a1;
         checkArray(l, 2, out a1);
         UnityEngine.GradientAlphaKey[] a2;
         checkArray(l, 3, out a2);
         self.SetKeys(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
예제 #2
0
    private UnityEngine.Gradient MatrixToColormap(double[,] matrix)
    {
        UnityEngine.Gradient map = new UnityEngine.Gradient();

        int rowCount = matrix.GetLength(0);

        GradientColorKey[] colorKey = new GradientColorKey[rowCount];

        Color temp = new Color();

        for (int i = 0; i < rowCount; i++)
        {
            temp.r = (float)matrix[i, 0];
            temp.g = (float)matrix[i, 1];
            temp.b = (float)matrix[i, 2];

            colorKey[i].color = temp;
            colorKey[i].time  = (float)i / rowCount;
        }

        GradientAlphaKey[] alphaKey = new GradientAlphaKey[2];
        alphaKey[0].alpha = 1.0f;
        alphaKey[0].time  = 0.0f;
        alphaKey[1].alpha = 0.0f;
        alphaKey[1].time  = 1.0f;

        map.SetKeys(colorKey, alphaKey);

        return(map);
    }
예제 #3
0
    public void ApplyToUnityParticleSystem(UnityEngine.ParticleSystem ups, ParticleSystem ps)
    {
        var colorModule = ups.colorOverLifetime;

        var gradient = new UnityEngine.Gradient();

        gradient.mode = UnityEngine.GradientMode.Blend;
        UnityEngine.GradientColorKey[] gck = new UnityEngine.GradientColorKey[keyFrameLifeTime.Count];

        for (int i = 0; i < keyFrameLifeTime.Count; ++i)
        {
            gck[i].time  = keyFrameLifeTime[i];
            gck[i].color = new Color(r[i] / 255.0f, g[i] / 255.0f, b[i] / 255.0f);
        }
        UnityEngine.GradientAlphaKey[] gak;
        if (colorModule.enabled)
        {
            gak = colorModule.color.gradient.alphaKeys;
        }
        else
        {
            gak          = new UnityEngine.GradientAlphaKey[2];
            gak[0].time  = 0.0f;
            gak[0].alpha = 1.0f;
            gak[1].time  = 1.0f;
            gak[1].alpha = 1.0f;
        }
        gradient.SetKeys(gck, gak);
        colorModule.enabled = true;
        colorModule.color   = new UnityEngine.ParticleSystem.MinMaxGradient(gradient);
    }
예제 #4
0
	// Update is called once per frame
	void Update () {
    if (timer == 0) {
      LastColor = SoupMaterial.color;
    }

    if (!NextColor.Equals(SoupMaterial.color)) {
      timer += Time.deltaTime;
      Color c = Color.Lerp(LastColor, NextColor, timer / duration);
      SoupMaterial.color = c;
      SoupLight.color = c;
      SoupLight.intensity = Mathf.Max(1.5f * (duration - timer), 1);

      var col = Smoke.colorOverLifetime;
      col.enabled = true;

      Gradient grad = new Gradient();
      grad.SetKeys( new GradientColorKey[] { new GradientColorKey(c, 0.0f), new GradientColorKey(Color.gray, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) } );

      col.color = new ParticleSystem.MinMaxGradient(grad);

      if (timer >= duration) {
        SoupMaterial.color = NextColor;
        SoupLight.intensity = 1;
        timer = 0;
      }
    }
	}
예제 #5
0
 /// <summary>
 /// Creates a gradient between two colors
 /// </summary>
 public static Gradient Gradient(Color from, Color to)
 {
     var g = new Gradient();
     g.SetKeys(new[] {new GradientColorKey(from, 0), new GradientColorKey(to, 1)},
         new[] {new GradientAlphaKey(from.a, 0), new GradientAlphaKey(to.a, 1)});
     return g;
 }
예제 #6
0
            public static void SetPixelsFromGradients(Texture2D texture, Gradient[] gradients, int width, int height)
            {
                // check color/alpha keys count across gradients
                int colorCount = gradients[0].colorKeys.Length;
                int alphaCount = gradients[0].alphaKeys.Length;

                for (int i = 1; i < gradients.Length; i++)
                {
                    if (gradients[i].colorKeys.Length != colorCount)
                    {
                        Debug.LogError("[TCP2 Ramp Generator] Invalid Gradients: gradients need to have the same number of color/alpha keys to be interpolated properly.");
                        return;
                    }

                    if (gradients[i].alphaKeys.Length != alphaCount)
                    {
                        Debug.LogError("[TCP2 Ramp Generator] Invalid Gradients: gradients need to have the same number of color/alpha keys to be interpolated properly.");
                        return;
                    }
                }

                int blockHeight  = Mathf.FloorToInt(height / (float)(gradients.Length - 1));
                var lerpGradient = new Gradient();

                Color[] pixelsBuffer = new Color[width];
                for (int y = 0; y < height; y++)
                {
                    float l = (y % blockHeight) / (float)blockHeight;

                    int rampIndex     = Mathf.FloorToInt((y / (float)height) * (gradients.Length - 1));
                    int nextRampIndex = rampIndex + 1;

                    var g1 = gradients[rampIndex];
                    var g2 = gradients[nextRampIndex];

                    var colorKeys = new GradientColorKey[g1.colorKeys.Length];
                    for (int i = 0; i < g1.colorKeys.Length; i++)
                    {
                        colorKeys[i] = new GradientColorKey(
                            Color.Lerp(g1.colorKeys[i].color, g2.colorKeys[i].color, l),
                            Mathf.Lerp(g1.colorKeys[i].time, g2.colorKeys[i].time, l)
                            );
                    }

                    var alphaKeys = new GradientAlphaKey[g1.alphaKeys.Length];
                    for (int i = 0; i < g1.alphaKeys.Length; i++)
                    {
                        alphaKeys[i] = new GradientAlphaKey(
                            Mathf.Lerp(g1.alphaKeys[i].alpha, g2.alphaKeys[i].alpha, l),
                            Mathf.Lerp(g1.alphaKeys[i].time, g2.alphaKeys[i].time, l)
                            );
                    }
                    lerpGradient.SetKeys(colorKeys, alphaKeys);

                    var pixels = GetPixelsFromGradient(lerpGradient, width, 1, pixelsBuffer);
                    texture.SetPixels(0, height - y - 1, width, 1, pixels);
                }
                texture.Apply(false);
            }
        /// <summary>
        /// Initializes a new instance of Gradient.
        /// </summary>
        static GradientPresets()
        {
            // Grayscale gradient color keys
            var grayscaleColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.black, 0),
                new GradientColorKey(Color.white, 1)
            };

            // RGB gradient color keys
            var rgbColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.red, 0),
                new GradientColorKey(Color.green, 0.5f),
                new GradientColorKey(Color.blue, 1)
            };

            // RGBA gradient color keys
            var rgbaColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.red, 0),
                new GradientColorKey(Color.green, 1 / 3f),
                new GradientColorKey(Color.blue, 2 / 3f),
                new GradientColorKey(Color.black, 1)
            };

            // RGBA gradient alpha keys
            var rgbaAlphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(0, 2 / 3f), new GradientAlphaKey(1, 1)};

            // Terrain gradient color keys
            var terrainColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(new Color(0, 0, 0.5f), 0),
                new GradientColorKey(new Color(0.125f, 0.25f, 0.5f), 0.4f),
                new GradientColorKey(new Color(0.25f, 0.375f, 0.75f), 0.48f),
                new GradientColorKey(new Color(0, 0.75f, 0), 0.5f),
                new GradientColorKey(new Color(0.75f, 0.75f, 0), 0.625f),
                new GradientColorKey(new Color(0.625f, 0.375f, 0.25f), 0.75f),
                new GradientColorKey(new Color(0.5f, 1, 1), 0.875f),
                new GradientColorKey(Color.white, 1)
            };

            // Generic gradient alpha keys
            var alphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1)};

            _empty = new Gradient();

            _rgb = new Gradient();
            _rgb.SetKeys(rgbColorKeys.ToArray(), alphaKeys.ToArray());

            _rgba = new Gradient();
            _rgba.SetKeys(rgbaColorKeys.ToArray(), rgbaAlphaKeys.ToArray());

            _grayscale = new Gradient();
            _grayscale.SetKeys(grayscaleColorKeys.ToArray(), alphaKeys.ToArray());

            _terrain = new Gradient();
            _terrain.SetKeys(terrainColorKeys.ToArray(), alphaKeys.ToArray());
        }
예제 #8
0
	private void InitImpulseGradient ()
	{
		impulseGradient = new Gradient ();
		GradientColorKey[] gck = new GradientColorKey[impulseGradientColors.Length];
		GradientAlphaKey[] gak = new GradientAlphaKey[impulseGradientColors.Length];
		for (int i = 0; i < impulseGradientColors.Length; i++) {
			gck [i].color = impulseGradientColors [i];
			gak [i].alpha = 1.0f;
			gck [i].time = gak [i].time = impulseGradientTimes [i];
		}
		impulseGradient.SetKeys (gck, gak);
	}
예제 #9
0
 static public int SetKeys(IntPtr l)
 {
     try {
         UnityEngine.Gradient           self = (UnityEngine.Gradient)checkSelf(l);
         UnityEngine.GradientColorKey[] a1;
         checkType(l, 2, out a1);
         UnityEngine.GradientAlphaKey[] a2;
         checkType(l, 3, out a2);
         self.SetKeys(a1, a2);
         return(0);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
        public AmplifyLensFlare()
        {
            m_lensGradient = new UnityEngine.Gradient();

            UnityEngine.GradientColorKey[] colorKeys = new UnityEngine.GradientColorKey[] { new UnityEngine.GradientColorKey(Color.white, 0f),
                                                                                            new UnityEngine.GradientColorKey(Color.blue, 0.25f),
                                                                                            new UnityEngine.GradientColorKey(Color.green, 0.5f),
                                                                                            new UnityEngine.GradientColorKey(Color.yellow, 0.75f),
                                                                                            new UnityEngine.GradientColorKey(Color.red, 1f) };
            UnityEngine.GradientAlphaKey[] alphaKeys = new UnityEngine.GradientAlphaKey[] { new UnityEngine.GradientAlphaKey(1f, 0f),
                                                                                            new UnityEngine.GradientAlphaKey(1f, 0.25f),
                                                                                            new UnityEngine.GradientAlphaKey(1f, 0.5f),
                                                                                            new UnityEngine.GradientAlphaKey(1f, 0.75f),
                                                                                            new UnityEngine.GradientAlphaKey(1f, 1f) };
            m_lensGradient.SetKeys(colorKeys, alphaKeys);
        }
예제 #11
0
 static int SetKeys(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.Gradient           obj  = (UnityEngine.Gradient)ToLua.CheckObject(L, 1, typeof(UnityEngine.Gradient));
         UnityEngine.GradientColorKey[] arg0 = ToLua.CheckObjectArray <UnityEngine.GradientColorKey>(L, 2);
         UnityEngine.GradientAlphaKey[] arg1 = ToLua.CheckObjectArray <UnityEngine.GradientAlphaKey>(L, 3);
         obj.SetKeys(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #12
0
        /// <summary>
        /// Returns a gradient that represents a linear interpolation between two colors.
        /// </summary>
        /// <param name="color1"></param>
        /// <param name="color2"></param>
        /// <returns></returns>
        public static Gradient GetLerp(Color color1, Color color2)
        {
            var gradient = new Gradient();

            var leftColorKey = new GradientColorKey(color1, 0);
            var rightColorKey = new GradientColorKey(color2, 1);

            var leftAlphaKey = new GradientAlphaKey(color1.a, 0);
            var rightAlphaKey = new GradientAlphaKey(color1.a, 1);

            gradient.SetKeys(
                new[]{leftColorKey, rightColorKey},
                new[]{leftAlphaKey, rightAlphaKey});

            return gradient;
        }
예제 #13
0
        public AmplifyGlare()
        {
            m_currentGlareIdx = ( int )m_currentGlareType;

            m_cromaticAberrationGrad = new UnityEngine.Gradient();

            UnityEngine.GradientColorKey[] colorKeys = new UnityEngine.GradientColorKey[] { new UnityEngine.GradientColorKey(Color.white, 0f),
                                                                                            new UnityEngine.GradientColorKey(Color.blue, 0.25f),
                                                                                            new UnityEngine.GradientColorKey(Color.green, 0.5f),
                                                                                            new UnityEngine.GradientColorKey(Color.yellow, 0.75f),
                                                                                            new UnityEngine.GradientColorKey(Color.red, 1f) };
            UnityEngine.GradientAlphaKey[] alphaKeys = new UnityEngine.GradientAlphaKey[] { new UnityEngine.GradientAlphaKey(1f, 0f),
                                                                                            new UnityEngine.GradientAlphaKey(1f, 0.25f),
                                                                                            new UnityEngine.GradientAlphaKey(1f, 0.5f),
                                                                                            new UnityEngine.GradientAlphaKey(1f, 0.75f),
                                                                                            new UnityEngine.GradientAlphaKey(1f, 1f) };
            m_cromaticAberrationGrad.SetKeys(colorKeys, alphaKeys);


            _rtBuffer = new RenderTexture[MaxStarLines * MaxPasses];

            m_weigthsMat = new Matrix4x4[4];
            m_offsetsMat = new Matrix4x4[4];

            m_amplifyGlareCache = new AmplifyGlareCache();

            m_whiteReference = new Color(0.63f, 0.63f, 0.63f, 0.0f);
            m_aTanFoV        = Mathf.Atan(Mathf.PI / MaxLineSamples);


            m_starDefArr = new StarDefData[] { new StarDefData(StarLibType.Cross, "Cross", 2, 4, 1.0f, 0.85f, 0.0f, 0.5f, -1.0f, 90.0f),
                                               new StarDefData(StarLibType.Cross_Filter, "CrossFilter", 2, 4, 1.0f, 0.95f, 0.0f, 0.5f, -1.0f, 90.0f),
                                               new StarDefData(StarLibType.Snow_Cross, "snowCross", 3, 4, 1.0f, 0.96f, 0.349f, 0.5f, -1.0f, -1),
                                               new StarDefData(StarLibType.Vertical, "Vertical", 1, 4, 1.0f, 0.96f, 0.0f, 0.0f, -1.0f, -1),
                                               new StarDefData(StarLibType.Sunny_Cross, "SunnyCross", 4, 4, 1.0f, 0.88f, 0.0f, 0.0f, 0.95f, 45.0f) };

            m_glareDefArr = new GlareDefData[] { new GlareDefData(StarLibType.Cross, 0.00f, 0.5f),                        //Cheap Lens
                                                 new GlareDefData(StarLibType.Cross_Filter, 0.44f, 0.5f),                 //Cross Screen
                                                 new GlareDefData(StarLibType.Cross_Filter, 1.22f, 1.5f),                 //Cross Screen Spectral
                                                 new GlareDefData(StarLibType.Snow_Cross, 0.17f, 0.5f),                   //Snow Cross
                                                 new GlareDefData(StarLibType.Snow_Cross, 0.70f, 1.5f),                   //Snow Cross Spectral
                                                 new GlareDefData(StarLibType.Sunny_Cross, 0.00f, 0.5f),                  //Sunny Cross
                                                 new GlareDefData(StarLibType.Sunny_Cross, 0.79f, 1.5f),                  //Sunny Cross Spectral
                                                 new GlareDefData(StarLibType.Vertical, 1.57f, 0.5f),                     //Vertical Slits
                                                 new GlareDefData(StarLibType.Vertical, 0.00f, 0.5f)                      //Horizontal slits
            };
        }
예제 #14
0
    public static UnityEngine.Gradient GenerateConstGradient(uint[] colors, float[] colorRatios)
    {
        var gradient = new UnityEngine.Gradient();

        gradient.mode = UnityEngine.GradientMode.Blend;
        UnityEngine.GradientColorKey[] gck = new UnityEngine.GradientColorKey[colors.Length];
        UnityEngine.GradientAlphaKey[] gak = new UnityEngine.GradientAlphaKey[colors.Length];
        for (int i = 0; i < colors.Length; ++i)
        {
            gck[i].time  = colorRatios[i];
            gck[i].color = ValueTypeUtil.GetColor(colors[i]);
            gak[i].time  = colorRatios[i];
            gak[i].alpha = 1.0f;
        }
        gradient.SetKeys(gck, gak);
        return(gradient);
    }
예제 #15
0
	public void CreateGradTexture(){
		// Create gradient object and assign generic starting colours
		Grad = new Gradient();
		LastGrad = new Gradient();
		GradientColorKey[] gck = new GradientColorKey[2];
		gck[0] = new GradientColorKey(Color.black, 0f);
		gck[1] = new GradientColorKey(Color.white, 1f);
		GradientAlphaKey[] gak = new GradientAlphaKey[2];
		gak[0] = new GradientAlphaKey(1f, 0f);
		gak[1] = new GradientAlphaKey(1f, 1f);
		Grad.SetKeys(gck, gak);
		LastGrad.SetKeys(gck, gak);
		
		outTexture = new Texture2D(_gradientSizeX,_gradientSizeY);
		outTexture.hideFlags = HideFlags.HideAndDontSave;
//		Debug.Log (outTexture);
	}
예제 #16
0
 public void Init()
 {
     if (m_lensGradient.alphaKeys.Length == 0 && m_lensGradient.colorKeys.Length == 0)
     {
         UnityEngine.GradientColorKey[] colorKeys = new UnityEngine.GradientColorKey[] { new UnityEngine.GradientColorKey(Color.white, 0f),
                                                                                         new UnityEngine.GradientColorKey(Color.blue, 0.25f),
                                                                                         new UnityEngine.GradientColorKey(Color.green, 0.5f),
                                                                                         new UnityEngine.GradientColorKey(Color.yellow, 0.75f),
                                                                                         new UnityEngine.GradientColorKey(Color.red, 1f) };
         UnityEngine.GradientAlphaKey[] alphaKeys = new UnityEngine.GradientAlphaKey[] { new UnityEngine.GradientAlphaKey(1f, 0f),
                                                                                         new UnityEngine.GradientAlphaKey(1f, 0.25f),
                                                                                         new UnityEngine.GradientAlphaKey(1f, 0.5f),
                                                                                         new UnityEngine.GradientAlphaKey(1f, 0.75f),
                                                                                         new UnityEngine.GradientAlphaKey(1f, 1f) };
         m_lensGradient.SetKeys(colorKeys, alphaKeys);
     }
 }
예제 #17
0
    public static Color Grad(float x)
    {
        /*
        // Terrain gradient color keys
        List<GradientColorKey> terrainColorKeys = new List<GradientColorKey>
        {
            new GradientColorKey(new Color(0, 0, 0.5f), 0),
            new GradientColorKey(new Color(0.125f, 0.25f, 0.5f), 0.4f),
            new GradientColorKey(new Color(0.25f, 0.375f, 0.75f), 0.48f),
            new GradientColorKey(new Color(0, 0.75f, 0), 0.5f),
            new GradientColorKey(new Color(0.75f, 0.75f, 0), 0.625f),
            new GradientColorKey(new Color(0.625f, 0.375f, 0.25f), 0.75f),
            new GradientColorKey(new Color(0.5f, 1, 1), 0.875f),
            new GradientColorKey(Color.white, 1)
        };

        // Generic gradient alpha keys
        var alphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1)};
        */

        Gradient g = new Gradient();
        GradientColorKey[] gck;
        GradientAlphaKey[] gak;

        // Populate the color keys at the relative time 0 and 1 (0 and 100%)
        gck = new GradientColorKey[2];
        gck[0].color = Color.red;
        gck[0].time = 0.0f;
        gck[1].color = Color.blue;
        gck[1].time = 1.0f;

        // Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
        gak = new GradientAlphaKey[2];
        gak[0].alpha = 1.0f;
        gak[0].time = 0.0f;
        gak[1].alpha = 0.0f;
        gak[1].time = 1.0f;

        //g.SetKeys(terrainColorKeys.ToArray(), alphaKeys.ToArray());
        g.SetKeys(gck,gak);

        return g.Evaluate(x);;
    }
예제 #18
0
    void Start () {
        GradientColorKey[] gradColorKey;
        GradientAlphaKey[] gradAlphaKey;

        grad = new Gradient();
        gradColorKey = new GradientColorKey[3];
        gradAlphaKey = new GradientAlphaKey[1];

        gradColorKey[0].color = Color.magenta;
        gradColorKey[0].time = 0.0f;
        gradColorKey[1].color = Color.green;
        gradColorKey[1].time = 0.5f;
        gradColorKey[2].color = Color.magenta;
        gradColorKey[2].time = 1.0f;

        gradAlphaKey[0].alpha = 1.0f;

        grad.SetKeys(gradColorKey,gradAlphaKey);
    }
예제 #19
0
    private UnityEngine.Gradient ColorMap()
    {
        UnityEngine.Gradient map = new UnityEngine.Gradient();

        GradientColorKey[] colorKey = new GradientColorKey[8];

        // manual entry of matlab jet(8)
        colorKey[0].color = new Color(0f, 0f, 1f);
        colorKey[0].time  = (float)1 / 8;

        colorKey[1].color = new Color(0f, 0.5f, 1f);
        colorKey[1].time  = (float)2 / 8;

        colorKey[2].color = new Color(0f, 1f, 1f);
        colorKey[2].time  = (float)3 / 8;

        colorKey[3].color = new Color(0.5f, 1f, 0.5f);
        colorKey[3].time  = (float)4 / 8;

        colorKey[4].color = new Color(1f, 1f, 0f);
        colorKey[4].time  = (float)5 / 8;

        colorKey[5].color = new Color(1f, 0.5f, 0f);
        colorKey[5].time  = (float)6 / 8;

        colorKey[6].color = new Color(1f, 0f, 0f);
        colorKey[6].time  = (float)7 / 8;

        colorKey[7].color = new Color(0.5f, 0f, 0f);
        colorKey[7].time  = 1f;

        GradientAlphaKey[] alphaKey = new GradientAlphaKey[2];
        alphaKey[0].alpha = 1.0f;
        alphaKey[0].time  = 0.0f;
        alphaKey[1].alpha = 0.0f;
        alphaKey[1].time  = 1.0f;

        map.SetKeys(colorKey, alphaKey);

        return(map);
    }
        public override void CreateModel(Transform parent)
        {
            GameObject model = Object.Instantiate(Resources.Load("ParticleSystem")) as GameObject;

            if (model != null)
            {
                var colorOverLifetimeModule = model.GetComponent<ParticleSystem>().colorOverLifetime;
                var gradient = new Gradient();
                var gradientColorKeys = new GradientColorKey[]
                {new GradientColorKey(_startColor, 0f), new GradientColorKey(_endColor, 1f)};
                var gradientAlphaKeys = new GradientAlphaKey[]
                {new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 0.8f), new GradientAlphaKey(0f, 1f)};
                    // only fade out in the last 20% of lifetime
                gradient.SetKeys(gradientColorKeys, gradientAlphaKeys);
                colorOverLifetimeModule.color = new ParticleSystem.MinMaxGradient(gradient);

                model.transform.SetParent(parent);
                model.transform.localPosition = LocalCoinPosition();
                SetModel(model);
            }
        }
예제 #21
0
    public void ApplyToUnityParticleSystem(UnityEngine.ParticleSystem ups, ParticleSystem ps)
    {
        var colorModule = ups.colorOverLifetime;

        var gradient = new UnityEngine.Gradient();

        gradient.mode = UnityEngine.GradientMode.Blend;
        UnityEngine.GradientColorKey[] gck;

        if (justAlpha)
        {
            gck          = new UnityEngine.GradientColorKey[2];
            gck[0].time  = 0.0f;
            gck[0].color = ps.Emitter.color.getValue(gck[0].time);
            gck[1].time  = 1.0f;
            gck[1].color = ps.Emitter.color.getValue(gck[1].time);
        }
        else
        {
            gck = new UnityEngine.GradientColorKey[colors.Count];

            for (int i = 0; i < colors.Count; ++i)
            {
                gck[i].time  = colorRatios[i] / 255.0f;
                gck[i].color = ValueTypeUtil.GetColor(colors[i]);
            }
        }

        UnityEngine.GradientAlphaKey[] gak = new UnityEngine.GradientAlphaKey[alphaRatios.Count];

        for (int i = 0; i < alphaRatios.Count; ++i)
        {
            gak[i].time  = alphaRatios[i] / 255.0f;
            gak[i].alpha = alphas[i];
        }

        gradient.SetKeys(gck, gak);
        colorModule.enabled = true;
        colorModule.color   = new UnityEngine.ParticleSystem.MinMaxGradient(gradient);
    }
예제 #22
0
        public Color EvaluateColor(double value)
        {
            if (_unityGradient == null)
            {
                var colorKeys = Stops
                    .Select(i => i.TryConvertToColorKey(Min, Max))
                    .Where(i => i != null)
                    .Select(i => i.Value)
                    .ToArray();

                var alphaKeys = Stops
                    .Select(i => i.TryConvertToAlphaKey(Min, Max))
                    .Where(i => i != null)
                    .Select(i => i.Value)
                    .ToArray();

                _unityGradient = new Gradient();
                _unityGradient.SetKeys(colorKeys, alphaKeys);
            }

            return _unityGradient.Evaluate((float)((value - Min) / (Max - Min)));
        }
예제 #23
0
            // legacy version
            public static void LegacySetGradientFromUserData(string userData, Gradient gradient)
            {
                var keys = userData.Split('\n');

                if (keys == null || keys.Length < 3 || keys[0] != "GRADIENT")
                {
                    EditorApplication.Beep();
                    Debug.LogError("[TCP2_GradientManager] Invalid Gradient Texture\nMake sure the texture was created with the Ramp Generator.");
                    return;
                }

                var ckData     = keys[1].Split('#');
                var colorsKeys = new GradientColorKey[ckData.Length];

                for (var i = 0; i < ckData.Length; i++)
                {
                    var data = ckData[i].Split(',');
                    colorsKeys[i] = new GradientColorKey(HexToColor(data[0]), float.Parse(data[1], CultureInfo.InvariantCulture));
                }
                var akData    = keys[2].Split('#');
                var alphaKeys = new GradientAlphaKey[akData.Length];

                for (var i = 0; i < akData.Length; i++)
                {
                    var data = akData[i].Split(',');
                    alphaKeys[i] = new GradientAlphaKey(float.Parse(data[0], CultureInfo.InvariantCulture), float.Parse(data[1], CultureInfo.InvariantCulture));
                }
                gradient.SetKeys(colorsKeys, alphaKeys);

#if UNITY_5_5_OR_NEWER
                if (keys.Length >= 4)
                {
                    gradient.mode = (GradientMode)Enum.Parse(typeof(GradientMode), keys[3]);
                }
#endif
            }
예제 #24
0
	IEnumerator DrawTransparentCircles() {
		currentOverlay.SetPixels32(blankOverlay.GetPixels32());
		List<Vector2> convertedLocations = new List<Vector2>();

		foreach(AnomalousEvent anomaly in AEM.EventList.Values) {
			foreach(GridLocation gl in anomaly.gridNumToLocations) {
				Debug.Log ("GridLocation");
				if(gl.statusCode > 0) {
					float tempX = currentOverlay.width * ((-180 - gl.spawnLocation.y)/(-180 - 180));
					float tempY = currentOverlay.height * ((-90 - gl.spawnLocation.x)/(-90 - 90));
					convertedLocations.Add (new Vector2(tempX,tempY));
				}
			}
		}

		Gradient g = new Gradient();
		GradientColorKey[] gck = new GradientColorKey[2];
		gck[0].color = Color.red;
		gck[0].time = 0.0f;
		gck[1].color = Color.yellow;
		gck[1].time = 1.0f;
		GradientAlphaKey[] gak = new GradientAlphaKey[2];
		gak[0].alpha = 0.75f;
		gak[0].time = 0.0f;
		gak[1].alpha = 0.0f;
		gak[1].time = 1.0f;
		g.SetKeys(gck,gak);

		foreach(Vector2 loc in convertedLocations) {
			for(int x = (int)Mathf.Clamp(loc.x - tempCircleSize, 0,overlayWidth - 1); x < (int)Mathf.Clamp(loc.x + tempCircleSize, 0,overlayWidth - 1); x++) {
				for(int y = (int)Mathf.Clamp(loc.y - tempCircleSize, 0,overlayHeight -1); y < (int)Mathf.Clamp(loc.y + tempCircleSize, 0,overlayHeight - 1); y++) {
					float dist = Vector2.Distance(loc, new Vector2(x,y));

					if(dist<tempCircleSize) {
						Color temp = currentOverlay.GetPixel(x,y);
						Color blend;
						if (WaterLandMask.GetPixel(x,y) != Color.white){
							blend = Color.clear;
						} else {
							blend = Color.white;
						}

						if(temp != Color.clear) {
							if(temp.a > g.Evaluate(dist/tempCircleSize).a)
								currentOverlay.SetPixel(x,y,(temp * blend));
							else
								currentOverlay.SetPixel(x,y,(g.Evaluate(dist/tempCircleSize) * blend));
						} else {
							currentOverlay.SetPixel(x,y,(g.Evaluate(dist/tempCircleSize) * blend));
						}
					}


				}
				if( x % 10 == 0)
					yield return null;
			}
			currentOverlay.Apply();
			MapOverlay.GetComponent<Renderer>().material.SetTexture("_MainTex", currentOverlay);
		}
		//Debug.Log ("done");

		//currentOverlay = temp;


	}
예제 #25
0
	void Awake()
	{
		if ( velcols == null )
		{
			velcols = new Gradient();

			GradientColorKey[] keys = new GradientColorKey[5];

			for ( int i = 0; i < 5; i++ )
			{
				keys[i].color = Cols[i];
				keys[i].time = (float)i / 4.0f;
			}

			GradientAlphaKey[] akeys = new GradientAlphaKey[2];
			akeys[0].alpha = 1.0f;
			akeys[0].time = 0.0f;
			akeys[1].alpha = 1.0f;
			akeys[1].time = 0.0f;

			velcols.SetKeys(keys, akeys);
		}
	}
예제 #26
0
 private void SetParticleColors()
 {
     redTail = new Gradient();
     redTail.SetKeys(new GradientColorKey[] {
         new GradientColorKey (Color.white, 0.0f),
         new GradientColorKey (new Color (0.97f, 0.25f, 0.25f), 0.21f),
         new GradientColorKey (new Color(0.51f, 0.06f, 0.06f), 0.57f),
         new GradientColorKey (Color.white, 1.0f)
     }, new GradientAlphaKey[] {
         new GradientAlphaKey (1.0f, 0.0f),
         new GradientAlphaKey (1.0f, 0.76f),
         new GradientAlphaKey (0.0f, 1.0f)
     });
     greenTail = new Gradient();
     greenTail.SetKeys(new GradientColorKey[] {
         new GradientColorKey (Color.white, 0.0f),
         new GradientColorKey (new Color (0.25f, 0.97f, 0.34f), 0.21f),
         new GradientColorKey (new Color(0.12f, 0.72f, 0.47f), 0.57f),
         new GradientColorKey (Color.white, 1.0f)
     }, new GradientAlphaKey[] {
         new GradientAlphaKey (1.0f, 0.0f),
         new GradientAlphaKey (1.0f, 0.76f),
         new GradientAlphaKey (0.0f, 1.0f)
     });
     blueTail = new Gradient();
     blueTail.SetKeys(new GradientColorKey[] {
         new GradientColorKey (Color.white, 0.0f),
         new GradientColorKey (new Color (0.25f, 0.25f, 0.97f), 0.21f),
         new GradientColorKey (new Color(0.04f, 0.04f, 0.38f), 0.57f),
         new GradientColorKey (Color.white, 1.0f)
     }, new GradientAlphaKey[] {
         new GradientAlphaKey (1.0f, 0.0f),
         new GradientAlphaKey (1.0f, 0.76f),
         new GradientAlphaKey (0.0f, 1.0f)
     });
     cyanTail = new Gradient();
     cyanTail.SetKeys(new GradientColorKey[] {
         new GradientColorKey (Color.white, 0.0f),
         new GradientColorKey (new Color (0.25f, 0.82f, 0.97f), 0.21f),
         new GradientColorKey (new Color(0.19f, 0.23f, 0.63f), 0.57f),
         new GradientColorKey (Color.white, 1.0f)
     }, new GradientAlphaKey[] {
         new GradientAlphaKey (1.0f, 0.0f),
         new GradientAlphaKey (1.0f, 0.76f),
         new GradientAlphaKey (0.0f, 1.0f)
     });
     magentaTail = new Gradient();
     magentaTail.SetKeys(new GradientColorKey[] {
         new GradientColorKey (Color.white, 0.0f),
         new GradientColorKey (new Color (0.97f, 0.25f, 0.95f), 0.21f),
         new GradientColorKey (new Color(0.38f, 0.04f, 0.38f), 0.57f),
         new GradientColorKey (Color.white, 1.0f)
     }, new GradientAlphaKey[] {
         new GradientAlphaKey (1.0f, 0.0f),
         new GradientAlphaKey (1.0f, 0.76f),
         new GradientAlphaKey (0.0f, 1.0f)
     });
     yellowTail = new Gradient();
     yellowTail.SetKeys(new GradientColorKey[] {
         new GradientColorKey (Color.white, 0.0f),
         new GradientColorKey (new Color (0.97f, 0.95f, 0.25f), 0.21f),
         new GradientColorKey (new Color(0.38f, 0.34f, 0.04f), 0.57f),
         new GradientColorKey (Color.white, 1.0f)
     }, new GradientAlphaKey[] {
         new GradientAlphaKey (1.0f, 0.0f),
         new GradientAlphaKey (1.0f, 0.76f),
         new GradientAlphaKey (0.0f, 1.0f)
     });
     orangeTail = new Gradient();
     orangeTail.SetKeys(new GradientColorKey[] {
         new GradientColorKey (Color.white, 0.0f),
         new GradientColorKey (new Color (0.86f, 0.52f, 0.0f), 0.21f),
         new GradientColorKey (new Color(0.38f, 0.27f, 0.04f), 0.57f),
         new GradientColorKey (Color.white, 1.0f)
     }, new GradientAlphaKey[] {
         new GradientAlphaKey (1.0f, 0.0f),
         new GradientAlphaKey (1.0f, 0.76f),
         new GradientAlphaKey (0.0f, 1.0f)
     });
 }
예제 #27
0
    void setBoostGrad()
    {
        var col = Boost.colorOverLifetime;
        col.enabled = true;
        Gradient grad = new Gradient();
        var gck = new GradientColorKey[3];
        gck[0].color = boostLevel.startColor;
        gck[0].time = 0.0f;
        gck[1].color = primaryMaterial.color;
        gck[1].time = 0.1f;
        gck[2].color = secondaryMaterial.color;
        gck[2].time = 1.0f;
        var gak = new GradientAlphaKey[2];
        gak[0].alpha = 1.0f;
        gak[0].time = 0.0f;
        gak[1].alpha = 1.0f;
        gak[1].time = 1.0f;
        grad.SetKeys(gck, gak);

        col.color = new ParticleSystem.MinMaxGradient(grad);
    }
    public void UpdateEmitters(float power)
    {
        UpdateInputs(power);

        for (int i = 0; i < persistentEmitters.Count; i++)
        {
            PersistentKSPShurikenEmitter pkpe = persistentEmitters[i];

            if (pkpe.go == null)
                continue;

            float finalScale = fixedScale * specialScale;

            float finalSizeClamp = sizeClamp + sizeClampCurve.Value(inputs);

            float sizePower = size.Value(inputs) * finalScale;
            pkpe.minSize = Mathf.Min(pkpe.minSizeBase * sizePower, finalSizeClamp);
            pkpe.maxSize = Mathf.Min(pkpe.maxSizeBase * sizePower, finalSizeClamp);

            float emissionPower = emission.Value(inputs) * emissionMult;
            pkpe.minEmission = Mathf.FloorToInt(pkpe.minEmissionBase * emissionPower);
            pkpe.maxEmission = Mathf.FloorToInt(pkpe.maxEmissionBase * emissionPower);

            float energyPower = energy.Value(inputs);
            pkpe.minEnergy = pkpe.minEnergyBase * energyPower;
            pkpe.maxEnergy = pkpe.maxEnergyBase * energyPower;

            float velocityPower = speed.Value(inputs) * finalScale;
            pkpe.localVelocity = pkpe.localVelocityBase * velocityPower;
            pkpe.worldVelocity = pkpe.worldVelocityBase * velocityPower;

            float forcePower = force.Value(inputs);
            pkpe.force = pkpe.forceBase * forcePower;

            ParticleSystem.ForceOverLifetimeModule fol = pkpe.pe.forceOverLifetime;
            fol.enabled = pkpe.force.sqrMagnitude > 0 || pkpe.rndForce.sqrMagnitude > 0;
            fol.x = new ParticleSystem.MinMaxCurve(pkpe.forceBase.x, pkpe.force.x + pkpe.rndForce.x);
            fol.y = new ParticleSystem.MinMaxCurve(pkpe.forceBase.y, pkpe.force.y + pkpe.rndForce.y);
            fol.z = new ParticleSystem.MinMaxCurve(pkpe.forceBase.z, pkpe.force.z + pkpe.rndForce.z);

            pkpe.sizeGrow = grow.Value(inputs);

            float currentScale = scale.Value(inputs) * finalScale;
            pkpe.shape1D = pkpe.scale1DBase * currentScale;
            pkpe.shape2D = pkpe.scale2DBase * currentScale;
            pkpe.shape3D = pkpe.scale3DBase * currentScale;

            pkpe.sizeClamp = finalSizeClamp;
            pkpe.randomInitalVelocityOffsetMaxRadius = randomInitalVelocityOffsetMaxRadius + initalVelocityOffsetMaxRadius.Value(inputs);

            pkpe.randConeEmit = randConeEmit.Value(inputs);
            pkpe.xyForce = xyForce.Value(inputs);
            pkpe.zForce = zForce.Value(inputs);

            pkpe.vRandPosOffset = vRandPosOffset.Value(inputs);
            pkpe.vPosOffset = vPosOffset.Value(inputs);

            pkpe.physical = physical && !SmokeScreenConfig.Instance.globalPhysicalDisable;
            pkpe.initialDensity = initialDensity;
            pkpe.dragCoefficient = dragCoefficient;

            pkpe.collide = collide && !SmokeScreenConfig.Instance.globalCollideDisable;
            pkpe.stickiness = stickiness;
            pkpe.collideRatio = collideRatio;

            pkpe.logarithmicGrow = logGrow.Value(inputs);
            pkpe.logarithmicGrowScale = logGrowScale.Value(inputs);

            pkpe.linearGrow = linGrow.Value(inputs);

            if (alpha.Value(inputs) != 1 || linAlphaDecay.Value(inputs) != 0 || logAlphaDecay.Value(inputs) != 0)
            {
                //Color[] cols = new Color[5];

                GradientColorKey[] colorKeys = new GradientColorKey[5];
                GradientAlphaKey[] alphaKeys = new GradientAlphaKey[5];

                for (int t = 0; t < 5; t++)
                {
                    float a =
                        Mathf.Clamp01(alpha.Value(inputs) *
                                      (1 - linAlphaDecay.Value(inputs) * (t / 4f) -
                                       Mathf.Log(logAlphaDecay.Value(inputs) * (t / 4f) + 1)));
                    colorKeys[t] = new GradientColorKey(Color.red, t * 0.25f);
                    alphaKeys[t] = new GradientAlphaKey(a, t * 0.25f);
                }

                ParticleSystem.ColorOverLifetimeModule col = pkpe.pe.colorOverLifetime;
                col.enabled = true;

                Gradient gradient = new Gradient();
                gradient.SetKeys(colorKeys, alphaKeys);

                col.color = new ParticleSystem.MinMaxGradient(gradient);
            }

            pkpe.go.transform.localPosition = localPosition
                                              + offsetDirection.normalized * offset.Value(inputs) * finalScale;

            pkpe.go.transform.localRotation = Quaternion.Euler(localRotation);

            //if (renderMode != lastRenderMode)
            //{
            //    // Bad code is bad
            //    try
            //    {
            //        pkpe.pe.particleRenderMode = (ParticleRenderMode)Enum.Parse(typeof (ParticleRenderMode), renderMode);
            //    }
            //    catch (ArgumentException) { }
            //    lastRenderMode = renderMode;
            //}
        }
    }
	void Awake() {
		if(!GetComponent<MeshFilter>()) {
			var mf = gameObject.AddComponent<MeshFilter>();
			mf.sharedMesh = new Mesh();
			mf.sharedMesh.bounds = new Bounds(Vector3.zero, Vector3.one * 10000f);
			mf.sharedMesh.SetTriangles((int[])null, 0);
		}
		if(!GetComponent<MeshRenderer>()) {
			var mr = gameObject.AddComponent<MeshRenderer>();
			mr.useLightProbes = mr.receiveShadows = false;
			mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
			mr.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
		}

		if(occlusionShader == null)
			occlusionShader = Shader.Find("Hidden/AtmosphericScattering_Occlusion");

		m_occlusionMaterial = new Material(occlusionShader);
		m_occlusionMaterial.hideFlags = HideFlags.HideAndDontSave;

		if(worldRayleighColorRamp == null) {
			worldRayleighColorRamp = new Gradient();
			worldRayleighColorRamp.SetKeys(
				new[]{ new GradientColorKey(new Color(0.3f, 0.4f, 0.6f), 0f), new GradientColorKey(new Color(0.5f, 0.6f, 0.8f), 1f) },
			new[]{ new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }
			);
		}
		if(worldMieColorRamp == null) {
			worldMieColorRamp = new Gradient();
			worldMieColorRamp.SetKeys(
				new[]{ new GradientColorKey(new Color(0.95f, 0.75f, 0.5f), 0f), new GradientColorKey(new Color(1f, 0.9f, 8.0f), 1f) },
			new[]{ new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }
			);
		}

		m_isAwake = true;
	}
예제 #30
0
        /// <summary>
        /// Initializes a new instance of Gradient.
        /// </summary>
        static GradientPresets()
        {
            // Generic gradient alpha keys
            var alphaKeys = new List<GradientAlphaKey> { new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1) };

            // RGBA gradient alpha keys
            var rgbaAlphaKeys = new List<GradientAlphaKey> { new GradientAlphaKey(0, 2 / 3f), new GradientAlphaKey(1, 1) };

            // cloud alpha keys
            var cloudAlphaKeys = new List<GradientAlphaKey> { new GradientAlphaKey(0, 0), new GradientAlphaKey(1, 1) };

            // Grayscale gradient color keys
            var grayscaleColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.black, 0),
                new GradientColorKey(Color.white, 1)
            };

            var cloudColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(new Color(1,1,1,0), 0f),
                new GradientColorKey(new Color(1,1,1,0), 0.5f),
                new GradientColorKey(new Color(1,1,1,0), 1f)
            };

            // RGB gradient color keys
            var rgbColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.red, 0),
                new GradientColorKey(Color.green, 0.5f),
                new GradientColorKey(Color.blue, 1)
            };

            // RGBA gradient color keys
            var rgbaColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.red, 0),
                new GradientColorKey(Color.green, 1 / 3f),
                new GradientColorKey(Color.blue, 2 / 3f),
                new GradientColorKey(Color.black, 1)
            };

            var one = 1f / 255f;

            // Terrain gradient color keys
            var terrainColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(new Color(one * 13,  one * 48,  one * 76), 0),      // deep ocean
                new GradientColorKey(new Color(one * 28,  one * 74,  one * 107), 0.42f), // shallow water
                new GradientColorKey(new Color(one * 169, one * 160, one * 124), 0.45f), // beach
                new GradientColorKey(new Color(one * 92,  one * 131, one * 57), 0.46f),  // green land
                new GradientColorKey(new Color(one * 125, one * 112, one * 88), 0.55f),  // arid / desert
                new GradientColorKey(new Color(one * 92,  one * 131, one * 57), 0.60f),  // green land
                new GradientColorKey(new Color(one * 11,  one * 40,  one * 4), 0.94f),   // forest
                new GradientColorKey(new Color(one * 236, one * 240, one * 249), 1)      // mountain peaks
            };

            _empty = new Gradient();

            _rgb = new Gradient();
            _rgb.SetKeys(rgbColorKeys.ToArray(), alphaKeys.ToArray());

            _rgba = new Gradient();
            _rgba.SetKeys(rgbaColorKeys.ToArray(), rgbaAlphaKeys.ToArray());

            _grayscale = new Gradient();
            _grayscale.SetKeys(grayscaleColorKeys.ToArray(), alphaKeys.ToArray());

            _cloud = new Gradient();
            _cloud.SetKeys(cloudColorKeys.ToArray(), cloudAlphaKeys.ToArray());

            _terrain = new Gradient();
            _terrain.SetKeys(terrainColorKeys.ToArray(), alphaKeys.ToArray());
        }
예제 #31
0
    static public void PatchColorGradient(ColorParameter c1, Gradient c2)
    {

        GradientColorKey[] ck = new GradientColorKey[c1.Colors.Count];
        GradientAlphaKey[] ak = new GradientAlphaKey[c1.Colors.Count];

        for (int i = 0; i < c1.Colors.Count; i++)
        {
            ColorKey k = c1.Colors[i];

            ck[i].color = k.Color;
            ck[i].time = k.t;

            ak[i].alpha = k.Color.a;
            ak[i].time = k.t;
        }

        c2.SetKeys(ck, ak);
    }
예제 #32
0
		//creating a color gradient, straight from the unity docs, with added alpha component
		public static Gradient GetColorGradient(Color startColor, Color endColor)
		{
			Gradient g = new Gradient();
			
			// Populate the color keys at the relative time 0 and 1 (0 and 100%)
			GradientColorKey[] gck = new GradientColorKey[2];
			gck[0].color = startColor;
			gck[0].time = 0.0f;
			gck[1].color = endColor;
			gck[1].time = 1.0f;
			
			// Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
			GradientAlphaKey[] gak = new GradientAlphaKey[2];
			gak[0].alpha = startColor.a;
			gak[0].time = 0.0f;
			gak[1].alpha = endColor.a;
			gak[1].time = 1.0f;
			
			g.SetKeys(gck, gak);
			return g;
		}
예제 #33
0
		public Porkchop(ManeuverParameters[,] nodes)
		{
			Gradient colours = new Gradient();
			var colourKeys = new GradientColorKey[6];
			colourKeys[0].color = new Color(0.25f, 0.25f, 1.0f);
			colourKeys[0].time = 0.0f;
			colourKeys[1].color = new Color(0.5f, 0.5f, 1.0f);
			colourKeys[1].time = 0.01f;
			colourKeys[2].color = new Color(0.5f, 1.0f, 1.0f);
			colourKeys[2].time = 0.25f;
			colourKeys[3].color = new Color(0.5f, 1.0f, 0.5f);
			colourKeys[3].time = 0.5f;
			colourKeys[4].color = new Color(1.0f, 1.0f, 0.5f);
			colourKeys[4].time = 0.75f;
			colourKeys[5].color = new Color(1.0f, 0.5f, 0.5f);
			colourKeys[5].time = 1.0f;

			var alphaKeys = new GradientAlphaKey[2];
			alphaKeys[0].alpha = 1.0f;
			alphaKeys[0].time = 0.0f;
			alphaKeys[1].alpha = 1.0f;
			alphaKeys[1].time = 1.0f;

			colours.SetKeys(colourKeys, alphaKeys);

			double DVminsqr = double.MaxValue;
			double DVmaxsqr = double.MinValue;
			for (int i = 0; i < nodes.GetLength(0); i++)
			{
				for (int j = 0; j < nodes.GetLength(1); j++)
				{
					if (nodes[i, j] != null)
					{
						double DVsqr = nodes[i, j].dV.sqrMagnitude;
						if (DVsqr < DVminsqr)
						{
							DVminsqr = DVsqr;
						}

						DVmaxsqr = Math.Max(DVmaxsqr, nodes[i, j].dV.sqrMagnitude);
					}
				}
			}

			texture = new Texture2D(nodes.GetLength(0), nodes.GetLength(1), TextureFormat.RGB24, false);
			double logDVminsqr = Math.Log(DVminsqr);
			double logDVmaxsqr = Math.Min(Math.Log(DVmaxsqr), logDVminsqr + 4);


			for (int i = 0; i < nodes.GetLength(0); i++)
			{
				for (int j = 0; j < nodes.GetLength(1); j++)
				{
					if (nodes[i, j] == null)
					{
						texture.SetPixel(i, j, colours.Evaluate(1));
					}
					else
					{
						double lambda = (Math.Log(nodes[i, j].dV.sqrMagnitude) - logDVminsqr) / (logDVmaxsqr - logDVminsqr);
						texture.SetPixel(i, j, colours.Evaluate((float)lambda));
					}
				}
			}

			texture.Apply();

#if DEBUG
			string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
			System.IO.File.WriteAllBytes(dir + "/Porkchop.png", texture.EncodeToPNG());
#endif
		}
        protected Gradient ConstructGradient()
        {
            Gradient g = new Gradient();
            GradientColorKey[] gkColor = new GradientColorKey[7];
            GradientAlphaKey[] gkAlpha = new GradientAlphaKey[4];

            gkColor[0].color = Color.white;
            gkColor[1].color = Color.red;
            gkColor[2].color = Color.yellow;
            gkColor[3].color = Color.green;
            gkColor[4].color = Color.blue;
            gkColor[5].color = Color.magenta;
            gkColor[6].color = Color.black;

            gkColor[0].time = 0f;
            gkColor[1].time = 0.166f;
            gkColor[2].time = 0.33f;
            gkColor[3].time = 0.5f;
            gkColor[4].time = 0.66f;
            gkColor[5].time = 0.833f;
            gkColor[6].time = 1f;

            gkAlpha[0].alpha = 0.75f;
            gkAlpha[1].alpha = 0.75f;
            gkAlpha[2].alpha = 0.75f;
            gkAlpha[3].alpha = 0.75f;

            gkAlpha[0].time = 0f;
            gkAlpha[1].time = 0.33f;
            gkAlpha[2].time = 0.66f;
            gkAlpha[3].time = 1f;

            g.SetKeys(gkColor, gkAlpha);

            return g;
        }
		public static bool Deserialize(string str, out Gradient gradient)
		{
			gradient = null;

			string[] arrays = str.Split('\n');

			if(arrays.Length < 2)
				return false;

			string[] colors_str = arrays[0].Split('|');
			string[] alphas_str = arrays[1].Split('|');

			if(colors_str.Length < 2 || alphas_str.Length < 2)
				return false;

			List<GradientColorKey> colors = new List<GradientColorKey>();
			List<GradientAlphaKey> alphas = new List<GradientAlphaKey>();

			foreach(string s in colors_str)
			{
				string[] key = s.Split('&');

				if(key.Length < 2)
					continue;

				Color value;
				float time;

				if(!TryParseColor(key[0], out value))
					continue;

				if(!float.TryParse(key[1], out time))
					continue;

				colors.Add( new GradientColorKey(value, time) );
			}

			foreach(string s in alphas_str)
			{
				string[] key = s.Split('&');

				if(key.Length < 2)
					continue;

				float alpha, time;

				if(!float.TryParse(key[0], out alpha))
					continue;
				if(!float.TryParse(key[1], out time))
					continue;

				alphas.Add( new GradientAlphaKey(alpha, time) );
			}

			gradient = new Gradient();
			gradient.SetKeys(colors.ToArray(), alphas.ToArray());

			return true;
		}
    public override void OnInitialize()
    {
        //Print("Init");

        // Restore the Curve config from the node content backup
        // Done because I could not get the serialization of MultiInputCurve to work
        if (node_backup != string.Empty)
        {
            Restore();
        }

        List<Transform> transforms = new List<Transform>(hostPart.FindModelTransforms(transformName));
        if (transforms.Count == 0)
        {
            Print("Cannot find transform " + transformName);
            return;
        }
        GameObject model = GameDatabase.Instance.GetModel(modelName);
        if (model == null)
        {
            Print("Cannot find model " + modelName);
            return;
        }
        model.SetActive(true);
        KSPParticleEmitter templateKspParticleEmitter = model.GetComponentInChildren<KSPParticleEmitter>();

        if (templateKspParticleEmitter == null)
        {
            Print("Cannot find particle emitter on " + modelName);
            Destroy(model);
            return;
        }

        if (persistentEmitters == null)
        {
            persistentEmitters = new List<PersistentKSPShurikenEmitter>();
        }

        if (hostPart.Modules.Contains("ProceduralSRB"))
        {
            PartModule pm = hostPart.Modules["ProceduralSRB"];

            specialScale = pm.Fields.GetValue<float>("bellScale");
            Print("Found ProceduralSRB. Rescaling by " + specialScale.ToString("F3") + " final scale " + (fixedScale * specialScale).ToString("F3"));
        }

        for (int i = 0; i < transforms.Count; i++)
        {
            GameObject emitterGameObject = Instantiate(model) as GameObject;
            KSPParticleEmitter childKSPParticleEmitter = emitterGameObject.GetComponentInChildren<KSPParticleEmitter>();

            //if (shader != null)
            //{
            //    childKSPParticleEmitter.material.shader = shader;
            //    childKSPParticleEmitter.pr.material.shader = shader;
            //}

            if (childKSPParticleEmitter != null)
            {
                // Destroy them ?
                childKSPParticleEmitter.pr.enabled = false;
                childKSPParticleEmitter.pe.enabled = false;
                childKSPParticleEmitter.enabled = false;

                ParticleSystem particleSystem = childKSPParticleEmitter.gameObject.AddComponent<ParticleSystem>();
                ParticleSystemRenderer particleSystemRenderer = childKSPParticleEmitter.gameObject.GetComponent<ParticleSystemRenderer>();

                PersistentKSPShurikenEmitter pkpe = new PersistentKSPShurikenEmitter(
                    emitterGameObject,
                    particleSystem,
                    particleSystemRenderer,
                    templateKspParticleEmitter);

                particleSystem.simulationSpace = childKSPParticleEmitter.pe.useWorldSpace
                    ? ParticleSystemSimulationSpace.World
                    : ParticleSystemSimulationSpace.Local;

                particleSystem.maxParticles = particleCountLimit;

                particleSystemRenderer.material = childKSPParticleEmitter.pr.material;

                // TODO Actually copy the mode from childKSPParticleEmitter.particleRenderMode?
                particleSystemRenderer.renderMode = ParticleSystemRenderMode.Billboard;

                try
                {
                    childKSPParticleEmitter.particleRenderMode =
                        (ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), renderMode);
                }
                catch (ArgumentException)
                {
                    Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleRenderMode");
                }

                switch (childKSPParticleEmitter.particleRenderMode)
                {
                    case ParticleRenderMode.Billboard:
                        particleSystemRenderer.renderMode = ParticleSystemRenderMode.Billboard;
                        break;
                    case ParticleRenderMode.Stretch:
                        particleSystemRenderer.renderMode = ParticleSystemRenderMode.Stretch;
                        break;
                    case ParticleRenderMode.SortedBillboard:
                        particleSystemRenderer.renderMode = ParticleSystemRenderMode.Billboard;
                        particleSystemRenderer.sortMode = ParticleSystemSortMode.Distance;
                        break;
                    case ParticleRenderMode.HorizontalBillboard:
                        particleSystemRenderer.renderMode = ParticleSystemRenderMode.HorizontalBillboard;
                        break;
                    case ParticleRenderMode.VerticalBillboard:
                        particleSystemRenderer.renderMode = ParticleSystemRenderMode.VerticalBillboard;
                        break;
                    default:
                        particleSystemRenderer.renderMode = ParticleSystemRenderMode.Billboard;
                        break;
                }

                //particleSystemRenderer.alignment = ParticleSystemRenderSpace.View;

                if (childKSPParticleEmitter.doesAnimateColor)
                {
                    ParticleSystem.ColorOverLifetimeModule col = particleSystem.colorOverLifetime;
                    col.enabled = true;

                    GradientColorKey[] colorKeys = new GradientColorKey[5];
                    GradientAlphaKey[] alphaKeys = new GradientAlphaKey[5];

                    Color[] colors = childKSPParticleEmitter.colorAnimation;

                    float step = 1f / (colors.Length - 1);

                    for (int t = 0; t < colors.Length; t++)
                    {
                        colorKeys[t] = new GradientColorKey(colors[t], t * step);
                        alphaKeys[t] = new GradientAlphaKey(colors[t].a, t * step);
                    }

                    Gradient gradient = new Gradient();
                    gradient.SetKeys(colorKeys, alphaKeys);

                    col.color = new ParticleSystem.MinMaxGradient(gradient);
                }

                //try
                //{
                //    particleSystemRenderer.renderMode =
                //        (ParticleSystemRenderMode)Enum.Parse(typeof (ParticleSystemRenderMode), renderMode);
                //}
                //catch (ArgumentException)
                //{
                //    Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleSystemRenderMode");
                //}

                persistentEmitters.Add(pkpe);

                DisableCollider(pkpe.go);

                emitterGameObject.transform.SetParent(transforms[i]);

                emitterGameObject.transform.localPosition = localPosition;
                emitterGameObject.transform.localRotation = Quaternion.Euler(localRotation);
                emitterGameObject.SetLayerRecursive(layerId);
            }
        }

        Destroy(model);

        list.Add(this);

        // 1.0 don't seems to properly do this for engines.
        OnEvent(0);
    }
예제 #37
0
파일: _.cs 프로젝트: Apolix96/AntenaBall
    static Gradient Lerp(Gradient a, Gradient b, float t, bool noAlpha, bool noColor)
    {
        //list of all the unique key times
        var keysTimes = new List <float>();

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

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

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

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

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

        //Pick colors of both gradients at key times and lerp them
        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);
        }

        var g = new UnityEngine.Gradient();

        g.SetKeys(clrs, alphas);

        return(g);
    }
예제 #38
0
    // Use this for initialization
    void Start()
    {
        //activated = true;
        //cachedY = timeTransform.position.y;

        minXValue = 0;
        maxXValue = timeTransform.rect.width;

        //currentTime = maxTime;
        g = new Gradient();

        // Populate the color keys at the relative time 0 and 1 (0 and 100%)
        gck = new GradientColorKey[3];
        gck[0].color = new Color32(9,183,62,1);
        gck[0].time = 0.0f;
        gck[1].color = new Color32(255,228,0,1);
        gck[1].time = 0.5f;
        gck[2].color = new Color32(219,101,63,1);
        gck[2].time = 1.0f;

        // Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
        gak = new GradientAlphaKey[2];
        gak[0].alpha = 1.0f;
        gak[0].time = 0.0f;
        gak[1].alpha = 1.0f;
        gak[1].time = 1.0f;
        g.SetKeys(gck, gak);

        CurrentTime = maxTime;
    }
예제 #39
0
        public void Create()
        {
            // Init
            enable = true;

            threshold =0;
            mixing =0.7f;
            intensity =1;

            smallCount = 0;
            mediumCount = 0;
            largeCount = 0;

            // Color gradient
            gradient = new Gradient();

            GradientColorKey[] colork = new GradientColorKey[4];
            colork[0].color = Color.white;
            colork[0].time = 0.0f;

            colork[1].color = new Color( 1,245f/255f,200f/255f);
            colork[1].time = 0.33f;

            colork[2].color = new Color( 1,190f/255f,190f/255f);
            colork[2].time = 0.66f;

            colork[3].color = new Color( 189f/255f,1,1);
            colork[3].time = 1f;

            GradientAlphaKey[] alphak = new GradientAlphaKey[2];
            alphak[0].alpha = 1.0f;
            alphak[0].time = 0.0f;

            alphak[1].alpha = 1.0f;
            alphak[1].time = 0.0f;

            gradient.SetKeys(colork,alphak);

            // Cluster
            clusterBox = new StarCluster[6];
            for (int i=0;i<6;i++){
            clusterBox[i] = new StarCluster();
            }

            clusterCount = Random.Range(1,50);
            SetupCluster();
        }
예제 #40
0
    // Use this for initialization
    void Start()
    {
        ren = GetComponent<MeshRenderer>();
        mat = ren.material;
        initialPos = transform.position;

        pillarGradient = new Gradient();

        gck = pillarGradient.colorKeys;
        gck[0].color = mat.color;
        gck[0].time = 0.0f;
        gck[1].color = hotColor;
        gck[1].time = 1.0f;

        gak = pillarGradient.alphaKeys;
        gak[0].alpha = 1.0f;
        gak[0].time = 0.0f;
        gak[1].alpha = 1.0f;
        gak[1].time = 1.0f;

        pillarGradient.SetKeys(gck, gak);
    }
예제 #41
0
    void setGradient()
    {
        gradientKeys = new GradientColorKey[4];
        gradientKeys [0].color = headColor_hsv;
        gradientKeys [0].time = 0.0f;
        gradientKeys [1].color = headASColor_hsv;
        gradientKeys [1].time = 0.2f;
        gradientKeys [2].color = bottomAScolor_hsv;
        gradientKeys [2].time = 0.7f;
        gradientKeys [3].color = bottomColor_hsv;
        gradientKeys [3].time = 1.0f;

        gradientAlpha = new GradientAlphaKey[4];
        gradientAlpha [0].alpha = 1.0f;
        gradientAlpha [1].alpha = 1.0f;
        gradientAlpha [2].alpha = 1.0f;
        gradientAlpha [3].alpha = 1.0f;
        gradientAlpha[0].time = 0.0f;
        gradientAlpha[1].time = 0.2f;
        gradientAlpha[2].time = 0.7f;
        gradientAlpha[3].time = 1.0f;

        randomGradient = new Gradient();
        randomGradient.SetKeys(gradientKeys,gradientAlpha);

        gradientKeys = new GradientColorKey[4];
        gradientKeys [0].color = bottomColor_hsv;
        gradientKeys [0].time = 0.0f;
        gradientKeys [1].color = bottomAScolor_hsv;
        gradientKeys [1].time = 0.2f;
        gradientKeys [2].color = headASColor_hsv;
        gradientKeys [2].time = 0.7f;
        gradientKeys [3].color = headColor_hsv;
        gradientKeys [3].time = 1.0f;

        randomGradient2 = new Gradient();
        randomGradient2.SetKeys(gradientKeys,gradientAlpha);
    }
예제 #42
0
		public static Gradient GetGradient(string key)
		{
			Gradient gradient = null;

			if( z_GradientSerializer.Deserialize(EditorPrefs.GetString(key), out gradient) )
				return gradient;

			Gradient g = new Gradient();
			
			g.SetKeys(
				new GradientColorKey[] { 
					new GradientColorKey(new Color(.1f, 0f, 1f, 1f), 0f),
					new GradientColorKey(Color.black, 1f)
					},
				new GradientAlphaKey[] {
					new GradientAlphaKey(1f, 0f),
					new GradientAlphaKey(1f, 1f),
					});

			return g;

		}
예제 #43
0
        /// <summary>
        /// Initializes a new instance of Gradient.
        /// </summary>
        static GradientPresets()
        {
            // Grayscale gradient color keys
            var grayscaleColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.black, 0),
                new GradientColorKey(Color.white, 1)
            };

            var nebulaColorsA = new List<GradientColorKey>
            {
                new GradientColorKey(new Color(0,0,0,1.0f), 0f),
                new GradientColorKey(new Color(0,0,0,1.0f), .75f),
                new GradientColorKey(new Color(0.2f, 0.2f, 0.35f, 1.0f), 0.76f),
                new GradientColorKey(new Color(0.1f, 0.1f, 0.15f, 1.0f), 0.77f),
                new GradientColorKey(new Color(0.15f, 0.15f, 0.15f, 1.0f), 0.775f),
                new GradientColorKey(new Color(0.2f, 0.2f, 0.35f, 1.0f), 0.8f),
                new GradientColorKey(new Color(0.1f, 0.1f, 0.15f, 1.0f), 0.86f),
                new GradientColorKey(new Color(0,0,0,1.0f), .865f)
            };

            var nebulaColorsB = new List<GradientColorKey>
            {
                new GradientColorKey(new Color(0,0,0,1.0f), 0f),
                new GradientColorKey(new Color(0,0,0,1.0f), .70f),
                new GradientColorKey(new Color(0.2f, 0.2f, 0.35f, 1.0f), 0.72f),
                new GradientColorKey(new Color(0.1f, 0.1f, 0.15f, 1.0f), 0.73f),
                new GradientColorKey(new Color(0.15f, 0.15f, 0.15f, 1.0f), 0.735f),
                new GradientColorKey(new Color(0.2f, 0.2f, 0.35f, 1.0f), 0.75f),
                new GradientColorKey(new Color(0.1f, 0.1f, 0.15f, 1.0f), 0.766f),
                new GradientColorKey(new Color(0,0,0,1.0f), .8f)
            };

            var nebulaColorsC = new List<GradientColorKey>
            {
                new GradientColorKey(Color.black, 0),
                new GradientColorKey(new Color(.15f,.15f,.15f,1.0f), .50f),
                new GradientColorKey(new Color(.45f,.45f,.45f,1.0f), .55f),
                new GradientColorKey(new Color(.55f,.65f,.65f,1.0f), .60f),
                new GradientColorKey(new Color(.45f,.45f,.45f,1.0f), .65f),
                new GradientColorKey(new Color(.15f,.15f,.15f,1.0f), .70f),
                new GradientColorKey(Color.black, .75f)
            };

            var nebulaColorsD = new List<GradientColorKey>
            {
                new GradientColorKey(Color.black, 0),
                new GradientColorKey(new Color(.15f,.15f,.2f,1.0f), .65f),
                new GradientColorKey(new Color(.45f,.45f,.5f,1.0f), .67f),
                new GradientColorKey(new Color(.55f,.65f,.7f,1.0f), .68f),
                new GradientColorKey(new Color(.45f,.45f,.5f,1.0f), .69f),
                new GradientColorKey(new Color(.15f,.15f,.2f,1.0f), .74f),
                new GradientColorKey(Color.black, .75f)
            };

            // RGB gradient color keys
            var rgbColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.red, 0),
                new GradientColorKey(Color.green, 0.5f),
                new GradientColorKey(Color.blue, 1)
            };

            // RGBA gradient color keys
            var rgbaColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.red, 0),
                new GradientColorKey(Color.green, 1 / 3f),
                new GradientColorKey(Color.blue, 2 / 3f),
                new GradientColorKey(Color.black, 1)
            };

            var planetColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(new Color(0.36f, 0.22f, 0.6f), 0),
                new GradientColorKey(Color.green, 1 / 3f),
                new GradientColorKey(Color.blue, 2 / 3f),
                new GradientColorKey(Color.black, 1)
            };

            var planetLightColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(Color.black, 0),
                new GradientColorKey(Color.white, 1 / 3f),
                new GradientColorKey(Color.black, 2 / 3f),
                new GradientColorKey(Color.black, 1)
            };

            // RGBA gradient alpha keys
            var rgbaAlphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(0, 2 / 3f), new GradientAlphaKey(1, 1)};

            // Terrain gradient color keys
            var terrainColorKeys = new List<GradientColorKey>
            {
                new GradientColorKey(new Color(0, 0, 0.5f), 0),
                new GradientColorKey(new Color(0.125f, 0.25f, 0.5f), 0.4f),
                new GradientColorKey(new Color(0.25f, 0.375f, 0.75f), 0.48f),
                new GradientColorKey(new Color(0, 0.75f, 0), 0.5f),
                new GradientColorKey(new Color(0.75f, 0.75f, 0), 0.625f),
                new GradientColorKey(new Color(0.625f, 0.375f, 0.25f), 0.75f),
                new GradientColorKey(new Color(0.5f, 1, 1), 0.875f),
                new GradientColorKey(Color.white, 1)
            };

            // Generic gradient alpha keys
            var alphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1)};

            _empty = new Gradient();

            _rgb = new Gradient();
            _rgb.SetKeys(rgbColorKeys.ToArray(), alphaKeys.ToArray());

            _rgba = new Gradient();
            _rgba.SetKeys(rgbaColorKeys.ToArray(), rgbaAlphaKeys.ToArray());

            _grayscale = new Gradient();
            _grayscale.SetKeys(grayscaleColorKeys.ToArray(), alphaKeys.ToArray());

            _terrain = new Gradient();
            _terrain.SetKeys(terrainColorKeys.ToArray(), alphaKeys.ToArray());

            _nebulaColorsA = new Gradient();
            _nebulaColorsA.SetKeys(nebulaColorsA.ToArray(), alphaKeys.ToArray());

            _nebulaColorsB = new Gradient();
            _nebulaColorsB.SetKeys(nebulaColorsB.ToArray(), alphaKeys.ToArray());

            _nebulaColorsC = new Gradient();
            _nebulaColorsC.SetKeys(nebulaColorsC.ToArray(), alphaKeys.ToArray());

            _nebulaColorsD = new Gradient();
            _nebulaColorsD.SetKeys(nebulaColorsD.ToArray(), alphaKeys.ToArray());

            _planetColorKeys = new Gradient();
            _planetColorKeys.SetKeys(planetColorKeys.ToArray(), alphaKeys.ToArray());

            _planetLightColorKeys = new Gradient();
            _planetLightColorKeys.SetKeys(planetLightColorKeys.ToArray(), alphaKeys.ToArray());
        }
예제 #44
0
    // Use this for initialization
    void Start()
    {
        // On zoom
        myCamera.to = 3.22f;

        inTuto = PlayerPrefs.GetInt(Constants.PROPULSION_GAME_MAX_PLAYED, 0) < 1;
        //inTuto = PropulsionLevelConfiguration.showTutorial;

        // TODO will not be needed to check max level later...
        int maxDifficulty = PlayerPrefs.GetInt(Constants.PROPULSION_GAME_MAX_DIFFICULTY, 1);
        currentDifficulty = PropulsionLevelConfiguration.currentLevel;
        currentDifficulty = currentDifficulty < 1 ? 1 :
                (currentDifficulty > maxDifficulty ? maxDifficulty : currentDifficulty);

        parentArea = GameObject.Find("/Container").transform;
        // load Tutorial level if needed
        if(inTuto) {
            grid = instanciateLevelFromXml(levelTuto);
        }
        else {
            grid = instanciateLevelFromXml (getRandomLevel(currentDifficulty));
        }
        instanciatePipeGrid (grid);

        // pipe gradient, very ugly
        gradient = new Gradient();
        // Populate the color keys at the relative time 0 and 1 (0 and 100%)
        gck = new GradientColorKey[3];
        gck[0].color = new Color32(0,228,255,1);
        gck[0].time = 0.0f;
        gck[1].color = new Color32(228,198,109,1);
        gck[1].time = 0.5f;
        gck[2].color = new Color32(219,101,63,1);
        gck[2].time = 1.0f;

        // Populate the alpha  keys at relative time 0 and 1  (0 and 100%)
        gak = new GradientAlphaKey[2];
        gak[0].alpha = 1.0f;
        gak[0].time = 0.0f;
        gak[1].alpha = 1.0f;
        gak[1].time = 1.0f;
        gradient.SetKeys(gck, gak);

        // manage timer
        timebar.endCallback = onTimerEnd;

        // start camera zoom (the game is virtually paused before zoom is done)
        isPause = true;
        Time.timeScale = 1;
        myCamera.zoomFinishedCallback = delegate() {
            emilieSpeakTime();
        };
    }