Ejemplo n.º 1
0
    //飞向玩家身上
    public void FlyToPlayer()
    {
        //先把特效关掉
        if (mEffect)
        {
            ComplexObjectPool.Release(mEffect);
            mEffect = null;
        }

        if (null != mController)
        {
            mController.ShowModel(false);
            mController.ShowEffect(true);
        }
        var myPos = ObjManager.Instance.MyPlayer.Position;
        var dir   = (Position - myPos).normalized;

        mControlPoint          = Position + dir * Random.Range(ControlPointOffsetDistanceMin, ControlPointOffsetDistanceMax);
        mControlPoint.y       += Random.Range(ControlPointOffsetHeightMin, ControlPointOffsetHeightMax);
        mControlPointMoveSpeed = ControlPointSpeed;
        mMoveSpeed             = MoveSpeed;
        mControlPointReached   = false;

        mState = DropItemState.FlyToPlayer;
    }
Ejemplo n.º 2
0
    //初始化
    public override bool Init(InitBaseData initData, Action callback = null)
    {
        base.Init(initData);

        Reset();

        var data = initData as InitDropItemData;

        if (data == null)
        {
            return(false);
        }
        mOwnerIsMe       = false;
        mCanAutoPickup   = true;
        HasAutoFightMove = false;
        var player = ObjManager.Instance.MyPlayer;

        if (player)
        {
            if (data.Owner.Contains(player.GetObjId()))
            {
                mOwnerIsMe = true;
                //mCanAutoPickup = true;
            }
            else if (data.Owner.Count <= 0)
            {
//新增,这种是谁都可以拾取的
                mOwnerIsMe = true;
            }
        }
        mOwnerPickUpProtectionTime = Game.Instance.ServerTime.AddSeconds(data.RemianSeconds);
        mLifeTime = DateTime.Now.AddSeconds(TotalLifeTime);

        //float height = GameLogic.Instance.Scene.GetTerrainHeight(data.TargetPos) + 0.1f;
        //mTargetPos = new Vector3(data.TargetPos.x, height, data.TargetPos.y);

        if (-1 == TerrainLayerMask)
        {
            TerrainLayerMask = LayerMask.GetMask(GAMELAYER.ShadowReceiver);
        }
        var        ray = new Ray(new Vector3(data.TargetPos.x, 50, data.TargetPos.y), Vector3.down);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 80, TerrainLayerMask))
        {
            mTargetPos    = hit.point;
            mTargetPos.y += 0.1f;
        }
        else
        {
            var height = GameLogic.GetTerrainHeight(data.TargetPos.x, data.TargetPos.y) + 0.1f;
            mTargetPos = new Vector3(data.TargetPos.x, height, data.TargetPos.y);
        }

        LoadResourceAction = () =>
        {
            if (State == ObjState.Deleted)
            {
                return;
            }

            State = ObjState.LoadingResource;
            LoadRes(() =>
            {
                State = ObjState.Normal;
                if (true != data.PlayDrop)
                {
                    //不需要播放掉落动画
                    Position = mTargetPos;
                    mState   = DropItemState.StayOnGround;

                    // 初始特效
                    if (mTableData != null && mTableData.Quality > 0 && !mEffect)
                    {
                        var resource = Table.GetClientConfig(600 + mTableData.Quality);

                        if (!string.IsNullOrEmpty(resource.Value))
                        {
                            CreateQualityEffect(resource.Value, o =>
                            {
                                if (DropItemState.StayOnGround != mState && DropItemState.Droping != mState)
                                {
                                    ComplexObjectPool.Release(o);
                                    mEffect = null;
                                }
                            });
                        }
                    }
                }
                else
                {
                    //需要播放掉落动画
                    StartCoroutine(Delay());
                    mState = DropItemState.Delay;
                }

                if (null != callback)
                {
                    callback();
                }

                mController = mModel.GetComponent <DropItemController>();
                if (null != mController)
                {
                    mController.ShowModel(true);
                    mController.ShowEffect(false);
                }
            });
        };

        EventDispatcher.Instance.AddEventListener(EquipBagNotFullChange.EVENT_TYPE, OnEquipRecycleSuccess);
        EventDispatcher.Instance.AddEventListener(UIEvent_PickSettingChanged.EVENT_TYPE, OnPickupSettingChanged);
        if (mOwnerIsMe)
        {
            ObjManager.Instance.MyPlayer.AutoCombat.AddDropPos(this);
        }
        return(true);
    }