Пример #1
0
        //仓库信息输入
        public static void SetStoreAnwData(IList <PMsg_StagePropUnit> list)
        {
            StorageDeltaList storageDeltaList = Farm_Game_StoreInfoModel.storage;

            if (list != null)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    //移除该id的信息,后面重新输入
                    storageDeltaList.Seeds.Remove(list[i].Id);
                    storageDeltaList.Results.Remove(list[i].Id);
                    storageDeltaList.Oils.Remove(list[i].Id);
                    storageDeltaList.DogFoods.Remove(list[i].Id);
                    storageDeltaList.Fertilizers.Remove(list[i].Id);
                    storageDeltaList.Elixirs.Remove(list[i].Id);
                    storageDeltaList.Formulas.Remove(list[i].Id);
                    //若数量为0,则表示该物品已从仓库移除

                    BaseAtrribute item = LoadObjctDateConfig.Instance.GetAtrribute(list[i].Id);

                    if (list[i].Count == 0)
                    {
                        switch (item.Type)
                        {
                        case ObjectType.Seed:
                            Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", list[i].Id, "test1"));

                            storageDeltaList.Seeds.Remove(list[i].Id);
                            Seed seed;
                            if (storageDeltaList.Seeds.TryGetValue(list[i].Id, out seed))
                            {
                                Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", seed.Name, "test1"));
                            }

                            Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", "test", "test1"));

                            break;

                        case ObjectType.Result:
                            storageDeltaList.Results.Remove(list[i].Id);
                            break;

                        case ObjectType.SeniorOil:
                        case ObjectType.PrimaryOil:
                        case ObjectType.SemiOil:
                            storageDeltaList.Oils.Remove(list[i].Id);
                            break;

                        case ObjectType.DogFood:
                            storageDeltaList.DogFoods.Remove(list[i].Id);
                            break;

                        case ObjectType.Fertilizer:
                            storageDeltaList.Fertilizers.Remove(list[i].Id);
                            break;

                        case ObjectType.elixir:
                            storageDeltaList.Elixirs.Remove(list[i].Id);
                            break;

                        case ObjectType.formula:
                            storageDeltaList.Formulas.Remove(list[i].Id);
                            break;

                        default:
                            Debug.LogError("后台返回了不该在仓库的东西:" + item.Name);
                            break;
                        }
                    }
                    else
                    {
                        if (item != null)
                        {
                            switch (item.Type)
                            {
                            case ObjectType.Seed:

                                storageDeltaList.Seeds.Add(list[i].Id, SetSeedAnwData(list[i]));
                                //                                Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", storageDeltaList.Seeds[list[i].Id].Name, storageDeltaList.Seeds[list[i].Id].ObjectNum));

                                break;

                            case ObjectType.Result:
                                storageDeltaList.Results.Add(list[i].Id, SetResultAnwData(list[i]));
                                break;

                            case ObjectType.SeniorOil:
                            case ObjectType.PrimaryOil:
                            case ObjectType.SemiOil:
                                storageDeltaList.Oils.Add(list[i].Id, SetOilAnwData(list[i]));
                                break;

                            case ObjectType.DogFood:
                                storageDeltaList.DogFoods.Add(list[i].Id, SetDogFoodAnwData(list[i]));
                                break;

                            case ObjectType.Fertilizer:
                                storageDeltaList.Fertilizers.Add(list[i].Id, SetFertilizerAnwData(list[i]));
                                break;

                            case ObjectType.elixir:
                                storageDeltaList.Elixirs.Add(list[i].Id, SetElixirAnwData(list[i]));
                                break;

                            case ObjectType.formula:
                                storageDeltaList.Formulas.Add(list[i].Id, SetFormulaAnwData(list[i]));
                                break;

                            default:
                                Debug.LogError("后台返回了不该在仓库的东西:" + item.Name);
                                break;
                            }
                        }
                    }
                }

                if (storageDeltaList.Seeds.Count == 0)
                {
                    if (ViewMgr.Instance.isOpen(ViewNames.SeedBarView))
                    {
                        SystemMsgView.SystemFunction(Function.OpenDialog, Info.SeedNumNotEngouth, ViewNames.ShopView, (
                                                         () =>
                        {
                            SeedBarView.PlayBack();
                        }));
                    }
                }
            }
            Farm_Game_StoreInfoModel.storage = storageDeltaList;
        }
