public static void UpdateVoiceIndicator(GUIImage soundIcon, float voipAmplitude, float deltaTime) { if (voiceIconSheetRects == null) { var soundIconStyle = GUI.Style.GetComponentStyle("GUISoundIcon"); Rectangle sourceRect = soundIconStyle.Sprites.First().Value.First().Sprite.SourceRect; var indexPieces = soundIconStyle.Element.Attribute("sheetindices").Value.Split(';'); voiceIconSheetRects = new Rectangle[indexPieces.Length]; for (int i = 0; i < indexPieces.Length; i++) { Point location = sourceRect.Location + XMLExtensions.ParsePoint(indexPieces[i].Trim()) * sourceRect.Size; voiceIconSheetRects[i] = new Rectangle(location, sourceRect.Size); } } Pair <string, float> userdata = soundIcon.UserData as Pair <string, float>; userdata.Second = Math.Max(voipAmplitude, userdata.Second - deltaTime); if (userdata.Second <= 0.0f) { soundIcon.Visible = false; } else { soundIcon.Visible = true; int sheetIndex = (int)Math.Floor(userdata.Second * voiceIconSheetRects.Length); sheetIndex = MathHelper.Clamp(sheetIndex, 0, voiceIconSheetRects.Length - 1); soundIcon.SourceRect = voiceIconSheetRects[sheetIndex]; soundIcon.OverrideState = GUIComponent.ComponentState.None; soundIcon.HoverColor = Color.White; } }