private void Update() { RaycastHit hit; if (Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out hit)) { // if hitting same object do nothing if (lastFaderHit && hit.transform == lastFaderHit.transform) { return; } // if looking on different object start fade out previous if exists lastFaderHit?.FadeOut(); // start fade in current var current = hit.transform.GetComponent <ColorFade>(); current?.FadeIn(); // update previous hit lastFaderHit = current; } else { // if looking at nothing start fadeout previous hit if exists lastFaderHit?.FadeOut(); // reset previous hit lastFaderHit = null; } }
/// <summary> /// /// </summary> /// <param name="index"></param> /// <param name="time"></param> /// <param name="Color"></param> public void insertColorFader(int index, double time, Color4 Color) { ColorFade newFade = new ColorFade(); newFade.FadeTime = time; newFade.Color = Color; FadeList.Insert(index, newFade); }
void Awake() { GC = GetComponent <ColorFade>(); image = gameObject.GetComponent <Image>(); image.color = startColor; r = image.color.r; g = image.color.g; g = image.color.b; a = image.color.a; }
//Color:颜色 private void ColorButton_Tapped(object sender, TappedRoutedEventArgs e) { if (ColorPanel.Opacity == 0) { ColorShow.Begin(); } else { ColorFade.Begin(); } }
/// <summary> /// Makes a ColorFader, Must have the 1st ColorFader's threshold set to 0. /// The order the Dictionary entries will be the order of the colors for the Fader (at least for now) /// </summary> /// <param name="dictionary"> double (the key and the threshold) is about how many seconds for the particle to completely become that color /// , Color4 is the color for that </param> public ColorFader(Dictionary <double, Color4> dictionary) { ColorFade cf = new ColorFade(); //giving it a starting capacity of 4, don't think we should need more than that FadeList = new List <ColorFade>(4); foreach (var item in dictionary) { cf.Color = item.Value; cf.FadeTime = item.Key; FadeList.Add(cf); } }
public ParticleEffect(string fileName) { Name = fileName; colorFade_ = new ObservableCollection <ParticleColorFade>(); texAnim_ = new ObservableCollection <ParticleTexAnim>(); type_ = EmitterType.Box; string path = System.IO.Path.ChangeExtension(fileName, "xml"); if (System.IO.File.Exists(path)) { XmlDocument doc = new XmlDocument(); doc.Load(path); foreach (XmlElement mat in doc.DocumentElement.GetElementsByTagName("material")) { Material = mat.GetAttribute("name"); } foreach (XmlElement num in doc.DocumentElement.GetElementsByTagName("numparticles")) { foreach (XmlElement u in doc.DocumentElement.GetElementsByTagName("updateinvisible")) { UpdateInvisible = u.GetAttribute("enable").Equals("true"); } } foreach (XmlElement rel in doc.DocumentElement.GetElementsByTagName("relative")) { Relative = rel.GetAttribute("enable").Equals("true"); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("scaled")) { Scaled = s.GetAttribute("enable").Equals("true"); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("sorted")) { Sorted = s.GetAttribute("enable").Equals("true"); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("animlodbias")) { AnimLodBias = float.Parse(s.GetAttribute("value")); } foreach (XmlElement t in doc.DocumentElement.GetElementsByTagName("emittertype")) { foreach (EmitterType type in Enum.GetValues(typeof(EmitterType))) { if (type.ToString().ToLower().Equals(t.GetAttribute("value"))) { Type = type; break; } } } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("emittersize")) { EmitterSize = Vector3.FromString(s.GetAttribute("value")); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("emitterradius")) { EmitterRadius = float.Parse(s.GetAttribute("value")); } foreach (XmlElement d in doc.DocumentElement.GetElementsByTagName("direction")) { DirectionMax = Vector3.FromString(d.GetAttribute("max")); DirectionMin = Vector3.FromString(d.GetAttribute("min")); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("constantforce")) { ConstantForce = Vector3.FromString(s.GetAttribute("value")); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("dampingforce")) { DampingForce = float.Parse(s.GetAttribute("value")); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("activetime")) { ActiveTime = float.Parse(s.GetAttribute("value")); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("inactivetime")) { InActiveTime = float.Parse(s.GetAttribute("value")); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("interval")) { Interval = MinMax.FromElement(s); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("emissionrate")) { EmissionRate = MinMax.FromElement(s); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("particlesize")) { if (s.HasAttribute("min")) { MinSize = Vector2.FromString(s.GetAttribute("min")); } if (s.HasAttribute("max")) { MaxSize = Vector2.FromString(s.GetAttribute("max")); } if (s.HasAttribute("value")) { MinSize = Vector2.FromString(s.GetAttribute("value")); MaxSize = Vector2.FromString(s.GetAttribute("value")); } } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("timetolive")) { TimeToLive = MinMax.FromElement(s); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("velocity")) { Velocity = MinMax.FromElement(s); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("rotation")) { Rotation = MinMax.FromElement(s); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("rotationspeed")) { RotationSpeed = MinMax.FromElement(s); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("sizedelta")) { Vector2 sd = new Vector2(); if (s.HasAttribute("add")) { sd.X = float.Parse(s.GetAttribute("add")); } if (s.HasAttribute("mul")) { sd.Y = float.Parse(s.GetAttribute("mul")); } SizeDelta = sd; } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("colorfade")) { ColorFade.Add(new ParticleColorFade(s)); } foreach (XmlElement s in doc.DocumentElement.GetElementsByTagName("texanim")) { TextureAnim.Add(new ParticleTexAnim(s)); } } else { // Add the initial color fade // ColorFade.Add(new ParticleColorFade() { Color = new UColor(1, 1, 1, 1), Time = 0 }); } }
void Start() { colorFade = GetComponent <ColorFade>(); }