public static SerializableGradientAlphaKey[] FromGradientColorKeys(GradientAlphaKey[] ks)
 {
     SerializableGradientAlphaKey[] keys = new SerializableGradientAlphaKey[ks.Length];
     for(int i = 0; i < keys.Length; i++)
     keys[i] = new SerializableGradientAlphaKey(ks[i]);
     return keys;
 }
Ejemplo n.º 2
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);
    }
 public static GradientAlphaKey[] ToGradientColorKeys(SerializableGradientAlphaKey[] incoming)
 {
     GradientAlphaKey[] keys = new GradientAlphaKey[incoming.Length];
     for(int i = 0; i < keys.Length; i++)
     keys[i] = incoming[i].ToGradientColorKey();
     return keys;
 }
 static void Gradient_alphaKeys(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.Gradient _this = (UnityEngine.Gradient)vc.csObj;
         var result = _this.alphaKeys;
         var arrRet = result;
         for (int i = 0; arrRet != null && i < arrRet.Length; i++)
         {
             JSMgr.datax.setObject((int)JSApi.SetType.SaveAndTempTrace, arrRet[i]);
             JSApi.moveSaveID2Arr(i);
         }
         JSApi.setArrayS((int)JSApi.SetType.Rval, (arrRet != null ? arrRet.Length : 0), true);
     }
     else
     {
         UnityEngine.GradientAlphaKey[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.GradientAlphaKey[]>(() =>
         {
             int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
             int length  = JSApi.getArrayLength(jsObjID);
             var ret     = new UnityEngine.GradientAlphaKey[length];
             for (var i = 0; i < length; i++)
             {
                 JSApi.getElement(jsObjID, i);
                 ret[i] = (UnityEngine.GradientAlphaKey)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
             }
             return(ret);
         });
         UnityEngine.Gradient _this = (UnityEngine.Gradient)vc.csObj;
         _this.alphaKeys = arg0;
     }
 }
    static bool Gradient_SetKeys__GradientColorKey_Array__GradientAlphaKey_Array(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 2)
        {
            UnityEngine.GradientColorKey[] arg0 = JSDataExchangeMgr.GetJSArg <UnityEngine.GradientColorKey[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new UnityEngine.GradientColorKey[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (UnityEngine.GradientColorKey)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            UnityEngine.GradientAlphaKey[] arg1 = JSDataExchangeMgr.GetJSArg <UnityEngine.GradientAlphaKey[]>(() =>
            {
                int jsObjID = JSApi.getObject((int)JSApi.GetType.Arg);
                int length  = JSApi.getArrayLength(jsObjID);
                var ret     = new UnityEngine.GradientAlphaKey[length];
                for (var i = 0; i < length; i++)
                {
                    JSApi.getElement(jsObjID, i);
                    ret[i] = (UnityEngine.GradientAlphaKey)JSMgr.datax.getObject((int)JSApi.GetType.SaveAndRemove);
                }
                return(ret);
            });
            ((UnityEngine.Gradient)vc.csObj).SetKeys(arg0, arg1);
        }

        return(true);
    }
Ejemplo n.º 6
0
 static public int constructor(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.GradientAlphaKey o;
         if (argc == 3)
         {
             System.Single a1;
             checkType(l, 2, out a1);
             System.Single a2;
             checkType(l, 3, out a2);
             o = new UnityEngine.GradientAlphaKey(a1, a2);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc <= 2)
         {
             o = new UnityEngine.GradientAlphaKey();
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         return(error(l, "New object failed."));
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int constructor(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.GradientAlphaKey o;
         System.Single a1;
         checkType(l, 2, out a1);
         System.Single a2;
         checkType(l, 3, out a2);
         o = new UnityEngine.GradientAlphaKey(a1, a2);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     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
 }
Ejemplo n.º 8
0
        public override object Read <T>(ES3Reader reader)
        {
            var instance = new UnityEngine.GradientAlphaKey();

            ReadInto <T>(reader, instance);
            return(instance);
        }
 static public int set_time(IntPtr l)
 {
     UnityEngine.GradientAlphaKey o = (UnityEngine.GradientAlphaKey)checkSelf(l);
     System.Single v;
     checkType(l, 2, out v);
     o.time = v;
     setBack(l, o);
     return(0);
 }
Ejemplo n.º 10
0
 static public int constructor(IntPtr l)
 {
     UnityEngine.GradientAlphaKey o;
     System.Single a1;
     checkType(l, 2, out a1);
     System.Single a2;
     checkType(l, 3, out a2);
     o = new UnityEngine.GradientAlphaKey(a1, a2);
     pushObject(l, o);
     return(1);
 }
Ejemplo n.º 11
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);
	}
 static public int ctor_s(IntPtr l)
 {
     try {
         UnityEngine.GradientAlphaKey o;
         o = new UnityEngine.GradientAlphaKey();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// resets the alphas of the Colors gradient with a default 1-1 alpha preset if alphas parameter is null,
 /// else the alpha array passed as argument is used to populate it
 /// </summary>
 /// <param name="alphas">an array of alpha values to use for reset of the Colors gradient. If null is passed a preset gradient is used. The alpha values are distributed along the gradient timeline at fixed steps</param>
 public void ResetGradientAlphas(float[] alphas = null)
 {
     if (alphas != null)
     {
         if (alphas.Length > 0)
         {
             UnityEngine.GradientAlphaKey[] gradient = new UnityEngine.GradientAlphaKey[alphas.Length];
             for (int i = 0; i < alphas.Length; i++)
             {
                 float time = (i == alphas.Length - 1) ? 1 : ((float)i / (float)(alphas.Length - 1));
                 gradient[i] = new UnityEngine.GradientAlphaKey(alphas[i], time);
                 ResetGradientAlphas(gradient);
             }
         }
     }
 }
Ejemplo n.º 14
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;
        }
 static void GradientAlphaKey_time(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.GradientAlphaKey _this = (UnityEngine.GradientAlphaKey)vc.csObj;
         var result = _this.time;
         JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result));
     }
     else
     {
         System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
         UnityEngine.GradientAlphaKey _this = (UnityEngine.GradientAlphaKey)vc.csObj;
         _this.time = arg0;
         JSMgr.changeJSObj(vc.jsObjID, _this);
     }
 }
        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);
        }
	static public int constructor(IntPtr l) {
		try {
			UnityEngine.GradientAlphaKey o;
			System.Single a1;
			checkType(l,2,out a1);
			System.Single a2;
			checkType(l,3,out a2);
			o=new UnityEngine.GradientAlphaKey(a1,a2);
			pushValue(l,true);
			pushValue(l,o);
			return 2;
		}
		catch(Exception e) {
			return error(l,e);
		}
	}
