private static void OnPart(Message msg) { PartEvent?.Invoke(new SystemMsgEventArgs() { msg = msg }); }
void onEditorPartEvent(ConstructionEventType evt, Part part) { #if DEBUG switch (evt) { case ConstructionEventType.PartDragging: case ConstructionEventType.PartOffsetting: case ConstructionEventType.PartRotating: /* these events are too noisy for logging */ break; default: Debug.Log($"[RCSBA]: Editor Part Event {evt} {part.partInfo.name}"); break; } #endif PartEvent?.Invoke(); switch (evt) { case ConstructionEventType.PartCopied: case ConstructionEventType.PartCreated: OnSelectionChanged(); break; case ConstructionEventType.PartPicked: if (part != EditorLogic.RootPart) { OnSelectionChanged(); } break; case ConstructionEventType.PartDropped: if (part != EditorLogic.RootPart) { OnSelectionChanged(); } break; case ConstructionEventType.PartDeleted: OnSelectionChanged(); break; case ConstructionEventType.PartAttached: case ConstructionEventType.PartDetached: OnVesselPartChanged(); OnSelectionChanged(); break; case ConstructionEventType.PartDragging: PartDrag?.Invoke(); break; } }
public void RemovePart(Part a_part) { if (!m_colliderDict.ContainsKey(a_part)) { Debug.LogWarningFormat("Tried to remove part {0} from {1} but it's not in the dictionary.", a_part, name); return; } Destroy(m_colliderDict[a_part]); m_colliderDict.Remove(a_part); OnDetach.Invoke(a_part); }
public void AttachPart(Part a_part) { a_part.transform.localScale = Vector2.one; Collider2D collider = null; { var poly = a_part.GetComponent <PolygonCollider2D>(); if (poly != null) { collider = gameObject.AddComponent <PolygonCollider2D>(); collider.offset = (Vector2)a_part.transform.localPosition + poly.offset; ((PolygonCollider2D)collider).points = (Vector2[])poly.points.Clone(); } } { var box = a_part.GetComponent <BoxCollider2D>(); if (box != null) { collider = gameObject.AddComponent <BoxCollider2D>(); collider.offset = (Vector2)a_part.transform.localPosition + box.offset; ((BoxCollider2D)collider).size = box.size; } } { var circle = a_part.GetComponent <CircleCollider2D>(); if (circle != null) { collider = gameObject.AddComponent <CircleCollider2D>(); collider.offset = (Vector2)a_part.transform.localPosition + circle.offset; ((CircleCollider2D)collider).radius = circle.radius; } } m_colliderDict[a_part] = collider; OnAttach.Invoke(a_part); }
private async Task Reader() { using (HttpClient client = new HttpClient { Timeout = Timeout.InfiniteTimeSpan }) { for (int i = 1; AutoReconnect && (RetryLimit == -1 || i <= RetryLimit); i++) { try { using (var response = await client.GetAsync($"https://stream.lobi.co/2/group/{GroupID}?token={AccessToken}", HttpCompletionOption.ResponseHeadersRead)) using (var reader = new System.IO.StreamReader(await response.Content.ReadAsStreamAsync())) { i = 0; //カウンタ初期化 Connected = true; //Connected!! ConnectedEvent?.Invoke(GroupID); while (!reader.EndOfStream) { token = new CancellationTokenSource(); //トークン初期化 var jobj = await _Read(reader, token.Token); //Jsonデータ読み取り var ev = jobj["event"]?.ToString(); if (ev == "chat") { ChatEvent?.Invoke(GroupID, JsonConvert.DeserializeObject <Chat>(jobj["chat"].ToString())); } else if (ev == "chat_deleted") { ChatDeletedEvent?.Invoke(GroupID, jobj["id"].ToString()); } else if (ev == "part") { PartEvent?.Invoke(GroupID, JsonConvert.DeserializeObject <UserMinimal>(jobj["user"].ToString())); } else if (ev == "archive") { ArchiveEvent?.Invoke(GroupID); } } } token = null; Connected = false; DisconnectedEvent?.Invoke(GroupID); } catch (OperationCanceledException) { token = null; Connected = false; DisconnectedEvent?.Invoke(GroupID); return; } catch (Exception ex) { if (Connected) { token = null; Connected = false; DisconnectedEvent?.Invoke(GroupID);//必要かな?? } else { token = null; Connected = false;//一応ね } FailConnectEvent?.Invoke(GroupID, ex); } await Task.Delay(RetryCoolTimeMilliseconds);//クールタイム } } }
protected virtual void RaisePartEvent(TokenEventArgs e) { PartEvent?.Invoke(this, e); }
public static ResponseData InFunction(string comMessage) { var messageArg = new MessageArgs(comMessage); return(PartEvent?.Invoke(null, messageArg)); // 触发事件,执行所有注册过的函数 }