Inheritance: MonoBehaviour
示例#1
0
        public void Init()
        {
            FileInfo logFile = new System.IO.FileInfo("Log4Net.config");
            if (logFile.Exists)
            {
                // Log4Net is configured using a DOMConfigurator.
                log4net.Config.XmlConfigurator.Configure(logFile);
            }
            else
            {
                // Set up a simple configuration that logs on the console.
                log4net.Config.BasicConfigurator.Configure();
            }

            // Log an baseInfo level message
            if (log.IsDebugEnabled)
            {
                if (string.IsNullOrEmpty(System.Threading.Thread.CurrentThread.Name))
                    System.Threading.Thread.CurrentThread.Name = "Main(" + System.Threading.Thread.CurrentThread.ManagedThreadId + ")";
                log.Debug("Interaction Tests Start");
            }

            descriptorManager.AddBootstrapDescriptors(Sxta1516.ResourcesNames.BootstrapObjectModel);

            reliableChannel = new XrtiChannel(channel);
            Dictionary<TransportationType, XrtiChannel> channelList = new Dictionary<TransportationType, XrtiChannel>();
            channelList[TransportationType.HLA_RELIABLE] = reliableChannel;
            channelList[TransportationType.HLA_BEST_EFFORT] = reliableChannel;
            helper = new InteractionManager(descriptorManager, channelList);

            myListener = new MyTestBootstrapObjectListener(syncObject);
            helper.AddInteractionListener(myListener);
        }
 // Use this for initialization
 void Awake()
 {
     startTime = 0f;
     timeBar = GetComponent<Slider> ();
     timeLabel = GetComponentInChildren<Text> ();
     InteractionManager.instance = this;
 }
 // Use this for initialization
 void Start()
 {
     interaction1 = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<InteractionManager>();
     grabScript = GameObject.FindGameObjectWithTag ("MainCamera").GetComponent<GrabDropScript>();
     active = false;
     gameOver = false;
 }
 // Init.
 void Awake()
 {
     _collider = GetComponent<Collider> ();
     _renderer = GetComponent<Renderer> ();
     _im = GetComponent<InteractionManager> ();
     _camera = GameObject.FindWithTag ("Player").GetComponentInChildren<Camera> ();
     _im.onAwake ();
 }
    // Update is called once per frame
    void Update()
    {
        if (manager == null)
        {
            manager = InteractionManager.Instance;
        }
        if (manager != null && manager.IsInteractionInited())
        {
            if (manager.IsLeftHandPrimary() &&  Entered)
            {
                // if the left hand is primary, check for left hand grip
                if (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Grip && LeftHand == LastEnteredCollider.gameObject)
                {
                    isLeftHandDrag = true;
                    HandObject = LeftHand;
                    Debug.Log("Left grip");
                    MyCollider.isTrigger = false;

                }
            }
            else if (manager.IsRightHandPrimary() && Entered)
            {
                // if the right hand is primary, check for right hand grip
                if (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Grip && RightHand == LastEnteredCollider.gameObject)
                {
                    isRightHandDrag = true;
                    HandObject = RightHand;
                    Debug.Log("Right grip");
                    MyCollider.isTrigger = false;
                    MyCollider.isTrigger = false;

                }
            }
            if (HandObject != null)
            {
                bool isReleased = isLeftHandDrag ? (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Release) :
                       (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Release);
                if (isReleased)
                {
                    isLeftHandDrag = false;
                    isRightHandDrag = false;
                    HandObject = null;
                    MyCollider.isTrigger = true;
                    Debug.Log("Release");
                }
            }
        }
        if (HandObject != null)
        {
            gameObject.transform.position = //HandObject.transform.position;
            new Vector3(HandObject.transform.position.x ,
                HandObject.transform.position.y ,
                HandObject.transform.position.z + transform.localScale.z / 2);
            //gameObject.transform.localRotation = HandObject.transform.rotation;
        }
    }
 // Use this for initialization
 void Start()
 {
     //initialize inner processes vars
     player = GameObject.FindGameObjectWithTag ("MainCamera").gameObject;
     playerCamera = player.GetComponent<Camera>();
     //waypointManager = GameObject.FindGameObjectWithTag ("WaypointHelpers").GetComponent<WaypointManager>();
     //animator = GetComponent<Animator>();
     interactionManager = GameObject.FindGameObjectWithTag ("GameController").GetComponent<InteractionManager>();
     Debug.Log (interactionManager.name);
 }
    private Transform thisTransform; //camera's transform

    #endregion Fields

    #region Methods

    void Start()
    {
        cameraWidthPx = Camera.main.pixelWidth;
        cameraHeightPx = Camera.main.pixelHeight;
        initialTargetX = cameraTarget.transform.position.x;
        initialTargetY = cameraTarget.transform.position.y;

        thisTransform = this.transform;
        intManager = GameObject.FindWithTag("kinect-interaction").GetComponent<InteractionManager>();
    }
