Example #1
0
 void OnDestroy()
 {
     ObjectEmitManager.GetInstance().RemoveEmitter(this);
 }
Example #2
0
        private ObjectEmitCalculateResult OnCalculate(ObjectEmitCalculateParams args, ref ObjectEmitCalculateResult result)
        {
            switch (args.emitter.launchType)
            {
            //存在一次发射不同方向的可能
            case EObjectEmitLaunchType.Line:
            {
                float lAngle = args.emitter.launchLineAngle * Mathf.Deg2Rad;
                result.startMoveSpeed.x       = args.emitter.launchMoveSpeed * Mathf.Cos(lAngle);
                result.startMoveSpeed.y       = args.emitter.launchMoveSpeed * Mathf.Sin(lAngle);
                args.emitter.launchLineAngle += args.emitter.launchLineRPT;

                result.startPosition.x = args.emitter.launchLineDistance * Mathf.Cos(lAngle);
                result.startPosition.y = args.emitter.launchLineDistance * Mathf.Sin(lAngle);

                result.startEulerAngles.z = (lAngle * Mathf.Rad2Deg) - 90;
                result.startAngleSpeed.z  = args.emitter.launchAngleSpeed;
            }
            break;

            case EObjectEmitLaunchType.Sector:
            {
                float sectorAnglePerTimes = args.emitter.launchSectorSpreadAngle / args.emitter.launchNum;
                float sectorAngle         = (sectorAnglePerTimes * args.index + args.emitter.launchSectorStartAngle) * Mathf.Deg2Rad;

                result.startPosition.x = args.emitter.launchSectorRadius * Mathf.Cos(sectorAngle);
                result.startPosition.y = args.emitter.launchSectorRadius * Mathf.Sin(sectorAngle);

                result.startMoveSpeed.x = args.emitter.launchMoveSpeed * Mathf.Cos(sectorAngle);
                result.startMoveSpeed.y = args.emitter.launchMoveSpeed * Mathf.Sin(sectorAngle);

                result.startAngleSpeed.z  = args.emitter.launchAngleSpeed;
                result.startEulerAngles.z = (sectorAngle * Mathf.Rad2Deg) - 90;
            }
            break;

            case EObjectEmitLaunchType.Random:
            {
                //随机位置
                float minR  = args.emitter.launchRandomMinRadius;
                float maxR  = args.emitter.launchRandomMaxRadius;
                float r     = ObjectEmitManager.GetInstance().GetRandom().Next((int)(minR * 100), (int)((maxR * 100) + 1)) / 100f;
                float angle = ObjectEmitManager.GetInstance().GetRandom().Next(0, 361) * Mathf.Deg2Rad;
                float rX    = r * Mathf.Cos(angle);
                float rY    = r * Mathf.Sin(angle);
                result.startPosition.x = rX;
                result.startPosition.y = rY;

                result.startMoveSpeed.x = args.emitter.launchMoveSpeed * (float)Mathf.Cos(angle);
                result.startMoveSpeed.y = args.emitter.launchMoveSpeed * (float)Mathf.Sin(angle);

                result.startAngleSpeed.z  = args.emitter.launchAngleSpeed;
                result.startEulerAngles.z = (angle * Mathf.Rad2Deg) - 90;
            }
            break;

            case EObjectEmitLaunchType.FixedPoint:
            {
                //固定位置
                if (args.emitter.launchFixedPointPoints.Length > 0)
                {
                    var ponit = args.emitter.launchFixedPointPoints[(args.index + args.times) % args.emitter.launchFixedPointPoints.Length];
                    result.startPosition.x = ponit.x;
                    result.startPosition.y = ponit.y;
                    result.startPosition.z = ponit.z;
                }
            }
            break;

            case EObjectEmitLaunchType.Custom:
            {
                if (args.emitter.launchCustomCallback != null)
                {
                    result = args.emitter.launchCustomCallback.Calculate(args);
                }
            }
            break;
            }

            return(result);
        }
Example #3
0
 void Start()
 {
     ObjectEmitManager.GetInstance().AddEmitter(this, launchName);
 }
Example #4
0
        void Launch()
        {
            if (!m_isCanEmit)
            {
                return;
            }

            if (launchEntities.Length > 0)
            {
                int  index       = 0;
                bool isNeedIndex = true;
                for (int i = 0; i < launchNum; i++)
                {
                    switch (launchOrderType)
                    {
                    case EObjectEmitCreateOrderType.Orderly:
                    {
                        index = launchOrderOrderlyByTimes ? Math.Abs(launchTimes % launchEntities.Length) : (i % launchEntities.Length);
                    }
                    break;

                    case EObjectEmitCreateOrderType.Random:
                    {
                        if (!isNeedIndex)
                        {
                            break;
                        }
                        if (launchOrderOrderlyByTimes)
                        {
                            isNeedIndex = false;
                        }
                        index = ObjectEmitManager.GetInstance().GetRandom().Next(0, launchEntities.Length);        //随机函数,从中取一个
                    }
                    break;

                    case EObjectEmitCreateOrderType.Fixed:
                    {
                        index = launchOrderFixedIndex;
                    }
                    break;
                    }

                    ///
                    m_objectEmitCreateParams.parent = launchParent;
                    m_objectEmitCreateParams.prefab = launchEntities[index];

                    m_objectEmitCalculateParams.emitter = this;
                    m_objectEmitCalculateParams.index   = i;
                    m_objectEmitCalculateParams.times   = Mathf.Abs(launchTimes);

                    m_objectEmitCalculateResult.startPosition    = Vector3.zero;
                    m_objectEmitCalculateResult.startEulerAngles = Vector3.zero;
                    m_objectEmitCalculateResult.startAngleSpeed  = Vector3.zero;
                    m_objectEmitCalculateResult.startMoveSpeed   = Vector3.zero;

                    ///
                    m_objectEmitLaunchParams.createResult    = ObjectEmitManager.GetInstance().GetHandler().OnCreate(m_objectEmitCreateParams);
                    m_objectEmitLaunchParams.calculateResult = OnCalculate(m_objectEmitCalculateParams, ref m_objectEmitCalculateResult);

                    //发射前的校验
                    if (launchRelative != null)
                    {
                        m_objectEmitLaunchParams.calculateResult.startPosition += launchRelative.transform.position;
                    }

                    if (launchFixAngle)
                    {
                        m_objectEmitLaunchParams.calculateResult.startEulerAngles.z = 0;
                        m_objectEmitLaunchParams.calculateResult.startAngleSpeed.z  = 0;
                    }

                    ObjectEmitManager.GetInstance().GetHandler().OnLaunch(m_objectEmitLaunchParams);
                }
            }
            launchTimes--;
        }