Esempio n. 1
0
        /// <summary>
        /// A function called when the plugin is loaded.
        /// </summary>
        /// <param name="fileSystem">The instance of FileSytem class</param>
        /// <returns>Whether the plugin has been loaded successfully.</returns>
        public bool Load(FileSystem fileSystem)
        {
            FileSystem = fileSystem;
            //HACK: In order to avoid meddling with a shipped interface (or making this field public and increasing the mess), let's grab it via reflection
            CurrentHost = (HostInterface)typeof(FileSystem).GetField("currentHost", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(fileSystem);

            if (loading)
            {
                InputTranslator.Load();
            }

            // Start thread for LibUsb-based controllers
            LibUsb.LibUsbThread = new Thread(LibUsb.LibUsbLoop);
            LibUsb.LibUsbThread.Start();

            // Initialize the array of button properties
            for (int i = 0; i < ButtonProperties.Length; i++)
            {
                ButtonProperties[i] = new ButtonProp();
            }

            // Load settings from the config file
            LoadConfig();

            // Create the config form
            configForm = new Config();

            // Define the list of commands
            // We allocate 50 slots per handle plus one slot per command
            int commandCount = Translations.CommandInfos.Length;

            Controls = new InputControl[100 + commandCount];
            // Brake notches
            for (int i = 0; i < 50; i++)
            {
                Controls[i].Command = Translations.Command.BrakeAnyNotch;
                Controls[i].Option  = i;
            }
            // Power notches
            for (int i = 50; i < 100; i++)
            {
                Controls[i].Command = Translations.Command.PowerAnyNotch;
                Controls[i].Option  = i - 50;
            }
            // Other commands
            for (int i = 0; i < commandCount; i++)
            {
                Controls[i + 100].Command = (Translations.Command)i;
            }

            // Configure the mappings for the buttons and notches
            ConfigureMappings();

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// A function called when the plugin is loaded.
        /// </summary>
        /// <param name="fileSystem">The instance of FileSytem class</param>
        /// <returns>Whether the plugin has been loaded successfully.</returns>
        public bool Load(FileSystem fileSystem)
        {
            FileSystem = fileSystem;

            // Initialize the array of button properties
            for (int i = 0; i < ButtonProperties.Length; i++)
            {
                ButtonProperties[i] = new ButtonProp();
            }

            // Load settings from the config file
            LoadConfig();

            // Create the config form
            configForm = new Config();

            // Define the list of commands
            // We allocate 50 slots per handle plus one slot per command
            int commandCount = Translations.CommandInfos.Length;

            Controls = new InputControl[100 + commandCount];
            // Brake notches
            for (int i = 0; i < 50; i++)
            {
                Controls[i].Command = Translations.Command.BrakeAnyNotch;
                Controls[i].Option  = i;
            }
            // Power notches
            for (int i = 50; i < 100; i++)
            {
                Controls[i].Command = Translations.Command.PowerAnyNotch;
                Controls[i].Option  = i - 50;
            }
            // Other commands
            for (int i = 0; i < commandCount; i++)
            {
                Controls[i + 100].Command = (Translations.Command)i;
            }

            // Configure the mappings for the buttons and notches
            ConfigureMappings();

            return(true);
        }
Esempio n. 3
0
    private void RaycastForProp(bool fire)
    {
        LayerMask  hitMask = LayerMask.GetMask("Prop", "Default");
        RaycastHit hit;
        Ray        ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f));

        Debug.DrawRay(ray.origin, ray.direction, Color.yellow, 0.1f);
        if (Physics.Raycast(ray, out hit, raycastDistance, hitMask))
        {
            Debug.DrawRay(ray.origin, ray.direction, Color.red, 0.1f);
            Prop        prop   = hit.collider.GetComponentInParent <Prop>();
            ButtonProp  button = hit.collider.GetComponentInParent <ButtonProp>();
            PowerSource source = hit.collider.GetComponentInParent <PowerSource>();
            if (prop != null)
            {
                if (!prop.HeavyObject)
                {
                    InGame_Interface.instance.ChangeCrosshair(Color.cyan);
                }

                if (fire)
                {
                    if (prop.HeavyObject)
                    {
                        prop.Push((prop.transform.position - transform.position) * throwForce);
                    }
                    else
                    {
                        if (source != null)
                        {
                            if (source.parentSocket == null || (source.parentSocket != null && !source.parentSocket.lockPower))
                            {
                                if (source.parentSocket != null)
                                {
                                    source.parentSocket.DisablePowerSource();
                                }
                                source.playerHolding = this;
                                heldProp             = prop.PickUp();
                                pickUpRot            = heldProp.transform.rotation;
                                InGame_Interface.instance.ChangeCrosshair(Color.cyan);
                            }
                        }
                        else
                        {
                            heldProp  = prop.PickUp();
                            pickUpRot = heldProp.transform.rotation;
                            InGame_Interface.instance.ChangeCrosshair(Color.cyan);
                        }
                    }
                }
            }
            else if (button != null)
            {
                if (button.CanBeActivated())
                {
                    InGame_Interface.instance.ChangeCrosshair(Color.green);
                }
                else
                {
                    InGame_Interface.instance.ChangeCrosshair(Color.yellow);
                }

                if (fire && button.CanBeActivated())
                {
                    button.Activate();
                }
            }
            else
            {
                InGame_Interface.instance.ChangeCrosshair(Color.gray);
            }
        }
        else
        {
            Debug.DrawRay(ray.origin, ray.direction, Color.yellow, 0.1f);
            InGame_Interface.instance.ChangeCrosshair(Color.gray);
        }
    }