示例#8
0
    // Use this for initialization
    IEnumerator Start()
    {
        FireballParticles.enableEmission = false;
        FireballCoreParticles.enableEmission = false;

        while (KManager == null && IManager == null)
        {
            KManager = KinectManager.Instance;
            IManager = InteractionManager.Instance;
        }

        yield return null;
    }
    void Start()
    {
        GameObject playerGameObject = GameObject.Find("hero");					//get player and set to pProp
        pProp = playerGameObject.GetComponent<PlayerProperties>();

        speechManager = GameObject.FindWithTag("kinect-speech").GetComponent<SpeechManager>();
        intManager = GameObject.FindWithTag("kinect-interaction").GetComponent<InteractionManager>();
        heartIcon = GameObject.Find("heart_icon").GetComponent<GUITexture>();

        //coins and lives are slightly bigger if using a larger screen
        livesText.fontSize = Screen.width/40;
        if (livesText.fontSize < 20) livesText.fontSize = 20; //impose min size restriction
        coinsText.fontSize = livesText.fontSize;
    }
    // Use this for initialization
    void Start()
    {
        //anObject=GameObject.Find("GameManager");
        if(manager==null)
        manager = InteractionManager.Instance;
        if (GetComponent<Collider> () == null) {

            box2D = GetComponent<Collider2D> ();
        } else
            box = GetComponent<Collider> ();
        depth = -Camera.main.transform.position.z  + transform.position.z;

        if (gManager == null)
            gManager = GameManager.Instance();
    }
