public static Vector2 AlphaKeyToVector(GradientAlphaKey key) { return(new Vector2(key.alpha, key.time)); }
private static void SetPresetContainerValues(PresetContainer presetContainer) { // set color base Gradient gradient = new Gradient(); GradientAlphaKey[] gak = { new GradientAlphaKey(55.0f / 255.0f, 0.0f), new GradientAlphaKey(75.0f / 255.0f, 0.21f), new GradientAlphaKey(255.0f / 255.0f, 0.31f), new GradientAlphaKey(255.0f / 255.0f, 0.69f), new GradientAlphaKey(75.0f / 255.0f, 0.79f), new GradientAlphaKey(75.0f / 255.0f, 1.0f) }; string[] colorsAsHex = { "#3C3C3C", "#727272", "#A8553E", "#DAD6D6", "#D6D6D6", "#C5BFBF", "#A8553E", "#3C3C3C" }; Color[] colors = new Color[colorsAsHex.Length]; for (int i = 0; i < colors.Length; i++) { UnityEngine.ColorUtility.TryParseHtmlString(colorsAsHex[i], out colors[i]); } GradientColorKey[] gck = { new GradientColorKey(colors[0], 0.0f), new GradientColorKey(colors[1], 0.159f), new GradientColorKey(colors[2], 0.244f), new GradientColorKey(colors[3], 0.318f), new GradientColorKey(colors[4], 0.5f), new GradientColorKey(colors[5], 0.694f), new GradientColorKey(colors[6], 0.762f), new GradientColorKey(colors[7], 0.835f) }; gradient.alphaKeys = gak; gradient.colorKeys = gck; presetContainer.colorBase = gradient; // set color over gradient = new Gradient(); gak = new GradientAlphaKey[] { new GradientAlphaKey(255.0f / 255.0f, 0.0f), new GradientAlphaKey(255.0f / 255.0f, 1.0f) }; colorsAsHex = new string[] { "#131313", "#656565", "#C5C1C1", "#C2C2C2", "#656565", "#131313" }; colors = new Color[colorsAsHex.Length]; for (int i = 0; i < colors.Length; i++) { UnityEngine.ColorUtility.TryParseHtmlString(colorsAsHex[i], out colors[i]); } gck = new GradientColorKey[] { new GradientColorKey(colors[0], 0.0f), new GradientColorKey(colors[1], 0.203f), new GradientColorKey(colors[2], 0.303f), new GradientColorKey(colors[3], 0.674f), new GradientColorKey(colors[4], 0.752f), new GradientColorKey(colors[5], 1.0f) }; gradient.alphaKeys = gak; gradient.colorKeys = gck; presetContainer.colorOver = gradient; // set fog base gradient = new Gradient(); gak = new GradientAlphaKey[] { new GradientAlphaKey(255.0f / 255.0f, 0.0f), new GradientAlphaKey(255.0f / 255.0f, 1.0f) }; colorsAsHex = new string[] { "#131313", "#353027", "#5E6E75", "#7C8382", "#6D6D6D", "#765338", "#171717", "#131313" }; colors = new Color[colorsAsHex.Length]; for (int i = 0; i < colors.Length; i++) { UnityEngine.ColorUtility.TryParseHtmlString(colorsAsHex[i], out colors[i]); } gck = new GradientColorKey[] { new GradientColorKey(colors[0], 0.0f), new GradientColorKey(colors[1], 0.25f), new GradientColorKey(colors[2], 0.309f), new GradientColorKey(colors[3], 0.5f), new GradientColorKey(colors[4], 0.7f), new GradientColorKey(colors[5], 0.744f), new GradientColorKey(colors[6], 0.776f), new GradientColorKey(colors[7], 1.0f) }; gradient.alphaKeys = gak; gradient.colorKeys = gck; presetContainer.fogBase = gradient; // set fog over gradient = new Gradient(); gak = new GradientAlphaKey[] { new GradientAlphaKey(255.0f / 255.0f, 0.0f), new GradientAlphaKey(255.0f / 255.0f, 1.0f) }; colorsAsHex = new string[] { "#090808", "#7C7777", "#8E9396", "#7D706C", "#151515", "#131313" }; colors = new Color[colorsAsHex.Length]; for (int i = 0; i < colors.Length; i++) { UnityEngine.ColorUtility.TryParseHtmlString(colorsAsHex[i], out colors[i]); } gck = new GradientColorKey[] { new GradientColorKey(colors[0], 0.2f), new GradientColorKey(colors[1], 0.309f), new GradientColorKey(colors[2], 0.5f), new GradientColorKey(colors[3], 0.7f), new GradientColorKey(colors[4], 0.81f), new GradientColorKey(colors[5], 1.0f) }; gradient.alphaKeys = gak; gradient.colorKeys = gck; presetContainer.fogOver = gradient; // set star gradient gradient = new Gradient(); gak = new GradientAlphaKey[] { new GradientAlphaKey(255.0f / 255.0f, 0.0f), new GradientAlphaKey(255.0f / 255.0f, 0.19f), new GradientAlphaKey(0.0f / 255.0f, 0.245f), new GradientAlphaKey(0.0f / 255.0f, 0.75f), new GradientAlphaKey(255.0f / 255.0f, 0.8f), new GradientAlphaKey(255.0f / 255.0f, 1.0f) }; colorsAsHex = new string[] { "#FFFFFF", "#FFFFFF" }; colors = new Color[colorsAsHex.Length]; for (int i = 0; i < colors.Length; i++) { UnityEngine.ColorUtility.TryParseHtmlString(colorsAsHex[i], out colors[i]); } gck = new GradientColorKey[] { new GradientColorKey(colors[0], 0.0f), new GradientColorKey(colors[1], 1.0f) }; gradient.alphaKeys = gak; gradient.colorKeys = gck; presetContainer.starGradient = gradient; // set cloud noise base gradient = new Gradient(); gak = new GradientAlphaKey[] { new GradientAlphaKey(0.0f / 255.0f, 0.45f), new GradientAlphaKey(217.0f / 255.0f, 0.75f), new GradientAlphaKey(255.0f / 255.0f, 1.0f) }; colorsAsHex = new string[] { "#000000", "#989898", "#FFFFFF" }; colors = new Color[colorsAsHex.Length]; for (int i = 0; i < colors.Length; i++) { UnityEngine.ColorUtility.TryParseHtmlString(colorsAsHex[i], out colors[i]); } gck = new GradientColorKey[] { new GradientColorKey(colors[0], 0.0f), new GradientColorKey(colors[1], 0.45f), new GradientColorKey(colors[2], 1.0f) }; gradient.alphaKeys = gak; gradient.colorKeys = gck; presetContainer.cloudNoiseBase = gradient; // set cloud noise over gradient = new Gradient(); gak = new GradientAlphaKey[] { new GradientAlphaKey(207.0f / 255.0f, 0.0f), new GradientAlphaKey(255.0f / 255.0f, 1.0f) }; colorsAsHex = new string[] { "#7C7C7C", "#FFFFFF" }; colors = new Color[colorsAsHex.Length]; for (int i = 0; i < colors.Length; i++) { UnityEngine.ColorUtility.TryParseHtmlString(colorsAsHex[i], out colors[i]); } gck = new GradientColorKey[] { new GradientColorKey(colors[0], 0.0f), new GradientColorKey(colors[1], 1.0f) }; gradient.alphaKeys = gak; gradient.colorKeys = gck; presetContainer.cloudNoiseOver = gradient; // set sky tint string colorAsHex = "#80808000"; Color color; UnityEngine.ColorUtility.TryParseHtmlString(colorAsHex, out color); presetContainer.skyTint = color; // set masser color colorAsHex = "#AF4B4BFF"; UnityEngine.ColorUtility.TryParseHtmlString(colorAsHex, out color); presetContainer.MasserColor = color; // set secunda color colorAsHex = "#C3C3C3FF"; UnityEngine.ColorUtility.TryParseHtmlString(colorAsHex, out color); presetContainer.SecundaColor = color; // set atmosphere offset presetContainer.atmsphrOffset = 1; // set atmosphere base curve presetContainer.atmosphereBase = new AnimationCurve(); presetContainer.atmosphereBase.preWrapMode = WrapMode.Clamp; presetContainer.atmosphereBase.postWrapMode = WrapMode.Clamp; presetContainer.atmosphereBase.keys = new Keyframe[] { new Keyframe(0.0f, 0.9f), new Keyframe(0.3f, 0.1f), new Keyframe(0.65f, 0.1f), new Keyframe(1.0f, 1.0f) }; // set atmosphere over curve presetContainer.atmosphereOver = new AnimationCurve(); presetContainer.atmosphereOver.preWrapMode = WrapMode.Loop; presetContainer.atmosphereOver.postWrapMode = WrapMode.Loop; presetContainer.atmosphereOver.keys = new Keyframe[] { new Keyframe(0.0f, -0.33f), new Keyframe(1.0f, -0.33f) }; // set moon alpha base curve presetContainer.moonAlphaBase = new AnimationCurve(); presetContainer.moonAlphaBase.preWrapMode = WrapMode.Clamp; presetContainer.moonAlphaBase.postWrapMode = WrapMode.Clamp; presetContainer.moonAlphaBase.keys = new Keyframe[] { new Keyframe(0.0f, 0.3f), new Keyframe(0.28f, 0.0f), new Keyframe(0.8f, 0.1f), new Keyframe(1.0f, 0.3f) }; presetContainer.moonAlphaBase.SmoothTangents(1, 1.0f); presetContainer.moonAlphaBase.SmoothTangents(2, 1.0f); // set moon alpha over curve presetContainer.moonAlphaOver = new AnimationCurve(); presetContainer.moonAlphaOver.preWrapMode = WrapMode.Loop; presetContainer.moonAlphaOver.postWrapMode = WrapMode.Loop; presetContainer.moonAlphaOver.keys = new Keyframe[] { new Keyframe(0.0f, 0.045f), new Keyframe(0.29f, 0.0f), new Keyframe(1.0f, 0.045f) }; presetContainer.moonAlphaOver.SmoothTangents(1, 1.0f); }
public static object ReadFromBinary(DataType dataType, BinaryReader br) { object value = null; if (dataType == DataType.String) { value = br.ReadString(); } else if (dataType == DataType.Char) { value = br.ReadChar(); } else if (dataType == DataType.Boolean) { byte byteValue = br.ReadByte(); value = (byteValue != 0); } else if (dataType == DataType.Integer) { value = br.ReadInt32(); } else if (dataType == DataType.Long) { value = br.ReadInt64(); } else if (dataType == DataType.Float) { value = br.ReadSingle(); } else if (dataType == DataType.Double) { value = br.ReadDouble(); } else if (dataType == DataType.Vector2) { value = new Vector2(br.ReadSingle(), br.ReadSingle()); } else if (dataType == DataType.Vector3) { value = new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } else if (dataType == DataType.Vector4) { value = new Vector4(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } #if UNITY_2017_2_OR_NEWER else if (dataType == DataType.Vector2Int) { value = new Vector2Int(br.ReadInt32(), br.ReadInt32()); } else if (dataType == DataType.Vector3Int) { value = new Vector3Int(br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); } #endif else if (dataType == DataType.Bounds) { value = new Bounds(new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle())); } #if UNITY_2017_2_OR_NEWER else if (dataType == DataType.BoundsInt) { value = new BoundsInt(new Vector3Int(br.ReadInt32(), br.ReadInt32(), br.ReadInt32()), new Vector3Int(br.ReadInt32(), br.ReadInt32(), br.ReadInt32())); } #endif else if (dataType == DataType.Quaternion) { value = new Quaternion(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } else if (dataType == DataType.Rect) { value = new Rect(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } #if UNITY_2017_2_OR_NEWER else if (dataType == DataType.RectInt) { value = new RectInt(br.ReadInt32(), br.ReadInt32(), br.ReadInt32(), br.ReadInt32()); } #endif else if (dataType == DataType.Color) { value = new Color(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } else if (dataType == DataType.Color32) { value = new Color32(br.ReadByte(), br.ReadByte(), br.ReadByte(), br.ReadByte()); } else if (dataType == DataType.AnimationCurve) { int keyframeCount = br.ReadInt32(); Keyframe[] keyframes = new Keyframe[keyframeCount]; for (int i = 0; i < keyframeCount; i++) { keyframes[i] = new Keyframe(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } value = new AnimationCurve(keyframes); } else if (dataType == DataType.Gradient) { GradientMode gradientMode = (GradientMode)br.ReadByte(); GradientAlphaKey[] alphaKeys = new GradientAlphaKey[br.ReadInt32()]; for (int i = 0; i < alphaKeys.Length; i++) { alphaKeys[i] = new GradientAlphaKey(br.ReadSingle(), br.ReadSingle()); } GradientColorKey[] colorKeys = new GradientColorKey[br.ReadInt32()]; for (int i = 0; i < colorKeys.Length; i++) { colorKeys[i] = new GradientColorKey(new Color(br.ReadSingle(), br.ReadSingle(), br.ReadSingle(), br.ReadSingle()), br.ReadSingle()); } value = new Gradient() { mode = gradientMode, alphaKeys = alphaKeys, colorKeys = colorKeys }; } else if (dataType == DataType.Enum) { value = br.ReadInt32(); } else if (dataType == DataType.UnityObjectReference) { string guidString = br.ReadString(); if (string.IsNullOrEmpty(guidString)) { value = Guid.Empty; } else { value = new Guid(guidString); // Read guid } } else if (dataType == DataType.Unknown) { value = br.ReadString(); // Read Type name } else { Debug.LogWarning("Could not read " + dataType); } return(value); }
public static object Load(System.Type type, string text, object oldValue) { if (type == null) { return(null); } if (type.IsPrimitive) { if (string.IsNullOrEmpty(text)) { try { return(Activator.CreateInstance(type)); } catch (MissingMethodException) { Debug.LogError(type.Name + " Doesn't seem to have a default constructor"); throw; } } return(Convert.ChangeType(text, type, CultureInfo.InvariantCulture)); } else if (typeof(UnityEngine.Object).IsAssignableFrom(type)) { object obj = new ObjectWrapper(); EditorJsonUtility.FromJsonOverwrite(text, obj); return(((ObjectWrapper)obj).obj); } else if (type.IsAssignableFrom(typeof(AnimationCurve))) { AnimCurveWrapper sac = new AnimCurveWrapper(); JsonUtility.FromJsonOverwrite(text, sac); AnimationCurve curve = oldValue != null ? (AnimationCurve)oldValue : new AnimationCurve(); if (sac.frames != null) { Keyframe[] keys = new UnityEngine.Keyframe[sac.frames.Length]; for (int i = 0; i < sac.frames.Length; ++i) { keys[i].time = sac.frames[i].time; keys[i].value = sac.frames[i].value; keys[i].inTangent = sac.frames[i].inTangent; keys[i].outTangent = sac.frames[i].outTangent; if (sac.version == 1) { AnimationUtility.SetKeyLeftTangentMode(ref keys[i], sac.frames[i].leftTangentMode); AnimationUtility.SetKeyRightTangentMode(ref keys[i], sac.frames[i].rightTangentMode); AnimationUtility.SetKeyBroken(ref keys[i], sac.frames[i].broken); } else { AnimationUtility.SetKeyLeftTangentMode(ref keys[i], (TangentMode)((sac.frames[i].tangentMode & kLeftTangentMask) >> 1)); AnimationUtility.SetKeyRightTangentMode(ref keys[i], (TangentMode)((sac.frames[i].tangentMode & kRightTangentMask) >> 5)); AnimationUtility.SetKeyBroken(ref keys[i], (sac.frames[i].tangentMode & kBrokenMask) != 0); } } curve.keys = keys; curve.preWrapMode = sac.preWrapMode; curve.postWrapMode = sac.postWrapMode; } return(curve); } else if (type.IsAssignableFrom(typeof(Gradient))) { GradientWrapper gw = new GradientWrapper(); Gradient gradient = oldValue != null ? (Gradient)oldValue : new Gradient(); JsonUtility.FromJsonOverwrite(text, gw); gradient.mode = gw.gradientMode; GradientColorKey[] colorKeys = null; if (gw.colorKeys != null) { colorKeys = new GradientColorKey[gw.colorKeys.Length]; for (int i = 0; i < gw.colorKeys.Length; ++i) { colorKeys[i].color = gw.colorKeys[i].color; colorKeys[i].time = gw.colorKeys[i].time; } } else { colorKeys = new GradientColorKey[0]; } GradientAlphaKey[] alphaKeys = null; if (gw.alphaKeys != null) { alphaKeys = new GradientAlphaKey[gw.alphaKeys.Length]; for (int i = 0; i < gw.alphaKeys.Length; ++i) { alphaKeys[i].alpha = gw.alphaKeys[i].alpha; alphaKeys[i].time = gw.alphaKeys[i].time; } } else { alphaKeys = new GradientAlphaKey[0]; } gradient.SetKeys(colorKeys, alphaKeys); return(gradient); } else if (type == typeof(string)) { return(text.Substring(1, text.Length - 2).Replace("\\\"", "\"")); } else if (type == typeof(SerializableType)) { var obj = new SerializableType(text.Substring(1, text.Length - 2)); return(obj); } else if (type.IsArrayOrList()) { List <string> elements = ParseArray(text); if (elements == null) { return(null); } if (type.IsArray) { int listCount = elements.Count; Array arrayObj = (Array)Activator.CreateInstance(type, new object[] { listCount }); for (int index = 0; index < listCount; index++) { arrayObj.SetValue(Load(type.GetElementType(), elements[index], null), index); } return(arrayObj); } else //List { int listCount = elements.Count; IList listObj = (IList)Activator.CreateInstance(type, new object[0]); for (int index = 0; index < listCount; index++) { listObj.Add(Load(type.GetElementType(), elements[index], null)); } return(listObj); } } else { try { object obj = Activator.CreateInstance(type); EditorJsonUtility.FromJsonOverwrite(text, obj); return(obj); } catch (MissingMethodException) { Debug.LogError(type.Name + " Doesn't seem to have a default constructor"); throw; } } }
private static GradientAlphaKey FTime(this GradientAlphaKey key, Func <float, float> f) { key.time = f(key.time); return(key); }
public static void RefreshTexture(double[,] nodes, Texture2D texture) { 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); int width = nodes.GetLength(0); int height = nodes.GetLength(1); double DVminsqr = double.MaxValue; double DVmaxsqr = double.MinValue; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { double DVsqr = nodes[i, j] * nodes[i, j]; if (DVsqr < DVminsqr) { DVminsqr = DVsqr; } DVmaxsqr = Math.Max(DVmaxsqr, nodes[i, j] * nodes[i, j]); } } double logDVminsqr = Math.Log(DVminsqr); double logDVmaxsqr = Math.Min(Math.Log(DVmaxsqr), logDVminsqr + 4); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { double lambda = (Math.Log(nodes[i, j] * nodes[i, j]) - 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 }
private static Texture2D GenerateGradient(Rect rect, IList <StyleSheetResolver.Value[]> args) { long key = (long)rect.width * 30 + (long)rect.height * 8; foreach (var arg in args) { for (int i = 0; i < arg.Length; ++i) { key += arg[i].GetHashCode() * i + 1; } } if (s_Gradients.ContainsKey(key) && s_Gradients[key] != null) { return(s_Gradients[key]); } if (s_Gradients.Count > 300) { while (s_Gradients.Count > 250) { s_Gradients.Remove(s_Gradients.Keys.ToList().First()); } } var width = (int)rect.width; var height = (int)rect.height; Gradient gradient = new Gradient(); var gt = new Texture2D(width, height) { alphaIsTransparency = true }; var colorKeys = new GradientColorKey[args.Count]; var alphaKeys = new GradientAlphaKey[args.Count]; float increment = args.Count <= 1 ? 1f : 1f / (args.Count - 1); float autoStep = 0; for (int i = 0; i < args.Count; ++i) { var values = args[i]; if (values.Length == 1) { colorKeys[i].color = values[0].AsColor(); colorKeys[i].time = autoStep; } else if (values.Length == 2) { colorKeys[i].color = values[0].AsColor(); colorKeys[i].time = values[1].AsFloat(); } else { Debug.LogError("Invalid gradient value argument"); } alphaKeys[i].time = colorKeys[i].time; alphaKeys[i].alpha = colorKeys[i].color.a; autoStep = Mathf.Clamp(autoStep + increment, 0f, 1f); } gradient.SetKeys(colorKeys, alphaKeys); float yStep = 1F / height; for (int y = height - 1; y >= 0; --y) { Color color = gradient.Evaluate(1f - (y * yStep)); for (int x = width - 1; x >= 0; --x) { gt.SetPixel(x, y, color); } } gt.Apply(); s_Gradients[key] = gt; return(gt); }
//private void OnDisable() //{ // Debug.Log("Disable"); //} //private void OnEnable() //{ // Debug.Log("OnEnable"); //} //[ImageEffectOpaque] private void OnRenderImage(RenderTexture source, RenderTexture destination) { Camera cam = GetComponent <Camera>(); //cam.depthTextureMode |= DepthTextureMode.Depth; var shouldRender = CheckResources() && ((cam && cam.actualRenderingPath == RenderingPath.DeferredShading)); if (!shouldRender) { Graphics.Blit(source, destination); return; } if (material) { //Camera cam = Camera.main; //Transform CamTrans = cam.transform; //float near = cam.nearClipPlane; //float far = cam.farClipPlane; //float halfHeight = cam.nearClipPlane * Mathf.Tan(cam.fieldOfView * 0.5f * Mathf.Deg2Rad); //Vector3 toRight = CamTrans.right * halfHeight * cam.aspect; //Vector3 upVector = CamTrans.up * halfHeight; //Vector3 topVector = CamTrans.forward * near + upVector; //Vector3 bottomVector = CamTrans.forward * near - upVector; //Vector3 bottomLeft = bottomVector - toRight; //左下 //Vector3 bottomRight = bottomVector + toRight; //右下 //Vector3 topLeft = topVector - toRight; //左上 //Vector3 topRight = topVector + toRight; //右上 //List<Vector4> l = new List<Vector4> //{ // bottomLeft,bottomRight,topLeft,topRight //}; //material.SetVectorArray("_CameraMat", l); int num = 7; List <Vector4> l = new List <Vector4>(); for (float i = 0; i <= 1.0f; i += 1.0f / num) { var c = fogColorRamp.Evaluate(i); if (fogColorMultiplyLight) { var light = GameObject.FindGameObjectWithTag("MainLight").GetComponent <Light>(); c *= light.intensity * fogColorIntensityFactor; } l.Add(c); } material.SetVectorArray("_ColorGradient", l); material.SetInt("_ColorGradient_Num", l.Count - 1); material.SetFloat("_FogDensity", fogDensity); material.SetFloat("_FogStartDepth", fogStartDepth); material.SetFloat("_SkyFogDensity", skyDensity); if (useSkyDensity) { material.EnableKeyword("FOG_SKY"); } else { material.DisableKeyword("FOG_SKY"); } if (useFogHeight) { material.EnableKeyword("FOG_USE_HEIGHT"); } else { material.DisableKeyword("FOG_USE_HEIGHT"); } material.DisableKeyword("FOG_ATTENUATION_LINEAR"); material.DisableKeyword("FOG_ATTENUATION_EXPONENT"); material.DisableKeyword("FOG_ATTENUATION_EXPONENT_SQUARE"); switch (fogAttenuationType) { case AttenuationType.Linear: material.EnableKeyword("FOG_ATTENUATION_LINEAR"); break; case AttenuationType.Exponent: material.EnableKeyword("FOG_ATTENUATION_EXPONENT"); break; case AttenuationType.ExponentSquare: material.EnableKeyword("FOG_ATTENUATION_EXPONENT_SQUARE"); break; } material.SetFloat("_FogHeight", fogHeight); material.SetFloat("_FogHeightScale", fogHeightScale); var mieColorM20 = worldMieColorRamp.Evaluate(0.00f); var mieColorO00 = worldMieColorRamp.Evaluate(0.50f); var mieColorP20 = worldMieColorRamp.Evaluate(1.00f); material.SetFloat("u_MiePhaseAnisotropy", miePhaseAnisotropy); material.SetFloat("u_WorldMieDensity", worldMieDensity); material.SetFloat("u_HeightMieDensity", fogMieDensity); material.SetVector("u_MieColorM20", (Vector4)mieColorM20 * worldMieColorIntensity); material.SetVector("u_MieColorO00", (Vector4)mieColorO00 * worldMieColorIntensity); material.SetVector("u_MieColorP20", (Vector4)mieColorP20 * worldMieColorIntensity); material.SetFloat("u_HeightMieDistanceScale", heightMieDistanceScale); var d = -sunSource.forward; d.Normalize(); material.SetVector("u_SunDirection", new Vector4(d.x, d.y, d.z, 1)); Graphics.Blit(source, destination, material); GradientColorKey[] gck = new GradientColorKey[l.Count]; GradientAlphaKey[] gak = new GradientAlphaKey[l.Count]; for (int i = 0; i < l.Count; ++i) { gak[i].alpha = l[i].w; gak[i].time = 1.0f / num * i; gck[i].color = new Color(l[i].x, l[i].y, l[i].z); gck[i].time = 1.0f / num * i; } gradientSample.SetKeys(gck, gak); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); // Draw the default inspector changeColor = GUILayout.Toggle(changeColor, "Change color"); changeIndex = GUILayout.Toggle(changeIndex, "Change index"); changeRange = GUILayout.Toggle(changeRange, "Change range"); changeMultiplier = GUILayout.Toggle(changeMultiplier, "Change multiplier"); if (GUILayout.Button("Apply changes") && (changeColor || changeRange || changeMultiplier || changeIndex)) { List <Object> undoList = new List <Object>(); foreach (GameObject g in childObjects) { undoList.Add(g.GetComponent <GenericAudioResponse>()); } Undo.RecordObjects(undoList.ToArray(), "Using ARS Sequence Tool"); if (changeColor) { List <ColorAudioResponse> list = new List <ColorAudioResponse>(); for (int i = 0; i < childObjects.Count; i++) { if (childObjects[i].GetComponent <ColorAudioResponse>()) { list.Add(childObjects[i].GetComponent <ColorAudioResponse>()); } } for (int i = 0; i < list.Count; i++) { GradientColorKey[] colorKey = new GradientColorKey[] { new GradientColorKey(targetObject.gradientRangeStart.Evaluate((float)i / list.Count), 0), new GradientColorKey(targetObject.gradientRangeEnd.Evaluate((float)i / list.Count), 1) }; GradientAlphaKey[] alphaKey = new GradientAlphaKey[] { new GradientAlphaKey(targetObject.gradientRangeStart.Evaluate((float)i / list.Count).a, 0), new GradientAlphaKey(targetObject.gradientRangeEnd.Evaluate((float)i / list.Count).a, 1) }; list[i].gradient.SetKeys(colorKey, alphaKey); } } if (changeIndex) { for (int i = 0; i < childObjects.Count; i++) { foreach (GenericAudioResponse g in childObjects[i].GetComponents <GenericAudioResponse>()) { g.frequencyIndex = (int)((targetObject.indexRangeEnd - targetObject.indexRangeStart) * ((float)i / (float)childObjects.Count)) + targetObject.indexRangeStart; } } } if (changeRange) { for (int i = 0; i < childObjects.Count; i++) { foreach (GenericAudioResponse g in childObjects[i].GetComponents <GenericAudioResponse>()) { g.range = (int)((targetObject.rangeRangeEnd - targetObject.rangeRangeStart) * ((float)i / (float)childObjects.Count)) + targetObject.rangeRangeStart; } } } if (changeMultiplier) { for (int i = 0; i < childObjects.Count; i++) { foreach (GenericAudioResponse g in childObjects[i].GetComponents <GenericAudioResponse>()) { g.multiplier = (int)((targetObject.multiplierRangeEnd - targetObject.multiplierRangeStart) * ((float)i / (float)childObjects.Count)) + targetObject.multiplierRangeStart; } } } } EditorUtility.SetDirty(target); // Save the changes back to the object }
public virtual void Update() { if (!this.lineRenderer) { this.Start(); } if (this.requireEnabled) { this.lineRenderer.enabled = this.enabled; } if (this.requireRaycastHit) { this.lineRenderer.enabled = this.lineRenderer.enabled && Physics.Raycast(this.transform.position, this.transform.forward, this.maxLength); } if (!this.lineRenderer.enabled) { return; } bool wasObstructed = this.closestPoint < this.maxLength; // Check for obstructions this.closestPoint = this.maxLength; foreach (RaycastHit hit in Physics.RaycastAll(this.transform.position, this.transform.forward, this.maxLength)) { if ((hit.point - this.transform.position).sqrMagnitude < (this.closestPoint * this.closestPoint)) { this.closestPoint = (hit.point - this.transform.position).magnitude; } } foreach (Vector3 p in this.points) { //Debug.DrawLine(this.transform.TransformPoint(p), this.transform.TransformPoint(p) + (Vector3.up * 0.25f), Color.gray); } //Debug.DrawLine(this.transform.position, this.transform.position + (this.transform.forward * this.closestPoint), Color.blue); if ((this.closestPoint >= this.maxLength) && wasObstructed) // If obstruction has been cleared since last frame, reset beam { this.lineRenderer.colorGradient = this.gradient; this.lineRenderer.positionCount = this.points.Length; this.lineRenderer.SetPositions(this.points); return; } float progress = this.closestPoint / this.maxLength; // Generate partial beam Gradient colorGradient = new Gradient(); //print(progress + " * " + gradient.colorKeys.Length + " = " + progress * (gradient.colorKeys.Length - 1) + " | " + Mathf.Ceil(progress * (points.Length - 1))); GradientColorKey[] colorKeys = new GradientColorKey[(int)Mathf.Max(2, 1 + Mathf.Ceil(progress * (this.gradient.colorKeys.Length - 1)))]; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[(int)Mathf.Max(2, 1 + Mathf.Ceil(progress * (this.gradient.alphaKeys.Length - 1)))]; int i = 0; while (i < Mathf.Max(colorKeys.Length, alphaKeys.Length)) { if (i < colorKeys.Length) { colorKeys[i] = new GradientColorKey(this.gradient.colorKeys[i].color, Mathf.Clamp01(this.gradient.colorKeys[i].time / progress)); } if (i < alphaKeys.Length) { alphaKeys[i] = new GradientAlphaKey(this.gradient.alphaKeys[i].alpha, Mathf.Clamp01(this.gradient.alphaKeys[i].time / progress)); } i++; } colorKeys[colorKeys.Length - 1].color = this.gradient.Evaluate(progress); alphaKeys[alphaKeys.Length - 1].alpha = colorKeys[colorKeys.Length - 1].color.a; colorGradient.SetKeys(colorKeys, alphaKeys); this.lineRenderer.colorGradient = colorGradient; this.lineRenderer.positionCount = (int)Mathf.Max(2, Mathf.Min(1 + Mathf.Ceil(progress * (this.points.Length - 1)), this.points.Length)); this.lineRenderer.SetPositions(this.points); this.lineRenderer.SetPosition(this.lineRenderer.positionCount - 1, Vector3.forward * this.closestPoint); }
/// LateUpdate is called every frame, if the Behaviour is enabled. /// It is called after all Update functions have been called. void LateUpdate() { // Check incase object has been destroyed or force is yet to be calculated PhysicsObject newInfluencer; PhysicsEngine.ForceExerter forceExerter; if (physicsEngine.strongest_force.TryGetValue(ID, out forceExerter) && physicsObjects.ContainsKey(forceExerter.id)) { newInfluencer = physicsObjects[forceExerter.id]; // If new influencer if (newInfluencer != biggestGravitationalInfluencer) { if (_drawPastPath) { // Clear previous trail if in new orbit relativeTrailPositions.Clear(); } } // Update biggestGravitationalInfluencer = newInfluencer; } // Future relative predicted path if (UiManager.displayFuturePath) { // First frame setup if (!_drawFuturePath) { // Setup colour keys GradientColorKey[] colorKeys = new GradientColorKey[2]; colorKeys[0].color = Color.blue; colorKeys[0].time = 0.0f; colorKeys[1].color = Color.blue; colorKeys[1].time = 0.0f; // Setup alpha keys GradientAlphaKey[] alphaKeys = new GradientAlphaKey[3]; alphaKeys[0].alpha = 1.0f; alphaKeys[0].time = 0.0f; alphaKeys[1].alpha = 1.0f; alphaKeys[1].time = 0.5f; alphaKeys[2].alpha = 0.0f; alphaKeys[2].time = 1.0f; // Set colour gradient Gradient gradient = new Gradient(); gradient.SetKeys(colorKeys, alphaKeys); lineRenderer.colorGradient = gradient; // Set flag _drawFuturePath = true; } lineRenderer.useWorldSpace = true; uint segments = 500; // Predict future path Vector3[] positions = PredictOrbit(biggestGravitationalInfluencer, segments); if (positions != null) { // Set positions lineRenderer.positionCount = (int)segments; lineRenderer.SetPositions(positions); } } // Past Drawn relative path else if (UiManager.displayPastPath) { // First frame setup if (!_drawPastPath) { // Setup colour keys GradientColorKey[] colorKeys = new GradientColorKey[2]; colorKeys[0].color = Color.cyan; colorKeys[0].time = 0.0f; colorKeys[1].color = Color.cyan; colorKeys[1].time = 0.0f; // Setup alpha keys GradientAlphaKey[] alphaKeys = new GradientAlphaKey[3]; alphaKeys[0].alpha = 0.0f; alphaKeys[0].time = 0.0f; alphaKeys[1].alpha = 1.0f; alphaKeys[1].time = 0.5f; alphaKeys[2].alpha = 1.0f; alphaKeys[2].time = 1.0f; // Set colour gradient Gradient gradient = new Gradient(); gradient.SetKeys(colorKeys, alphaKeys); lineRenderer.colorGradient = gradient; // Set flag _drawPastPath = true; } // Update trail vertex count lineRenderer.positionCount = relativeTrailPositions.Count; // Manually translate all positions to acheive local space without rotation or scale lineRenderer.useWorldSpace = true; // for each position for (int i = 0; i < lineRenderer.positionCount; i++) { Vector3 relativePos = relativeTrailPositions.ElementAt(i); lineRenderer.SetPosition(i, relativePos + biggestGravitationalInfluencer.transform.position); } // Track position if (timeSinceLastPosition > 1.0f && Time.timeScale != 0.0f) { // Add to relative positions queue relativeTrailPositions.Enqueue(transform.position - biggestGravitationalInfluencer.transform.position); // Reset timer timeSinceLastPosition = 0.0f; } // Increment timer else { timeSinceLastPosition += Time.unscaledDeltaTime * 100.0f; } } // If flag is true but realtime value false: // Turn off future path if (_drawFuturePath && !UiManager.displayFuturePath) { // Reset flag _drawFuturePath = false; // Clear path lineRenderer.positionCount = 0; } // If flag is true but realtime value false: // Turn off past path if (_drawPastPath && !UiManager.displayPastPath) { // Reset flag _drawPastPath = false; // Clear path lineRenderer.positionCount = 0; relativeTrailPositions.Clear(); } }
private Color[] TileTexture(int x, int y) { ChunkTile tile = ManagerInstance.Get <WorldManager>().completeMap[x, y]; if (x >= 0 && x < WorldManager.worldWidth * Chunk.WIDTH && y >= 0 && y < WorldManager.worldHeight * Chunk.HEIGHT) { //check for cached version for (int i = 0; i < m_textureCache.Count; i++) { if (m_textureCache[i].tileIdentity == tile.identity) { bool foundCached = true; for (int bX = 0; bX < 3; bX++) { for (int bY = 0; bY < 3; bY++) { if (m_textureCache[i].borderMap[bX, bY].border != tile.drawMap.borderMap[bX, bY].border) { foundCached = false; } if (m_textureCache[i].borderMap[bX, bY].type != tile.drawMap.borderMap[bX, bY].type) { foundCached = false; } } } if (foundCached) { return(m_textureCache[i].texture); } } } Color[] pix = new Color[TILE_RESOLUTION * TILE_RESOLUTION]; for (int i = 0; i < pix.Length; i++) { pix[i] = ManagerInstance.Get <DatabaseManager>().dataBase.GetDefaultTexture(tile.identity)[i] * Random.Range(1.05f, 1.2f); } if (x - 1 >= 0) { if (tile.drawMap.borderMap[0, 1].border) { //draw shadowMap if (tile.drawMap.borderMap[0, 1].type == BorderType.Shadow) { for (int i = 0; i < pix.Length; i++) { if (i % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.35f, 0.45f); } if ((i - 1) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.45f, 0.55f); } if ((i - 2) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.55f, 0.65f); } if ((i - 3) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.65f, 0.75f); } if ((i - 4) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.75f, 0.85f); } } } else if (tile.drawMap.borderMap[0, 1].type == BorderType.Merge) { Color[] neightborTex = ManagerInstance.Get <DatabaseManager>().dataBase.GetGraphicsFor(ManagerInstance.Get <WorldManager>().completeMap[x - 1, y].identity).texture; for (int i = 0; i < pix.Length; i++) { Gradient gradient = new Gradient(); GradientColorKey[] gck = new GradientColorKey[2]; gck[0].color = pix[i]; gck[0].time = 0.0f; gck[1].color = neightborTex[i]; 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 = 1.0f; gak[0].time = 0.0f; gak[1].alpha = 1f; gak[1].time = 1.0f; gradient.SetKeys(gck, gak); if (i % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.8f); } if ((i - 1) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.775f); } if ((i - 2) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.65f); } if ((i - 3) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.525f); } if ((i - 4) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.4f); } if ((i - 5) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.375f); } if ((i - 6) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.25f); } if ((i - 7) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.125f); } if ((i - 8) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0f); } } } } } if (y + 1 < WorldManager.worldHeight * Chunk.HEIGHT) { if (tile.drawMap.borderMap[1, 2].border) { if (tile.drawMap.borderMap[1, 2].type == BorderType.Shadow) { for (int i = 0; i < pix.Length; i++) { if (i > pix.Length - (TILE_RESOLUTION + 1)) { pix[i] *= Random.Range(0.35f, 0.45f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 2 && i < pix.Length - (TILE_RESOLUTION + 1)) { pix[i] *= Random.Range(0.45f, 0.55f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 3 && i < pix.Length - (TILE_RESOLUTION + 1) * 2) { pix[i] *= Random.Range(0.55f, 0.65f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 4 && i < pix.Length - (TILE_RESOLUTION + 1) * 3) { pix[i] *= Random.Range(0.65f, 0.75f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 5 && i < pix.Length - (TILE_RESOLUTION + 1) * 4) { pix[i] *= Random.Range(0.75f, 0.85f); } } } else if (tile.drawMap.borderMap[1, 2].type == BorderType.Merge) { Color[] neightborTex = ManagerInstance.Get <DatabaseManager>().dataBase.GetGraphicsFor(ManagerInstance.Get <WorldManager>().completeMap[x, y + 1].identity).texture; for (int i = 0; i < pix.Length; i++) { Gradient gradient = new Gradient(); GradientColorKey[] gck = new GradientColorKey[2]; gck[0].color = pix[i]; gck[0].time = 0.0f; gck[1].color = neightborTex[i]; 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 = 1.0f; gak[0].time = 0.0f; gak[1].alpha = 1f; gak[1].time = 1.0f; gradient.SetKeys(gck, gak); if (i > pix.Length - (TILE_RESOLUTION + 1)) { pix[i] = gradient.Evaluate(0.8f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 2 && i < pix.Length - (TILE_RESOLUTION + 1)) { pix[i] = gradient.Evaluate(0.775f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 3 && i < pix.Length - (TILE_RESOLUTION + 1) * 2) { pix[i] = gradient.Evaluate(0.65f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 4 && i < pix.Length - (TILE_RESOLUTION + 1) * 3) { pix[i] = gradient.Evaluate(0.525f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 5 && i < pix.Length - (TILE_RESOLUTION + 1) * 4) { pix[i] = gradient.Evaluate(0.4f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 6 && i < pix.Length - (TILE_RESOLUTION + 1) * 5) { pix[i] = gradient.Evaluate(0.375f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 7 && i < pix.Length - (TILE_RESOLUTION + 1) * 6) { pix[i] = gradient.Evaluate(0.25f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 8 && i < pix.Length - (TILE_RESOLUTION + 1) * 7) { pix[i] = gradient.Evaluate(0.125f); } if (i > pix.Length - (TILE_RESOLUTION + 1) * 9 && i < pix.Length - (TILE_RESOLUTION + 1) * 8) { pix[i] = gradient.Evaluate(0f); } } } } } if (x + 1 < WorldManager.worldWidth * Chunk.WIDTH) { if (tile.drawMap.borderMap[2, 1].border) { if (tile.drawMap.borderMap[2, 1].type == BorderType.Shadow) { for (int i = 0; i < pix.Length; i++) { if ((i + 1) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.35f, 0.45f); } if ((i + 2) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.45f, 0.55f); } if ((i + 3) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.55f, 0.65f); } if ((i + 4) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.65f, 0.75f); } if ((i + 5) % TILE_RESOLUTION == 0) { pix[i] *= Random.Range(0.75f, 0.85f); } } } else if (tile.drawMap.borderMap[2, 1].type == BorderType.Merge) { Color[] neightborTex = ManagerInstance.Get <DatabaseManager>().dataBase.GetGraphicsFor(ManagerInstance.Get <WorldManager>().completeMap[x + 1, y].identity).texture; for (int i = 0; i < pix.Length; i++) { Gradient gradient = new Gradient(); GradientColorKey[] gck = new GradientColorKey[2]; gck[0].color = pix[i]; gck[0].time = 0.0f; gck[1].color = neightborTex[i]; 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 = 1.0f; gak[0].time = 0.0f; gak[1].alpha = 1f; gak[1].time = 1.0f; gradient.SetKeys(gck, gak); if ((i + 1) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.8f); } if ((i + 2) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.775f); } if ((i + 3) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.65f); } if ((i + 4) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.525f); } if ((i + 5) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.4f); } if ((i + 6) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.375f); } if ((i + 7) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.25f); } if ((i + 8) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0.125f); } if ((i + 9) % TILE_RESOLUTION == 0) { pix[i] = gradient.Evaluate(0f); } } } } } if (y - 1 >= 0) { if (tile.drawMap.borderMap[1, 0].border) { if (tile.drawMap.borderMap[1, 0].type == BorderType.Shadow) { for (int i = 0; i < pix.Length; i++) { //TODO Fix 1 pixelline shade if (i < TILE_RESOLUTION) { pix[i] *= Random.Range(0.35f, 0.45f); } if (i < TILE_RESOLUTION * 2 && i > TILE_RESOLUTION) { pix[i] *= Random.Range(0.45f, 0.55f); } if (i < TILE_RESOLUTION * 3 && i > TILE_RESOLUTION * 2) { pix[i] *= Random.Range(0.55f, 0.65f); } if (i < TILE_RESOLUTION * 4 && i > TILE_RESOLUTION * 3) { pix[i] *= Random.Range(0.65f, 0.75f); } if (i < TILE_RESOLUTION * 5 && i > TILE_RESOLUTION * 4) { pix[i] *= Random.Range(0.75f, 0.85f); } } } else if (tile.drawMap.borderMap[1, 0].type == BorderType.Merge) { Color[] neightborTex = ManagerInstance.Get <DatabaseManager>().dataBase.GetGraphicsFor(ManagerInstance.Get <WorldManager>().completeMap[x, y - 1].identity).texture; for (int i = 0; i < pix.Length; i++) { Gradient gradient = new Gradient(); GradientColorKey[] gck = new GradientColorKey[2]; gck[0].color = pix[i]; gck[0].time = 0.0f; gck[1].color = neightborTex[i]; 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 = 1.0f; gak[0].time = 0.0f; gak[1].alpha = 1f; gak[1].time = 1.0f; gradient.SetKeys(gck, gak); if (i < TILE_RESOLUTION) { pix[i] = gradient.Evaluate(0.8f); } if (i < TILE_RESOLUTION * 2 && i > TILE_RESOLUTION) { pix[i] = gradient.Evaluate(0.775f); } if (i < TILE_RESOLUTION * 3 && i > TILE_RESOLUTION * 2) { pix[i] = gradient.Evaluate(0.65f); } if (i < TILE_RESOLUTION * 4 && i > TILE_RESOLUTION * 3) { pix[i] = gradient.Evaluate(0.525f); } if (i < TILE_RESOLUTION * 5 && i > TILE_RESOLUTION * 4) { pix[i] = gradient.Evaluate(0.4f); } if (i < TILE_RESOLUTION * 6 && i > TILE_RESOLUTION * 5) { pix[i] = gradient.Evaluate(0.375f); } if (i < TILE_RESOLUTION * 7 && i > TILE_RESOLUTION * 6) { pix[i] = gradient.Evaluate(0.25f); } if (i < TILE_RESOLUTION * 8 && i > TILE_RESOLUTION * 7) { pix[i] = gradient.Evaluate(0.125f); } if (i < TILE_RESOLUTION * 9 && i > TILE_RESOLUTION * 8) { pix[i] = gradient.Evaluate(0f); } } } } } tile.drawMap.Redraw(); //cache the new texture ChunkTileCachedTexture textureCache = new ChunkTileCachedTexture(tile.identity, tile.drawMap.borderMap, pix); m_textureCache.Add(textureCache); return(pix); } return(DebugTexture(tile.identity)); }
void Update() { gunsound = GetComponent <AudioSource>(); corsurePosition = transform.position; tempPosition = transform.position; corsurePosition = InputTracking.GetLocalPosition(XRNode.RightHand); head = InputTracking.GetLocalPosition(XRNode.Head); //corsurePosition += new Vector3(0f,0f,.3f); corsureRotation.x = InputTracking.GetLocalRotation(XRNode.RightHand).eulerAngles.x; corsureRotation.y = InputTracking.GetLocalRotation(XRNode.RightHand).eulerAngles.y; corsureRotation.z = InputTracking.GetLocalRotation(XRNode.RightHand).eulerAngles.z; Vector3 UpVector = Quaternion.Euler(corsureRotation) * Vector3.forward; Vector3 MidcorsureVec = UpVector / 5f; corsurePosition += MidcorsureVec; Debug.Log(string.Format(" UpVectorUpVector: ") + UpVector); currentPosition = corsurePosition + tempPosition; LaserGunRange = TransformMapping.currentConcentrate; //forwardVector *= LaserGunRange; LineRenderer lineRenderer = GetComponent <LineRenderer>(); //Vector3 UpVector = Vector3.up;// (0, 1, 0); if (Concentaration_Bar.Bar_Range >= 0.4f && Concentaration_Bar.Bar_Range < 0.5f) { UpVector *= ((((Concentaration_Bar.Bar_Range * 10) % 4) % 10) / 3f); Vector3[] positions = new Vector3[2]; positions[0] = currentPosition; positions[1] = UpVector + currentPosition; lineRenderer.positionCount = positions.Length; lineRenderer.SetPositions(positions); GradientColorKey[] colorKeys = new GradientColorKey[2]; colorKeys[0] = new GradientColorKey(Color.blue, 0f); //At 0% set to red colorKeys[1] = new GradientColorKey(Color.green, 1f); GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2]; alphaKeys[0] = new GradientAlphaKey(1f, 0f); alphaKeys[1] = new GradientAlphaKey(1f, 1f); Gradient gradient = new Gradient(); gradient.SetKeys(colorKeys, alphaKeys); lineRenderer.colorGradient = gradient; } else if (Concentaration_Bar.Bar_Range >= 0.5f && Concentaration_Bar.Bar_Range < 0.6f) { Vector3 MidforVec = UpVector / 6f; //Vector3 MidVec = new Vector3(0, 0.3f, 0); Vector3 MidVector = MidforVec + currentPosition; UpVector *= ((((Concentaration_Bar.Bar_Range * 10) % 5) % 10) / 3f); Vector3[] positions = new Vector3[3]; positions[0] = currentPosition; positions[1] = MidVector; positions[2] = UpVector + MidVector; lineRenderer.positionCount = positions.Length; lineRenderer.SetPositions(positions); GradientColorKey[] colorKeys = new GradientColorKey[3]; colorKeys[0] = new GradientColorKey(Color.blue, 0f); //At 0% set to red colorKeys[1] = new GradientColorKey(Color.green, .5f); colorKeys[2] = new GradientColorKey(Color.yellow, 1f); GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2]; alphaKeys[0] = new GradientAlphaKey(1f, 0f); alphaKeys[1] = new GradientAlphaKey(1f, 1f); Gradient gradient = new Gradient(); gradient.SetKeys(colorKeys, alphaKeys); lineRenderer.colorGradient = gradient; } else if (Concentaration_Bar.Bar_Range >= 0.6f && Concentaration_Bar.Bar_Range < 0.7f) { //Vector3 MidVec = new Vector3(0, 0.3f, 0); Vector3 MidforVec = UpVector / 6f; Vector3 MidVector = MidforVec + currentPosition; //Vector3 QuVec = new Vector3(0, 0.6f, 0); Vector3 QuforVec = UpVector / 3f; Vector3 QuVector = QuforVec + currentPosition; UpVector *= ((((Concentaration_Bar.Bar_Range * 10) % 6) % 10) / 3f); Vector3[] positions = new Vector3[4]; positions[0] = currentPosition; positions[1] = MidVector; positions[2] = QuVector; positions[3] = UpVector + QuVector; lineRenderer.positionCount = positions.Length; lineRenderer.SetPositions(positions); GradientColorKey[] colorKeys = new GradientColorKey[4]; colorKeys[0] = new GradientColorKey(Color.blue, 0f); //At 0% set to red colorKeys[1] = new GradientColorKey(Color.green, .3f); colorKeys[2] = new GradientColorKey(Color.yellow, .6f); colorKeys[3] = new GradientColorKey(Color.red, 1f); GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2]; alphaKeys[0] = new GradientAlphaKey(1f, 0f); alphaKeys[1] = new GradientAlphaKey(1f, 1f); Gradient gradient = new Gradient(); gradient.SetKeys(colorKeys, alphaKeys); lineRenderer.colorGradient = gradient; } else { } //lineRenderer.SetPosition(0, currentPosition); //lineRenderer.SetPosition(1, forwardVector + currentPosition); //Debug.Log(string.Format(" LaserGunRange: ") + LaserGunRange); RaycastHit Shot; if (Physics.Raycast(currentPosition, UpVector, out Shot, LaserGunRange)) { TargetScore10 target1 = Shot.transform.GetComponent <TargetScore10>(); TargetScore20 target2 = Shot.transform.GetComponent <TargetScore20>(); TargetScore30 target3 = Shot.transform.GetComponent <TargetScore30>(); TargetScore40 target4 = Shot.transform.GetComponent <TargetScore40>(); TargetScore50 target5 = Shot.transform.GetComponent <TargetScore50>(); TargetScore60 target6 = Shot.transform.GetComponent <TargetScore60>(); TargetScore70 target7 = Shot.transform.GetComponent <TargetScore70>(); TargetScore80 target8 = Shot.transform.GetComponent <TargetScore80>(); TargetScore90 target9 = Shot.transform.GetComponent <TargetScore90>(); TargetScore100 target10 = Shot.transform.GetComponent <TargetScore100>(); Rigidbody hit = Shot.transform.GetComponent <Rigidbody>(); //Debug.Log(string.Format(" actTarget: ") + randTarget+" "+ randTarget1 + " "+ randTarget2); if (target1 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target1.transform.position, 5.0f, 3.0f); target1.Die(ActTarget.actTarget); } else if (target2 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target2.transform.position, 5.0f, 3.0f); target2.Die(ActTarget.actTarget); } else if (target3 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target3.transform.position, 5.0f, 3.0f); target3.Die(ActTarget.actTarget); } else if (target4 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target4.transform.position, 5.0f, 3.0f); target4.Die(ActTarget.actTarget); } else if (target5 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target5.transform.position, 5.0f, 3.0f); target5.Die(ActTarget.actTarget); } else if (target6 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target6.transform.position, 5.0f, 3.0f); target6.Die(ActTarget.actTarget); } else if (target7 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target7.transform.position, 5.0f, 3.0f); target7.Die(ActTarget.actTarget); } else if (target8 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target8.transform.position, 5.0f, 3.0f); target8.Die(ActTarget.actTarget); } else if (target9 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target9.transform.position, 5.0f, 3.0f); target9.Die(ActTarget.actTarget); } else if (target10 != null) { gunsound.Play(); hit.AddExplosionForce(-1000.0f, target10.transform.position, 5.0f, 3.0f); target10.Die(ActTarget.actTarget); } else { } } }
// Use this for initialization void Start() { //S'il y a une erreur ici s'assurer que le prefab "Balancing" est bien dans la scène balanceData = GameObject.Find("Balancing").GetComponent <Balancing>(); playerHP = balanceData.playerMaxHP; recoveryTime = balanceData.recoveryTime; flashingRate = balanceData.flashingRate; knockBackTime = balanceData.knockBackTime; knockBackLaser = balanceData.knockBackLaser; knockBackBlade1 = balanceData.knockBackBlade1; knockBackBlade2 = balanceData.knockBackBlade2; knockBackBlade3 = balanceData.knockBackBlade3; knockBackMeteor = balanceData.knockBackMeteor; laserDamage = balanceData.laserDamage; criticalSpeed = balanceData.criticalSpeed; lastAttackerDuration = balanceData.lastAttackerDuration; freezeFrameDuration = balanceData.freezeFrameDuration; thornsDamage = balanceData.thornsDamage; knockBackThorns = balanceData.knockBackThorns; playerMovement = GetComponent <PlayerMovement>(); trail = GetComponent <TrailRenderer>(); lifeParticlesManagerScript = lifeParticlesManager.GetComponent <LifeParticlesManager>(); sprite = GetComponent <SpriteRenderer>(); startMaterial = sprite.material; FbOnDeath = GameObject.Find("LevelScripts").GetComponent <FeedbacksOnDeath> (); woundedMaterial = Resources.Load <Material>("Material/SpriteBlink" + playerMovement.playerNumber); //Switch gérant la couleur de la trail et la couleur des particules switch (sprite.sprite.name) { case "0": colorTrail[0].color = new Color(.9215686f, 0.7294118f, 0.345098f); colorTrail[1].color = new Color(0.9647059f, 0.5882353f, 0.2235294f); deathParticle = Resources.Load <ParticleSystem>("Particles/Nuke/NukeOrange"); hitLittle = Resources.Load <ParticleSystem>("Particles/HitLittle/HitLittleOrange"); hitHard = Resources.Load <ParticleSystem>("Particles/HitHard/HitHardOrange"); hitLaser = Resources.Load <ParticleSystem>("Particles/LaserHitPlayer/LaserHitPlayerOrange"); break; case "1": colorTrail[0].color = new Color(0.9960784f, 0.5686275f, 0.7568628f); colorTrail[1].color = new Color(0.8705882f, 0.282353f, 0.5137255f); deathParticle = Resources.Load <ParticleSystem>("Particles/Nuke/NukePink"); hitLittle = Resources.Load <ParticleSystem>("Particles/HitLittle/HitLittlePink"); hitHard = Resources.Load <ParticleSystem>("Particles/HitHard/HitHardPink"); hitLaser = Resources.Load <ParticleSystem>("Particles/LaserHitPlayer/LaserHitPlayerPink"); break; case "2": colorTrail[0].color = new Color(0.2313726f, 0.572549f, 0.9882353f); colorTrail[1].color = new Color(0.04313726f, 0.4117647f, 0.5882353f); deathParticle = Resources.Load <ParticleSystem>("Particles/Nuke/NukeBlue"); hitLittle = Resources.Load <ParticleSystem>("Particles/HitLittle/HitLittleBlue"); hitHard = Resources.Load <ParticleSystem>("Particles/HitHard/HitHardBlue"); hitLaser = Resources.Load <ParticleSystem>("Particles/LaserHitPlayer/LaserHitPlayerBlue"); break; case "3": colorTrail[0].color = new Color(0.4627451f, 0.7372549f, 0.2862745f); colorTrail[1].color = new Color(0.3294118f, 0.6470588f, 0.1960784f); deathParticle = Resources.Load <ParticleSystem>("Particles/Nuke/NukeGreen"); hitLittle = Resources.Load <ParticleSystem>("Particles/HitLittle/HitLittleGreen"); hitHard = Resources.Load <ParticleSystem>("Particles/HitHard/HitHardGreen"); hitLaser = Resources.Load <ParticleSystem>("Particles/LaserHitPlayer/LaserHitPlayerGreen"); break; case "4": colorTrail[0].color = new Color(0.9098039f, 0.1176471f, 0.3176471f); colorTrail[1].color = new Color(0.509804f, 0.02352941f, 0.2784314f); deathParticle = Resources.Load <ParticleSystem>("Particles/Nuke/NukeYellow"); hitLittle = Resources.Load <ParticleSystem>("Particles/HitLittle/HitLittleYellow"); hitHard = Resources.Load <ParticleSystem>("Particles/HitHard/HitHardYellow"); hitLaser = Resources.Load <ParticleSystem>("Particles/LaserHitPlayer/LaserHitPlayerYellow"); break; default: print("Default case switch start PlayerLifeManager.cs"); break; } alphaTrail[0].alpha = 1; alphaTrail[0].time = 0; alphaTrail[1].alpha = 0; alphaTrail[1].time = 1; colorTrail[0].time = 0; colorTrail[1].time = 1; trailGradient.SetKeys(colorTrail, alphaTrail); trail.colorGradient = trailGradient; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2]; alphaKeys[0].alpha = .157f; alphaKeys[0].time = 0; alphaKeys[1] = trailGradient.alphaKeys[1]; woundedGradient.SetKeys(trailGradient.colorKeys, alphaKeys); }
void SelectVector(VectorController v) { Debug.Log(v.LineRenderer.GetPosition(1)); #region GetCurrentGradient previosColorKey = new GradientColorKey[2]; previosColorKey[0].color = v.LineRenderer.startColor; previosColorKey[0].time = 0.0f; previosColorKey[1].color = v.LineRenderer.endColor; previosColorKey[1].time = 1.0f; //alpha gradient previosAlphaKey = new GradientAlphaKey[2]; previosAlphaKey[0].alpha = 1.0f; previosAlphaKey[0].time = 0.0f; previosAlphaKey[1].alpha = 1.0f; previosAlphaKey[1].time = 1.0f; #endregion #region NewGradient GradientColorKey[] colorKey; GradientAlphaKey[] alphaKey; colorKey = new GradientColorKey[2]; colorKey[0].color = Color.black; colorKey[0].time = 0.0f; colorKey[1].color = Color.black; colorKey[1].time = 1.0f; //gradient alpha alphaKey = new GradientAlphaKey[2]; alphaKey[0].alpha = 1.0f; alphaKey[0].time = 0.0f; alphaKey[1].alpha = 1.0f; alphaKey[1].time = 1.0f; Gradient _gradient = new Gradient(); _gradient.SetKeys(colorKey, alphaKey); v.LineRenderer.colorGradient = _gradient; #endregion #region SetGradient if (changeCount > 0) { Gradient _mGradient = new Gradient(); _mGradient.SetKeys(previosColorKey, previosAlphaKey); _previosVectorController.LineRenderer.colorGradient = _mGradient; } #endregion changeCount += 1; _previosVectorController = v; }
public static Gradient Read(string fileName, char delimiter = delimiter) { using (var reader = new StreamReader(fileName)) { List <float> rList = new List <float>(); List <float> gList = new List <float>(); List <float> bList = new List <float>(); List <float> aList = new List <float>(); ReadFile(); // Simplify color and alpha list however possible SimplifyGradient(); return(BuildGradient(BuildCols(), aList)); void ReadFile() { string line; while ((line = reader.ReadLine()) != null) { string[] split = line.Split(delimiter); if (split.Length >= 3) { float r, g, b, a; bool foundR = float.TryParse(split[0], out r); bool foundG = float.TryParse(split[1], out g); bool foundB = float.TryParse(split[2], out b); if (foundR && foundG && foundB) { rList.Add(r); gList.Add(g); bList.Add(b); } // See if there's an a value given if (split.Length == 4) { bool foundA = float.TryParse(split[3], out a); if (foundA && foundR && foundG && foundB) { aList.Add(a); } } } } if (rList.Count != gList.Count || rList.Count != bList.Count) { string e = "r, b, and g counts do not match. Found " + rList.Count + " r values, " + gList.Count + " g values, " + bList.Count + " b values."; throw new Exception(e); } if (rList.Count < 2) { Debug.LogWarning("Not enough color keys given, reverting to default colors"); rList = new List <float>(2); gList = new List <float>(2); bList = new List <float>(2); float[] def = new float[] { 1f, 1f }; rList.AddRange(def); gList.AddRange(def); bList.AddRange(def); } if (aList.Count < 2) { aList = new List <float>(2); aList.AddRange(new float[] { 1f, 1f }); } } void SimplifyGradient() { int maxSimplifications = 5; if (rList.Count > 8) { string warn = "Gradients can only contain 8 keys, " + fileName + " contains " + rList.Count + "."; while (rList.Count > 8) { if (maxSimplifications > 0) { SimplifyCols(); maxSimplifications--; warn += "\nSimplified down to " + rList.Count + " keys.\n"; } else { string s = "Gradient " + fileName; for (int k = 0; k < rList.Count; k++) { s += "\n" + k + ": (" + rList[k] + ", " + gList[k] + ", " + bList[k] + ")"; } Debug.Log(s); warn += "\nCould not simplify " + fileName + " to 8 color keys, removing random elements."; while (rList.Count > 8) { int randInd = UnityEngine.Random.Range(1, rList.Count - 1); rList.RemoveAt(randInd); gList.RemoveAt(randInd); bList.RemoveAt(randInd); } } } Debug.LogWarning(warn); } else if (rList.Count < 2) { Debug.LogWarning("Not enough color keys given, reverting to default colors"); rList = new List <float>(2); gList = new List <float>(2); bList = new List <float>(2); float[] def = new float[] { 1f, 1f }; rList.AddRange(def); gList.AddRange(def); bList.AddRange(def); } // Simplify alpha array, if necessary if (aList.Count > 8) { string warn = aList.Count + " alpha keys found. Removing random keys until only 8 are given."; while (aList.Count > 8) { int randInd = UnityEngine.Random.Range(1, aList.Count - 1); aList.RemoveAt(randInd); } } else if (aList.Count < 2) { aList = new List <float>(2); aList.AddRange(new float[] { 1f, 1f }); } void SimplifyCols() { List <int> rExt = rList.GetExtrema(true, true); // Ends are marked by rExt, so we don't need duplciate keys in g and b List <int> gExt = gList.GetExtrema(false, true); List <int> bExt = bList.GetExtrema(false, true); // Gather all extrema into one unique list List <int> allExtrema = new List <int>(rExt.Count + gExt.Count + bExt.Count); foreach (int ext in rExt) { allExtrema.Add(ext); } foreach (int ext in gExt) { // If this color is already marked as a key by red list, don't add the duplicate if (!allExtrema.Contains(ext)) { allExtrema.Add(ext); } } foreach (int ext in bExt) { // If this color is already marked as a key by red OR green list, don't add the duplicate if (!allExtrema.Contains(ext)) { allExtrema.Add(ext); } } allExtrema.Sort(); /// "Merge" the extrema lists s.t. each color list contains it's value at its extrema /// AND it's color value at other colors' extremas List <float> rTemp = new List <float>(allExtrema.Count); List <float> gTemp = new List <float>(allExtrema.Count); List <float> bTemp = new List <float>(allExtrema.Count); foreach (int ext in allExtrema) { rTemp.Add(rList[ext]); gTemp.Add(gList[ext]); bTemp.Add(bList[ext]); } rList = rTemp; gList = gTemp; bList = bTemp; } } Color[] BuildCols() { Color[] colors = new Color[rList.Count]; for (int i = 0; i < colors.Length; i++) { colors[i] = new Color(rList[i], gList[i], bList[i]); } return(colors); } Gradient BuildGradient(Color[] colors, List <float> alphas) { // Apply colors and alphas Gradient gradient = new Gradient(); gradient.SetKeys(BuildColorKeys(), BuildAlphaKeys()); return(gradient); GradientColorKey[] BuildColorKeys() { GradientColorKey[] colKeys = new GradientColorKey[colors.Length]; for (int i = 0; i < colors.Length; i++) { float time = (float)i / (colors.Length - 1); colKeys[i] = new GradientColorKey(colors[i], time); } return(colKeys); } GradientAlphaKey[] BuildAlphaKeys() { GradientAlphaKey[] alphaKeys = new GradientAlphaKey[alphas.Count]; for (int i = 0; i < alphaKeys.Length; i++) { float time = (float)i / (alphas.Count - 1); alphaKeys[i] = new GradientAlphaKey(alphas[i], time); } return(alphaKeys); } } } }
private void UpdateColor() { // Update gradient info Gradient gradient = new Gradient(); GradientColorKey[] colorKey = new GradientColorKey[2]; colorKey[0].color = _colorHead; colorKey[0].time = 0.0f; colorKey[1].color = _colorTail; colorKey[1].time = 1.0f; GradientAlphaKey[] alphaKey = new GradientAlphaKey[2]; alphaKey[0].alpha = _colorHead.a; alphaKey[0].time = 0.0f; alphaKey[1].alpha = _colorTail.a; alphaKey[1].time = 1.0f; gradient.SetKeys(colorKey, alphaKey); // Modify colors TMP_TextInfo tInfo = _text.textInfo; Dictionary <int, Color[]> newColors = new Dictionary <int, Color[]>(); // key = materialReferenceIndex int characterCount = tInfo.characterCount; for (int i = 0; i < characterCount; i++) { TMP_CharacterInfo cInfo = tInfo.characterInfo[i]; // Clone original color data int meshInfoIndex = cInfo.materialReferenceIndex; if (!newColors.ContainsKey(meshInfoIndex)) { Color32[] oriColors32 = tInfo.meshInfo[cInfo.materialReferenceIndex].colors32.Clone() as Color32[]; Color[] oriColors = new Color[oriColors32.Length]; for (int j = 0; j < oriColors32.Length; j++) { oriColors[j] = oriColors32[j]; } newColors.Add(meshInfoIndex, oriColors); } // Skip handling if not visible if (!cInfo.isVisible) { continue; } // Calculation of color value float time = 0 + (1.0f / characterCount) * i; if (characterCount > 1) { time = 0 + (1.0f / (characterCount - 1)) * i; } Color c = gradient.Evaluate(time); // Over write color value Color[] colors = newColors[meshInfoIndex]; for (int j = 0; j < 4; j++) { colors[cInfo.vertexIndex + j] = c; } } // Update mesh for (int i = 0; i < tInfo.meshInfo.Length; i++) { if (!newColors.ContainsKey(i)) { continue; } TMP_MeshInfo mInfo = tInfo.meshInfo[i]; mInfo.mesh.colors = newColors[i]; _text.UpdateGeometry(mInfo.mesh, i); } }
public AlphaStep(GradientAlphaKey key) { step = key.time; alpha = key.alpha; }
private float _tmpAngularVelocity; //random angular velocity from -angularVelocity to +angularVelocity, if randomRotation is true; override public void Explode() { if (on) { if (isFlipbook) { _psTextureSheet.enabled = true; _psTextureSheet.numTilesX = (int)gridSize.x; _psTextureSheet.numTilesY = (int)gridSize.y; } if (useWorldSpace) { _psMain.simulationSpace = ParticleSystemSimulationSpace.World; } else { _psMain.simulationSpace = ParticleSystemSimulationSpace.Local; } _scaledDuration = timeScale * duration; _scaledDurationVariation = timeScale * durationVariation; _scaledStartRadius = size * startRadius; if (!_delayedExplosionStarted) { _explodeDelay = explodeDelayMin + (Random.value * (explodeDelayMax - explodeDelayMin)); } if (_explodeDelay <= 0) { if (useExplicitColorAnimation) { float timeDivision = 1.0f / colorAnimation.Length; _psCoLGradientColor = new GradientColorKey[colorAnimation.Length]; _psCoLGradientAlpha = new GradientAlphaKey[colorAnimation.Length]; for (int i = 0; i < colorAnimation.Length; i++) { _psCoLGradientColor[i] = new GradientColorKey(colorAnimation[i], (timeDivision * i) + timeDivision); _psCoLGradientAlpha[i] = new GradientAlphaKey(colorAnimation[i].a, (timeDivision * i) + timeDivision); } _psCoLGradient.SetKeys(_psCoLGradientColor, _psCoLGradientAlpha); _psColorOverLifetime.color = _psCoLGradient; } else //auto fade { float timeDivision = 1 / colorAnimation.Length; _psCoLGradientColor = new GradientColorKey[colorAnimation.Length]; _psCoLGradientAlpha = new GradientAlphaKey[colorAnimation.Length]; for (int i = 0; i < colorAnimation.Length; i++) { _psCoLGradientColor[i] = new GradientColorKey(color, timeDivision * i); } _psCoLGradientAlpha = new GradientAlphaKey[] { new GradientAlphaKey(color.a * .7f, timeDivision * 0), new GradientAlphaKey(color.a * 1f, timeDivision * 1), new GradientAlphaKey(color.a * .5f, timeDivision * 2), new GradientAlphaKey(color.a * .3f, timeDivision * 3), new GradientAlphaKey(color.a * 0f, timeDivision * 4), }; _psCoLGradient.SetKeys(_psCoLGradientColor, _psCoLGradientAlpha); _psColorOverLifetime.color = _psCoLGradient; } _tmpCount = count * detail; if (_tmpCount < 1) { _tmpCount = 1; } if (useWorldSpace) { _thisPos = this.gameObject.transform.position; } else { _thisPos = new Vector3(0, 0, 0); } for (int i = 1; i <= _tmpCount; i++) { _tmpPos = Vector3.Scale(Random.insideUnitSphere, new Vector3(_scaledStartRadius, _scaledStartRadius, _scaledStartRadius)); _tmpPos = _thisPos + _tmpPos; _tmpDir = Vector3.Scale(Random.insideUnitSphere, new Vector3(velocity.x, velocity.y, velocity.z)); _tmpDir.y = (_tmpDir.y + (2 * (Mathf.Abs(_tmpDir.y) * upwardsBias))); if (randomRotation == true) { _randomizedRotation = Random.Range(-1f, 1f); _tmpAngularVelocity = Random.Range(-1f, 1f) * angularVelocity; } else { _randomizedRotation = 0f; _tmpAngularVelocity = angularVelocity; } _tmpDir = Vector3.Scale(_tmpDir, new Vector3(size, size, size)); _tmpParticleSize = size * (particleSize + (Random.value * sizeVariation)); _tmpDuration = _scaledDuration + (Random.value * _scaledDurationVariation); _psEmitParams.position = _tmpPos; _psEmitParams.velocity = _tmpDir; _psEmitParams.startSize = _tmpParticleSize; _psEmitParams.startLifetime = _tmpDuration; _psEmitParams.startColor = color; _psEmitParams.rotation = _randomizedRotation; _psEmitParams.angularVelocity = _tmpAngularVelocity; _particleSystem.Emit(_psEmitParams, 1); } _psMain.startLifetime = _tmpDuration; _psRenderer.material = material; _emitTime = Time.time; _delayedExplosionStarted = false; _explodeDelay = 0f; //End, so emit _psEmission.enabled = true; _psColorOverLifetime.enabled = true; _psSizeOverLifetime.enabled = true; _psVelocityOverLifetime.enabled = true; _psEmission.enabled = false; } else { //tell update to start reducing the start delay and call explode again when it's zero _delayedExplosionStarted = true; } } }
public void LoadModel() { #region Gradient Creation Gradient grad; GradientColorKey[] gck; GradientAlphaKey[] gak; grad = new Gradient(); gck = new GradientColorKey[5]; gck[0].color = Color.red; gck[0].time = 1.0F; gck[1].color = Color.yellow; gck[1].time = 0.75F; gck[2].color = Color.green; gck[2].time = 0.5F; gck[3].color = Color.cyan; gck[3].time = 0.25F; gck[4].color = Color.blue; gck[4].time = 0.0F; 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); #endregion #region Stress import string[] StressDataLines = ElemStress.text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); float[] StressAll = new float[StressDataLines.Length - 1]; float[] StressFront = new float[StressDataLines.Length / 2]; float[] StressBack = new float[StressDataLines.Length / 2]; int i1 = 0; int i2 = 0; for (int i = 1; i < (StressDataLines.Length); i++) { string[] StressData = StressDataLines[i].Split(","[0]); string[] StressData2 = StressData[11].Split(")"[0]); string StressSide = StressData2[0]; string FrontStress = " (fraction = 1.0"; string BackStress = " (fraction = -1.0"; StressAll[i - 1] = float.Parse(StressData[12]); if (StressSide.Equals(FrontStress)) { StressFront[i1] = float.Parse(StressData[12]); i1 = i1 + 1; } else if (StressSide.Equals(BackStress)) { StressBack[i2] = float.Parse(StressData[12]); i2 = i2 + 1; } else { Debug.Log("Failure in comparison"); } } float maxStress = StressAll.Max(); float minStress = StressAll.Min(); float range = maxStress - minStress; float[] GradStressFront = new float[StressFront.Length]; float[] GradStressBack = new float[StressBack.Length]; for (int i = 0; i < StressFront.Length; i++) { GradStressFront[i] = (StressFront[i] - minStress) / range; GradStressBack[i] = (StressBack[i] - minStress) / range; } #endregion #region Node Pos Import string[] NodeDataLines = SpatialDisplacement.text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); Vector3[] Locations = new Vector3[NodeDataLines.Length]; Vector3[] DeltaLocations = new Vector3[NodeDataLines.Length]; Vector3[] NewLocations = new Vector3[NodeDataLines.Length]; for (int i = 1; i < NodeDataLines.Length; i++) { string[] coord = NodeDataLines[i].Split(","[0]); float coordx = float.Parse(coord[5]); float coordy = float.Parse(coord[6]); float coordz = float.Parse(coord[7]); float deltax = float.Parse(coord[12]); float deltay = float.Parse(coord[13]); float deltaz = float.Parse(coord[14]); float newx = coordx + deltax; float newy = coordy + deltay; float newz = coordz + deltaz; Locations[i] = new Vector3(coordx, coordy, coordz); DeltaLocations[i] = new Vector3(deltax, deltay, deltaz); NewLocations[i] = new Vector3(newx, newy, newz); } #endregion GameObject model1undeformed = new GameObject("Model 1 Undeformed"); model1undeformed.transform.position = new Vector3(0, 0, 0); model1undeformed.transform.parent = GameObject.Find("Model Space").transform; GameObject model1deformed = new GameObject("Model 1 Deformed"); model1deformed.transform.position = new Vector3(0, 0, 0); model1deformed.transform.parent = GameObject.Find("Model Space").transform; model1deformed.AddComponent <MeshCombine>(); model1undeformed.SetActive(false); #region Element Mesh Creation string[] ElemDataLines = ElemConnectivity.text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < ElemDataLines.Length; i++) { string[] element = ElemDataLines[i].Split(","[0]); Vector3[] VerticesUndeformed = { Locations[int.Parse(element[3])], Locations[int.Parse(element[4])], Locations[int.Parse(element[5])], Locations[int.Parse(element[6])] }; Vector3[] VerticesDeformed = { NewLocations[int.Parse(element[3])], NewLocations[int.Parse(element[4])], NewLocations[int.Parse(element[5])], NewLocations[int.Parse(element[6])] }; int[] TrianglesFront = { 0, 1, 2, 0, 2, 3 }; int[] TrianglesBack = { 0, 2, 1, 0, 3, 2 }; #region Deformed Mesh GameObject elemfrontdeformed = new GameObject("Element " + i + " Front" + " Deformed"); elemfrontdeformed.AddComponent <MeshRenderer>(); Mesh meshfrontdeformed = elemfrontdeformed.AddComponent <MeshFilter>().mesh; meshfrontdeformed.vertices = VerticesDeformed; meshfrontdeformed.triangles = TrianglesFront; elemfrontdeformed.transform.parent = model1deformed.transform; //elemfrontdeformed.GetComponent<MeshRenderer>().material.color = grad.Evaluate(GradStressFront[i - 1]); #region Material Assignment if (GradStressFront[i - 1] < 0.0769 && GradStressFront[i - 1] >= 0) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C13; } else if (GradStressFront[i - 1] < 0.1538 && GradStressFront[i - 1] >= 0.0769) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C12; } else if (GradStressFront[i - 1] < 0.2307 && GradStressFront[i - 1] >= 0.1538) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C11; } else if (GradStressFront[i - 1] < 0.3077 && GradStressFront[i - 1] >= 0.2307) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C10; } else if (GradStressFront[i - 1] < 0.3846 && GradStressFront[i - 1] >= 0.3077) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C9; } else if (GradStressFront[i - 1] < 0.4615 && GradStressFront[i - 1] >= 0.3846) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C8; } else if (GradStressFront[i - 1] < 0.5385 && GradStressFront[i - 1] >= 0.4615) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C7; } else if (GradStressFront[i - 1] < 0.6154 && GradStressFront[i - 1] >= 0.5385) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C6; } else if (GradStressFront[i - 1] < 0.6923 && GradStressFront[i - 1] >= 0.6154) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C5; } else if (GradStressFront[i - 1] < 0.7692 && GradStressFront[i - 1] >= 0.6923) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C4; } else if (GradStressFront[i - 1] < 0.8462 && GradStressFront[i - 1] >= 0.7692) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C3; } else if (GradStressFront[i - 1] < 0.9231 && GradStressFront[i - 1] >= 0.8462) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C2; } else if (GradStressFront[i - 1] <= 1 && GradStressFront[i - 1] >= 0.9231) { elemfrontdeformed.GetComponent <MeshRenderer>().material = C1; } #endregion GameObject elembackdeformed = new GameObject("Element " + i + " Back" + " Deformed"); elembackdeformed.AddComponent <MeshRenderer>(); Mesh meshbackdeformed = elembackdeformed.AddComponent <MeshFilter>().mesh; meshbackdeformed.vertices = VerticesDeformed; meshbackdeformed.triangles = TrianglesBack; elembackdeformed.transform.parent = model1deformed.transform; //elembackdeformed.GetComponent<MeshRenderer>().material.color = grad.Evaluate(GradStressBack[i - 1]); #region Material Assignment if (GradStressBack[i - 1] < 0.0769 && GradStressBack[i - 1] >= 0) { elembackdeformed.GetComponent <MeshRenderer>().material = C13; } else if (GradStressBack[i - 1] < 0.1538 && GradStressBack[i - 1] >= 0.0769) { elembackdeformed.GetComponent <MeshRenderer>().material = C12; } else if (GradStressBack[i - 1] < 0.2307 && GradStressBack[i - 1] >= 0.1538) { elembackdeformed.GetComponent <MeshRenderer>().material = C11; } else if (GradStressBack[i - 1] < 0.3077 && GradStressBack[i - 1] >= 0.2307) { elembackdeformed.GetComponent <MeshRenderer>().material = C10; } else if (GradStressBack[i - 1] < 0.3846 && GradStressBack[i - 1] >= 0.3077) { elembackdeformed.GetComponent <MeshRenderer>().material = C9; } else if (GradStressBack[i - 1] < 0.4615 && GradStressBack[i - 1] >= 0.3846) { elembackdeformed.GetComponent <MeshRenderer>().material = C8; } else if (GradStressBack[i - 1] < 0.5385 && GradStressBack[i - 1] >= 0.4615) { elembackdeformed.GetComponent <MeshRenderer>().material = C7; } else if (GradStressBack[i - 1] < 0.6154 && GradStressBack[i - 1] >= 0.5385) { elembackdeformed.GetComponent <MeshRenderer>().material = C6; } else if (GradStressBack[i - 1] < 0.6923 && GradStressBack[i - 1] >= 0.6154) { elembackdeformed.GetComponent <MeshRenderer>().material = C5; } else if (GradStressBack[i - 1] < 0.7692 && GradStressBack[i - 1] >= 0.6923) { elembackdeformed.GetComponent <MeshRenderer>().material = C4; } else if (GradStressBack[i - 1] < 0.8462 && GradStressBack[i - 1] >= 0.7692) { elembackdeformed.GetComponent <MeshRenderer>().material = C3; } else if (GradStressBack[i - 1] < 0.9231 && GradStressBack[i - 1] >= 0.8462) { elembackdeformed.GetComponent <MeshRenderer>().material = C2; } else if (GradStressBack[i - 1] <= 1 && GradStressBack[i - 1] >= 0.9231) { elembackdeformed.GetComponent <MeshRenderer>().material = C1; } #endregion #endregion } #endregion GameObject ModelSpace = GameObject.Find("Model Space"); model1deformed.SendMessage("CombineMeshNew"); }
// Use this for initialization public void LoadModel() { #region Gradient Creation Gradient grad; GradientColorKey[] gck; GradientAlphaKey[] gak; grad = new Gradient(); gck = new GradientColorKey[5]; gck[0].color = Color.red; gck[0].time = 1.0F; gck[1].color = Color.yellow; gck[1].time = 0.75F; gck[2].color = Color.green; gck[2].time = 0.5F; gck[3].color = Color.cyan; gck[3].time = 0.25F; gck[4].color = Color.blue; gck[4].time = 0.0F; 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); #endregion #region Node and Stress import string[] NodeDataLines = NodeData.text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); Vector3[] Locations = new Vector3[NodeDataLines.Length]; float[] stress = new float[NodeDataLines.Length]; for (int i = 1; i < NodeDataLines.Length; i++) { string[] coord = NodeDataLines[i].Split(","[0]); float coordx = float.Parse(coord[3]); float coordy = float.Parse(coord[2]); float coordz = float.Parse(coord[1]); stress[i] = float.Parse(coord[4]); Locations[i] = new Vector3(coordx, coordy, coordz); } float maxStress = stress.Max(); float minStress = stress.Min(); float range = maxStress - minStress; float[] gradstress = new float[stress.Length]; for (int i = 1; i < stress.Length; i++) { gradstress[i] = (stress[i] - minStress) / range; } #endregion GameObject scaleconfig = GameObject.Find("ColourScale"); scaleconfig.GetComponent <ScaleConfig>().SetScaleValues(maxStress, minStress); GameObject model1 = new GameObject("model1"); model1.transform.position = new Vector3(0, 0, 0); model1.transform.parent = GameObject.Find("ModelSpace").transform; model1.tag = "FEAModels"; string[] ElemDataLines = ElemData.text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // change i< once testing done for (int i = 1; i < ElemDataLines.Length; i++) { string[] element = ElemDataLines[i].Split(","[0]); Vector3[] vertices = { Locations[int.Parse(element[8])], Locations[int.Parse(element[16])], Locations[int.Parse(element[9])], Locations[int.Parse(element[15])], Locations[int.Parse(element[17])], Locations[int.Parse(element[8])], Locations[int.Parse(element[15])], Locations[int.Parse(element[7])], Locations[int.Parse(element[14])], Locations[int.Parse(element[6])], Locations[int.Parse(element[17])], Locations[int.Parse(element[9])], Locations[int.Parse(element[20])], Locations[int.Parse(element[19])], Locations[int.Parse(element[18])], Locations[int.Parse(element[21])], Locations[int.Parse(element[4])], Locations[int.Parse(element[11])], Locations[int.Parse(element[3])], Locations[int.Parse(element[10])], Locations[int.Parse(element[2])], Locations[int.Parse(element[13])], Locations[int.Parse(element[5])], Locations[int.Parse(element[11])], Locations[int.Parse(element[13])], Locations[int.Parse(element[4])], Locations[int.Parse(element[12])], Locations[int.Parse(element[5])], Locations[int.Parse(element[20])], Locations[int.Parse(element[21])], Locations[int.Parse(element[8])], Locations[int.Parse(element[16])], Locations[int.Parse(element[9])] }; int[] triangles = { 0, 3, 1, 2, 1, 4, 3, 7, 8, 4, 8, 9, 4, 1, 3, 4, 3, 8, 5, 12, 6, 6, 13, 7, 13, 17, 18, 12, 16, 17, 12, 17, 6, 17, 13, 6, 7, 13, 8, 8, 14, 9, 13, 18, 19, 19, 20, 14, 13, 19, 14, 13, 14, 8, 9, 14, 10, 10, 15, 11, 20, 21, 14, 21, 22, 15, 21, 15, 10, 21, 10, 14, 18, 23, 19, 19, 24, 20, 23, 25, 26, 24, 26, 27, 19, 23, 24, 23, 26, 24, 25, 28, 26, 26, 29, 27, 28, 30, 31, 31, 32, 29, 28, 29, 26, 28, 31, 29, }; float[] uvus = { 0, 0.124023438f, 0.248046875f, 0.372070313f, 0.49609375f, 0.620117188f, 0.744140625f, 0.868164063f, 0.9921875f }; float[] uvvs = { 0, 0.166015625f, 0.33203125f, 0.498046875f, 0.6640625f, 0.830078125f, 0.99609375f }; Vector2[] uvs = { new Vector2(uvus[0], uvvs[2]), new Vector2(uvus[0], uvvs[3]), new Vector2(uvus[0], uvvs[4]), new Vector2(uvus[1], uvvs[2]), new Vector2(uvus[1], uvvs[4]), new Vector2(uvus[2], uvvs[0]), new Vector2(uvus[2], uvvs[1]), new Vector2(uvus[2], uvvs[2]), new Vector2(uvus[2], uvvs[3]), new Vector2(uvus[2], uvvs[4]), new Vector2(uvus[2], uvvs[5]), new Vector2(uvus[2], uvvs[6]), new Vector2(uvus[3], uvvs[0]), new Vector2(uvus[3], uvvs[2]), new Vector2(uvus[3], uvvs[4]), new Vector2(uvus[3], uvvs[6]), new Vector2(uvus[4], uvvs[0]), new Vector2(uvus[4], uvvs[1]), new Vector2(uvus[4], uvvs[2]), new Vector2(uvus[4], uvvs[3]), new Vector2(uvus[4], uvvs[4]), new Vector2(uvus[4], uvvs[5]), new Vector2(uvus[4], uvvs[6]), new Vector2(uvus[5], uvvs[2]), new Vector2(uvus[5], uvvs[4]), new Vector2(uvus[6], uvvs[2]), new Vector2(uvus[6], uvvs[3]), new Vector2(uvus[6], uvvs[4]), new Vector2(uvus[7], uvvs[2]), new Vector2(uvus[7], uvvs[4]), new Vector2(uvus[8], uvvs[2]), new Vector2(uvus[8], uvvs[3]), new Vector2(uvus[8], uvvs[4]) }; #region Texture Creation var texture1 = new Texture2D(512, 256, TextureFormat.ARGB32, false); int side1y1 = 85; int side1y2 = 169; int side1ymid = 127; int side1x1 = 0; int side1x2 = 126; int side1xmid = 63; for (int y = 85; y < 170; y++) { for (int x = 0; x < 127; x++) { float d0 = Mathf.Sqrt(Mathf.Pow((x - side1x1), 2f) + Mathf.Pow((y - side1y1), 2f)); float d1 = Mathf.Sqrt(Mathf.Pow((x - side1x1), 2f) + Mathf.Pow((y - side1ymid), 2f)); float d2 = Mathf.Sqrt(Mathf.Pow((x - side1x1), 2f) + Mathf.Pow((y - side1y2), 2f)); float d3 = Mathf.Sqrt(Mathf.Pow((x - side1xmid), 2f) + Mathf.Pow((y - side1y1), 2f)); float d4 = Mathf.Sqrt(Mathf.Pow((x - side1xmid), 2f) + Mathf.Pow((y - side1y2), 2f)); float d5 = Mathf.Sqrt(Mathf.Pow((x - side1x2), 2f) + Mathf.Pow((y - side1y1), 2f)); float d6 = Mathf.Sqrt(Mathf.Pow((x - side1x2), 2f) + Mathf.Pow((y - side1ymid), 2f)); float d7 = Mathf.Sqrt(Mathf.Pow((x - side1x2), 2f) + Mathf.Pow((y - side1y2), 2f)); float z0 = gradstress[int.Parse(element[8])]; float z1 = gradstress[int.Parse(element[16])]; float z2 = gradstress[int.Parse(element[9])]; float z3 = gradstress[int.Parse(element[15])]; float z4 = gradstress[int.Parse(element[17])]; float z5 = gradstress[int.Parse(element[7])]; float z6 = gradstress[int.Parse(element[14])]; float z7 = gradstress[int.Parse(element[6])]; float zidi = (z0 / d0) + (z1 / d1) + (z2 / d2) + (z3 / d3) + (z4 / d4) + (z5 / d5) + (z6 / d6) + (z7 / d7); float inversedi = (1 / d0) + (1 / d1) + (1 / d2) + (1 / d3) + (1 / d4) + (1 / d5) + (1 / d6) + (1 / d7); float zxy = (zidi / inversedi); texture1.SetPixel(x, y, grad.Evaluate(zxy)); } } texture1.SetPixel(side1x1, side1y1, grad.Evaluate(gradstress[int.Parse(element[8])])); texture1.SetPixel(side1x1, side1ymid, grad.Evaluate(gradstress[int.Parse(element[16])])); texture1.SetPixel(side1x1, side1y2, grad.Evaluate(gradstress[int.Parse(element[9])])); texture1.SetPixel(side1xmid, side1y1, grad.Evaluate(gradstress[int.Parse(element[15])])); texture1.SetPixel(side1xmid, side1y2, grad.Evaluate(gradstress[int.Parse(element[17])])); texture1.SetPixel(side1x2, side1y1, grad.Evaluate(gradstress[int.Parse(element[7])])); texture1.SetPixel(side1x2, side1ymid, grad.Evaluate(gradstress[int.Parse(element[14])])); texture1.SetPixel(side1x2, side1y2, grad.Evaluate(gradstress[int.Parse(element[6])])); int side2y1 = 0; int side2y2 = 84; int side2ymid = 42; int side2x1 = 127; int side2x2 = 253; int side2xmid = 190; for (int y = 0; y < 85; y++) { for (int x = 127; x < 254; x++) { float d0 = Mathf.Sqrt(Mathf.Pow((x - side2x1), 2f) + Mathf.Pow((y - side2y1), 2f)); float d1 = Mathf.Sqrt(Mathf.Pow((x - side2x1), 2f) + Mathf.Pow((y - side2ymid), 2f)); float d2 = Mathf.Sqrt(Mathf.Pow((x - side2x1), 2f) + Mathf.Pow((y - side2y2), 2f)); float d3 = Mathf.Sqrt(Mathf.Pow((x - side2xmid), 2f) + Mathf.Pow((y - side2y1), 2f)); float d4 = Mathf.Sqrt(Mathf.Pow((x - side2xmid), 2f) + Mathf.Pow((y - side2y2), 2f)); float d5 = Mathf.Sqrt(Mathf.Pow((x - side2x2), 2f) + Mathf.Pow((y - side2y1), 2f)); float d6 = Mathf.Sqrt(Mathf.Pow((x - side2x2), 2f) + Mathf.Pow((y - side2ymid), 2f)); float d7 = Mathf.Sqrt(Mathf.Pow((x - side2x2), 2f) + Mathf.Pow((y - side2y2), 2f)); float z0 = gradstress[int.Parse(element[8])]; float z1 = gradstress[int.Parse(element[15])]; float z2 = gradstress[int.Parse(element[7])]; float z3 = gradstress[int.Parse(element[20])]; float z4 = gradstress[int.Parse(element[19])]; float z5 = gradstress[int.Parse(element[4])]; float z6 = gradstress[int.Parse(element[11])]; float z7 = gradstress[int.Parse(element[3])]; float zidi = (z0 / d0) + (z1 / d1) + (z2 / d2) + (z3 / d3) + (z4 / d4) + (z5 / d5) + (z6 / d6) + (z7 / d7); float inversedi = (1 / d0) + (1 / d1) + (1 / d2) + (1 / d3) + (1 / d4) + (1 / d5) + (1 / d6) + (1 / d7); float zxy = (zidi / inversedi); texture1.SetPixel(x, y, grad.Evaluate(zxy)); } } texture1.SetPixel(side2x1, side2y1, grad.Evaluate(gradstress[int.Parse(element[8])])); texture1.SetPixel(side2x1, side2ymid, grad.Evaluate(gradstress[int.Parse(element[15])])); texture1.SetPixel(side2x1, side2y2, grad.Evaluate(gradstress[int.Parse(element[7])])); texture1.SetPixel(side2xmid, side2y1, grad.Evaluate(gradstress[int.Parse(element[20])])); texture1.SetPixel(side2xmid, side2y2, grad.Evaluate(gradstress[int.Parse(element[19])])); texture1.SetPixel(side2x2, side2y1, grad.Evaluate(gradstress[int.Parse(element[4])])); texture1.SetPixel(side2x2, side2ymid, grad.Evaluate(gradstress[int.Parse(element[11])])); texture1.SetPixel(side2x2, side2y2, grad.Evaluate(gradstress[int.Parse(element[3])])); int side3y1 = 85; int side3y2 = 169; int side3ymid = 127; int side3x1 = 127; int side3x2 = 253; int side3xmid = 190; for (int y = 85; y < 170; y++) { for (int x = 127; x < 254; x++) { float d0 = Mathf.Sqrt(Mathf.Pow((x - side3x1), 2f) + Mathf.Pow((y - side3y1), 2f)); float d1 = Mathf.Sqrt(Mathf.Pow((x - side3x1), 2f) + Mathf.Pow((y - side3ymid), 2f)); float d2 = Mathf.Sqrt(Mathf.Pow((x - side3x1), 2f) + Mathf.Pow((y - side3y2), 2f)); float d3 = Mathf.Sqrt(Mathf.Pow((x - side3xmid), 2f) + Mathf.Pow((y - side3y1), 2f)); float d4 = Mathf.Sqrt(Mathf.Pow((x - side3xmid), 2f) + Mathf.Pow((y - side3y2), 2f)); float d5 = Mathf.Sqrt(Mathf.Pow((x - side3x2), 2f) + Mathf.Pow((y - side3y1), 2f)); float d6 = Mathf.Sqrt(Mathf.Pow((x - side3x2), 2f) + Mathf.Pow((y - side3ymid), 2f)); float d7 = Mathf.Sqrt(Mathf.Pow((x - side3x2), 2f) + Mathf.Pow((y - side3y2), 2f)); float z0 = gradstress[int.Parse(element[7])]; float z1 = gradstress[int.Parse(element[14])]; float z2 = gradstress[int.Parse(element[6])]; float z3 = gradstress[int.Parse(element[19])]; float z4 = gradstress[int.Parse(element[18])]; float z5 = gradstress[int.Parse(element[3])]; float z6 = gradstress[int.Parse(element[10])]; float z7 = gradstress[int.Parse(element[2])]; float zidi = (z0 / d0) + (z1 / d1) + (z2 / d2) + (z3 / d3) + (z4 / d4) + (z5 / d5) + (z6 / d6) + (z7 / d7); float inversedi = (1 / d0) + (1 / d1) + (1 / d2) + (1 / d3) + (1 / d4) + (1 / d5) + (1 / d6) + (1 / d7); float zxy = (zidi / inversedi); texture1.SetPixel(x, y, grad.Evaluate(zxy)); } } texture1.SetPixel(side3x1, side3y1, grad.Evaluate(gradstress[int.Parse(element[7])])); texture1.SetPixel(side3x1, side3ymid, grad.Evaluate(gradstress[int.Parse(element[14])])); texture1.SetPixel(side3x1, side3y2, grad.Evaluate(gradstress[int.Parse(element[6])])); texture1.SetPixel(side3xmid, side3y1, grad.Evaluate(gradstress[int.Parse(element[19])])); texture1.SetPixel(side3xmid, side3y2, grad.Evaluate(gradstress[int.Parse(element[18])])); texture1.SetPixel(side3x2, side3y1, grad.Evaluate(gradstress[int.Parse(element[3])])); texture1.SetPixel(side3x2, side3ymid, grad.Evaluate(gradstress[int.Parse(element[10])])); texture1.SetPixel(side3x2, side3y2, grad.Evaluate(gradstress[int.Parse(element[2])])); int side4y1 = 170; int side4y2 = 254; int side4ymid = 212; int side4x1 = 127; int side4x2 = 253; int side4xmid = 190; for (int y = 170; y < 255; y++) { for (int x = 127; x < 254; x++) { float d0 = Mathf.Sqrt(Mathf.Pow((x - side4x1), 2f) + Mathf.Pow((y - side4y1), 2f)); float d1 = Mathf.Sqrt(Mathf.Pow((x - side4x1), 2f) + Mathf.Pow((y - side4ymid), 2f)); float d2 = Mathf.Sqrt(Mathf.Pow((x - side4x1), 2f) + Mathf.Pow((y - side4y2), 2f)); float d3 = Mathf.Sqrt(Mathf.Pow((x - side4xmid), 2f) + Mathf.Pow((y - side4y1), 2f)); float d4 = Mathf.Sqrt(Mathf.Pow((x - side4xmid), 2f) + Mathf.Pow((y - side4y2), 2f)); float d5 = Mathf.Sqrt(Mathf.Pow((x - side4x2), 2f) + Mathf.Pow((y - side4y1), 2f)); float d6 = Mathf.Sqrt(Mathf.Pow((x - side4x2), 2f) + Mathf.Pow((y - side4ymid), 2f)); float d7 = Mathf.Sqrt(Mathf.Pow((x - side4x2), 2f) + Mathf.Pow((y - side4y2), 2f)); float z0 = gradstress[int.Parse(element[6])]; float z1 = gradstress[int.Parse(element[17])]; float z2 = gradstress[int.Parse(element[9])]; float z3 = gradstress[int.Parse(element[18])]; float z4 = gradstress[int.Parse(element[21])]; float z5 = gradstress[int.Parse(element[2])]; float z6 = gradstress[int.Parse(element[13])]; float z7 = gradstress[int.Parse(element[5])]; float zidi = (z0 / d0) + (z1 / d1) + (z2 / d2) + (z3 / d3) + (z4 / d4) + (z5 / d5) + (z6 / d6) + (z7 / d7); float inversedi = (1 / d0) + (1 / d1) + (1 / d2) + (1 / d3) + (1 / d4) + (1 / d5) + (1 / d6) + (1 / d7); float zxy = (zidi / inversedi); texture1.SetPixel(x, y, grad.Evaluate(zxy)); } } texture1.SetPixel(side4x1, side4y1, grad.Evaluate(gradstress[int.Parse(element[6])])); texture1.SetPixel(side4x1, side4ymid, grad.Evaluate(gradstress[int.Parse(element[17])])); texture1.SetPixel(side4x1, side4y2, grad.Evaluate(gradstress[int.Parse(element[9])])); texture1.SetPixel(side4xmid, side4y1, grad.Evaluate(gradstress[int.Parse(element[18])])); texture1.SetPixel(side4xmid, side4y2, grad.Evaluate(gradstress[int.Parse(element[21])])); texture1.SetPixel(side4x2, side4y1, grad.Evaluate(gradstress[int.Parse(element[2])])); texture1.SetPixel(side4x2, side4ymid, grad.Evaluate(gradstress[int.Parse(element[13])])); texture1.SetPixel(side4x2, side4y2, grad.Evaluate(gradstress[int.Parse(element[5])])); int side5y1 = 85; int side5y2 = 169; int side5ymid = 127; int side5x1 = 254; int side5x2 = 380; int side5xmid = 317; for (int y = 85; y < 170; y++) { for (int x = 254; x < 381; x++) { float d0 = Mathf.Sqrt(Mathf.Pow((x - side5x1), 2f) + Mathf.Pow((y - side5y1), 2f)); float d1 = Mathf.Sqrt(Mathf.Pow((x - side5x1), 2f) + Mathf.Pow((y - side5ymid), 2f)); float d2 = Mathf.Sqrt(Mathf.Pow((x - side5x1), 2f) + Mathf.Pow((y - side5y2), 2f)); float d3 = Mathf.Sqrt(Mathf.Pow((x - side5xmid), 2f) + Mathf.Pow((y - side5y1), 2f)); float d4 = Mathf.Sqrt(Mathf.Pow((x - side5xmid), 2f) + Mathf.Pow((y - side5y2), 2f)); float d5 = Mathf.Sqrt(Mathf.Pow((x - side5x2), 2f) + Mathf.Pow((y - side5y1), 2f)); float d6 = Mathf.Sqrt(Mathf.Pow((x - side5x2), 2f) + Mathf.Pow((y - side5ymid), 2f)); float d7 = Mathf.Sqrt(Mathf.Pow((x - side5x2), 2f) + Mathf.Pow((y - side5y2), 2f)); float z0 = gradstress[int.Parse(element[3])]; float z1 = gradstress[int.Parse(element[10])]; float z2 = gradstress[int.Parse(element[2])]; float z3 = gradstress[int.Parse(element[11])]; float z4 = gradstress[int.Parse(element[13])]; float z5 = gradstress[int.Parse(element[4])]; float z6 = gradstress[int.Parse(element[12])]; float z7 = gradstress[int.Parse(element[5])]; float zidi = (z0 / d0) + (z1 / d1) + (z2 / d2) + (z3 / d3) + (z4 / d4) + (z5 / d5) + (z6 / d6) + (z7 / d7); float inversedi = (1 / d0) + (1 / d1) + (1 / d2) + (1 / d3) + (1 / d4) + (1 / d5) + (1 / d6) + (1 / d7); float zxy = (zidi / inversedi); texture1.SetPixel(x, y, grad.Evaluate(zxy)); } } texture1.SetPixel(side5x1, side5y1, grad.Evaluate(gradstress[int.Parse(element[3])])); texture1.SetPixel(side5x1, side5ymid, grad.Evaluate(gradstress[int.Parse(element[10])])); texture1.SetPixel(side5x1, side5y2, grad.Evaluate(gradstress[int.Parse(element[2])])); texture1.SetPixel(side5xmid, side5y1, grad.Evaluate(gradstress[int.Parse(element[11])])); texture1.SetPixel(side5xmid, side5y2, grad.Evaluate(gradstress[int.Parse(element[13])])); texture1.SetPixel(side5x2, side5y1, grad.Evaluate(gradstress[int.Parse(element[4])])); texture1.SetPixel(side5x2, side5ymid, grad.Evaluate(gradstress[int.Parse(element[12])])); texture1.SetPixel(side5x2, side5y2, grad.Evaluate(gradstress[int.Parse(element[5])])); int side6y1 = 85; int side6y2 = 169; int side6ymid = 127; int side6x1 = 381; int side6x2 = 507; int side6xmid = 444; for (int y = 85; y < 170; y++) { for (int x = 381; x < 508; x++) { float d0 = Mathf.Sqrt(Mathf.Pow((x - side6x1), 2f) + Mathf.Pow((y - side6y1), 2f)); float d1 = Mathf.Sqrt(Mathf.Pow((x - side6x1), 2f) + Mathf.Pow((y - side6ymid), 2f)); float d2 = Mathf.Sqrt(Mathf.Pow((x - side6x1), 2f) + Mathf.Pow((y - side6y2), 2f)); float d3 = Mathf.Sqrt(Mathf.Pow((x - side6xmid), 2f) + Mathf.Pow((y - side6y1), 2f)); float d4 = Mathf.Sqrt(Mathf.Pow((x - side6xmid), 2f) + Mathf.Pow((y - side6y2), 2f)); float d5 = Mathf.Sqrt(Mathf.Pow((x - side6x2), 2f) + Mathf.Pow((y - side6y1), 2f)); float d6 = Mathf.Sqrt(Mathf.Pow((x - side6x2), 2f) + Mathf.Pow((y - side6ymid), 2f)); float d7 = Mathf.Sqrt(Mathf.Pow((x - side6x2), 2f) + Mathf.Pow((y - side6y2), 2f)); float z0 = gradstress[int.Parse(element[4])]; float z1 = gradstress[int.Parse(element[12])]; float z2 = gradstress[int.Parse(element[5])]; float z3 = gradstress[int.Parse(element[20])]; float z4 = gradstress[int.Parse(element[21])]; float z5 = gradstress[int.Parse(element[8])]; float z6 = gradstress[int.Parse(element[16])]; float z7 = gradstress[int.Parse(element[9])]; float zidi = (z0 / d0) + (z1 / d1) + (z2 / d2) + (z3 / d3) + (z4 / d4) + (z5 / d5) + (z6 / d6) + (z7 / d7); float inversedi = (1 / d0) + (1 / d1) + (1 / d2) + (1 / d3) + (1 / d4) + (1 / d5) + (1 / d6) + (1 / d7); float zxy = (zidi / inversedi); texture1.SetPixel(x, y, grad.Evaluate(zxy)); } } texture1.SetPixel(side6x1, side6y1, grad.Evaluate(gradstress[int.Parse(element[4])])); texture1.SetPixel(side6x1, side6ymid, grad.Evaluate(gradstress[int.Parse(element[12])])); texture1.SetPixel(side6x1, side6y2, grad.Evaluate(gradstress[int.Parse(element[5])])); texture1.SetPixel(side6xmid, side6y1, grad.Evaluate(gradstress[int.Parse(element[20])])); texture1.SetPixel(side6xmid, side6y2, grad.Evaluate(gradstress[int.Parse(element[21])])); texture1.SetPixel(side6x2, side6y1, grad.Evaluate(gradstress[int.Parse(element[8])])); texture1.SetPixel(side6x2, side6ymid, grad.Evaluate(gradstress[int.Parse(element[16])])); texture1.SetPixel(side6x2, side6y2, grad.Evaluate(gradstress[int.Parse(element[9])])); texture1.Apply(); #endregion GameObject elem = new GameObject("elem" + i); elem.AddComponent <MeshRenderer>(); Mesh mesh = elem.AddComponent <MeshFilter>().mesh; mesh.vertices = vertices; mesh.triangles = triangles; mesh.uv = uvs; elem.GetComponent <MeshRenderer>().material.mainTexture = texture1; elem.GetComponent <MeshRenderer>().material.mainTexture.filterMode = FilterMode.Point; elem.transform.parent = model1.transform; //var pngData = texture1.EncodeToPNG(); //File.WriteAllBytes("F:/Programming/FYP/GitHub/HoloLens-FEA-University-of-Bath/" + i + ".png", pngData); } model1.transform.position = ModelCreationCube.position; }
static UnityEngine.Gradient Lerp(UnityEngine.Gradient a, UnityEngine.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); }
public static Gradient WhiteFadeIn() { GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_White }; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { Alpha0_0, Alpha1_1 }; return(New(colorKeys, alphaKeys)); }
private void OnDrawGizmos() { if (Nodes == null || Nodes.Count == 0) { return; } float highCost = Nodes.Max(x => x.CostSoFar); float lowCost = Nodes.Min(x => x.CostSoFar); float fixer = 0; if (lowCost < 0) { fixer = lowCost * -1; } Gradient gradient = new Gradient(); GradientColorKey key0 = new GradientColorKey(Color.white, 0); GradientAlphaKey alfa0 = new GradientAlphaKey(1, 0); GradientAlphaKey alfa1 = new GradientAlphaKey(0, 1); gradient.SetKeys( new GradientColorKey[] { key0 }, new GradientAlphaKey[] { alfa0, alfa1 }); gradient.mode = GradientMode.Blend; foreach (var node in Nodes) { //draw Nodes float percentage = 1 - ((node.CostSoFar + fixer) / (highCost + fixer)); Gizmos.color = gradient.Evaluate(percentage); Gizmos.DrawSphere(node.position, 0.15f); //draw connections //foreach (var connection in node.Connections) //{ // TileNode fromNode = connection.FromNode as TileNode; // TileNode toNode = connection.ToNode as TileNode; // Gizmos.DrawLine(fromNode.position, toNode.position); //} } //show best path if (bestPath == null) { return; } Gizmos.color = Color.magenta; bool first = true; foreach (var connection in bestPath) { Vector3 from = ((TileNode)connection.FromNode).position; Vector3 to = ((TileNode)connection.ToNode).position; Gizmos.DrawLine(from, to); if (first) { Gizmos.DrawCube(from, 0.5f * Vector3.one); first = false; } } }
public static Gradient BlackFadeOut() { GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_Black }; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { Alpha0_1, Alpha1_0 }; return(New(colorKeys, alphaKeys)); }
public static void Write(this NetDataWriter writer, GradientAlphaKey value) { writer.Write(value.alpha); writer.Write(value.time); }
public static Gradient BlackToWhite() { GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_Black, Color1_White }; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { Alpha0_1 }; return(New(colorKeys, alphaKeys)); }
private void SaveTo24Sys(Gradient colorGradient, Color theColor) { if (colorGradient.colorKeys.Length != 8 || colorGradient.alphaKeys.Length != 8) { GradientColorKey[] colorKeys = new GradientColorKey[8]; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[8]; for (int i = 0; i < 8; i++) { colorKeys[i].color = Color.black; alphaKeys[i].alpha = 1; } colorGradient.SetKeys(colorKeys, alphaKeys); } if (colorGradient.colorKeys.Length == 8 || colorGradient.alphaKeys.Length == 8) { GradientColorKey[] colorKeys = colorGradient.colorKeys; GradientAlphaKey[] alphaKeys = colorGradient.alphaKeys; colorKeys[0].time = NightEnd / 24f; alphaKeys[0].time = NightEnd / 24f; colorKeys[1].time = MorningStart / 24f; alphaKeys[1].time = MorningStart / 24f; colorKeys[2].time = MorningEnd / 24f; alphaKeys[2].time = MorningEnd / 24f; colorKeys[3].time = DayStart / 24f; alphaKeys[3].time = DayStart / 24f; colorKeys[4].time = DayEnd / 24f; alphaKeys[4].time = DayEnd / 24f; colorKeys[5].time = DuskStart / 24f; alphaKeys[5].time = DuskStart / 24f; colorKeys[6].time = DuskEnd / 24f; alphaKeys[6].time = DuskEnd / 24f; colorKeys[7].time = NightStart / 24f; alphaKeys[7].time = NightStart / 24f; switch (DayTime) { case DayInterval.Day: colorKeys[3].color = theColor; alphaKeys[3].alpha = theColor.a; colorKeys[4].color = theColor; alphaKeys[4].alpha = theColor.a; break; case DayInterval.Dusk: colorKeys[5].color = theColor; alphaKeys[5].alpha = theColor.a; colorKeys[6].color = theColor; alphaKeys[6].alpha = theColor.a; break; case DayInterval.Night: colorKeys[0].color = theColor; alphaKeys[0].alpha = theColor.a; colorKeys[7].color = theColor; alphaKeys[7].alpha = theColor.a; break; case DayInterval.Morning: colorKeys[1].color = theColor; alphaKeys[1].alpha = theColor.a; colorKeys[2].color = theColor; alphaKeys[2].alpha = theColor.a; break; } colorGradient.SetKeys(colorKeys, alphaKeys); } }
public static Gradient WhiteToBlack() { GradientColorKey[] colorKeys = new GradientColorKey[] { Color0_White, Color1_Black }; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[] { Alpha0_1 }; return(New(colorKeys, alphaKeys)); }
public void SetKeys(GradientColorKey[] colorKeys, GradientAlphaKey[] alphaKeys){}
public override void RenderOnto(GameObject canvas, Vector3 position) { if (Tile.Terrain.TerrainType == Terrain.TerrainTypes.DesertHill || Tile.Terrain.TerrainType == Terrain.TerrainTypes.GrassHill) { Vector3 positionNew = new Vector3(position.x, position.y + 0.3f, position.z); RenderOntoSprite(canvas, positionNew, "Textures/structures/FactoryNew", new Vector2(5f, 5f)); } else { Vector3 positionNew = new Vector3(position.x, position.y + 0.15f, position.z); RenderOntoSprite(canvas, positionNew, "Textures/structures/FactoryNew", new Vector2(5f, 5f)); } // Render smoke. if (smoke != null) { // Reuse existing smoke. smoke.transform.SetParent(GameObject.transform); smoke.transform.localPosition = new Vector3(-2.7f, 6.6f); smoke.transform.localScale = new Vector3(1, 1, 1); } else { smoke = new GameObject(); smoke.transform.SetParent(GameObject.transform); smoke.transform.localPosition = new Vector3(-2.7f, 6.6f); smoke.transform.localScale = new Vector3(1, 1, 1); ParticleSystem particles = smoke.AddComponent <ParticleSystem>(); Particles.InitParticleSystem(particles); var main = particles.main; main.startLifetime = 4; main.startSize = 1; main.startSpeed = 1; main.startColor = new Color(221, 221, 221); main.maxParticles = 40; var emission = particles.emission; emission.rateOverTime = 4; emission.enabled = true; var shape = particles.shape; shape.angle = 10; shape.radius = 0.0001f; shape.rotation = new Vector3(-90, 90, 0); shape.scale = new Vector3(0.05f, 0.05f, 0.05f); shape.enabled = true; var limit = particles.limitVelocityOverLifetime; limit.limit = 1; limit.dampen = 1; limit.multiplyDragByParticleSize = false; limit.multiplyDragByParticleVelocity = true; limit.drag = 4; limit.enabled = true; var force = particles.forceOverLifetime; force.x = new ParticleSystem.MinMaxCurve(0.15f, 0.2f); force.y = new ParticleSystem.MinMaxCurve(-0.37f, 0.4f); force.randomized = true; force.enabled = true; var colorOverLifetime = particles.colorOverLifetime; Gradient gradientLifetime = new Gradient(); GradientColorKey[] colorKeys = new GradientColorKey[2]; colorKeys[0].color = new Color(178, 178, 178); colorKeys[0].time = 0.0f; colorKeys[1].color = Color.white; colorKeys[1].time = 0.1f; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[2]; alphaKeys[0].alpha = 1; alphaKeys[0].time = 0.6f; alphaKeys[1].alpha = 0; alphaKeys[1].time = 1.0f; gradientLifetime.SetKeys(colorKeys, alphaKeys); colorOverLifetime.color = gradientLifetime; colorOverLifetime.enabled = true; var sizeOverLifetime = particles.sizeOverLifetime; sizeOverLifetime.size = new ParticleSystem.MinMaxCurve(1, new AnimationCurve(new Keyframe(0.0f, 0.1f), new Keyframe(0.23f, 0.3f))); sizeOverLifetime.enabled = true; var renderer = smoke.GetComponent <ParticleSystemRenderer>(); renderer.sortingLayerName = "Structure"; renderer.sortingOrder = 1000; Material material = new Material(renderer.material); material.mainTexture = Resources.Load <Texture>("Textures/CloudParticle"); renderer.material = material; } }