| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- /// <summary>
- /// ZWN-XHJ
- /// 20211019
- /// </summary>
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /*using static System.Net.Mime.MediaTypeNames;*/
- public class humancost : MonoBehaviour
- {
- public human_area human_cur;
- //public FollowBoxManager followBoxManager;
- public Image show;
- public Sprite[] show_spr;
- private Color32 color_start = new Color32(255, 255, 255, 0),
- color_end = new Color32(255, 255, 255, 255);
- private Vector3 vec_start = new Vector3(-1920, 0, 0),
- vec_end = new Vector3(0, 0, 0);
- bool human_cost = false;
- bool cost_success = false;
- public GameObject show_green;
- public GameObject total, half;
- float alignArea = 0;
- public float AlignArea
- {
- get { return alignArea; }
- set { alignArea = value; }
- }
- /// <summary>
- /// 当符合条件后,判断为True
- /// </summary>
- public bool Cost_Success
- {
- get { return cost_success; }
- set { cost_success = value; }
- }
- int area_num = -1;
- public int Area_Num
- {
- get { return area_num; }
- set { area_num = value; }
- }
- int last_num = -2;
- private Transform tra_self;
- /// <summary>
- /// 当符合条件后,判断为True
- /// </summary>
- public bool Cost_Change
- {
- get { return cost_change; }
- set { cost_change = value; }
- }
- bool cost_change = false;
- // Use this for initialization
- void Start()
- {
- if (!human_cost)
- {
- if (human_cur.human_area_state_cur == human_area_state.totalbody)
- {
- total.SetActive(true);
- half.SetActive(false);
- }
- else if (human_cur.human_area_state_cur == human_area_state.halfbody)
- {
- total.SetActive(false);
- half.SetActive(true);
- }
- show_green.SetActive(false);
- if (tra_self == null)
- {
- tra_self = this.transform;
- }
- tra_self.localPosition = vec_start;
- area_num = -1;
- show_true();
- cost_success = false;
- human_cost = false;
- }
- }
- /// <summary>
- /// 开始检测需调用
- /// </summary>
- public void human_init()
- {
- // zwn_interface.single.zwn_init();
- if (time_cost != 0)
- time_cost = 0;
- if (human_cur.human_area_state_cur == human_area_state.totalbody)
- {
- total.SetActive(true);
- half.SetActive(false);
- }
- else if (human_cur.human_area_state_cur == human_area_state.halfbody)
- {
- total.SetActive(false);
- half.SetActive(true);
- }
- show_green.SetActive(false);
- if (tra_self == null)
- {
- tra_self = this.transform;
- }
- tra_self.localPosition = vec_end;
- area_num = -1;
- last_num = -2;
- show_true();
- cost_change = false;
- cost_success = false;
- human_cost = true;
- }
- /// <summary>
- /// 结束检测
- /// </summary>
- public void human_end()
- {
- show_green.SetActive(false);
- if (tra_self == null)
- {
- tra_self = this.transform;
- }
- tra_self.localPosition = vec_start;
- area_num = -1;
- last_num = -2;
- show_true();
- cost_change = false;
- cost_success = true;
- human_cost = false;
- }
- float time_cost = 0;
- //public Text text_id;
- // Update is called once per frame
- void Update()
- {
- if (Application.platform == RuntimePlatform.Android)// 使用Unity切换Platform无法模拟
- {
- //text_id.text = "当前ID:" + zwn_interface_android.single.Cur_ID;
- }
- /* if (Cost_Change)
- {
- switch (Area_Num)
- {
- case -1: //没有人
- break;
- case 0://对齐
- break;
- case 1://请向右一点
- break;
- case 2://请向左一点
- break;
- case 3://请向后一点
- break;
- case 4://请向前一点
- break;
- }
- Cost_Change = false;
- }*/
- if (human_cost && !cost_success)
- {
- //area_num = human_cur.human_area_true();
- ////print("area_num " + area_num);
- //if (last_num != area_num)
- //{
- // cost_change = true;
- // last_num = area_num;
- //}
- ////print("area_num" + area_num);
- //show_true();
- //if (area_num == 0)
- if (FollowBoxManager.sigle.GetIsSuccee)
- {
- show_green.SetActive(true);
- time_cost += Time.deltaTime;
- if (time_cost >= 2)
- {
- human_end();
- float x = (zwn_common_data.single.zwn_transform_pose[5].x - zwn_common_data.single.zwn_transform_pose[6].x);
- float y = (zwn_common_data.single.zwn_transform_pose[5].y - zwn_common_data.single.zwn_transform_pose[11].y);
- float area = Mathf.Abs(x * y);
- alignArea = area;
- }
- }
- else
- {
- show_green.SetActive(false);
- if (time_cost != 0)
- time_cost = 0;
- }
- }
- }
- void show_true()
- {
- if (area_num == -1)
- {
- if (show.color != color_start)
- show.color = color_start;
- }
- else
- {
- for (int i = 0; i < show_spr.Length; i++)
- {
- if (area_num == i)
- {
- show.sprite = show_spr[i];
- show.SetNativeSize();
- }
- }
- if (show.color != color_end)
- show.color = color_end;
- }
- }
- public void halfbody()
- {
- human_cur.human_area_state_cur = human_area_state.halfbody;
- human_init1();
- }
- public void totalbody()
- {
- human_cur.human_area_state_cur = human_area_state.totalbody;
- human_init1();
- }
- /// <summary>
- /// 开始检测需调用
- /// </summary>
- public void human_init1()
- {
- if (time_cost != 0)
- time_cost = 0;
- if (human_cur.human_area_state_cur == human_area_state.totalbody)
- {
- total.SetActive(true);
- half.SetActive(false);
- }
- else if (human_cur.human_area_state_cur == human_area_state.halfbody)
- {
- total.SetActive(false);
- half.SetActive(true);
- }
- show_green.SetActive(false);
- if (tra_self == null)
- {
- tra_self = this.transform;
- }
- tra_self.localPosition = vec_end;
- area_num = -1;
- last_num = -2;
- show_true();
- cost_change = false;
- cost_success = false;
- human_cost = true;
- }
- public void SetCostChange(bool bCostChange)
- {
- cost_change = bCostChange;
- }
- public void SetCostSuccess(bool bCostSuccess)
- {
- cost_success = bCostSuccess;
- }
- }
|