示例#11
0
    // Use this for initialization
    public virtual void Start()
    {
        inZone = false;
        buttonDownTime = 0.0f;
        //Debug.Log(GameObject.FindGameObjectWithTag("Player"));
        //Debug.Log(GameObject.FindGameObjectWithTag("Player").GetComponent<InteractionManager>());
        interactionManager = GameObject.FindGameObjectWithTag("Player").GetComponent<InteractionManager>();
        interactionTimer = GameObject.Find("InteractionTimer").GetComponent<InteractionTimer>();

        displayName = "TestObject";

        lootTables = new Item[0][];
        lootFrequencyTables = new int[0][];

        numberOfItemsDropped = new int[0];
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="core"></param>
    public Interaction(Core core)
    {
        this.core = core;

        this.isLeftHandGripped = false;
        this.isLeftHandReleased = false;
        this.isRightHandGripped = false;
        this.isRightHandReleased = false;

        this.manager = core.GetComponent<InteractionManager>();

        this.leftHandGUITexture = GameObject.Find("LeftHand").GetComponent<GUITexture>();
        this.rightHandGUITexture = GameObject.Find("RightHand").GetComponent<GUITexture>();

        this.interactionObjects = new List<InteractionObject>();

        this.core.StartCoroutine(this.update());
    }
示例#13
0
    void Awake()
    {
        #region singleton
        if(instance == null)
        {
            instance = this;
        }
        else if(instance != this)
        {
            Destroy(gameObject);
        }
        #endregion

        #region component initializations
        pause			= GetComponent<PauseMenu>();
        notebook		= gameObject.GetComponentInChildren<NoteBook>();
        movement 		= GetComponent<MovementManager> ();
        interaction		= GetComponent<InteractionManager> ();
        #endregion
    }
示例#14
0
    // Update is called once per frame
    void Update()
    {
        if ((manager != null && manager.IsInteractionInited()) && (Kmanager != null) && (!manager.IsSceneReady()))
        {

            if (!manager.isPlayerDetected())
            {
                Idle_Timer += Time.deltaTime;
                //DebugGUI.guiText.text = "Idle : " + Idle_Timer.ToString();
                if (Idle_Timer > 5.0f)
                {
                    Idle_Timer = 0;
                    PlayerPrefs.SetInt("prodPlayAgain", 0); // Enables the splash screen on load
                    Application.LoadLevel(Application.loadedLevelName);
                }
            }
            else
                Idle_Timer = 0;

            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                Kmanager.SensorAngle += 2;
                KinectWrapper.NuiCameraElevationSetAngle(Kmanager.SensorAngle);
            }
            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                Kmanager.SensorAngle -= 2;
                KinectWrapper.NuiCameraElevationSetAngle(Kmanager.SensorAngle);
            }

        }
        else
        {
            if (manager == null)
              manager = InteractionManager.Instance;
            if (Kmanager == null)
              Kmanager = KinectManager.Instance;
        }
    }
示例#15
0
 void Awake()
 {
     highlight = GetComponent<Light>();
     highlight.enabled = false;
     interaction = GameObject.FindGameObjectWithTag("Player").GetComponent<InteractionManager>();
 }
 void Awake()
 {
     manager = GetComponent<InteractionManager>();
     handCursor = GameObject.Find("HandCursor");
     speechManager = GameObject.FindWithTag("kinect-speech").GetComponent<SpeechManager>();
 }
示例#17
0
    /// <summary>
    /// Updates the avatar each frame.
    /// </summary>
    /// <param name="UserID">User ID</param>
    public void UpdateAvatar(Int64 UserID)
    {
        if (!gameObject.activeInHierarchy)
        {
            return;
        }

        // Get the KinectManager instance
        if (kinectManager == null)
        {
            kinectManager = KinectManager.Instance;
        }

        // move the avatar to its Kinect position
        if (!externalRootMotion)
        {
            MoveAvatar(UserID);
        }

        // get the left hand state and event
        if (kinectManager && kinectManager.GetJointTrackingState(UserID, (int)KinectInterop.JointType.HandLeft) != KinectInterop.TrackingState.NotTracked)
        {
            KinectInterop.HandState          leftHandState = kinectManager.GetLeftHandState(UserID);
            InteractionManager.HandEventType leftHandEvent = InteractionManager.HandStateToEvent(leftHandState, lastLeftHandEvent);

            if (leftHandEvent != InteractionManager.HandEventType.None)
            {
                lastLeftHandEvent = leftHandEvent;
            }
        }

        // get the right hand state and event
        if (kinectManager && kinectManager.GetJointTrackingState(UserID, (int)KinectInterop.JointType.HandRight) != KinectInterop.TrackingState.NotTracked)
        {
            KinectInterop.HandState          rightHandState = kinectManager.GetRightHandState(UserID);
            InteractionManager.HandEventType rightHandEvent = InteractionManager.HandStateToEvent(rightHandState, lastRightHandEvent);

            if (rightHandEvent != InteractionManager.HandEventType.None)
            {
                lastRightHandEvent = rightHandEvent;
            }
        }

        // rotate the avatar bones
        for (var boneIndex = 0; boneIndex < bones.Length; boneIndex++)
        {
            if (!bones[boneIndex])
            {
                continue;
            }

            if (boneIndex2JointMap.ContainsKey(boneIndex))
            {
                KinectInterop.JointType joint = !mirroredMovement ? boneIndex2JointMap[boneIndex] : boneIndex2MirrorJointMap[boneIndex];
                TransformBone(UserID, joint, boneIndex, !mirroredMovement);
            }
            else if (specIndex2JointMap.ContainsKey(boneIndex))
            {
                // special bones (clavicles)
                List <KinectInterop.JointType> alJoints = !mirroredMovement ? specIndex2JointMap[boneIndex] : specIndex2MirrorMap[boneIndex];

                if (alJoints.Count >= 2)
                {
                    //Debug.Log(alJoints[0].ToString());
                    Vector3 baseDir = alJoints[0].ToString().EndsWith("Left") ? Vector3.left : Vector3.right;
                    TransformSpecialBone(UserID, alJoints[0], alJoints[1], boneIndex, baseDir, !mirroredMovement);
                }
            }
        }
    }
 public TimelineInteraction(InteractionManager interactionManager)
 {
     _interactionManager = interactionManager;
 }
 void Awake()
 {
     manager = GameObject.Find ("Main Camera").GetComponent<InteractionManager> ();
 }
