| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- /*
- * File Name: ZwnAmlogicHand
- * Author: Guan B
- * Version: 1.0.0
- * Data: 2022.04.08
- * Des: 调用SDK接口Demo
- * Other: Zeewain
- */
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ZwnAmlogicHand : MonoBehaviour
- {
- private AndroidJavaClass javaClass;
- public GameObject showPrefabs;
- public Transform showPointParent;
- public GameObject showRectfabs;
- List<GameObject> showHandList = new List<GameObject>();
- List<GameObject> showHandListTwo = new List<GameObject>();
- List<GameObject> showHandRectList = new List<GameObject>();
- List<GameObject> showHandOriginaltList = new List<GameObject>();
- List<GameObject> showHandOriginaltListTwo = new List<GameObject>();
- private int handCount = 21;
- Dictionary<int, Vector3[]> handData = new Dictionary<int, Vector3[]>();
- Dictionary<int, Vector3[]> handOriginalData = new Dictionary<int, Vector3[]>();
- Dictionary<int, Vector2> handWeightHeightData = new Dictionary<int, Vector2>();
- Dictionary<int, Vector3> handRectPointData = new Dictionary<int, Vector3>();
- Vector3 default_vec = new Vector3(-Screen.width, -Screen.height, 0);
- Vector3[] handChangeData;
- // Start is called before the first frame update
- void Start()
- {
- javaClass = new AndroidJavaClass("com.zee.unity.UnityHelper");
- ZwnAmLogicSDK.InitAndroidJavaClass(javaClass);
- handChangeData = new Vector3[21];
- }
- // Update is called once per frame
- void Update()
- {
- if (ZwnAmlogicHelperData.isCanOpenCamera)
- {
- ZwnAmlogicHelperData.isCanOpenCamera = false;
- ZwnAmLogicSDK.OpenCamera(ZwnAmlogicHelperData.cameraId);
- }
- if (ZwnAmlogicHelperData.isOpenCamera)
- {
- ZwnAmlogicHelperData.initPersonPoseNum = ZwnAmLogicSDK.InitHand(ZwnAmlogicHelperData.landmarkType, ZwnAmlogicHelperData.deviceType, ZwnAmlogicHelperData.threadNum);
- if (ZwnAmlogicHelperData.initPersonPoseNum == 0)
- {
- ZwnAmLogicSDK.SetHandLandmarkStatus(true);
- ZwnAmLogicSDK.SetHandMaxNum(2, 0);
- ZwnAmLogicSDK.SetHandScoreThreshold(0.5f);
- ZwnAmLogicSDK.SetHandSmoothnessStatus(true);
- }
- }
- if (ZwnAmlogicHelperData.initPersonPoseNum == 0)
- {
- ZwnAmlogicHelperData.isOpenCamera = false;
- GetHandData();
- GetHandRectData();
- //GetHandOriginalData();
- }
- ShowChangeHandPoint();
- ShowHandRectPoint();
- //ShowHandOriginalData();
- }
- /// <summary>
- /// 获取转换后的手部数据
- /// </summary>
- void GetHandData()
- {
- handData = ZwnAmLogicSDK.GetHandInfo();
- }
- /// <summary>
- /// 获取转换后的手部框位置和大小
- /// </summary>
- void GetHandRectData()
- {
- handRectPointData = ZwnAmLogicSDK.GetHandRectPointInfo();
- handWeightHeightData = ZwnAmLogicSDK.GetHandRectWeightHeightInfo();
- }
- /// <summary>
- /// 获取手部原始点的数据
- /// </summary>
- void GetHandOriginalData()
- {
- handOriginalData = ZwnAmLogicSDK.GetOriginalHandInfo();
- }
- /// <summary>
- /// 显示转换后点的位置
- /// </summary>
- public void ShowChangeHandPoint()
- {
- if (handData.Count > 0 && handData != null)
- {
- if (handData.Count == 1)
- {
- for (int i = 0; i < handCount; i++)
- {
- if (i >= showHandList.Count)
- {
- GameObject go = Instantiate(showPrefabs);
- showHandList.Add(go);
- go.transform.SetParent(showPointParent);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- showHandList[i].transform.localPosition = handData[0][i];
- }
- }
- else if (handData.Count == 2)
- {
- for (int i = 0; i < handCount; i++)
- {
- if (i >= showHandList.Count)
- {
- GameObject go = Instantiate(showPrefabs);
- showHandList.Add(go);
- go.transform.SetParent(showPointParent);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- showHandList[i].transform.localPosition = handData[0][i];
- }
- for (int i = 0; i < handCount; i++)
- {
- if (i >= showHandListTwo.Count)
- {
- GameObject go = Instantiate(showPrefabs);
- showHandListTwo.Add(go);
- go.transform.SetParent(showPointParent);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- showHandListTwo[i].transform.localPosition = handData[1][i];
- }
- }
- }
- else
- {
- if (showHandList.Count > 0)
- {
- for (int i = 0; i < showHandList.Count; i++)
- {
- showHandList[i].transform.localPosition = default_vec;
- }
- }
- if (showHandListTwo.Count > 0)
- {
- for (int i = 0; i < showHandListTwo.Count; i++)
- {
- showHandListTwo[i].transform.localPosition = default_vec;
- }
- }
- }
- }
- /// <summary>
- /// 显示手部框的位置和大小
- /// </summary>
- public void ShowHandRectPoint()
- {
- if (handRectPointData.Count > 0 && handWeightHeightData.Count > 0)
- {
- for (int i = 0; i < handRectPointData.Count; i++)
- {
- if (i >= showHandRectList.Count)
- {
- GameObject go = Instantiate(showRectfabs);
- showHandRectList.Add(go);
- go.transform.SetParent(showPointParent);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- showHandRectList[i].transform.localPosition = handRectPointData[i];
- showHandRectList[i].GetComponent<RectTransform>().sizeDelta = handWeightHeightData[i];
- }
- }
- else
- {
- if (showHandRectList.Count > 0)
- {
- for (int i = 0; i < showHandRectList.Count; i++)
- {
- showHandRectList[i].transform.localPosition = default_vec;
- }
- }
- }
- }
- /// <summary>
- /// 显示手部原始点数据
- /// </summary>
- public void ShowHandOriginalData()
- {
- if (handOriginalData.Count > 0 && handOriginalData != null)
- {
- if (handOriginalData.Count == 1)
- {
- for (int i = 0; i < handCount; i++)
- {
- if (i >= showHandOriginaltList.Count)
- {
- GameObject go = Instantiate(showPrefabs);
- showHandOriginaltList.Add(go);
- go.transform.SetParent(showPointParent);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- showHandOriginaltList[i].transform.localPosition = handOriginalData[0][i];
- }
- }
- else if (handOriginalData.Count == 2)
- {
- for (int i = 0; i < handCount; i++)
- {
- if (i >= showHandOriginaltList.Count)
- {
- GameObject go = Instantiate(showPrefabs);
- showHandOriginaltList.Add(go);
- go.transform.SetParent(showPointParent);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- showHandOriginaltList[i].transform.localPosition = handOriginalData[0][i];
- }
- for (int i = 0; i < handCount; i++)
- {
- if (i >= showHandOriginaltListTwo.Count)
- {
- GameObject go = Instantiate(showPrefabs);
- showHandOriginaltListTwo.Add(go);
- go.transform.SetParent(showPointParent);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- showHandOriginaltListTwo[i].transform.localPosition = handOriginalData[1][i];
- }
- }
- }
- else
- {
- if (showHandOriginaltList.Count > 0)
- {
- for (int i = 0; i < showHandOriginaltList.Count; i++)
- {
- showHandOriginaltList[i].transform.localPosition = default_vec;
- }
- }
- if (showHandOriginaltListTwo.Count > 0)
- {
- for (int i = 0; i < showHandOriginaltListTwo.Count; i++)
- {
- showHandOriginaltListTwo[i].transform.localPosition = default_vec;
- }
- }
- }
- }
- private void OnDestroy()
- {
- ZwnAmLogicSDK.ReleaseZeePose();
- ZwnAmLogicSDK.CloseCamera();
- }
- }
|