<commit_before>﻿using Leap.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Valve.VR;
using VRGIN.Controls;
using VRGIN.Controls.LeapMotion;
using VRGIN.Controls.Speech;
using VRGIN.Core;
using VRGIN.Helpers;
using VRGIN.U46.Controls.Leap;
using VRGIN.Visuals;

namespace VRGIN.Modes
{
    public enum ImpersonationMode
    {
        Approximately,
        Exactly
    }

    public abstract class ControlMode : ProtectedBehaviour
    {
        private static bool _ControllerFound = false;

        public virtual void Impersonate(IActor actor)
        {
            this.Impersonate(actor, ImpersonationMode.Approximately);
        }

        public virtual void Impersonate(IActor actor, ImpersonationMode mode)
        {
            if (actor != null)
            {
                actor.HasHead = false;
            }
        }

        public abstract ETrackingUniverseOrigin TrackingOrigin { get; }

        /// <summary>
        /// Gets the left controller.
        /// </summary>
        public Controller Left { get; private set; }

        /// <summary>
        /// Gets the right controller.
        /// </summary>
        public Controller Right { get; private set; }

        /// <summary>
        /// Gets the left hand.
        /// </summary>
        public HandAttachments LeftHand { get; private set; }

        /// <summary>
        /// Gets the left hand.
        /// </summary>
        public HandModel LeftGraphicalHand { get; private set; }


        /// <summary>
        /// Gets the right hand.
        /// </summary>
        public HandAttachments RightHand { get; private set; }

        public HandModel RightGraphicalHand { get; private set; }


        public LeapServiceProvider LeapMotion { get; private set; }

        protected IEnumerable<IShortcut> Shortcuts { get; private set; }

        protected SteamVR_ControllerManager ControllerManager;
        internal event EventHandler<EventArgs> ControllersCreated = delegate { };

        protected override void OnStart()
        {
            CreateControllers();

            Shortcuts = CreateShortcuts();
            SteamVR_Render.instance.trackingSpace = TrackingOrigin;
        }

        protected virtual void OnEnable()
        {
            SteamVR_Utils.Event.Listen("device_connected", OnDeviceConnected);
        }

        protected virtual void OnDisable()
        {
            SteamVR_Utils.Event.Listen("device_connected", OnDeviceConnected);
        }

        static int cnter = 0;
        /// <summary>
        /// Creates both controllers by using <see cref="CreateRightController"/> and <see cref="CreateLeftController"/>.
        /// Override those methods to change the controller implementation to be used.
        /// </summary>
        protected virtual void CreateControllers()
        {
            var steamCam = VR.Camera.SteamCam;

            steamCam.origin.gameObject.SetActive(false);
            {
                ControllerManager = steamCam.origin.gameObject.AddComponent<SteamVR_ControllerManager>();

                if (VR.Settings.Leap)
                {
                    LeapMotion = CreateLeapHandController();
                    LeapMotion.transform.name = "Leap Motion Controller (" + (++cnter) + ")";
                    LeapMotion.transform.SetParent(steamCam.head.transform, false);
                    LeapMotion.transform.localRotation = Quaternion.Euler(-90f, 180f, 0);
                    LeapMotion.transform.localPosition += Vector3.forward * 0.08f;
                }

                Left = CreateLeftController();
                Left.transform.SetParent(steamCam.origin);

                Right = CreateRightController();
                Right.transform.SetParent(steamCam.origin);

                Left.Other = Right;
                Right.Other = Left;

                ControllerManager.left = Left.gameObject;
                ControllerManager.right = Right.gameObject;
            }
            steamCam.origin.gameObject.SetActive(true);

            VRLog.Info("---- Initialize left tools");
            InitializeTools(Left, true);

            VRLog.Info("---- Initialize right tools");
            InitializeTools(Right, false);

            ControllersCreated(this, new EventArgs());
        }

