private static void DrawGizmoConnection(IMultitoolMasterable device, GizmoType type) { DeviceLinker.InitDeviceLists(device.ConType); Gizmos.color = LinkColors.TryGetValue(device.ConType, out var color) ? color : Color.green; foreach (IMultitoolSlaveable slave in DeviceLinker.Slaves) { if (slave.Master != device) { continue; } GizmoUtils.DrawArrow( device.gameObject.transform.position, slave.gameObject.transform.position - device.gameObject.transform.position, false); } Gizmos.DrawSphere(device.gameObject.transform.position, 0.15f); }
public override void OnInspectorGUI() { // Render default inspector for the component. base.OnInspectorGUI(); EditorGUILayout.HelpBox("You can connect all slave devices at once via\n`Tools/Mapping/Device Linker`.", MessageType.Info); // Don't show connection elements; not relevant to runtime or prefab edit mode. if (Application.isPlaying || PrefabStageUtility.GetCurrentPrefabStage() != null) { return; } DeviceLinker.InitDeviceLists(thisDevice.ConType); if (thisDevice.RequireLink && thisDevice.Master == null) { EditorGUILayout.HelpBox("Not connected to any master device!", MessageType.Warning); } GUILayout.Label("Connect to a master device:"); GUILayout.BeginHorizontal(); if (GUILayout.Button("Closest")) { closestMasterDistance = DeviceLinker.TryLinkSlaveToClosestMaster(thisDevice); Save(); } if (thisDevice.Master != null) { if (GUILayout.Button("Closer")) { DeviceLinker.TryLinkToNextMaster(thisDevice, -1); Save(); } else if (GUILayout.Button("Further")) { DeviceLinker.TryLinkToNextMaster(thisDevice, 1); Save(); } } GUILayout.EndHorizontal(); if (closestMasterDistance == -1) { GUILayout.Label($"No master devices found!", EditorUIUtils.LabelStyle); } else if (closestMasterDistance > DeviceLinker.Masters[0].MaxDistance) { GUILayout.Label($"Closest master device is <b>{closestMasterDistance, 0:N}</b> tiles away, " + $"but this exceeds the maximum distance of <b>{DeviceLinker.Masters[0].MaxDistance}</b>!", EditorUIUtils.LabelStyle); } if (thisDevice.Master != null) { GUILayout.BeginHorizontal(); var distance = Vector3.Distance(thisDevice.gameObject.transform.position, thisDevice.Master.gameObject.transform.position); GUILayout.Label($"Connected to <b>{thisDevice.Master.gameObject.name}</b> " + $"(distance of <b>{distance, 0:N}</b> tiles).", EditorUIUtils.LabelStyle); if (GUILayout.Button("Clear", GUILayout.Width(EditorGUIUtility.currentViewWidth / 4))) { thisDevice.SetMasterEditor(null); Save(); } GUILayout.EndHorizontal(); } }
private void OnEnable() { DeviceLinker.InitDeviceLists(((IMultitoolMasterable)target).ConType, forceRefresh: true); }
private void OnEnable() { thisDevice = (IMultitoolSlaveable)target; DeviceLinker.InitDeviceLists(thisDevice.ConType, forceRefresh: true); }