protected override JobHandle OnUpdate(JobHandle inputDeps) { ////鼠标检测 //if (Input.GetMouseButtonDown(0)) //{ // _isForceOn = true; // _forceMode = ForceComponent.ForceMode.PULL; //} //if (Input.GetMouseButtonUp(0)) //{ // _isForceOn = false; //} ////right - push //if (Input.GetMouseButtonDown(1)) //{ // _isForceOn = true; // _forceMode = ForceComponent.ForceMode.PUSH; //} //if (Input.GetMouseButtonUp(1)) //{ // _isForceOn = false; //} //触屏检测 if (Input.touchCount >= 1) { if (Input.touches[0].phase == TouchPhase.Stationary || Input.touches[0].phase == TouchPhase.Moved) { _isForceOn = true; _forceMode = ForceComponent.ForceMode.PULL; } if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled) { _isForceOn = false; } //right - push if (Input.touches[0].phase == TouchPhase.Began) { _isForceOn = true; _forceMode = ForceComponent.ForceMode.PUSH; } if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled) { _isForceOn = false; } } //mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.touches[0].position.x, Input.touches[0].position.y, 248f/*Camera.main.transform.position.y*/)); //mousePos.z = 248.0f; mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.mousePosition.x, Input.mousePosition.y, 248f /*Camera.main.transform.position.y*/)); mousePos.z = 248.0f; //初始化一个job var job = new JobProcess { isForceOn = _isForceOn, forceMode = _forceMode, mousePosition = mousePos }; //开始job return(job.Schedule(this, inputDeps)); }
//系统会每帧调用这个函数 protected override JobHandle OnUpdate(JobHandle inputDeps) { //#if UNITY_STANDALONE // ------- input handle ------ //left - pull if (Input.GetMouseButtonDown(0)) { _isForceOn = true; _forceMode = ForceComponent.ForceMode.PULL; } if (Input.GetMouseButtonUp(0)) { _isForceOn = false; } //right - push if (Input.GetMouseButtonDown(1)) { _isForceOn = true; _forceMode = ForceComponent.ForceMode.PUSH; } if (Input.GetMouseButtonUp(1)) { _isForceOn = false; } if (Input.GetKey(KeyCode.W)) { Camera.main.transform.SetPositionAndRotation(Camera.main.transform.position + Vector3.down * 5f, Camera.main.transform.rotation); } if (Input.GetKey(KeyCode.S)) { Camera.main.transform.SetPositionAndRotation(Camera.main.transform.position + Vector3.up * 5f, Camera.main.transform.rotation); } mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.y)); mousePos.y = 0; // ------- end input handle ------ //#endif #if UNITY_ANDROID if (Input.touchCount == 1) { if (Input.touches[0].phase == TouchPhase.Moved) { _isForceOn = true; mousePos = Camera.main.ScreenToWorldPoint(new float3(Input.GetTouch(0).position.x, Input.GetTouch(0).position.y, Camera.main.transform.position.y)); mousePos.y = 0; } } else { //_isForceOn = false; } #endif //初始化一个job var job = new JobProcess { isForceOn = _isForceOn, forceMode = _forceMode, mousePosition = mousePos }; //开始job return(job.Schedule(this, inputDeps)); }