Пример #2
0
        public override void OnClicked(WorldObject worldObject)
        {
            base.OnClicked(worldObject);


            //开始进入播种模�?&& this.Brand == null
            if (CommonActionBarView.Action1 == GameAction.None && this.Plant == null)
            {
                if (!FriendFarmManager.Instance.isVisiting)
                {
                    //打开播种栏
                    ViewMgr.Instance.Open(ViewNames.SeedBarView);
                    if (ViewMgr.Instance.isOpen(ViewNames.FriendsListView))
                    {
                        ViewMgr.Instance.Close(ViewNames.FriendsListView);
                    }
                }
            }
            //判断翻地清除植物
            if (FieldsController.ProtocalAction == ProtocalAction.None && CommonActionBarView.Action1 == GameAction.Plow && this.Plant != null && this.EnablePlant == 1)
            {
                SystemMsgView.SystemFunction(Function.OpenDialog, Info.Reclaim, null, (delegate
                {
                    FieldsController.Instance.ReqSenPlowdAction(this.FarmID);
                    loadAni("Animation/fandi");
                }));
            }

            if (this.Plant == null)
            {
                //当前地块没有植物,进入无模�?
                CommonActionBarView.Action1 = GameAction.None;
                if (ViewMgr.Instance.isOpen(ViewNames.TimeBarView))
                {
                    ViewMgr.Instance.Close(ViewNames.TimeBarView);
                }
            }

            //施肥浇水除虫除草
            if (FieldsController.ProtocalAction == ProtocalAction.None && (CommonActionBarView.Action1 == GameAction.weed || CommonActionBarView.Action1 == GameAction.Debug || CommonActionBarView.Action1 == GameAction.Fertitlize || CommonActionBarView.Action1 == GameAction.Water))
            {
                SeletedFarmID = FarmID;

                switch (CommonActionBarView.Action1)
                {
                case GameAction.Debug:
                    if (this.plant.IsWorm == 1)
                    {
                        loadAni("Animation/chuchong");
//                            MusicManager.Instance.Playsfx(AudioNames.Debug);
                        FieldsController.Instance.SendWFActionReq(this.FarmID, CommonActionBarView.Action1, 701);
                        FieldsController.ProtocalAction = (ProtocalAction)((int)CommonActionBarView.Action1);
                    }
                    else
                    {
                        SystemMsgView.SystemFunction(Function.Tip, Info.PlantNoBug);
                    }
                    break;

                case GameAction.Fertitlize:
                    //                        loadAni("Animation/chuchong");
                    //    0                    FieldsController.ProtocalAction =ProtocalAction.Fertitlize;
                    //
                    //                        MusicManager.Instance.Playsfx(AudioNames.Fertilizer);
                    break;

                case GameAction.Water:
                    if (this.plant.IsWater == 1)
                    {
                        loadAni("Animation/jiaoshui");

//                            MusicManager.Instance.Playsfx(AudioNames.Water);

                        FieldsController.Instance.SendWFActionReq(this.FarmID, CommonActionBarView.Action1, 701);
                        FieldsController.ProtocalAction = (ProtocalAction)((int)CommonActionBarView.Action1);
                    }
                    else
                    {
                        SystemMsgView.SystemFunction(Function.Tip, Info.PlantNoNeedWater);
                    }
                    break;

                case GameAction.weed:

                    if (this.plant.IsGrass == 1)
                    {
                        loadAni("Animation/chucao");

//                            MusicManager.Instance.Playsfx(AudioNames.Weed);
                        FieldsController.Instance.SendWFActionReq(this.FarmID, CommonActionBarView.Action1, 701);
                        FieldsController.ProtocalAction = (ProtocalAction)((int)CommonActionBarView.Action1);
                    }
                    else
                    {
                        SystemMsgView.SystemFunction(Function.Tip, Info.PlantNoNeedWeed);
                    }
                    break;
                }
            }
            //如果当前已经打开播种栏,则可以播�?&& this.Brand == null
            if (FieldsController.ProtocalAction == ProtocalAction.None && this.EnablePlant == 1 &&
                this.Plant == null & ViewMgr.Instance.isOpen(ViewNames.SeedBarView) && SeedActionModel.currentId_Seed != 0)
            {
                //
                if (Farm_Game_StoreInfoModel.storage.Seeds.ContainsKey(SeedActionModel.currentId_Seed))
                {
                    SeletedFarmID = this.farmID;
                    FieldsController.Instance.ReqSeedAction(this.farmID, SeedActionModel.currentId_Seed);
                }
            }
            else if ((this.Plant != null || this.Brand != null) && CommonActionBarView.Action1 == GameAction.None)
            {
                //复位
                SeedBarView.PlayBack();

                SeedActionModel.currentId_Seed = 0;
                //当前时间条不等于4
                if (this.Plant != null)
                {
                    GlobalDispatcher.Instance.AddListener(GlobalEvent.OnViewLoadFinished, Flash);
                    GlobalDispatcher.Instance.DispathDelay(GlobalEvent.OnFarmUnitClick, plant);


                    ViewMgr.Instance.Open(ViewNames.TimeBarView);
                }
            }
            //如果单个植物可以收获
            if (FieldsController.ProtocalAction == ProtocalAction.None && CommonActionBarView.Action1 == GameAction.None && plant != null && plant.CurrentType == 4)
            {
                if (FriendFarmManager.Instance.isVisiting == false)
                {
                    Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", "FieldId", FarmID));

                    FieldsController.Instance.SendPluckReq(this.FarmID, LoginModel.Instance.Uid);
                }
                else
                {
                    if (plant.IsSteal == 0)
                    {
                        Debug.Log(string.Format("<color=#ffffffff><---{0}-{1}----></color>", "FieldId", FarmID));

                        FieldsController.Instance.SendPluckReq(this.FarmID, FriendFarmManager.Instance.FriendUid);
                    }
                }
            }
        }
