コード例 #1
0
        /// <summary>
        /// 取得该区域内所有的实体(矩阵)
        /// </summary>
        /// <param name="ltwm"></param>
        /// <param name="rotation"></param>
        /// <param name="forward"></param>
        /// <param name="position"></param>
        /// <param name="radius"></param>
        /// <param name="offsetX"></param>
        /// <param name="offsetY"></param>
        /// <param name="angleOffset"></param>
        /// <param name="layerMask"></param>
        /// <returns></returns>
        public static List <List <uint> > GetEntityInRange(Matrix4x4 ltwm, Quaternion rotation, Vector3 forward, Vector3 position, float radius, float offsetX = 0, float offsetY = 0, float angleOffset = 0, LayerMask layerMask = LayerMask.Monster | LayerMask.Character | LayerMask.Trap)
        {
            List <List <uint> > list        = new List <List <uint> >();
            List <uint>         listDummy   = new List <uint>();
            List <uint>         listMonster = new List <uint>();
            List <uint>         listPlayer  = new List <uint>();

            if (!GameWorld.Entities.ContainsKey(GameWorld.thePlayer.ID))
            {
                GameWorld.Entities.Add(GameWorld.thePlayer.ID, GameWorld.thePlayer);
            }
            Matrix4x4 m  = ltwm;
            Matrix4x4 m1 = new Matrix4x4();

            m1.SetRow(0, new Vector4(0, 0, offsetX, 0));
            m1.SetRow(1, new Vector4(0, 1, 0, 0));
            m1.SetRow(2, new Vector4(0, 0, 0, offsetX));
            m1.SetRow(3, new Vector4(0, 0, 0, 1));
            m = m * m1;
            Vector3 pos = new Vector3(m.m03, m.m13, m.m23);

            foreach (var pair in GameWorld.Entities)
            {
                EntityParent entity = pair.Value;
                if (!entity.Transform)
                {
                    continue;
                }
                ///如果实体不是在这个层内的话,直接过滤
                if (((1 << entity.Transform.gameObject.layer) & (int)layerMask) == 0)
                {
                    continue;
                }
                float entityRadius = ((float)entity.GetInAttr("scaleRadius")) / 100f;
                if ((pos - entity.Transform.position).magnitude < entityRadius + radius)
                {
                    continue;
                }
                if (pair.Value is EntityDummy)
                {
                    listDummy.Add(pair.Key);
                }
                else if (pair.Value is EntityPlayer)
                {
                    listPlayer.Add(pair.Key);
                }
                else if (pair.Value is EntityBeast)
                {
                    listMonster.Add(pair.Key);
                }
            }
            GameWorld.Entities.Remove(GameWorld.thePlayer.ID);
            list.Add(listDummy);
            list.Add(listMonster);
            list.Add(listPlayer);
            return(list);
        }
