public override void OnDown(int handIndex) { base.OnDown(handIndex); if (maxCount == 0) { return; } var targetObject = Instantiate(bindObject) as GameObject; var frontUI = targetObject.GetComponent <KGUI_ObjectFrontUI>() ?? targetObject.AddComponent <KGUI_ObjectFrontUI>(); frontUI.OnSet(); MOperateManager.SetObjectGrab(targetObject, handIndex, zValue); //KinectTransfer.SetObjectGrab(targetObject, zValue, handIndex: handIndex); targetObjects.Add(targetObject); if (maxCount != -1) { maxCount--; } if (maxCount == 0) { IsEnable = false; } }
IEnumerator Loading(Action start = default(Action), Action end = default(Action)) { MOperateManager.ActiveHandController(false); int[] nums = Utilitys.GetRandomSequence(LoadData.SpriteDatas.Count, LoadData.loadCount); for (int i = 0; i < nums.Length; i++) { SetBackground(LoadData.SpriteDatas[nums[i]].Value); yield return(new WaitForSeconds(LoadData.loadTime)); if (i == 0 && start != null) { start(); } } MOperateManager.ActiveHandController(true); if (end != null) { end(); yield return(new WaitForSeconds(1.0f)); } }
private void Awake() { behaviour = new MBehaviour(ExecutionPriority.Highest, -900, enabled); behaviour.OnAwake(() => { InputHands = new Dictionary <int, MInputHand>(); //初始化手的种类 var handUI = MHandUIManager.CreateHandUI(transform, handSprite, handSize); var inputHand = new MInputHand(0, handUI, OperatePlatform.Mouse); InputHands.Add(0, inputHand); isPlaying = true; //注册操作者相关事件 var operate = MOperateManager.AddOperateHand(inputHand); //注册方法 operate.OnGrab = OnGrabObject; operate.OnSetGrab = SetGrabObject; operate.OnEnable(); }); behaviour.OnUpdate(OnMouseUpdate); MBehaviourController.AddBehaviour(behaviour); }
IEnumerator RandomLoading(float time, float startTime, Action start = default(Action), float endTime = 0.5f, Action end = default(Action), Action endDelay = default(Action)) { MOperateManager.ActiveHandController(false); var value = Utilitys.GetRandomSequence(LoadData.SpriteDatas.Count, 1)[0]; SetBackground(LoadData.SpriteDatas[value].Value); yield return(new WaitForSeconds(startTime)); if (start != null) { start(); } yield return(new WaitForSeconds(time)); if (end != null) { end(); yield return(new WaitForSeconds(endTime)); if (endDelay != null) { endDelay(); } UIManager.Instance.HideUI("Loading"); } MOperateManager.ActiveHandController(true); //UIManager.Instance.HideUI(); }
public void OnUpdate() { if (!isActive) { return; } float dis = (GrabObject.transform.position - Camera.main.transform.position).magnitude; //相机到物体的距离 Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex); //当前手的屏幕坐标 //Vector3 vector = (screenHand-recordPos)*speed*Time.deltaTime; //手移动的向量 //移动距离转旋转值 x += (screenHand.x - recordPos.x) / 1920 * 360; y -= (screenHand.y - recordPos.y) / 1080 * 360; //限制范围 x = Mathf.Clamp(x, leftAndRight.x, leftAndRight.y); y = Mathf.Clamp(y, upAndDown.x, upAndDown.y); Quaternion q = Quaternion.Euler(y, x, 0); Vector3 direction = q * GrabObject.transform.forward; Camera.main.transform.position = GrabObject.transform.position - direction * dis; Camera.main.transform.rotation = q; recordPos = screenHand; }
private void LateUpdate() { switch (type) { case ProcessType.LateUpdate: OnUpdate(); break; case ProcessType.Grab: GameObject right = MOperateManager.GetObjectGrab(0); if (right != null && right == grabObject) { OnUpdate(); } GameObject left = MOperateManager.GetObjectGrab(1); if (left != null && left == grabObject) { OnUpdate(); } break; default: break; } }
void KinectMInputInitialize(KinectActiveHandStadus kinectActiveHandStadus) { InputHands = new Dictionary <int, MInputHand>(); switch (kinectActiveHandStadus) { case KinectActiveHandStadus.None: throw new Exception("单双手状态未选择"); case KinectActiveHandStadus.One: //初始化手的种类 var handUI = MHandUIManager.CreateHandUI(transform, rightHandSprite, handSize); var inputHand = new MInputHand(0, handUI, OperatePlatform.Kinect); InputHands.Add(0, inputHand); isPlaying = true; //注册操作者相关事件 var operate = MOperateManager.AddOperateHand(inputHand, this); //注册方法 operate.OnGrab = OnRightGrabObject; operate.OnSetGrab = SetGrabObject; operate.OnEnable(); break; case KinectActiveHandStadus.Two: //初始化手的种类 var rightHandUI = MHandUIManager.CreateHandUI(transform, rightHandSprite, handSize); var rightInputHand = new MInputHand(0, rightHandUI, OperatePlatform.Kinect); InputHands.Add(0, rightInputHand); var leftHandUI = MHandUIManager.CreateHandUI(transform, leftHandSprite, handSize); var leftInputHand = new MInputHand(1, leftHandUI, OperatePlatform.Kinect); InputHands.Add(1, leftInputHand); isPlaying = true; //注册操作者相关事件 var rightOperate = MOperateManager.AddOperateHand(rightInputHand, this); //注册方法 rightOperate.OnGrab = OnRightGrabObject; rightOperate.OnSetGrab = SetGrabObject; rightOperate.OnEnable(); //注册操作者相关事件 var leftOperate = MOperateManager.AddOperateHand(leftInputHand, this); //注册方法 leftOperate.OnGrab = OnLeftGrabObject; leftOperate.OnSetGrab = SetGrabObject; leftOperate.OnEnable(); break; default: break; } }
private void Update() { if (IsDown && handIndex != -1 && IsEnable && enabled) { //屏幕坐标 Vector3 screenPoint = MOperateManager.GetHandScreenPoint(handIndex); //将屏幕坐标传递出去 OnExecute(screenPoint); } }
/// <summary> /// 是否存在区域内 /// </summary> /// <param name="screenPoint">屏幕坐标</param> /// <param name="size">大小</param> /// <param name="handIndex">手势</param> /// <returns></returns> public static bool IsAreaContains(Vector2 screenPoint, Vector2 size, int handIndex) { //if (!KinectTransfer.IsHandActive(handIndex)) return false; //获取到此时手的屏幕坐标屏幕坐标 Vector3 screenHandPoint = MOperateManager.GetHandScreenPoint(handIndex); //根据自身此时的屏幕坐标,去算区域 return(ScreenPointContains(screenPoint, size, screenHandPoint)); }
public void OnOpen(int handIndex) { this.handIndex = handIndex; Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex); Vector3 vector = GrabObject.transform.position - Camera.main.transform.position; // Camera.main.transform.position=GrabObject.transform.forward*vector.magnitude;//相机朝向物体 Camera.main.transform.forward = vector.normalized; recordPos = screenHand; //记录手的屏幕坐标 isActive = true; }
/// <summary> /// 打开 /// </summary> public virtual void OnOpen(int handIndex = 0) { this.handIndex = handIndex; Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex); Vector3 screenPosition = MUtility.MainWorldToScreenPoint(GrabObject.transform.position); recordPos = MUtility.MainScreenToWorldPoint(new Vector3(screenHand.x, screenHand.y, screenPosition.z));//手的坐标 recordEuler = space == Space.World ? GrabObject.transform.eulerAngles : GrabObject.transform.localEulerAngles; isActive = true; }
/// <summary> /// 抓取背包创建 /// </summary> /// <param name="itemData"></param> /// <param name="handIndex"></param> /// <returns></returns> public GameObject CreatEquipment(KGUI_BackpackItem item, int handIndex) { KGUI_Backpack_ItemData itemData = item.dataConfig; var itemObject = Resources.Load <GameObject>(universalPath + itemData.ItemPath); var go = Instantiate(itemObject) as GameObject; go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y, -16.3f); KGUI_BackPackMark mark = go.GetComponent <KGUI_BackPackMark>() ?? go.AddComponent <KGUI_BackPackMark>(); if (mark != null) { //仪器背包创建调用 mark.OnCreateForBag(item, itemData.Name, handIndex); } //KinectTransfer.SetObjectGrab(go, handIndex); MOperateManager.SetObjectGrab(go, itemData.zValue, handIndex); this._handIndex = handIndex; #region 注释 //========================== //Vector3 screenDevice = KinectTransfer.GetScreenHandPos(handIndex); //Vector3 worldDevice = //========================== //go.transform.DOScale(Vector3.one * 15, 0.1f); //层改变成UI层,然后离开时,在转化为其他层 //设置抓取信息,不管相机如何移动,抓取的物体始终在屏幕坐标中。 //Vector3 position; ////屏幕坐标 //Vector3 screenPoint = KinectTransfer.GetMCKinectPositionStatus(out position, handIndex); //screenPoint.z = itemData.zValue; //float z = /*KinectConfig.mainCamera*/Camera.main.ScreenToWorldPoint(screenPoint).z; //go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y, 0.8f); //go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y,0); #endregion SetObjectFrontUI(false); return(go); }
void Update() { if (IsPressed && MSwitchManager.CurrentMode == OperateModeType.Tool) { Vector3 temp = MOperateManager.GetHandScreenPoint(handIndex); temp.x = Mathf.Clamp(temp.x, 0, Screen.width); temp.y = Mathf.Clamp(temp.y, 0, Screen.height); Vector2 mouse_world_position = MUtility.UICamera.ScreenToWorldPoint(temp); currentBrush(mouse_world_position); } }
/// <summary> /// 容器水平滚动 /// </summary> /// <param name="direction"></param> public void PanelScrollX(int direction) { if (isFollowHand) { var handXPos = MOperateManager.GetHandScreenPoint(curXHand); var x = recordXPos.x + handXPos.x - recordXHandPos.x; x = Mathf.Clamp(x, viewInfoX.minValue, viewInfoX.maxValue); var pos = content.localPosition; pos.x = x; content.localPosition = pos; } else { horizontal.Value -= direction * 1.5f * Time.deltaTime; } }
/// <summary> /// 容器垂直滚动 /// </summary> /// <param name="direction"></param> public void PanelScrollY(int direction) { if (isFollowHand) { var handPos = MOperateManager.GetHandScreenPoint(curHand); var y = recordPos.y + handPos.y - recordHandPos.y; y = Mathf.Clamp(y, viewInfoY.minValue, viewInfoY.maxValue); var pos = content.localPosition; pos.y = y; content.localPosition = pos; } else { vertical.Value -= direction * 1.5f * Time.deltaTime; } }
IEnumerator OnUpdate(int handIndex) { while (true) { yield return(new WaitForFixedUpdate()); Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex); Vector3 screenPosition = MUtility.MainWorldToScreenPoint(GrabObject.transform.position); Vector3 position = MUtility.MainScreenToWorldPoint(new Vector3(screenHand.x, screenHand.y, screenPosition.z)); if (OnCustomizeUpdate != null) { OnCustomizeUpdate.Invoke(GrabObject, position, handIndex); } } }
private void Update() { if (IsDown && handIndex != -1 && enabled) { //屏幕坐标 Vector3 screenPoint = MOperateManager.GetHandScreenPoint(handIndex); Vector3 screenDevice = MUtility.MarkWorldToScreenPoint(sliderObject.transform.position); Vector3 vPos = MUtility.MarkScreenToWorldPoint(new Vector3(screenPoint.x, screenPoint.y, screenDevice.z)); OnExecute(vPos); } //if (tempValue != Value) //{ // SetChangingValue(Value); //} }
private void Update() { if (!enabled) { return; } OnEnterHandle(0); //右手 OnEnterHandle(1); //左手 if (IsDown && handIndex != -1) { //屏幕坐标 Vector3 screenPoint = MOperateManager.GetHandScreenPoint(handIndex); //将屏幕坐标传递出去 OnExecute(screenPoint); } }
public virtual void OnUpdate() { if (!isActive) { return; } Vector3 screenHand = MOperateManager.GetHandScreenPoint(handIndex); Vector3 screenPosition = MUtility.MainWorldToScreenPoint(recordPos); Vector3 handPos = MUtility.MainScreenToWorldPoint(new Vector3(screenHand.x, screenHand.y, screenPosition.z)); //手的坐标 float dis = handPos.x - recordPos.x; //手移动的距离 float ratio = dis * speed; float angle = 0; Vector3 euler = recordEuler; angle = GetAngle(ratio, angle); euler = GetEuler(angle, euler); RotateSelf(euler); }
private void LateUpdate() { switch (type) { case ProcessType.LateUpdate: OnUpdate(); break; case ProcessType.Grab: GameObject temp = MOperateManager.GetObjectGrab(0); if (temp != null && temp == grabObject) { OnUpdate(); } break; default: break; } }
IEnumerator LoadingKey(string key, Action start = default(Action), Action end = default(Action)) { MOperateManager.ActiveHandController(false); SetBackground(LoadData.SpriteDatas.Find(obj => obj.key.Equals(key)).Value); if (start != null) { start(); } yield return(new WaitForSeconds(LoadData.loadTime)); if (end != null) { end(); yield return(new WaitForSeconds(1.0f)); } MOperateManager.ActiveHandController(true); }
/// <summary> /// Kinect控制端数据初始化 /// </summary> /// <param name="handModel">Hand model.</param> private void KinectInitialize(KinectHandModel handModel) { InputHands = new Dictionary <int, MInputHand>(); inputKinect = gameObject.GetComponent <MInputKinect>() ?? gameObject.AddComponent <MInputKinect>(); MInputKinect.HandModel = handModel; IsPlaying = true; //实例化右手 var rightHandUI = MHandUIManager.CreateHandUI(transform, rightHandOperate.handIcon); var rightInputHand = new MInputHand(rightHandOperate.HandIndex, rightHandUI, OperatePlatform.Kinect); rightHandUI.name = "kinect-Hand-0"; InputHands.Add(rightHandOperate.HandIndex, rightInputHand); //实例化左手 var leftHandUI = MHandUIManager.CreateHandUI(transform, leftHandOperate.handIcon); var leftInputHand = new MInputHand(leftHandOperate.HandIndex, leftHandUI, OperatePlatform.Kinect); leftHandUI.name = "Kinect-Hand-1"; InputHands.Add(leftHandOperate.HandIndex, leftInputHand); //右手操作端相关初始化与事件绑定 rightHandOperate.Operate = MOperateManager.AddOperateHand(rightInputHand, this); rightHandOperate.BindGrab(); //左手操作端相关初始化与事件的绑定 leftHandOperate.Operate = MOperateManager.AddOperateHand(leftInputHand, this); leftHandOperate.BindGrab(); IsEnable = true; //mouseController = gameObject.GetComponent<MouseController>() ?? gameObject.AddComponent<MouseController>(); //mouseController.IsEnable = false; //检查一次是否激活手 HandStop(2);//默认也禁止 }
/// <summary> /// 抓取背包创建 /// </summary> /// <param name="itemData"></param> /// <param name="handIndex"></param> /// <returns></returns> public GameObject CreatEquipment(KGUI_BackpackItem item, int handIndex) { KGUI_Backpack_ItemData itemData = item.dataConfig; var go = GenerateEquipment(item, itemData.ItemPath); go.transform.position = new Vector3(go.transform.position.x, go.transform.position.y, -16.3f); //KGUI_BackPackMark mark = go.GetComponent<KGUI_BackPackMark>() ?? go.AddComponent<KGUI_BackPackMark>(); //if (mark != null) //{ // //仪器背包创建调用 // mark.OnCreateForBag(item, itemData.Name, handIndex); //} //KinectTransfer.SetObjectGrab(go, handIndex); MOperateManager.SetObjectGrab(go, handIndex, itemData.zValue); this._handIndex = handIndex; SetObjectFrontUI(false); return(go); }
private void OnEnter(int arg0) { //获取到如果抓取的物体不能放回背包,则不做任何处理 var grabObject = MOperateManager.GetObjectGrab(arg0); if (grabObject != null) { KGUI_BackPackMark equ = grabObject.GetComponent <KGUI_BackPackMark>(); if (equ == null) { return; } if (!equ.IsFeaturesObjectEquals()) { return; } } OpenBag(arg0); SetObjectFrontUI(false); }
/// <summary> /// 是否存在区域内 /// </summary> /// <param name="transform">指定物体</param> /// <param name="handIndex"></param> /// <returns></returns> public static bool IsAreaContains(Transform transform, int handIndex) { //if (!KinectTransfer.IsHandActive(handIndex)) return false; try { //获取到此时手的屏幕坐标屏幕坐标 Vector3 screenHandPoint = MOperateManager.GetHandScreenPoint(handIndex); Vector3 screenPoint = MUtility.UIWorldToScreenPoint(transform.position); //根据自身此时的屏幕坐标,去算区域 RectTransform rectTransform = transform.GetComponent <RectTransform>(); return(ScreenPointContains(screenPoint, rectTransform.sizeDelta, screenHandPoint)); } catch (Exception) { return(false); //throw new Exception("手势可能没激活,如果是在编辑器上遇到此问题,不用理会"); } }
private void Update() { if (!enabled) { return; } if (!Active) { return; } OnEnterHandle(0); //右手 OnEnterHandle(1); //左手 if (!IsDown || handIndex == -1) { return; } //屏幕坐标 var screenPoint = MOperateManager.GetHandScreenPoint(handIndex); //将屏幕坐标传递出去 OnExecute(screenPoint); }
private void Awake() { behaviour = new MBehaviour(ExecutionPriority.Highest, -900, enabled); InputHands = new Dictionary <int, MInputHand>(); //初始化手的种类 var handUI = MHandUIManager.CreateHandUI(transform, handSprite, handSize); var inputHand = new MInputHand(0, handUI, OperatePlatform.Mouse); handUI.name = "Mouse-Hand"; InputHands.Add(0, inputHand); isPlaying = true; //注册操作者相关事件 operate = MOperateManager.AddOperateHand(inputHand, this); //注册方法 operate.OnGrab = OnGrabObject; operate.OnSetGrab = SetGrabObject; IsEnable = true; }
void SetObjectFrontUI(bool IsReset) { //获取到正在抓取的物体 var grabObject = MOperateManager.GetObjectGrab(_handIndex); if (grabObject == null) { return; } var frontUI = grabObject.GetComponent <KGUI_ObjectFrontUI>(); if (frontUI != null) { if (IsReset) { frontUI.OnReset(); } else { frontUI.OnSet(); } } }
// 双手操作处理 void KinectHandTwo() { //将他的屏幕坐标传递出去 InputHands[0].OnUpdate(MInputKinect.ScreenHandPostion(0)); if (MInputKinect.HandGrip(0)) { InputHands[0].SetGrip(); } if (MInputKinect.HandRelease(0)) { InputHands[0].SetIdle(); } //将他的屏幕坐标传递出去 InputHands[1].OnUpdate(MInputKinect.ScreenHandPostion(1)); if (MInputKinect.HandGrip(1)) { InputHands[1].SetGrip(); } if (MInputKinect.HandRelease(1)) { InputHands[1].SetIdle(); } KinectRotateZoom(); if (rightOperateObject != null) { switch (InputHands[0].HandStatus) { case MInputHandStatus.Grabing: var screenDevice = MUtility.MainWorldToScreenPoint(rightOperateObject.GrabObject.transform.position); Vector3 screenMouse = InputHands[0].ScreenPoint; Vector3 vPos = MUtility.MainScreenToWorldPoint(new Vector3(screenMouse.x, screenMouse.y, screenDevice.z)); //rightOperateObject.GrabObject.transform.position = vPos - rightOffset; Vector3 position = vPos - rightOffset; EventUpdateObject.SendListener(rightOperateObject.GrabObject, position, rightOperateObject.GrabObject.transform.rotation, InputHands[0].HandIndex); //需要处理偏移量 break; case MInputHandStatus.Idle: this.rightOperateObject = null; break; default: break; } } if (leftOperateObject != null) { switch (InputHands[1].HandStatus) { case MInputHandStatus.Grabing: var screenDevice = MUtility.MainWorldToScreenPoint(leftOperateObject.GrabObject.transform.position); Vector3 screenMouse = InputHands[1].ScreenPoint; Vector3 vPos = MUtility.MainScreenToWorldPoint(new Vector3(screenMouse.x, screenMouse.y, screenDevice.z)); //leftOperateObject.GrabObject.transform.position = vPos - leftOffset; Vector3 position = vPos - leftOffset; EventUpdateObject.SendListener(leftOperateObject.GrabObject, position, leftOperateObject.GrabObject.transform.rotation, InputHands[0].HandIndex); //需要处理偏移量 break; case MInputHandStatus.Idle: this.leftOperateObject = null; break; default: break; } } if (kinectHandStartStatus == KinectActiveHandStadus.One) { if (MInputKinect.IsHandActive(0) && !MInputKinect.IsHandActive(1) && isRight == false) { MOperateManager.GetOperateHand(0, OperatePlatform.Kinect).OnEnable(); MOperateManager.GetOperateHand(1, OperatePlatform.Kinect).OnDisable(); isRight = true; isLeft = false; } else if (MInputKinect.IsHandActive(1) && !MInputKinect.IsHandActive(0) && isLeft == false) { MOperateManager.GetOperateHand(1, OperatePlatform.Kinect).OnEnable(); MOperateManager.GetOperateHand(0, OperatePlatform.Kinect).OnDisable(); isLeft = true; isRight = false; } } }
private void OnDown(int arg0, bool arg1) { curHand = arg0; recordHandPos = MOperateManager.GetHandScreenPoint(curHand); recordPos = content.localPosition; }