示例#20
0
    void Update()
    {
        InteractionManager.GetCurrentReading();

        HandText.text = handPosition.ToString();
    }
示例#21
0
    void StartInteraction()
    {
        int hr = 0;

        try
        {
            // initialize Kinect sensor as needed
            hr = InteractionWrapper.InitKinectSensor();
            if (hr != 0)
            {
                throw new Exception("Initialization of Kinect sensor failed");
            }

            // initialize Kinect interaction
            hr = InteractionWrapper.InitKinectInteraction();
            if (hr != 0)
            {
                throw new Exception("Initialization of KinectInteraction failed");
            }

            // kinect interaction was successfully initialized
            instance = this;
            interactionInited = true;
        }
        catch (DllNotFoundException ex)
        {
            Debug.LogError(ex.ToString());
            if (debugText != null)
                debugText.guiText.text = "Please check the Kinect SDK installation.";
        }
        catch (Exception ex)
        {
            string message = ex.Message + " - " + InteractionWrapper.GetNuiErrorString(hr);
            Debug.LogError(ex.ToString());

            if (debugText != null)
            {
                debugText.guiText.text = message;
            }

            return;
        }

        //		// transform matrix - kinect to world
        //		Quaternion quatTiltAngle = new Quaternion();
        //		int sensorAngle = InteractionWrapper.GetKinectElevationAngle();
        //		quatTiltAngle.eulerAngles = new Vector3(-sensorAngle, 0.0f, 0.0f);
        //
        //		float heightAboveHips = SensorHeight - 1.0f;
        //		kinectToWorld.SetTRS(new Vector3(0.0f, heightAboveHips, 0.0f), quatTiltAngle, Vector3.one);

        //		// load cursor textures once
        //		if(!gripHandTexture)
        //		{
        //			gripHandTexture = (Texture)Resources.Load("GripCursor");
        //		}
        //		if(!releaseHandTexture)
        //		{
        //			releaseHandTexture = (Texture)Resources.Load("ReleaseCursor");
        //		}
        //		if(!normalHandTexture)
        //		{
        //			normalHandTexture = (Texture)Resources.Load("HandCursor");
        //		}

        // don't destroy the object on loading levels
        DontDestroyOnLoad(gameObject);
    }
 void Start()
 {
     var mat = gameObject.GetComponent<Renderer>().materials[0];
     baseTex = new Texture2D(960, 720, TextureFormat.RGBA32, false);
     colors = new Color32[baseTex.width * baseTex.height];
     mat.mainTexture = baseTex;
     Clear();
     Lines.Clear();
     manager = GameObject.FindGameObjectWithTag("MainCamera").GetComponents<InteractionManager>()[0];
 }
示例#23
0
 // Use this for initialization
 void Start()
 {
     interactionManager = GameObject.FindGameObjectWithTag("Player").GetComponent<InteractionManager>();;
 }