Ejemplo n.º 18
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
            };
        }
Ejemplo n.º 19
0
        /// <summary>
        /// resets the alphas of the Colors gradient with a default 1-1 alpha preset if alphas parameter is null,
        /// else the alpha array passed as argument is used to populate it
        /// </summary>
        /// <param name="alphas">an array of GradientAlphaKeys to use for reset of the Colors gradient. If null is passed a preset gradient is used</param>
        public void ResetGradientAlphas(UnityEngine.GradientAlphaKey[] alphas = null)
        {
            if (alphas == null)
            {
                alphas = new UnityEngine.GradientAlphaKey[]
                {
                    new UnityEngine.GradientAlphaKey(1, 0),
                    new UnityEngine.GradientAlphaKey(1, 1)
                };
            }

            if (Colors == null)
            {
                Colors = new UnityEngine.Gradient();
            }
            Colors.alphaKeys = alphas;
        }
 public static int constructor(IntPtr l)
 {
     try {
         UnityEngine.GradientAlphaKey o;
         System.Single a1;
         checkType(l,2,out a1);
         System.Single a2;
         checkType(l,3,out a2);
         o=new UnityEngine.GradientAlphaKey(a1,a2);
         pushValue(l,o);
         return 1;
     }
     catch(Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return 0;
     }
 }
 static public int constructor(IntPtr l)
 {
     LuaDLL.lua_remove(l, 1);
     UnityEngine.GradientAlphaKey o;
     if (matchType(l, 1, typeof(System.Single), typeof(System.Single)))
     {
         System.Single a1;
         checkType(l, 1, out a1);
         System.Single a2;
         checkType(l, 2, out a2);
         o = new UnityEngine.GradientAlphaKey(a1, a2);
         pushObject(l, o);
         return(1);
     }
     LuaDLL.luaL_error(l, "New object failed.");
     return(0);
 }
