Exemplo n.º 1
0
        // Update is called once per frame
        public virtual void FixedUpdate()
        {
            if (!isFireNow)
            {
                return;
            }
            if (!isFollow)
            {
                curveTime += Time.fixedDeltaTime * speed * 10 * magnitude;
                subDiff    = v3Diff * curveSpeed.Evaluate(curveTime);
                //				subDiff.y += high * curveHigh.Evaluate (curveTime);
                subDiff += highV3 * curveHigh.Evaluate(curveTime);
                if (!isMulHit && haveCollider)
                {
                    if (Physics.Raycast(transform.position, v3Diff, out hitInfor, 1f))
                    {
                        OnTriggerEnter(hitInfor.collider);
                    }
                }

                if (needRotate && subDiff.magnitude > 0.001f)
                {
                    Utl.RotateTowards(transform, origin + subDiff - transform.position);
                }
                transform.position = origin + subDiff;
                if (curveTime >= 1f)
                {
                    hitTarget = null;
                    onFinishFire(true);
                }
            }
            else
            {
                if (target == null || target.isDead ||
                    (RefreshTargetMSec > 0 &&
                     (DateEx.nowMS - lastResetTargetTime >= RefreshTargetMSec))
                    )
                {
                    lastResetTargetTime = DateEx.nowMS;
                    resetTarget();
                }
                subDiff = CalculateVelocity(transform.position);
                if (!isMulHit)
                {
                    if (Physics.Raycast(transform.position, v3Diff, out hitInfor, 1f))
                    {
                        OnTriggerEnter(hitInfor.collider);
                    }
                }
                //Rotate towards targetDirection (filled in by CalculateVelocity)
                if (targetDirection != Vector3.zero)
                {
                    Utl.RotateTowards(transform, targetDirection, turningSpeed);
                }
                transform.Translate(subDiff.normalized * Time.fixedDeltaTime * speed * 10, Space.World);
            }
        }
Exemplo n.º 2
0
//		void Start ()
//		{
//			Utl.setBodyMatEdit (transform);
//		}
                #endif

        void OnTriggerEnter(Collider collider)
        {
            CLUnit unit = collider.gameObject.GetComponent <CLUnit> ();

            if (unit != null && unit.isOffense != attacker.isOffense && !unit.isDead)
            {
                hitTarget = unit;
                onFinishFire(!isMulHit);
            }
        }
Exemplo n.º 3
0
        //是否分身

        public override void clean()
        {
            mAttacker = null;
//			hiddenLifeBar();
            isDead     = true;
            isCopyBody = false;
            CancelInvoke();
            StopAllCoroutines();
            state = CLRoleState.idel;
            base.clean();
        }
Exemplo n.º 4
0
        static void onFinishBorrowBullet(params object[] args)
        {
            CLBulletBase bullet = (CLBulletBase)(args [1]);

            if (bullet != null)
            {
                ArrayList list     = (ArrayList)(args [2]);
                CLUnit    attacker = (CLUnit)(list [0]);
                CLUnit    target   = (CLUnit)(list [1]);
                Vector3   orgPos   = (Vector3)(list [2]);
                Vector3   dir      = (Vector3)(list [3]);
                object    attr     = (list [4]);
                object    data     = (list [5]);
                object    callbak  = list [6];
//				fire (attacker, target, orgPos, dir, attr, data, callbak);
                bullet.doFire(attacker, target, orgPos, dir, attr, data, callbak);
                NGUITools.SetActive(bullet.gameObject, true);
            }
        }
Exemplo n.º 5
0
 void createBullet2(params object[] paras)
 {
     if (paras == null)
     {
         return;
     }
     object[] list = (object[])(paras[0]);
     if (list.Length >= 7)
     {
         CLUnit  attacker = (CLUnit)(list[0]);
         CLUnit  target   = (CLUnit)(list[1]);
         Vector3 orgPos   = (Vector3)(list[2]);
         Vector3 dir      = (Vector3)(list[3]);
         object  attr     = (object)(list[4]);
         object  data     = (object)(list[5]);
         object  callbak  = (object)(list[6]);
         CLBulletBase.fire(attacker, target, orgPos, dir, attr, data, callbak);
     }
     list = null;
 }
Exemplo n.º 6
0
        public static CLBulletBase fire(CLUnit attacker, CLUnit target, Vector3 orgPos,
                                        Vector3 dir, object attr, object data, object callbak)
        {
            if (attr == null || attacker == null)
            {
                Debug.LogError("bullet attr is null");
                return(null);
            }

            string bulletName = MapEx.getString(attr, "PrefabName");

            if (!CLBulletPool.havePrefab(bulletName))
            {
                ArrayList list = new ArrayList();
                list.Add(attacker);
                list.Add(target);
                list.Add(orgPos);
                list.Add(dir);
                list.Add(attr);
                list.Add(data);
                list.Add(callbak);
                CLBulletPool.borrowObjAsyn(bulletName, (Callback)onFinishBorrowBullet, list, null);
                return(null);
            }

            CLBulletBase bullet = CLBulletPool.borrowObj(bulletName);

            if (bullet == null)
            {
                return(null);
            }

            bullet.doFire(attacker, target, orgPos, dir, attr, data, callbak);
            NGUITools.SetActive(bullet.gameObject, true);
//		bullet.FixedUpdate();
            return(bullet);
        }
