Beispiel #1
0
        /// <summary>
        /// Gets the points.
        /// </summary>
        /// <param name="center">From position.中心点</param>
        /// <param name="eulerAngles">Euler angles.朝向</param>
        /// <param name="r">The red component.半径</param>
        /// <param name="left">Left.左半点列表</param>
        /// <param name="right">Right.右半点列表</param>
        public void getPoints(Vector3 center, Vector3 eulerAngles, float r, ref List <Vector3> left, ref List <Vector3> right)
        {
            //		float angle = 360.0f / (dirNum + 1);
            float   angle = 360.0f / (dirNum);
            int     half  = dirNum / 2;
            Vector3 pos   = Vector3.zero;

            for (int i = 0; i <= half; i++)
            {
                pos   = AngleEx.getCirclePointStartWithYV3(center, r, eulerAngles.y - i * angle);
                pos.y = rayHeight;
                left.Add(pos);

                pos   = AngleEx.getCirclePointStartWithYV3(center, r, eulerAngles.y - (dirNum - i) * angle);
                pos.y = rayHeight;
                right.Add(pos);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the circular cells.取得周围的cell的index
        /// </summary>
        /// <returns>The circular cells.</returns>
        /// <param name="centerPos">中心点 postion.</param>
        /// <param name="r">半径.</param>
        public List <int> getCircleCells(Vector3 centerPos, int r)
        {
            Dictionary <int, bool> map = new Dictionary <int, bool>();
            float   l      = Mathf.PI * 2 * r;
            int     n      = Mathf.CeilToInt(l / CellSize);
            float   angel  = 360.0f / n;
            Vector3 pos    = Vector3.zero;
            int     _index = 0;

            for (int i = 0; i < n; i++)
            {
                pos    = AngleEx.getCirclePointV3(centerPos, r, i * angel);
                _index = GetCellIndex(pos);
                if (_index >= 0 && !map.ContainsKey(_index))
                {
                    map[_index] = true;
                }
            }
            List <int> ret = new List <int>();

            ret.AddRange(map.Keys);
            return(ret);
        }
Beispiel #3
0
        public void fire(int firePointIndex, int numPoints, int numEach, float angle, float offsetTime, CLUnit attacker, CLUnit target, object attr, object data, object callbak)
        {
            if (attacker == null || attr == null)
            {
                return;
            }
            //#if UNITY_EDITOR
            //		CLTest cltest = GetComponent<CLTest>();
            //		if(cltest == null) {
            //			cltest = gameObject.AddComponent<CLTest>();
            //		}
            //		cltest.fire ( numPoints, numEach, angle, attacker);
            //#endif

            Transform firePoint = null;

            if (firePointIndex < 0 || firePoints == null || firePoints.Length <= firePointIndex)
            {
                firePoint = transform;
            }
            else
            {
                firePoint = firePoints[firePointIndex];
            }

            int  h       = NumEx.bio2Int(MapEx.getBytes(attr, "High"));
            bool isZeroY = h > 0 ? true : false;

            if (numPoints > 0)
            {
                // get fire point
                bool needFireMid = false;   //是否需要在中间发射(是奇数时需要)
                int  half        = numPoints / 2;
                if (numPoints % 2 == 0)
                {
                    needFireMid = false;
                }
                else
                {
                    needFireMid = true;
                }

                Vector3 pos2 = Vector3.zero;
                Vector3 dir  = Vector3.zero;
                for (int i = 0; i < numEach; i++)
                {
                    if (needFireMid)
                    {
                        dir = attacker.mbody.forward;
                        if (isZeroY)
                        {
                            dir.y = 0;
                        }
                        //					StartCoroutine (createBullet (attacker, target, firePoint.position, dir, attr, data, callbak, i * 0.1f));
                        object[] list =
                        {
                            attacker,
                            target,
                            firePoint.position,
                            dir,
                            attr,
                            data,
                            callbak
                        };
                        InvokeEx.invokeByFixedUpdate((Callback)createBullet2, list, i * offsetTime);
                    }
                    for (int j = 1; j <= half; j++)
                    {
                        pos2 = AngleEx.getCirclePointStartWithYV3(firePoint.position, 2, attacker.mbody.eulerAngles.y - j * angle);
                        if (isZeroY)
                        {
                            pos2.y = 0;
                        }
                        dir = pos2 - firePoint.position;
                        //					StartCoroutine (createBullet (attacker, target, firePoint.position, dir, attr, data, callbak, i * 0.1f));
                        object[] list =
                        {
                            attacker,
                            target,
                            firePoint.position,
                            dir,
                            attr,
                            data,
                            callbak
                        };
                        InvokeEx.invokeByFixedUpdate((Callback)createBullet2, list, i * offsetTime);

                        pos2 = AngleEx.getCirclePointStartWithYV3(firePoint.position, 2, attacker.mbody.eulerAngles.y + j * angle);
                        if (isZeroY)
                        {
                            pos2.y = 0;
                        }
                        dir = pos2 - firePoint.position;
                        //					StartCoroutine (createBullet (attacker, target, firePoint.position, dir, attr, data, callbak, i * 0.1f));
                        object[] list2 =
                        {
                            attacker,
                            target,
                            firePoint.position,
                            dir,
                            attr,
                            data,
                            callbak
                        };
                        InvokeEx.invokeByFixedUpdate((Callback)createBullet2, list2, i * offsetTime);
                    }
                }
            }
        }