protected virtual void Start() { emitActive = ParseRequest(emitActive); emitDeactive = ParseRequest(emitDeactive); switchSignal = ParseRequest(switchSignal); activeSignal = ParseRequest(activeSignal); deactiveSignal = ParseRequest(deactiveSignal); AddCallback(new Signal(switchSignal), () => selfActive = !selfActive); if (emitActive != "" && emitActive == activeSignal) { throw new ArgumentException("Signal When Active should not contains Emit Active."); } AddCallback(new Signal(activeSignal), () => selfActive = true); if (emitDeactive != "" && emitDeactive == deactiveSignal) { throw new ArgumentException("Signal When Deactive should not contains Emit Deactive."); } AddCallback(new Signal(deactiveSignal), () => selfActive = false); activeCallback += () => SignalManager.EmitSignal(emitActive); deactiveCallback += () => SignalManager.EmitSignal(emitDeactive); if (parent == null && this.transform.parent.GetComponent <Canvas>() == null) { throw new Exception("A UI Component must be attached to Canvas directly or has a parent mounted with UI Component."); } }
// Remove all callbacks that originally added by this object. // Use protected virtual modifier // to make sure there won't be an unconscious override. protected virtual void OnDestroy() { for (int i = 0; i < signalList.Count; i++) { SignalManager.RemoveSignalCallback(signalList[i], actionList[i]); } }
protected override void Update() { base.Update(); if (cursorHovering && VirtualCursor.scrolling) { SignalManager.EmitSignal(emitMouseScroll); } if (cursorHovering && !trigLast) { SignalManager.EmitSignal(emitMouseEnter); } if (!cursorHovering && trigLast) { SignalManager.EmitSignal(emitMouseLeave); } if (cursorHovering || trigLast) { if (VirtualCursor.position != lastCursorPos) { SignalManager.EmitSignal(emitMouseMove); } } trigLast = cursorHovering; lastCursorPos = VirtualCursor.position; }
protected void AddCallback(Signal x, Action action) { if (x.value == "") { return; // do nothing for empty string. } signalList.Add(x); actionList.Add(action); SignalManager.AddSignalCallback(x, action); }
protected override void Update() { emitMouseClick = ParseRequest(emitMouseClick); emitMouseRelease = ParseRequest(emitMouseRelease); base.Update(); if (cursorHovering && Input.GetMouseButtonDown(0)) { SignalManager.EmitSignal(emitMouseClick); } if (cursorHovering && Input.GetMouseButtonUp(0)) { SignalManager.EmitSignal(emitMouseRelease); } if (cursorHovering && Input.GetMouseButtonDown(1)) { SignalManager.EmitSignal(emitRightClick); } if (cursorHovering && Input.GetMouseButtonUp(1)) { SignalManager.EmitSignal(emitRightRelease); } if (cursorHovering && Input.GetMouseButtonDown(2)) { SignalManager.EmitSignal(emitMiddleClick); } if (cursorHovering && Input.GetMouseButtonUp(2)) { SignalManager.EmitSignal(emitMiddleRelease); } }
void Start() { foreach (var i in toSignals) { if (fromSignal == i) { throw new InvalidOperationException("Signal " + i + "Cannot be emitted when receiving signal " + fromSignal); } } AddCallback(new Signal(fromSignal), () => { if (toSignals == null) { return; } // Execute one by one, from top to bottom... for (int i = 0; i < toSignals.Length; i++) { SignalManager.EmitSignal(toSignals[i]); } }); }