Ejemplo n.º 22
0
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.GradientAlphaKey o;
         System.Single a1;
         checkType(l, 2, out a1);
         System.Single a2;
         checkType(l, 3, out a2);
         o = new UnityEngine.GradientAlphaKey(a1, a2);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Ejemplo n.º 23
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);
     }
 }
Ejemplo n.º 24
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);
    }
Ejemplo n.º 25
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);
	}
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.GradientAlphaKey gradientAlphaKey = new UnityEngine.GradientAlphaKey();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "alpha":
                    gradientAlphaKey.alpha = reader.ReadProperty <System.Single> ();
                    break;

                case "time":
                    gradientAlphaKey.time = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
            return(gradientAlphaKey);
        }
Ejemplo n.º 27
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);
    }
Ejemplo n.º 28
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);;
    }
        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);
            }
        }
Ejemplo n.º 30
0
 private void AssignBack()
 {
     this.m_RGBSwatches.Sort((Comparison<Swatch>) ((a, b) => this.SwatchSort(a, b)));
     GradientColorKey[] keyArray = new GradientColorKey[this.m_RGBSwatches.Count];
     for (int i = 0; i < this.m_RGBSwatches.Count; i++)
     {
         keyArray[i].color = this.m_RGBSwatches[i].m_Value;
         keyArray[i].time = this.m_RGBSwatches[i].m_Time;
     }
     this.m_AlphaSwatches.Sort((Comparison<Swatch>) ((a, b) => this.SwatchSort(a, b)));
     GradientAlphaKey[] keyArray2 = new GradientAlphaKey[this.m_AlphaSwatches.Count];
     for (int j = 0; j < this.m_AlphaSwatches.Count; j++)
     {
         keyArray2[j].alpha = this.m_AlphaSwatches[j].m_Value.r;
         keyArray2[j].time = this.m_AlphaSwatches[j].m_Time;
     }
     this.m_Gradient.colorKeys = keyArray;
     this.m_Gradient.alphaKeys = keyArray2;
     this.m_Gradient.mode = this.m_GradientMode;
     GUI.changed = true;
 }
Ejemplo n.º 31
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);
    }
Ejemplo n.º 32
0
    private static void AddCosmosParticle()
    {
        GameObject cpObj = new GameObject("Cosmos Particle");
        cpObj.transform.parent = Cosmos.instance.transform;
        CosmosParticle cp = cpObj.AddComponent<CosmosParticle>();

        cp.color = new Gradient();

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

        colork[1].color =  Color.white;;
        colork[1].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;

        cp.color.SetKeys(colork,alphak);
    }
 public SerializableGradientAlphaKey(GradientAlphaKey colorKey)
 {
     FromKeyframe(colorKey);
 }
 public void FromKeyframe(GradientAlphaKey gck)
 {
     this.time = gck.time;
     this.alpha = gck.alpha;
 }
Ejemplo n.º 35
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
		}
Ejemplo n.º 36
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);
		}
	}