示例#24
0
 void OnDestroy()
 {
     // uninitialize Kinect interaction
     if(interactionInited)
     {
         interactionInited = false;
         instance = null;
     }
 }
示例#25
0
 //----------------------------------- end of public functions --------------------------------------//
 void Start()
 {
     instance = this;
     interactionInited = true;
 }
示例#26
0
 void Awake()
 {
     manager = InteractionManager.Instance;
     Kmanager = KinectManager.Instance;
 }
    // Update is called once per frame
    void Update()
    {
        //Debug.Log (isGrabbed);
        if(manager==null)
            manager = InteractionManager.Instance;
        if (gManager == null)
            gManager = GameManager.Instance();

            if (manager.IsLeftHandPrimary ()) {
                // if the left hand is primary, check for left hand grip

                cursorCameraPosition = manager.GetLeftHandScreenPos ();
                cursorCameraPosition.z = 0;
                isLeftHand = true;

            } else if (manager.IsRightHandPrimary ()) {
                cursorCameraPosition = manager.GetRightHandScreenPos ();
                cursorCameraPosition.z = 0;
                isLeftHand = false;

            }
            //translate the camera position returned by the Kinect into coordinates in the scene
            if (cursorCameraPosition != Vector3.zero) {
                cursorScreenPosition.x = (int)(cursorCameraPosition.x * Camera.main.pixelWidth);
                cursorScreenPosition.y = (int)(cursorCameraPosition.y * Camera.main.pixelHeight);
                cursorScreenPosition.z = depth;
                worldCursorScreenPosition = Camera.main.ScreenToWorldPoint (cursorScreenPosition);
                worldCursorScreenPosition.z = 0;
                //Debug.Log (worldCursorScreenPosition);

                //someObject is for debugging purposes only
                //if(someObject==null)
                //	someObject=GameObject.CreatePrimitive(PrimitiveType.Sphere);
                //else
                //someObject.transform.position=Camera.main.ScreenToWorldPoint(cursorScreenPosition);

            }

            //Debug.Log (gManager.ToString()+" "+gManager.isHandGrabbing());
            //check if the box is being touched and is grabbed or not.
            if (box != null) {
                if (box.bounds.Contains (worldCursorScreenPosition) && worldCursorScreenPosition != Vector3.zero && !gManager.isHandGrabbing () && box) {
                    //Debug.Log (this.name+ " i am touch?"  + isTouched);
                    //Debug.Log (this.name+ " i am grab?"  + isGrabbed);
                    isTouched = true;
                    if (manager.GetLastLeftHandEvent () == InteractionManager.HandEventType.Grip) {
                        isGrabbed = true;
                        isLeftHand = true;
                        Debug.Log (gameObject.name + " I got Grabbed");
                        if (isDraggable)
                            gManager.handGrabs ();
                    }
                    if (manager.GetLastRightHandEvent () == InteractionManager.HandEventType.Grip) {
                        isGrabbed = true;
                        isLeftHand = false;
                        Debug.Log (gameObject.name + " I got Grabbed");
                        if (isDraggable)
                            gManager.handGrabs ();
                    }

                }
            }
            if (box2D != null) {
                //same as above, except with support for 2d collider
                if (box2D.bounds.Contains (worldCursorScreenPosition) && worldCursorScreenPosition != Vector3.zero && !gManager.isHandGrabbing ()) {
                    isTouched = true;
                    if (manager.GetLastLeftHandEvent () == InteractionManager.HandEventType.Grip) {
                        isGrabbed = true;
                        isLeftHand = true;
                        Debug.Log (gameObject.name + " I got Grabbed");
                        if (isDraggable)
                            gManager.handGrabs ();
                    }
                    if (manager.GetLastRightHandEvent () == InteractionManager.HandEventType.Grip) {
                        isGrabbed = true;
                        isLeftHand = false;
                        Debug.Log (gameObject.name + " I got Grabbed");
                        if (isDraggable)
                            gManager.handGrabs ();
                    }
                }
            }
            /*if (gManager.isHandGrabbing ()) {
            if(manager.GetLastLeftHandEvent()== InteractionManager.HandEventType.Release||manager.GetLastRightHandEvent()== InteractionManager.HandEventType.Release)
                gManager.handLoose();
        }
        */
            if (isDraggable && isGrabbed) {
                //cursorCameraPosition = isLeftHand ? manager.GetLeftHandScreenPos() : manager.GetRightHandScreenPos();
                cursorCameraPosition = manager.GetCursorPosition ();
                // convert the normalized screen pos to 3D-world pos
                cursorScreenPosition.x = (int)(cursorCameraPosition.x * Camera.main.pixelWidth);
                cursorScreenPosition.y = (int)(cursorCameraPosition.y * Camera.main.pixelHeight);
                cursorScreenPosition.z = depth;
                worldCursorScreenPosition = Camera.main.ScreenToWorldPoint (cursorScreenPosition);
                worldCursorScreenPosition.z = 0;
                Vector3 newObjectPos = worldCursorScreenPosition - dragOffset;
                transform.position = Vector3.Lerp (transform.position, newObjectPos, dragSpeed * Time.deltaTime);

            }

            //set it to drop the box when a hand loosens, regardless of position.
            if (isGrabbed) {
                if (isLeftHand && manager.GetLastLeftHandEvent () == InteractionManager.HandEventType.Release) {

                    isLeftHand = false;
                    isGrabbed = false;
                    if (isDraggable)
                        gManager.handLoose ();
                    //break;
                } else if (!isLeftHand && manager.GetLastRightHandEvent () == InteractionManager.HandEventType.Release) {
                    isGrabbed = false;
                    if (isDraggable)
                        gManager.handLoose ();
                }

            }
    }
