Exemplo n.º 1
0
    /// <summary>
    /// 在 GetPassengerFlow 中调用,
    /// 用来统计摄像机 PassengerFlowData 中的数据
    /// </summary>
    /// <param name="channel">摄像机的通道</param>
    /// <param name="ruleId">ruleID=0表示进,ruleID=1表示出</param>
    /// <param name="count">用来存放人数</param>
    /// <param name="ipFrom">服务器的IP地址</param>
    void PassengerFlow(int channel, int ruleId, int count, string ipFrom)
    {
        //字典集合DicPassengerFlowDataKey的键
        DicPassengerFlowDataKey = channel + ":" + ipFrom;

        //如果字典集合DicPassengerFlowDataKey中不包含DicPassengerFlowDataKey键(即表示没有这个摄像机)
        //则添加一个摄像机
        if (!DicPassengerFlowData.ContainsKey(DicPassengerFlowDataKey))
        {
            pfd.channel    = channel;
            pfd.ipFrom     = ipFrom;
            pfd.EnterCount = 0;
            pfd.ExitCount  = 0;
            pfd.SumCount   = 0;

            DicPassengerFlowData[DicPassengerFlowDataKey] = pfd;
        }

        //字典集合DicPassengerFlowDataKey中包含DicPassengerFlowDataKey键
        //如果包含这个摄像机,则赋值给pdf
        else
        {
            pfd = DicPassengerFlowData[DicPassengerFlowDataKey];
        }

        //表示进入一个人
        if (ruleId == 0)
        {
            pfd.SumCount        += (1 + count);
            PassengerEnterCount += (1 + count);
            pfd.EnterCount      += (1 + count);
        }

        //表示出去一个人
        else if (ruleId == 1)
        {
            pfd.SumCount       -= (1 + count);
            PassengerExitCount += (1 + count);
            pfd.ExitCount      += (1 + count);

            //如果摄像机上的SumCount小于0
            if (pfd.SumCount < 0)
            {
                pfd.SumCount = 0;
            }
        }

        else
        {
            return;
        }

        //将这个摄像机的人流信息存到 DicPassengerFlowData 这个字典集合中
        DicPassengerFlowData[DicPassengerFlowDataKey] = pfd;

        //判断PFArea这个引用是否为空
        if (PFArea != null)
        {
            PFArea.Invoke(DicPassengerFlowData);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 加载客流统计区域,及加载当天最新统计信息,
    /// 画客流统计区域
    /// </summary>
    /// <returns>The passenger flow area.</returns>
    IEnumerator LoadPassengerFlowArea()
    {
        Logger.Instance.WriteLog("加载客流统计区域,及加载当天最新统计信息");
        Logger.Instance.WriteLog("加载客流统计区域");


        //实例化一个PassengerFlowAreaDao类
        PassengerFlowAreaDao pfaDao = new PassengerFlowAreaDao();

        //调用PassengerFlowAreaDao中的Select001函数
        pfaDao.Select001();

        //将pfa.Result中的结构体赋值给infoLst
        infoLst = pfaDao.Result;

        //遍历infoLst集合
        foreach (var info in infoLst)
        {
            //如果PassengerFlowAreaInfo中的Name为主客流
            if (info.Name == "主客流")
            {
                //定义一个对象
                GameObject g = new GameObject();

                //将这个对象的位置初始化为原点
                g.transform.position = Vector3.zero;

                //给这个对象上挂PassengerFlowInfoDetail脚本,并用p来接收这个脚本
                PassengerFlowInfoDetail p = g.AddComponent <PassengerFlowInfoDetail>();

                //给这四个材质变量赋初值
                p.mat_red    = mat_red;
                p.mat_green  = mat_green;
                p.mat_yellow = mat_yellow;
                p.mat_orange = mat_orange;

                //得到人流控制面板UI
                p.PFInfoUI = PassengerInfo.GetComponent <PassengerFlowInfoUI>();
                //初始化对象p结构体PassengerFlowAreaInfo的信息
                p.Init(info, null);

                PFArea += p.UpdateData;

                continue;
            }

            //定义一个string类型的数组,并用"|"分割
            string[] point = info.Points.Split('|');

            //定义一个V3类型及的数组,长度为...?
            Vector3[] pts = new Vector3[point.Length / 3];

            //定义一个V3类型的变量,并初始化为原点
            Vector3 vec = Vector3.zero;

            //遍历客流统计区域顶点的集合
            for (int i = 0; i < pts.Length; i++)
            {
                pts[i] = new Vector3(float.Parse(point[i * 3]), float.Parse(point[i * 3 + 1]), float.Parse(point[i * 3 + 2]));
                vec   += pts[i];
            }

            vec /= pts.Length;

            int[] triangles = new int[pts.Length];

            for (int i = 0; i < triangles.Length; i++)
            {
                triangles[i] = i;
            }

            //定义一个对象
            GameObject go = new GameObject();

            //给这个对象设置层级
            go.layer = LayerMask.NameToLayer("PassengerFlowArea");

            //给go对象添加MeshRender组件
            MeshRenderer meshrend = go.AddComponent <MeshRenderer>();

            //meshrend.material.shader = Shader.Find("Particles/Alpha Blended");
            //meshrend.material.SetColor("_TintColor",new Color(0,1,0,0.2f));

            //给go对象赋值绿色材质
            meshrend.material = mat_green;

            //给go对象添加MeshFilter组件
            MeshFilter meshFilter = go.AddComponent <MeshFilter>();

            //给网格定点赋上pts三角形面片
            meshFilter.mesh.vertices = pts;

            //网格角度为triangles
            meshFilter.mesh.triangles = triangles;

            //重新计算网格的发现
            meshFilter.mesh.RecalculateNormals();

            //给go对象添加meshCollider组件
            MeshCollider mc = go.AddComponent <MeshCollider>();

            //将meshFilter的mesh赋值给MeshCollider的sharedMesh,作为共享网格
            mc.sharedMesh = meshFilter.mesh;

            //给go对象重新赋值一个坐标
            go.transform.position = new Vector3(0, 0.2f, 0);


            GameObject infoUI = Instantiate(PassengerFlowInfoShow) as GameObject;


            infoUI.transform.SetParent(PassengerFlowInfoShowParent);


            infoUI.transform.localScale = Vector3.one;

            infoUI.GetComponent <PassengerAreaUI>().Bind(vec, info.Name);

            //GameObject go = Instantiate(PassengerFlowAreaPrefab) as GameObject;


            PassengerFlowInfoDetail pfid = go.AddComponent <PassengerFlowInfoDetail>();

            pfid.mat_red    = mat_red;
            pfid.mat_green  = mat_green;
            pfid.mat_yellow = mat_yellow;
            pfid.mat_orange = mat_orange;

            pfid.Init(info, infoUI.GetComponent <PassengerAreaUI>());
            PFArea += pfid.UpdateData;
        }


        //从数据库加载当天最新的客流统计信息
        Logger.Instance.WriteLog("从数据库加载当天最新的客流统计信息");

        List <PassengerFlowInfoLog> InfoLogLst = pfaDao.Select003(DateTime.Now.ToString("yyyyMMdd") + "000000");

        PassengerFlowData _pfData = new PassengerFlowData();

        foreach (var logInfo in InfoLogLst)
        {
            _pfData.SumCount   = int.Parse(logInfo.SumCount);
            _pfData.EnterCount = int.Parse(logInfo.EnterCount);
            _pfData.ExitCount  = int.Parse(logInfo.ExitCount);
            DicPassengerFlowData[logInfo.PassengerFlowUrl] = _pfData;
        }

        if (PFArea != null)
        {
            PFArea.Invoke(DicPassengerFlowData);
        }
        yield return(infoLst);
    }