123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System.Collections;
- using System.Collections.Generic;
- using LitJson;
- using UnityEngine;
- public class pengzhuang : MonoBehaviour
- {
- public List<GameObject> golist;
- public int index;
- private void Start()
- {
- StartCoroutine(sendInfo());
- }
- void OnTriggerEnter(Collider collider)
- {
- //进入触发器执行的代码
- }
- void OnCollisionEnter(Collision collision)
- {
- Debug.Log("OnCollisionEnter" + index);
- server.SendMessage(getData("Enter", collision.gameObject));
- }
- void OnCollisionExit(Collision collision)
- {
- Debug.Log("OnCollisionExit" + index);
- server.SendMessage(getData("Exit", collision.gameObject));
- }
- private IEnumerator sendInfo()
- {
- while(true)
- {
- for (int i = 0; i < golist.Count; i++)
- {
- server.SendMessage(getData("None", golist[i]));
- }
- yield return new WaitForSeconds(0.5f);
- }
-
- }
- JsonData getData(string msg,GameObject go)
- {
- JsonData data = new JsonData();
- data["index"] = index;
- data["type"] = msg;
- data["distance"] = Vector3.Distance(this.transform.position,go.transform.position);
- data["size"] =new JsonData();
- data["size"]["x"] = go.GetComponent<BoxCollider>().size.x*go.transform.localScale.x;
- data["size"]["y"] = go.GetComponent<BoxCollider>().size.y * go.transform.localScale.y;
- data["size"]["z"] = go.GetComponent<BoxCollider>().size.z * go.transform.localScale.z;
- // Debug.Log("getData===>"+data.ToJson());
- return data;
- }
- }
|