private static void DrawGizmoConnection(IMultitoolSlaveable device, GizmoType type)
        {
            if (PrefabStageUtility.GetCurrentPrefabStage() != null)
            {
                return;                                                                 // Don't show in prefab mode.
            }
            if (type.HasFlag(GizmoType.Selected) || type.HasFlag(GizmoType.Active))
            {
                if (device.Master == null)
                {
                    return;
                }

                Gizmos.color = MasterDeviceInspector.LinkColors.TryGetValue(device.ConType, out var color) ? color : Color.green;
                GizmoUtils.DrawArrow(
                    device.Master.gameObject.transform.position,
                    device.gameObject.transform.position - device.Master.gameObject.transform.position,
                    false);
                Gizmos.DrawSphere(device.Master.gameObject.transform.position, 0.15f);
            }
            else if (type.HasFlag(GizmoType.NonSelected))
            {
                if (device.RequireLink == false || device.Master != null)
                {
                    return;
                }

                string icon = disconnectedGizmoIcons.TryGetValue(device.ConType, out var filename) ? filename : "no-wifi";
                Gizmos.DrawIcon(device.gameObject.transform.position, icon);
            }
        }
예제 #2
0
        /// <summary>
        /// Links the given slave device to the closest master device.
        /// <para>If the distance to the closest master device exceeds the multitool connection's range,
        /// then the slave's master device will be set as <c>null</c>.</para>
        /// <remarks><see cref="InitDeviceLists(MultitoolConnectionType)"/> is assumed to have been run.</remarks>
        /// </summary>
        /// <returns>The distance to the closest master device, connected or not. <c>-1</c> if no masters found.</returns>
        public static float TryLinkSlaveToClosestMaster(IMultitoolSlaveable slave)
        {
            if (Masters.Count < 1)
            {
                return(-1);
            }

            SortMastersToPosition(slave.gameObject.transform.position);

            float distance = Vector3.Distance(slave.gameObject.transform.position, Masters[0].gameObject.transform.position);

            slave.SetMasterEditor(distance > Masters[0].MaxDistance ? null : Masters[0]);

            return(distance);
        }
예제 #3
0
        /// <summary>
        /// Links the given slave device to the next master device in the given direction.
        /// <para>If the distance to the closest master device exceeds the multitool connection's range,
        /// then no action will take place.</para>
        /// <remarks><see cref="InitDeviceLists(MultitoolConnectionType)"/> is assumed to have been run.</remarks>
        /// </summary>
        /// <param name="direction">Expecting <c>1</c> for the next closest device, <c>-1</c> for closer.</param>
        /// <returns>The distance to the next master device. <c>-1</c> if no masters found.</returns>
        public static float TryLinkToNextMaster(IMultitoolSlaveable slave, int direction)
        {
            if (Masters.Count < 1)
            {
                return(-1);
            }

            SortMastersToPosition(slave.gameObject.transform.position);

            var index = slave.Master == null ? 0 : Masters.IndexOf(slave.Master);

            index = Mathf.Clamp(index + direction, 0, Masters.Count - 1);
            var master   = Masters[index];
            var distance = Vector3.Distance(slave.gameObject.transform.position, master.gameObject.transform.position);

            if (distance <= master.MaxDistance)
            {
                slave.SetMasterEditor(master);
            }

            return(distance);
        }
        private void OnEnable()
        {
            thisDevice = (IMultitoolSlaveable)target;

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