Ejemplo n.º 37
0
	Gradient[] MakeGradients(Color asteroidColor, Color mineralColor) {

		Gradient[] gradients = new Gradient[2];
		gradients[0] = new Gradient();
		GradientColorKey[] gck = new GradientColorKey[5];
		gck[0].color = Color.black;
		gck[0].time = 0;
		gck[1].color = asteroidColor;
		gck[1].time = threshold-blend;
		gck[2].color = asteroidColor*0.5f;
		gck[2].time = threshold;
		gck[3].color = mineralColor*0.8f;
		gck[3].time = threshold+blend;
		gck[4].color = mineralColor;
		gck[4].time = 1;
		GradientAlphaKey[] gak = new GradientAlphaKey[3];
		gak[0].alpha = 0.05f;
		gak[0].time = 0;
		gak[1].alpha = 0.05f;
		gak[1].time = threshold;
		gak[2].alpha = 1;
		gak[2].time = 1;
		gradients[0].SetKeys(gck, gak);
		
		gradients[1] = new Gradient();
		gck[0].color = new Color(0.3f,0.3f,0.3f);
		gck[0].time = 0;
		gck[1].color = new Color(1,1,1);
		gck[1].time = threshold-blend;
		gck[2].color = new Color(0.2f,0.2f,0.2f);
		gck[2].time = threshold;
		gck[3].color = new Color(0.1f,0.1f,0.1f);
		gck[3].time = threshold+blend;
		gck[4].color = new Color(0,0,0);
		gck[4].time = 1;
		gradients[1].SetKeys (gck, gak);

		return gradients;
	}
    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;
            //}
        }
    }
Ejemplo n.º 39
0
 private void AssignBack()
 {
   this.m_RGBSwatches.Sort((Comparison<GradientEditor.Swatch>) ((a, b) => this.SwatchSort(a, b)));
   GradientColorKey[] gradientColorKeyArray = new GradientColorKey[this.m_RGBSwatches.Count];
   for (int index = 0; index < this.m_RGBSwatches.Count; ++index)
   {
     gradientColorKeyArray[index].color = this.m_RGBSwatches[index].m_Value;
     gradientColorKeyArray[index].time = this.m_RGBSwatches[index].m_Time;
   }
   this.m_AlphaSwatches.Sort((Comparison<GradientEditor.Swatch>) ((a, b) => this.SwatchSort(a, b)));
   GradientAlphaKey[] gradientAlphaKeyArray = new GradientAlphaKey[this.m_AlphaSwatches.Count];
   for (int index = 0; index < this.m_AlphaSwatches.Count; ++index)
   {
     gradientAlphaKeyArray[index].alpha = this.m_AlphaSwatches[index].m_Value.r;
     gradientAlphaKeyArray[index].time = this.m_AlphaSwatches[index].m_Time;
   }
   this.m_Gradient.colorKeys = gradientColorKeyArray;
   this.m_Gradient.alphaKeys = gradientAlphaKeyArray;
   this.m_TextureDirty = true;
   GUI.changed = true;
 }
Ejemplo n.º 40
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);
    }
 static public int get_time(IntPtr l)
 {
     UnityEngine.GradientAlphaKey o = (UnityEngine.GradientAlphaKey)checkSelf(l);
     pushValue(l, o.time);
     return(1);
 }
