void DrawOptionsColumn(Rect rect, int rowIdx, SignalReceiver target) { if (!readonlySignal) { rect.height = Styles.OptionsStyle.normal.background.height; rect.width = Styles.OptionsStyle.normal.background.width; GUI.SetNextControlName(SignalOptions); if (GUI.Button(rect, Styles.OptionsStyle.normal.background, GUIStyle.none)) { var menu = new GenericMenu(); menu.AddItem(EditorGUIUtility.TrTextContent(Styles.SignalListDuplicateOption), false, () => { var evtCloner = ScriptableObject.CreateInstance <UnityEventCloner>(); evtCloner.evt = target.GetReactionAtIndex(rowIdx); var clone = Object.Instantiate(evtCloner); target.AddEmptyReaction(clone.evt); m_ShouldRefreshParent = true; }); menu.AddItem(EditorGUIUtility.TrTextContent(Styles.SignalListDeleteOption), false, () => { target.RemoveAtIndex(rowIdx); m_ShouldRefreshParent = true; }); menu.ShowAsContext(); } } }
void DrawSignalNameColumn(Rect rect, float padding, SignalReceiver target, int rowIdx) { using (new EditorGUI.DisabledScope(!enabled)) { if (!readonlySignal) { m_CurrentRowIdx = rowIdx; m_CurrentReceiver = target; rect.x += padding; rect.width -= padding; rect.height = EditorGUIUtility.singleLineHeight; GUI.SetNextControlName(SignalName); SignalUtility.DrawSignalNames(this, rect, GUIContent.none, false); } else { GUI.SetNextControlName(SignalNameReadOnly); var signalAsset = m_Asset.objectReferenceValue; GUI.Label(rect, signalAsset != null ? EditorGUIUtility.TempContent(signalAsset.name) : Styles.EmptySignalList); } } }
void DrawOptionsButton(Rect rect, int rowIdx, SignalReceiver target) { GUI.SetNextControlName(SignalOptions); if (EditorGUI.DropdownButton(rect, EditorGUI.GUIContents.titleSettingsIcon, FocusType.Passive, EditorStyles.iconButton)) { var menu = new GenericMenu(); menu.AddItem(new GUIContent(Styles.SignalListDuplicateOption), false, () => { Undo.RecordObject(target, Styles.UndoDuplicateRow); var evtCloner = ScriptableObject.CreateInstance <UnityEventCloner>(); evtCloner.evt = target.GetReactionAtIndex(rowIdx); var clone = Object.Instantiate(evtCloner); target.AddEmptyReaction(clone.evt); m_TreeView.dirty = true; PrefabUtility.RecordPrefabInstancePropertyModifications(target); }); menu.AddItem(new GUIContent(Styles.SignalListDeleteOption), false, () => { Undo.RecordObject(target, Styles.UndoDeleteRow); target.RemoveAtIndex(rowIdx); m_TreeView.dirty = true; PrefabUtility.RecordPrefabInstancePropertyModifications(target); }); menu.ShowAsContext(); } }
void OnEnable() { m_Target = target as SignalReceiver; m_SignalNameProperty = SignalReceiverUtility.FindSignalsProperty(serializedObject); m_EventsProperty = SignalReceiverUtility.FindEventsProperty(serializedObject); InitTreeView(m_SignalNameProperty, m_EventsProperty); }
private void SignalStrengthHandler(SignalReceiver receiver, SignalEmitter emitter, SignalDataSO signalDataSo, ISignalMessage signalMessage = null) { SignalStrength strength = GetStrength(receiver, emitter, signalDataSo.SignalRange); if (strength == SignalStrength.HEALTHY) { receiver.ReceiveSignal(strength, signalMessage); } if (strength == SignalStrength.TOOFAR) { emitter.SignalFailed(); } if (strength == SignalStrength.DELAYED) { StartCoroutine(DelayedSignalRecevie(receiver.DelayTime, receiver, strength, signalMessage)); return; } if (strength == SignalStrength.WEAK) { Random chance = new Random(); if (DMMath.Prob(chance.Next(0, 100))) { StartCoroutine(DelayedSignalRecevie(receiver.DelayTime, receiver, strength, signalMessage)); } emitter.SignalFailed(); } }
void OnEnable() { m_Target = target as SignalReceiver; InitTreeView(serializedObject); Undo.undoRedoPerformed += OnUndoRedo; }
/// <summary> /// Initialized loopback test /// </summary> public LoopbackTest() { _transmitter = new SignalTransmitter(); _receiver = new SignalReceiver(); _receiver.Message += new EventHandler <SignalReceiverEventArgs>(OnNewMessage); }
private void BindSignalReciever(SignalReceiver reciever) { SetPlayableDirector(); var binding = m_playableDirector.playableAsset.outputs.First(c => c.streamName.Contains("Signal")); m_playableDirector.SetGenericBinding(binding.sourceObject, reciever); }
private void button1_Click(object sender, EventArgs e) { var startDtSignalGenerator = new List <DateTime>(); var serialSignalGenerator = new SerialSignalGenerator("COM5"); serialSignalGenerator.dateTimes = startDtSignalGenerator; serialSignalGenerator.RunningMinutes = 1; var threadGenerator = new Thread(serialSignalGenerator.Start); var endDtSignalReceiver = new List <DateTime>(); var serialSignalReceiver = new SignalReceiver("COM6"); serialSignalReceiver.dateTimes = endDtSignalReceiver; var threadReceiver = new Thread(serialSignalReceiver.Start); threadReceiver.Start(); threadGenerator.Start(); threadGenerator.Join(); threadReceiver.Join(); var result = serialSignalGenerator.dateTimes.Zip(serialSignalReceiver.dateTimes).Select(tuple => { return((tuple.Second.Ticks - tuple.First.Ticks) * 100); }); var writer = new StreamWriter("result.txt"); foreach (var line in result) { writer.WriteLine(line); } writer.Flush(); writer.Close(); }
public SignalReceiverTreeView(TreeViewState state, MultiColumnHeader multiColumnHeader, SignalReceiver receiver, SerializedObject serializedObject) : base(state, multiColumnHeader) { m_Target = receiver; useScrollView = true; SetSerializedProperties(serializedObject); getNewSelectionOverride = (item, selection, shift) => new List<int>(); // Disable Selection }
public static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Transmitter = new SignalTransmitter(); Receiver = new SignalReceiver(); Application.Run(new MainWin()); }
protected virtual void DrawSignalNameColumn(Rect rect, float padding, SignalReceiver target, int rowIdx) { m_CurrentRowIdx = rowIdx; m_CurrentReceiver = target; rect.x += padding; rect.width -= padding; rect.height = EditorGUIUtility.singleLineHeight; SignalUtility.DrawSignalNames(this, rect, GUIContent.none, false); }
public SignalReceiverTreeView(TreeViewState state, MultiColumnHeader multiColumnHeader, SignalReceiver receiver, bool readonlySignal) : base(state, multiColumnHeader) { m_Target = receiver; var receiverSO = new SerializedObject(receiver); signals = SignalReceiverUtility.FindSignalsProperty(receiverSO); events = SignalReceiverUtility.FindEventsProperty(receiverSO); readonlySignals = readonlySignal; useScrollView = false; getNewSelectionOverride = (item, selection, shift) => new List <int>(); // Disable Selection }
private IEnumerator DelayedSignalRecevie(float waitTime, SignalReceiver receiver, SignalStrength strength, ISignalMessage signalMessage = null) { yield return(WaitFor.Seconds(waitTime)); if (receiver.gameObject == null) { //In case the object despawns before the signal reaches it yield break; } receiver.ReceiveSignal(strength, signalMessage); }
protected override void DrawSignalNameColumn(Rect rect, float padding, SignalReceiver target, int rowIdx) { var prevState = GUI.enabled; GUI.enabled = enabled; var signalAsset = m_Asset.objectReferenceValue; GUI.Label(rect, signalAsset != null ? EditorGUIUtility.TrTempContent(signalAsset.name) : Styles.EmptySignalList); GUI.enabled = prevState; }
public static void AddNewReaction(this SignalReceiver receiver, SignalAsset signalAsset) { if (signalAsset != null && receiver != null) { Undo.RecordObject(receiver, Styles.UndoAddReaction); var newEvent = new UnityEvent(); newEvent.AddPersistentListener(); var evtIndex = newEvent.GetPersistentEventCount() - 1; newEvent.RegisterVoidPersistentListenerWithoutValidation(evtIndex, receiver.gameObject, string.Empty); receiver.AddReaction(signalAsset, newEvent); PrefabUtility.RecordPrefabInstancePropertyModifications(receiver); } }
public static void AddNewReaction(this SignalReceiver receiver, SignalAsset signalAsset) { if (signalAsset != null && receiver != null) { Undo.RegisterCompleteObjectUndo(receiver, Styles.UndoAddReaction); var newEvent = new UnityEvent(); newEvent.AddPersistentListener(); var evtIndex = newEvent.GetPersistentEventCount() - 1; newEvent.RegisterVoidPersistentListenerWithoutValidation(evtIndex, receiver.gameObject, string.Empty); receiver.AddReaction(signalAsset, newEvent); } }
public void Draw(Rect rect, int colIdx, int rowIdx, float padding, SignalReceiver target) { switch (colIdx) { case 0: DrawSignalNameColumn(rect, padding, target, rowIdx); break; case 1: DrawReactionColumn(rect, rowIdx); break; default: throw new ArgumentOutOfRangeException(); } }
private bool MatchingEncryption(SignalReceiver receiver, SignalEmitter emitter) { if (receiver.EncryptionData == null) { return(true); } if (emitter.EncryptionData == null) { return(false); } if (emitter.EncryptionData.EncryptionSecret != receiver.EncryptionData.EncryptionSecret) { return(false); } return(true); }
public void AddSignalReciever() { m_signals = Resources.LoadAll(m_signalResourcePath, typeof(SignalAsset)); SignalReceiver reciever = this.gameObject.AddComponent <SignalReceiver>(); for (int i = 0; i < m_signals.Length; i++) { var ts = m_signals[i] as SignalAsset; UnityEvent evt = new UnityEvent(); UnityAction <SignalAsset> action = new UnityAction <SignalAsset>(_OnSignal); //UnityEditor.Events.UnityEventTools.RemovePersistentListener<SignalAsset>(evt, action); UnityEditor.Events.UnityEventTools.AddObjectPersistentListener <SignalAsset>(evt, action, ts); evt.SetPersistentListenerState(0, UnityEngine.Events.UnityEventCallState.EditorAndRuntime); // This one needs to add here instead of adding this after the UnityEvent instance. reciever.AddReaction(ts, evt); } BindSignalReciever(reciever); }
/// <summary> /// gets the signal strength between a receiver and an emitter /// the further the object is the weaker the signal. /// </summary> /// <returns>SignalStrength</returns> public SignalStrength GetStrength(SignalReceiver receiver, SignalEmitter emitter, int range) { int distance = (int)Vector3.Distance(receiver.gameObject.AssumedWorldPosServer(), emitter.gameObject.AssumedWorldPosServer()); if (range / 4 <= distance) { return(SignalStrength.DELAYED); } if (range / 2 <= distance) { return(SignalStrength.WEAK); } if (distance > range) { return(SignalStrength.TOOFAR); } return(SignalStrength.HEALTHY); }
static void Main(string[] args) { var endDtSignalReceiver = new List <DateTime>(); var serialSignalReceiver = new SignalReceiver("COM6"); serialSignalReceiver.RunningMinutes = 1; serialSignalReceiver.dateTimes = endDtSignalReceiver; var threadReceiver = new Thread(serialSignalReceiver.Start); threadReceiver.Start(); threadReceiver.Join(); var writer = new StreamWriter("result.txt"); foreach (var line in serialSignalReceiver.dateTimes) { writer.WriteLine(line.Ticks * 100); } writer.Flush(); writer.Close(); }
public static SignalReceiverTreeView CreateSignalInspectorList(TreeViewState state, MultiColumnHeaderState columnState, SignalReceiver target, int columnHeight, bool readonlySignal) { var header = new SignalReceiverHeader(columnState) { height = columnHeight }; header.ResizeToFit(); return(new SignalReceiverTreeView(state, header, target, readonlySignal)); }
public SignalInspectorList(TreeViewState state, MultiColumnHeader multiColumnHeader, SignalReceiver receiver) : base(state, multiColumnHeader, receiver) { }
public static SignalReceiverTreeView CreateSignalInspectorList(TreeViewState state, SignalReceiverHeader header, SignalReceiver target, SerializedObject so) { return(new SignalReceiverTreeView(state, header, target, so)); }
public static bool IsSignalAssetHandled(this SignalReceiver receiver, SignalAsset asset) { return(receiver != null && asset != null && receiver.GetRegisteredSignals().Contains(asset)); }
protected SignalList(TreeViewState state, MultiColumnHeader multiColumnHeader, SignalReceiver receiver) : base(state, multiColumnHeader) { m_Target = receiver; useScrollView = false; getNewSelectionOverride = (item, selection, shift) => new List <int>(); // Disable Selection }
private bool AreOnTheSameFrequancy(SignalReceiver receiver, SignalEmitter emitter) { return(Mathf.Approximately(receiver.Frequency, emitter.Frequency)); }
public void Emit() { SignalReceiver.Signal(channel, message, distance, transform.position); }
protected override void DrawOptionsColumn(Rect rect, int rowIdx, SignalReceiver target) { }