コード例 #2
0
        /// <summary>
        /// 取得直线上的所有实体
        /// </summary>
        /// <param name="ltwm"></param>
        /// <param name="rotation"></param>
        /// <param name="forward"></param>
        /// <param name="position"></param>
        /// <param name="length"></param>
        /// <param name="direction"></param>
        /// <param name="width"></param>
        /// <param name="offsetX"></param>
        /// <param name="offsetY"></param>
        /// <param name="angleOffset"></param>
        /// <param name="layerMask"></param>
        /// <returns></returns>
        public static List <List <uint> > GetEnitiesForntLineNew(Matrix4x4 ltwm, Quaternion rotation, Vector3 forward, Vector3 position, float length, Vector3 direction, float width, float offsetX = 0, float offsetY = 0, float angleOffset = 0, LayerMask layerMask = LayerMask.Monster | LayerMask.Character | LayerMask.Trap)
        {
            List <List <uint> > list        = new List <List <uint> >();
            List <uint>         listDummy   = new List <uint>();
            List <uint>         listMonster = new List <uint>();
            List <uint>         listPlayer  = new List <uint>();

            if (!GameWorld.Entities.ContainsKey(GameWorld.thePlayer.ID))
            {
                GameWorld.Entities.Add(GameWorld.thePlayer.ID, GameWorld.thePlayer);
            }
            foreach (var pair in GameWorld.Entities)
            {
                if (pair.Value.Transform == null)
                {
                    continue;
                }
                float     entityRadius = ((float)pair.Value.GetInAttr("scaleRadius")) / 100f;
                Matrix4x4 m            = ltwm;
                Matrix4x4 m1           = new Matrix4x4();
                m1.SetRow(0, new Vector4(0, 0, 0, (width + entityRadius) * 0.5f + offsetY));
                m1.SetRow(1, new Vector4(0, 1, 0, 0));
                m1.SetRow(2, new Vector4(0, 0, 0, 0));
                m1.SetRow(3, new Vector4(0, 0, 0, 1));
                m = m * m1;
                Vector3 pos0 = new Vector3(m.m03, m.m13, m.m23);

                m = ltwm;
                m1.SetRow(2, new Vector4(0, 0, 0, length + entityRadius + offsetX));
                m = m * m1;
                Vector3 pos1 = new Vector3(m.m03, m.m13, m.m23);

                m = ltwm;
                m1.SetRow(0, new Vector4(0, 0, 0 - (width + entityRadius) * 0.5f + offsetY));
                m = m * m1;
                Vector3 pos2 = new Vector3(m.m03, m.m13, m.m23);

                m = ltwm;
                m1.SetRow(2, new Vector4(0, 0, 0, offsetX));
                m = m * m1;
                Vector3 pos3    = new Vector3(m.m03, m.m13, m.m23);
                Vector3 postion = pair.Value.Transform.position;
                if (!InRect(position, pos0, pos1, pos2, pos3))
                {
                    continue;
                }
                if (pair.Value is EntityDummy)
                {
                    listDummy.Add(pair.Key);
                }
                else if (pair.Value is EntityPlayer)
                {
                    listPlayer.Add(pair.Key);
                }
                else if (pair.Value is EntityBeast)
                {
                    listMonster.Add(pair.Key);
                }
            }
            GameWorld.Entities.Remove(GameWorld.thePlayer.ID);
            return(list);
        }
コード例 #3
0
        /// <summary>
        /// 取得范围内所有的实体(坐标)
        /// </summary>
        /// <returns></returns>
        public static List <List <uint> > GetEntityInRange(Vector3 position, float radius, float offsetX = 0, float offsetY = 0, float angleOffset = 0, LayerMask layerMask = LayerMask.Monster | LayerMask.Character | LayerMask.Trap)
        {
            List <List <uint> > list        = new List <List <uint> >();
            List <uint>         listDummy   = new List <uint>();
            List <uint>         listMonster = new List <uint>();
            List <uint>         listPlayer  = new List <uint>();

            if (!GameWorld.Entities.ContainsKey(GameWorld.thePlayer.ID))
            {
                GameWorld.Entities.Add(GameWorld.thePlayer.ID, GameWorld.thePlayer);
            }
            foreach (var pair in GameWorld.Entities)
            {
                EntityParent entity = pair.Value;
                if (!entity.Transform)
                {
                    continue;
                }
                ///如果实体不是在这个层内的话,直接过滤
                if (((1 << entity.Transform.gameObject.layer) & (int)layerMask) == 0)
                {
                    continue;
                }
                float entityRadius = ((float)entity.GetInAttr("scaleRadius")) / 100f;
                if ((position - entity.Transform.position).magnitude < entityRadius + radius)
                {
                    continue;
                }
                if (pair.Value is EntityDummy)
                {
                    listDummy.Add(pair.Key);
                }
                else if (pair.Value is EntityPlayer)
                {
                    listPlayer.Add(pair.Key);
                }
                else if (pair.Value is EntityBeast)
                {
                    listMonster.Add(pair.Key);
                }
            }
            GameWorld.Entities.Remove(GameWorld.thePlayer.ID);
            list.Add(listDummy);
            list.Add(listMonster);
            list.Add(listPlayer);
            return(list);
        }