        private LeapServiceProvider CreateLeapHandController()
        {
            var serviceProvider = new GameObject("LeapHandController").AddComponent<LeapServiceProvider>();
            var handController = serviceProvider.gameObject.AddComponent<LeapHandController>();
            var handPool = handController.gameObject.AddComponent<HandPool>();
            handController.gameObject.AddComponent<PinchController>();
            serviceProvider._isHeadMounted = true;

            LeftGraphicalHand = BuildGraphicalHand(Chirality.Left);<commit_msg>Make sure that the controllers are always scaled 1.0<commit_after>﻿using Leap.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Valve.VR;
using VRGIN.Controls;
using VRGIN.Controls.LeapMotion;
using VRGIN.Controls.Speech;
using VRGIN.Core;
using VRGIN.Helpers;
using VRGIN.U46.Controls.Leap;
using VRGIN.Visuals;

namespace VRGIN.Modes
{
    public enum ImpersonationMode
    {
        Approximately,
        Exactly
    }

    public abstract class ControlMode : ProtectedBehaviour
    {
        private static bool _ControllerFound = false;

        public virtual void Impersonate(IActor actor)
        {
            this.Impersonate(actor, ImpersonationMode.Approximately);
        }

        public virtual void Impersonate(IActor actor, ImpersonationMode mode)
        {
            if (actor != null)
            {
                actor.HasHead = false;
            }
        }

        public abstract ETrackingUniverseOrigin TrackingOrigin { get; }

        /// <summary>
        /// Gets the left controller.
        /// </summary>
        public Controller Left { get; private set; }

        /// <summary>
        /// Gets the right controller.
        /// </summary>
        public Controller Right { get; private set; }

        /// <summary>
        /// Gets the left hand.
        /// </summary>
        public HandAttachments LeftHand { get; private set; }

        /// <summary>
        /// Gets the left hand.
        /// </summary>
        public HandModel LeftGraphicalHand { get; private set; }


        /// <summary>
        /// Gets the right hand.
        /// </summary>
        public HandAttachments RightHand { get; private set; }

        public HandModel RightGraphicalHand { get; private set; }


        public LeapServiceProvider LeapMotion { get; private set; }

        protected IEnumerable<IShortcut> Shortcuts { get; private set; }

        protected SteamVR_ControllerManager ControllerManager;
        internal event EventHandler<EventArgs> ControllersCreated = delegate { };

        protected override void OnStart()
        {
            CreateControllers();

            Shortcuts = CreateShortcuts();
            SteamVR_Render.instance.trackingSpace = TrackingOrigin;
        }

        protected virtual void OnEnable()
        {
            SteamVR_Utils.Event.Listen("device_connected", OnDeviceConnected);
        }

        protected virtual void OnDisable()
        {
            SteamVR_Utils.Event.Listen("device_connected", OnDeviceConnected);
        }

        static int cnter = 0;
        /// <summary>
        /// Creates both controllers by using <see cref="CreateRightController"/> and <see cref="CreateLeftController"/>.
        /// Override those methods to change the controller implementation to be used.
        /// </summary>
        protected virtual void CreateControllers()
        {
            var steamCam = VR.Camera.SteamCam;

            steamCam.origin.gameObject.SetActive(false);
            {
                ControllerManager = steamCam.origin.gameObject.AddComponent<SteamVR_ControllerManager>();

                if (VR.Settings.Leap)
                {
                    LeapMotion = CreateLeapHandController();
                    LeapMotion.transform.name = "Leap Motion Controller (" + (++cnter) + ")";
                    LeapMotion.transform.SetParent(steamCam.head.transform, false);
                    LeapMotion.transform.localRotation = Quaternion.Euler(-90f, 180f, 0);
                    LeapMotion.transform.localPosition += Vector3.forward * 0.08f;
                }

                Left = CreateLeftController();
                Left.transform.SetParent(steamCam.origin, false);

                Right = CreateRightController();
                Right.transform.SetParent(steamCam.origin, false);

                Left.Other = Right;
                Right.Other = Left;

                ControllerManager.left = Left.gameObject;
                ControllerManager.right = Right.gameObject;
            }
            steamCam.origin.gameObject.SetActive(true);

            VRLog.Info("---- Initialize left tools");
            InitializeTools(Left, true);

            VRLog.Info("---- Initialize right tools");
            InitializeTools(Right, false);

            ControllersCreated(this, new EventArgs());
        }

        private LeapServiceProvider CreateLeapHandController()
        {
            var serviceProvider = new GameObject("LeapHandController").AddComponent<LeapServiceProvider>();
            var handController = serviceProvider.gameObject.AddComponent<LeapHandController>();
            var handPool = handController.gameObject.AddComponent<HandPool>();
            handController.gameObject.AddComponent<PinchController>();
            serviceProvider._isHeadMounted = true;

            LeftGraphicalHand = BuildGraphicalHand(Chirality.Left);
{'fraction_non_alphanumeric': 0.09296405661337949, 'fraction_numerical': 0.002851033499643621, 'mean_word_length': 2.022153846153846, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6243169', 'n_tokens_mistral': 2540, 'n_tokens_neox': 2394, 'n_words': 567}