Exemplo n.º 1
0
        private void actionCard_BindingContextChanged(object sender, EventArgs e)
        {
            if (actionCard.BindingContext == null)
            {
                return;
            }

            // Create device view instance based on BindingContext type
            actionCard.InnerContent = DeviceLinker.GetDeviceViewForViewModel(actionCard.BindingContext.GetType());
            actionCard.InnerContent.BindingContext = actionCard.BindingContext;
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public RoomViewModel(RoomModel roomModel)
        {
            RoomModel        = roomModel;
            Background       = GetImage();
            DeviceViewModels = new ObservableCollection <IDeviceViewModel>();

            SelectDeviceCommand = new Command <string>((string deviceId) => {
                if (deviceId == null)
                {
                    return;
                }

                var deviceEnumerator = DeviceViewModels.Where((IDeviceViewModel deviceViewModel) => {
                    return(deviceViewModel.Id.Equals(deviceId));
                });

                SelectedDeviceViewModel = deviceEnumerator.First();
            });

            foreach (IDeviceModel deviceModel in RoomModel.Devices)
            {
                DeviceViewModels.Add(DeviceLinker.GetDeviceViewModelForModel(deviceModel));
            }
        }
Exemplo n.º 4
0
 private void OnEnable()
 {
     DeviceLinker.InitDeviceLists(((IMultitoolMasterable)target).ConType, forceRefresh: true);
 }
        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()
        {
            thisDevice = (IMultitoolSlaveable)target;

            DeviceLinker.InitDeviceLists(thisDevice.ConType, forceRefresh: true);
        }