Exemplo n.º 7
0
        public virtual void doFire(CLUnit attacker, CLUnit target, Vector3 orgPos, Vector3 dir, object attr, object data, object callbak)
        {
            this.attr        = attr;
            this.data        = data;
            this.attacker    = attacker;
            this.target      = target;
            onFinishCallback = callbak;

            int SpeedRandomFactor = MapEx.getBytes2Int(attr, "SpeedRandomFactor");

            //			int SpeedRandomFactor = NumEx.bio2Int (MapEx.getBytes (attr, "SpeedRandomFactor"));
            speed = MapEx.getBytes2Int(attr, "Speed") / 10.0f;
            //			speed = (NumEx.bio2Int (MapEx.getBytes (attr, "Speed"))) / 10.0f;
            if (SpeedRandomFactor > 0)
            {
                speed = speed + attacker.fakeRandom(-SpeedRandomFactor, SpeedRandomFactor) / 100.0f;
            }
            high = MapEx.getBytes2Int(attr, "High") / 10.0f;
            //			high = NumEx.bio2Int (MapEx.getBytes (attr, "High"));
            if (MapEx.getBool(attr, "IsHighOffset"))
            {
                high = high * (1.0f + attacker.fakeRandom(-200, 200) / 1000.0f);
            }
            bool isZeroY = high > 0 ? true : false;

            float dis = MapEx.getBytes2Int(attr, "Range") / 10.0f;

            //			float dis = NumEx.bio2Int (MapEx.getBytes (attr, "Range")) / 10.0f;
            isFollow            = MapEx.getBool(attr, "IsFollow");
            isMulHit            = MapEx.getBool(attr, "IsMulHit");
            needRotate          = MapEx.getBool(attr, "NeedRotate");
            RefreshTargetMSec   = MapEx.getBytes2Int(attr, "RefreshTargetMSec");
            lastResetTargetTime = DateEx.nowMS;
            lastResetToPosTime  = DateEx.nowMS;
            //dir.y = 0;
            Utl.RotateTowards(transform, dir);

            origin             = orgPos;
            transform.position = origin;
            Vector3 toPos = Vector3.zero;

            if (target != null && dis <= 0)
            {
                toPos = target.transform.position;
            }
            else
            {
                toPos = origin + dir.normalized * dis;
                //toPos.y = 0;
            }
            int PosRandomFactor = MapEx.getBytes2Int(attr, "PosRandomFactor");

            //			int PosRandomFactor = NumEx.bio2Int (MapEx.getBytes (attr, "PosRandomFactor"));
            if (PosRandomFactor > 0)
            {
                toPos.x += attacker.fakeRandom(-PosRandomFactor, PosRandomFactor) / 100.0f;
                toPos.y += attacker.fakeRandom(-PosRandomFactor, PosRandomFactor) / 100.0f;
            }

            //if (isZeroY) {
            //    toPos.y = 0;
            //}

            if (boxCollider != null)
            {
                if (MapEx.getBool(attr, "CheckTrigger"))
                {
                    boxCollider.enabled = true;
                }
                else
                {
                    boxCollider.enabled = false;
                }
            }
            haveCollider = (boxCollider != null && boxCollider.enabled);

            v3Diff = toPos - origin;

            if (angleOffset != 0)
            {
                Vector3 center = origin + v3Diff / 2.0f;
//				transform.position = center + new Vector3 (0, high, 0);
                Vector3 _v3 = Utl.RotateAround(center + new Vector3(0, high, 0), center, v3Diff, angleOffset * Mathf.Sin(Mathf.Deg2Rad * Utl.getAngle(v3Diff).y));
//				transform.RotateAround (center, v3Diff, angleOffset * Mathf.Sin (Mathf.Deg2Rad * Utl.getAngle (v3Diff).y));
                highV3 = _v3 - center;
            }
            else
            {
                highV3 = new Vector3(0, high, 0);
            }

            magnitude = v3Diff.magnitude <= 0.00001f ? 1 : 1.0f / v3Diff.magnitude;

            hitTarget  = null;
            curveTime  = 0;
            curveTime2 = 0;
            isStoped   = false;
            isFireNow  = true;
            RotateBullet();
            CancelInvoke("timeOut");
            int stayTime = MapEx.getBytes2Int(attr, "MaxStayTime");

//			int stayTime = NumEx.bio2Int (MapEx.getBytes (attr, "MaxStayTime"));
            if (stayTime > 0.00001)
            {
                Invoke("timeOut", stayTime / 10.0f);
            }
        }
Exemplo n.º 8
0
 public abstract void onHurtFinish(object skillAttr, CLUnit attacker);
Exemplo n.º 9
0
 public abstract bool onHurt(int hurt, object skillAttr, CLUnit attacker);
Exemplo n.º 10
0
 public abstract void onRelaseTarget(CLUnit attacker);
Exemplo n.º 11
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);
                    }
                }
            }
        }
Exemplo n.º 12
0
 public void fire(int numPoints, int numEach, float angle, float offsetTime, CLUnit attacker, CLUnit target, object bulletAttr, object data, object callbak)
 {
     fire(-1, numPoints, numEach, angle, offsetTime, attacker, target, bulletAttr, data, callbak);
 }
Exemplo n.º 13
0
 public void fire(CLUnit attacker, CLUnit target, object bulletAttr, object data, object callbak)
 {
     fire(1, 1, 0, attacker, target, bulletAttr, data, callbak);
 }
Exemplo n.º 14
0
        IEnumerator createBullet(CLUnit attacker, CLUnit target, Vector3 orgPos, Vector3 dir, object attr, object data, object callbak, float waitSeconds)
        {
            yield return(new WaitForSeconds(waitSeconds));

            CLBulletBase.fire(attacker, target, orgPos, dir, attr, data, callbak);
        }