Ejemplo n.º 42
0
    void SetGradientColorKey()
    {
        GradientColorKey[] sck = new GradientColorKey[7];

        sck [0].color = new Color (0.33f, 0.39f, 0.44f, 1f);
        sck [0].time = 0.25f;
        sck [1].color = new Color (0.96f, 0.6f, 0.15f, 1f);
        sck [1].time = 0.26f;
        sck [2].color = new Color (0.976f, 0.816f, 0.565f, 1f);
        sck [2].time = 0.32f;
        sck [3].color = new Color (0.984f, 0.871f, 0.729f, 1f);
        sck [3].time = 0.50f;
        sck [4].color = new Color (0.976f, 0.816f, 0.565f, 1f);
        sck [4].time = 0.68f;
        sck [5].color = new Color (0.96f, 0.6f, 0.15f, 1f);
        sck [5].time = 0.74f;
        sck [6].color = new Color (0.33f, 0.39f, 0.44f, 1f);
        sck [6].time = 0.75f;

        GradientAlphaKey[] sak = new GradientAlphaKey[2];
        sak [0].alpha = 1f;
        sak [0].time = 0f;
        sak [1].alpha = 1f;
        sak [1].time = 1f;

        LightColor.SetKeys (sck, sak);
    }
    static int _CreateGradientAlphaKey(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2)
        {
            float arg0 = (float)LuaScriptMgr.GetNumber(L, 1);
            float arg1 = (float)LuaScriptMgr.GetNumber(L, 2);
            GradientAlphaKey obj = new GradientAlphaKey(arg0,arg1);
            LuaScriptMgr.PushValue(L, obj);
            return 1;
        }
        else if (count == 0)
        {
            GradientAlphaKey obj = new GradientAlphaKey();
            LuaScriptMgr.PushValue(L, obj);
            return 1;
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: GradientAlphaKey.New");
        }

        return 0;
    }
Ejemplo n.º 44
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;
		}
Ejemplo n.º 45
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();
        }
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.GradientAlphaKey gradientAlphaKey = (UnityEngine.GradientAlphaKey)value;
     writer.WriteProperty("alpha", gradientAlphaKey.alpha);
     writer.WriteProperty("time", gradientAlphaKey.time);
 }
Ejemplo n.º 47
0
	Gradient[] MakeGenericGradients(Color asteroidColor) {
		Gradient[] gradients = new Gradient[2];
		gradients[0] = new Gradient();
		GradientColorKey[] gck = new GradientColorKey[2];
		gck[0].color = Color.black;
		gck[0].time = 0;
		gck[1].color = asteroidColor;
		gck[1].time = 1;
		GradientAlphaKey[] gak = new GradientAlphaKey[2];
		gak[0].alpha = 0.05f;
		gak[0].time = 0;
		gak[1].alpha = 0.05f;
		gak[1].time = 1;
		gradients[0].SetKeys (gck, gak);

		gradients[1] = new Gradient();
		gck[0].color = Color.black;
		gck[0].time = 0;
		gck[1].color = Color.white;
		gck[1].time = 1;
		gradients[1].SetKeys (gck, gak);

		return gradients;
	}
    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);
    }
        private void SetupValuesGradient()
        {
            GradientColorKey[] gck = new GradientColorKey[2];
            gck[0].color = Color.blue;
            gck[0].time = 0.0f;
            gck[1].color = new Color(1,0.7f,0,1);
            gck[1].time = 1.0f;

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

            valueGradient.SetKeys(gck,gak);
        }
Ejemplo n.º 50
0
		private void AssignBack()
		{
			this.m_RGBSwatches.Sort((GradientEditor.Swatch a, GradientEditor.Swatch b) => this.SwatchSort(a, b));
			GradientColorKey[] array = new GradientColorKey[this.m_RGBSwatches.Count];
			for (int i = 0; i < this.m_RGBSwatches.Count; i++)
			{
				array[i].color = this.m_RGBSwatches[i].m_Value;
				array[i].time = this.m_RGBSwatches[i].m_Time;
			}
			this.m_AlphaSwatches.Sort((GradientEditor.Swatch a, GradientEditor.Swatch b) => this.SwatchSort(a, b));
			GradientAlphaKey[] array2 = new GradientAlphaKey[this.m_AlphaSwatches.Count];
			for (int j = 0; j < this.m_AlphaSwatches.Count; j++)
			{
				array2[j].alpha = this.m_AlphaSwatches[j].m_Value.r;
				array2[j].time = this.m_AlphaSwatches[j].m_Time;
			}
			this.m_Gradient.colorKeys = array;
			this.m_Gradient.alphaKeys = array2;
			this.m_TextureDirty = true;
			GUI.changed = true;
		}
Ejemplo n.º 51
0
 public extern void SetKeys(GradientColorKey[] colorKeys, GradientAlphaKey[] alphaKeys);
        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;
        }