示例#28
0
    // Use this for initialization
    IEnumerator Start()
    {
        //        Resources.UnloadUnusedAssets();
        //splashScreenObj.renderer.material.SetFloat("_Blend", 0f);
        //        PlayerPrefs.SetInt("prodPlayAgain", 0); // Enables the splash screen on load
        //splashScreenObj.renderer.enabled = true;

        while (Kmanager == null || Imanager == null)
        {
            if (Kmanager == null)
                Kmanager = KinectManager.Instance;
            if (Imanager == null)
                Imanager = InteractionManager.Instance;

            yield return null;
        }

        guiManager = FindObjectOfType<GUIManager> ();
        Imanager.SetDisableCursor(true);

        yield return null;
    }
 void Start()
 {
     speechManager = GameObject.FindWithTag("kinect-speech").GetComponent<SpeechManager>();
     intManager = GameObject.FindWithTag("kinect-interaction").GetComponent<InteractionManager>();
     pMenu = GetComponent<MenuPause>();
     opMenu = GetComponent<MenuOptions>();
 }
    void Update()
    {
        if(resetObjects && draggedObject == null)
        {
            // reset the objects as needed
            resetObjects = false;
            ResetObjects ();
        }

        // get the interaction manager instance
        if(manager == null)
        {
            manager = InteractionManager.Instance;
        }

        if(manager != null && manager.IsInteractionInited())
        {
            if(draggedObject == null)
            {
                screenNormalPos = Vector3.zero;
                screenPixelPos = Vector3.zero;

                // if there is a hand grip, select the underlying object and start dragging it.
                if(manager.IsLeftHandPrimary())
                {
                    // if the left hand is primary, check for left hand grip
                    if(manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag = true;
                        screenNormalPos = manager.GetLeftHandScreenPos();
                    }
                }
                else if(manager.IsRightHandPrimary())
                {
                    // if the right hand is primary, check for right hand grip
                    if(manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Grip)
                    {
                        isLeftHandDrag = false;
                        screenNormalPos = manager.GetRightHandScreenPos();
                    }
                }

                // check if there is an underlying object to be selected
                if(screenNormalPos != Vector3.zero)
                {
                    // convert the normalized screen pos to pixel pos
                    screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                    screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                    Ray ray = Camera.main.ScreenPointToRay(screenPixelPos);

                    // check if there is an underlying objects
                    RaycastHit hit;
                    if(Physics.Raycast(ray, out hit))
                    {
                        foreach(GameObject obj in draggableObjects)
                        {
                            if(hit.collider.gameObject == obj)
                            {
                                // an object was hit by the ray. select it and start drgging
                                draggedObject = obj;
                                //draggedObjectDepth = draggedObject.transform.position.z - Camera.main.transform.position.z;
                                draggedObjectOffset = hit.point - draggedObject.transform.position;
                                draggedObjectOffset.z = 0; // don't change z-pos

                                draggedNormalZ = (minZ + screenNormalPos.z * (maxZ - minZ)) -
                                    draggedObject.transform.position.z; // start from the initial hand-z

                                // set selection material
                                draggedObjectMaterial = draggedObject.GetComponent<Renderer>().material;
                                draggedObject.GetComponent<Renderer>().material = selectedObjectMaterial;

                                // stop using gravity while dragging object
                                draggedObject.GetComponent<Rigidbody>().useGravity = false;
                                break;
                            }
                        }
                    }
                }

            }
            else
            {
                // continue dragging the object
                screenNormalPos = isLeftHandDrag ? manager.GetLeftHandScreenPos() : manager.GetRightHandScreenPos();

                // convert the normalized screen pos to 3D-world pos
                screenPixelPos.x = (int)(screenNormalPos.x * Camera.main.pixelWidth);
                screenPixelPos.y = (int)(screenNormalPos.y * Camera.main.pixelHeight);
                //screenPixelPos.z = screenNormalPos.z + draggedObjectDepth;
                screenPixelPos.z = (minZ + screenNormalPos.z * (maxZ - minZ)) - draggedNormalZ -
                    Camera.main.transform.position.z;

                newObjectPos = Camera.main.ScreenToWorldPoint(screenPixelPos) - draggedObjectOffset;
                draggedObject.transform.position = Vector3.Lerp(draggedObject.transform.position, newObjectPos, dragSpeed * Time.deltaTime);

                // check if the object (hand grip) was released
                bool isReleased = isLeftHandDrag ? (manager.GetLastLeftHandEvent() == InteractionManager.HandEventType.Release) :
                    (manager.GetLastRightHandEvent() == InteractionManager.HandEventType.Release);

                if(isReleased)
                {
                    // restore the object's material and stop dragging the object
                    draggedObject.GetComponent<Renderer>().material = draggedObjectMaterial;

                    if(useGravity)
                    {
                        // add gravity to the object
                        draggedObject.GetComponent<Rigidbody>().useGravity = true;
                    }

                    draggedObject = null;
                }
            }
        }
    }