Пример #3
0
        public void Update()
        {
            this.UpdateMouseWheel();
            bool mouseDown  = false;
            bool StartClick = false;
            bool ClickEnded = false;

            this._touchCount = Input.touchCount;
            Vector2 vector = this._mousePosition;

            if (this._touchCount < 2)
            {
                this._mousePosition = Input.mousePosition;
            }
            else
            {
                this._mousePosition = Input.GetTouch(0).position;
            }

            Vector2 vector2 = this._mousePosition - vector;

            //是否移动
            this._isMouseMoved = vector2.magnitude >= 0.1f;
            //两个手指取消点击
            if (this._touchCount > 1)
            {
                this._clickCancelled = true;
            }
            //一个手指点击
            if ((this._touchCount < 2) && Input.GetMouseButton(0))
            {
                mouseDown = true;
            }

            if (this._isMouseDown && !mouseDown)
            {
                //松开点击
                ClickEnded = true;
            }
            else if (!this._isMouseDown && mouseDown)
            {
                //开始点击
                StartClick = true;
            }
            //退出键点击
            if (Input.GetKeyDown(KeyCode.Escape) && !this._isEscapeDown)
            {
                this._isEscapeDown = true;
                if (this.Escape != null)
                {
                    this.Escape();
                }
            }

            //            Debug.Log("------test------");
            //退出点击完成
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                this._isEscapeDown = false;
            }
            this._isMouseDown = mouseDown;
            //两只手指的情况,以及pc端模拟
            if ((this._touchCount == 2) || Input.GetKey(KeyCode.LeftShift))
            {
                //左shift模拟
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    if (!this._pinchStarted)
                    {
                        this._currentPinchDistance = 100f;
                    }
                    else if (Input.GetKeyDown(KeyCode.UpArrow))
                    {
                        this._currentPinchDistance += 10f;
                    }
                    else if (Input.GetKeyDown(KeyCode.DownArrow))
                    {
                        this._currentPinchDistance -= 10f;
                    }
                }
                else
                {
                    //两手指捏的距离
                    Vector2 vector3 = this._mousePosition - Input.GetTouch(1).position;
                    this._currentPinchDistance = vector3.magnitude;
                }
                if (this._pinchStarted)
                {
                    if (this.PinchDistanceChanged != null)
                    {
                        //手势距离发生变化
                        this.PinchDistanceChanged();
                    }
                }
                else
                {
                    //开始手势
                    this._pinchStarted       = true;
                    this._startPinchDistance = this._currentPinchDistance;
                    if (this.PinchStarted != null)
                    {
                        this.PinchStarted();
                    }
                }
            }
            else if (this._pinchStarted)
            {
                //如果不用两只手指,并且已经开始过,表示手势结束
                this._pinchStarted = false;
                if (this.PinchEnded != null)
                {
                    this.PinchEnded();
                }
                this._startPinchDistance = this._currentPinchDistance = 0f;
            }
            //取消点击
            this._touchArgs.Cancelled = this._clickCancelled || this._clickPrevented;
            this._clickPrevented      = false;
            if (StartClick)
            {
                this._touchArgs.Phase = TouchPhase.Began;
            }
            else if (ClickEnded)
            {
                this._touchArgs.Phase = TouchPhase.Ended;
                this._clickCancelled  = false;
            }
            else if (this._isMouseMoved && this._isMouseDown)
            {
                this._touchArgs.Phase = TouchPhase.Moved;
            }
            else
            {
                //手指点击停留
                this._touchArgs.Phase = TouchPhase.Stationary;
            }

            if (this._dragObject != null)
            {
                //拖动物体赋值
                this._touchArgs.Target = this._dragObject;
            }
            else if (this._touchArgs.Phase != TouchPhase.Stationary)
            {
                if (!IsPointerOverUIObject(c, Input.mousePosition))

                {
                    Vector3      vec3    = Camera.main.ScreenToWorldPoint(Input.mousePosition); //从摄像机发出到点击坐标的射线
                    Vector2      vec2    = new Vector2(vec3.x, vec3.y);
                    RaycastHit2D hitInfo = Physics2D.Raycast(vec2, Vector2.zero);

                    if (hitInfo.collider != null)
                    {
//                        Debug.Log(hitInfo.collider.name);
                        //如果点击到背景
                        if (hitInfo.collider.name.Contains("BG"))
                        {
                            //复位
                            if (ViewMgr.Instance.isOpen(ViewNames.FriendsListView))
                            {
                                ViewMgr.Instance.Close(ViewNames.FriendsListView);
                            }
                            SeedBarView.PlayBack();
                            SeedActionModel.currentId_Seed = 0;
                            CommonActionBarView.Action1    = GameAction.None;
                            if (ViewMgr.Instance.isOpen(ViewNames.TimeBarView))
                            {
                                ViewMgr.Instance.Close(ViewNames.TimeBarView);

                                //(ViewMgr.Instance.views[ViewNames.CommonView].Viewlist[0]
                                //   .subViews[2] as CommonPlayerInfoView).isClicked = false ;
                            }
                        }
                        if (hitInfo.collider.name.Contains("land"))
                        {
                            Dictionary <int, FarmUnit> farms = FieldsModel.Instance.farms;;

                            int id = int.Parse(hitInfo.collider.name.Substring(4));


                            WorldObject farmUnit = farms[id];
                            _touchArgs.Target = farmUnit;
                        }
                        else
                        {
                            Dictionary <string, WorldObject> obj = FieldsModel.Instance.otherObjs;

                            if (obj.ContainsKey(hitInfo.collider.name))
                            {
                                Debug.Log(hitInfo.collider.name);
                                _touchArgs.Target = obj[hitInfo.collider.name];
                            }
                        }
                    }
                }



                if (this._touchArgs.Target != this._currentHitTarget)
                {
                    if (this._currentHitTarget != null)
                    {
                        //世界物体点击入口
                        this._currentHitTarget.DispatchTouch(this._touchArgs);
                    }
                    this._currentHitTarget = this._touchArgs.Target;
                }
                if (this._currentHitTarget != null)
                {
                    this._currentHitTarget.DispatchTouch(this._touchArgs);
                }
                if (ClickEnded)
                {
                    this._currentHitTarget = null;
                    this._touchArgs.Target = null;
                }
            }
        }