internal static void ClientMessageReceived(CrowdControlClient c, string raw) { try { Console.WriteLine("Message received: " + raw); // Decode the message from CC // { "id":1,"code":"kill","viewer":"sdk","type":1} var request = JsonSerializer.Deserialize <CrowdControlRequest>(raw); // Do the thing var eventName = EventNameDict[request.Code]; var status = 0; if (TimerCooldown.IsInitialised()) { try { EventLookup.Lookup(eventName, request.Viewer); } catch (Exception) { // On exception set failed flag status = 1; } } else { // Game is not yet ready for events, retry until it is. status = 3; } // Send the result to CC var response = new CrowdControlResponse(); response.Id = request.Id; response.Status = status; response.Message = "Effect: " + request.Code + ": " + response.Status; var resJson = JsonSerializer.Serialize <CrowdControlResponse>(response); Console.WriteLine("Sending response: " + resJson); c.Send(resJson, false); } catch (Exception e) { Console.WriteLine(e); } }
private void AlignText() { float scaleX = (1920f / Screen.width); float scaleY = (1920f / Screen.width); //float width = textText.preferredWidth; float width = getTextWidth(); float widestText = useGlobalTextWidth ? TimerCooldown.widestText : getTextWidth(); float x = Screen.width / 2 - (Screen.width / 1920f * widestText) - TimerCooldown.ActualTimerHeadingHeight(); float y = -Screen.height / 2 - yOffset + TimerCooldown.ActualTimerHeadingHeight(); x *= scaleX; y *= scaleY; float displayX; switch (textText.alignment) { case TextAnchor.UpperLeft: case TextAnchor.MiddleLeft: case TextAnchor.LowerLeft: displayX = x + width / 2f; goto IL_9A; case TextAnchor.UpperRight: case TextAnchor.MiddleRight: case TextAnchor.LowerRight: displayX = x - width / 2f; goto IL_9A; } displayX = x; IL_9A: float displayY = y; textObject.transform.localPosition = new Vector3(displayX, displayY, 0f); if (progressIcon != null) { progressIcon.rectTransform.localPosition = new Vector3(displayX - TimerCooldown.ActualTimerHeadingHeight() / 2 - width / 2f, displayY, 0f); } }
public CustomText(string text, float duration, int yOffset = 0, bool showProgress = false, bool useGlobalTextWidth = true) { this.duration = duration; this.yOffset = yOffset; startTime = Time.time; isFadingOut = false; this.useGlobalTextWidth = useGlobalTextWidth; textObject = new GameObject("TwitchInteractionTimerCooldown"); textText = textObject.AddComponent <Text>(); textFade = textObject.AddComponent <uGUI_TextFade>(); textFitter = textObject.AddComponent <ContentSizeFitter>(); textFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; textFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; textText.font = uGUI.main.intro.mainText.text.font; textText.fontSize = 16; textText.fontStyle = uGUI.main.intro.mainText.text.fontStyle; textText.alignment = TextAnchor.MiddleLeft; textText.color = uGUI.main.intro.mainText.text.color; textText.material = uGUI.main.intro.mainText.text.material; if (showProgress) { progressObject = new GameObject("TwitchInteractionTimerCooldownIcon"); progressIcon = progressObject.AddComponent <uGUI_ItemIcon>(); progressTexture = new Texture2D(TimerCooldown.ActualTimerTextHeight(), TimerCooldown.ActualTimerTextHeight()); for (int x = 0; x < progressTexture.width; x++) { for (int y = 0; y < progressTexture.height; y++) { float distanceFromCenter = (float)Math.Sqrt((x - progressTexture.width / 2) * (x - progressTexture.width / 2) + (y - progressTexture.height / 2) * (y - progressTexture.height / 2)); Color c = new Color(0, 0, 0, 0); if (distanceFromCenter <= progressTexture.height) { c = Color.white; } progressTexture.SetPixel(x, y, c); } } /*Atlas.Sprite progressSprite = new Atlas.Sprite(progressTexture); * progressIcon.SetForegroundSprite(progressSprite); * progressIcon.SetForegroundAlpha(1); * progressIcon.SetForegroundColors(Color.white, Color.white, Color.white); * progressIcon.SetForegroundAlpha(1, 1, 1); * progressIcon.SetForegroundChroma(1f); * progressIcon.SetBackgroundAlpha(0); * progressIcon.SetBackgroundColors(new Color(0, 0, 0, 0), new Color(0, 0, 0, 0), new Color(0, 0, 0, 0)); * progressIcon.SetForegroundAlpha(0); * progressIcon.SetForegroundColors(new Color(0, 0, 0, 0), new Color(0, 0, 0, 0), new Color(0, 0, 0, 0)); * progressIcon.SetAlpha(0, 0, 0); * progressIcon.foreground.canvasRenderer.SetColor(Color.white); * progressIcon.foreground.color = Color.white;*/ } // Do this so it also shows over black screens Graphic g = uGUI.main.overlays.overlays[0].graphic; textObject.transform.SetParent(g.transform, false); textText.canvas.overrideSorting = true; textObject.layer = 1; if (showProgress) { progressObject.transform.SetParent(g.transform, false); progressIcon.canvas.overrideSorting = true; progressObject.layer = 1; progressIcon.SetActive(true); } SetText(text); Update(); }
internal static void ClientMessageReceived(CrowdControlClient c, string raw) { try { Console.WriteLine("Message received: " + raw); // Decode the message from CC // { "id":1,"code":"kill","viewer":"sdk","type":1} var request = JsonSerializer.Deserialize <CrowdControlRequest>(raw); // Do the thing var eventName = EventNameDict[request.Code]; var status = 0; if (request.Id == 0 && request.Type == 255) { // Test message, ignore return; } if (TimerCooldown.IsInitialised()) { try { // Check to see if the event can fire currently fire, or is on cooldown. if (!EventLookup.IsRunningOrCooldown(eventName)) { // Not running or on cooldown, activate it if the type is "start" if (request.Type == 1) { EventLookup.Lookup(eventName, request.Viewer); } } else { // Event in use, retry. status = 3; } } catch (Exception) { // On exception set failed flag status = 1; } } else { // Game is not yet ready for events, retry until it is. status = 3; } // Send the result to CC var response = new CrowdControlResponse(); response.Id = request.Id; response.Status = status; response.Message = "Effect: " + request.Code + ": " + response.Status; var resJson = JsonSerializer.Serialize <CrowdControlResponse>(response); Console.WriteLine("Sending response: " + resJson); c.Send(resJson, false); } catch (Exception e) { Console.WriteLine(e); } }