示例#31
0
    void OnApplicationQuit()
    {
        // uninitialize Kinect interaction
        if (interactionInited)
        {
            InteractionWrapper.FinishKinectInteraction();
            InteractionWrapper.ShutdownKinectSensor();

            interactionInited = false;
            instance = null;
        }
    }
示例#32
0
    // Use this for initialization
    IEnumerator Start()
    {
        Resources.UnloadUnusedAssets();
        //        GameObject splashScreenObj = GameObject.Find("splash_screen");
        //splashScreenObj.renderer.material.SetFloat("_Blend", 0f);
        //        PlayerPrefs.SetInt("prodPlayAgain", 0); // Enables the splash screen on load
        //splashScreenObj.renderer.enabled = true;

        while (Kmanager == null || Imanager == null)
        {
            if (Kmanager == null)
                Kmanager = KinectManager.Instance;
            if (Imanager == null)
                Imanager = InteractionManager.Instance;

            yield return null;
        }

        //        appController.CMS_Started = true;
        // Disable the user map once game starts
        if (Application.loadedLevel == 2)
        {
            Kmanager.ComputeUserMap = false;
            Kmanager.DisplayUserMap = false;
        }
        else
        {
            Kmanager.ComputeUserMap = true;
            Kmanager.DisplayUserMap = true;
        }

        yield return null;
    }
示例#33
0
    // Use this for initialization
    void Start()
    {
        weaponInHand = Weapon.Weapons.Nothing;
        lifeManager = GetComponent<LifeManager_Player>();
        ioManager = GetComponent<InteractionManager>();
        gameController = GameController.Instance;

        EquipWeapon(startWeapon);

        lifeManager.onDamage += Hit;
        lifeManager.onDeath += Death;
        audioSource = GetComponent<AudioSource>();
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
        animator = GetComponent<Animator>();
        fpsController = GetComponent<FirstPersonController>();
        charController = GetComponent<CharacterController>();

        StartCoroutine(ScaleFov( true, 0.5f));
    }
        public bool Synchronize()
        {
#if UNITY_WSA
            foreach (var sourceState in InteractionManager.GetCurrentReading())
            {
                if (sourceState.source.kind != InteractionSourceKind.Controller)
                {
                    continue;
                }
                if (!IsMatchingHand(side, sourceState.source.handedness))
                {
                    continue;
                }

                // transform.localPosition assign attempt for 'RightController' is not valid. Input localPosition is { 0.000000, NaN, 0.000000 }.
                // transform.localRotation assign attempt for 'RightController' is not valid. Input rotation is { 0.000000, NaN, 0.000000, NaN }.
                // 컨트롤러의 값을 갖고왔다고 항상 믿을수 있는게 아니더라
                // 이 에러가 나중에 고쳐질거같진한데 언제 고쳐질지 믿을수없다
                // 게다가 좌표 동기화는 한번밖에 안하니
                // 진짜로 작동하는 순간에 잘못된 값이 들어오면 골치아프다
                // 값 검증을 거치자

                Vector3 grip_pos;
                if (!sourceState.sourcePose.TryGetPosition(out grip_pos, InteractionSourceNode.Grip))
                {
                    continue;
                }
                if (!WinMR_MathHelper.IsValidVector(grip_pos))
                {
                    continue;
                }

                Quaternion grip_rot;
                if (!sourceState.sourcePose.TryGetRotation(out grip_rot, InteractionSourceNode.Grip))
                {
                    continue;
                }
                if (!WinMR_MathHelper.IsValidQuaternion(grip_rot))
                {
                    continue;
                }


                Vector3 pointing_pos;
                if (!sourceState.sourcePose.TryGetPosition(out pointing_pos, InteractionSourceNode.Pointer))
                {
                    continue;
                }
                if (!WinMR_MathHelper.IsValidVector(pointing_pos))
                {
                    continue;
                }

                Quaternion pointing_rot;
                if (!sourceState.sourcePose.TryGetRotation(out pointing_rot, InteractionSourceNode.Pointer))
                {
                    continue;
                }
                if (!WinMR_MathHelper.IsValidQuaternion(pointing_rot))
                {
                    continue;
                }


                var mat_grip     = Matrix4x4.TRS(grip_pos, grip_rot, Vector3.one);
                var mat_pointing = Matrix4x4.TRS(pointing_pos, pointing_rot, Vector3.one);

                // 컨트롤러의 자식으로 pointing을 갖고싶다
                // mat_grip * mat_unknown = mat_pointing
                // mat_unknown = inv_mat_grip * mat_pointing
                var m = mat_grip.inverse * mat_pointing;
                WinMR_MathHelper.ApplyMatrix(transform, m);

                rel_pos = transform.localPosition;
                rel_rot = transform.localRotation;

                // 최초 상태를 적용
                var q = rel_rot * initial_rot;
                transform.localRotation = q;

                var diff = transform.localRotation * initial_pos;
                transform.localPosition += diff;

                return(true);
            }
            return(false);
#else
            return(false);
#endif
        }