Exemple #1
0
 public void _Hide()
 {
     Time.timeScale = 1;
     BETween.scale(Dialog.gameObject, 0.2f, new Vector3(1, 1, 1), new Vector3(1.3f, 1.3f, 1.3f)).method = BETweenMethod.easeOut;
     BETween.alpha(Dialog.gameObject, 0.2f, 1.0f, 0.0f).method = BETweenMethod.easeOut;
     BETween.alpha(gameObject, 0.2f, 0.5f, 0.0f).method        = BETweenMethod.easeOut;
     BETween.enable(gameObject, 0.01f, false).delay            = 0.3f;
     //gameObject.SetActive(false);
     if (SetModal)
     {
         SceneTown.isModalShow = false;
     }
 }
Exemple #2
0
        // set buttons position to align center
        // and add move animation
        public void ButtonReposition()
        {
            int   Count  = Buttons.Count;
            float Offset = (Count - 1) * 120.0f * -0.5f;

            for (int i = 0; i < Count; ++i)
            {
                Vector3 vEnd   = new Vector3(Offset, 80, 0);
                Vector3 vStart = new Vector3(Offset, -100, 0);
                Offset += 120.0f;

                BETween.position(Buttons[i].go, 0.2f, vStart, vEnd).delay = 0.1f * (float)i;
            }
        }
Exemple #3
0
 public void ShowProcess()
 {
     gameObject.transform.localPosition = Vector3.zero;
     gameObject.SetActive(true);
     if (SetModal)
     {
         SceneTown.isModalShow = true;
     }
     gameObject.GetComponent <Image>().color   = new Color32(0, 0, 0, 0);
     Dialog.transform.localScale               = new Vector3(0.7f, 0.7f, 0.7f);
     Dialog.GetComponent <CanvasGroup>().alpha = 0;
     BETween.scale(Dialog.gameObject, 0.2f, new Vector3(0.7f, 0.7f, 0.7f), new Vector3(1, 1, 1)).method = BETweenMethod.easeOutBack;
     BETween.alpha(Dialog.gameObject, 0.2f, 0.0f, 1.0f).method = BETweenMethod.easeOut;
     BETween.alpha(gameObject, 0.2f, 0.0f, 0.5f).method        = BETweenMethod.easeOut;
 }
Exemple #4
0
        // select building
        public void BuildingSelect(Building buildingNew)
        {
            // if user select selected building again
            bool SelectSame = (buildingNew == buildingSelected) ? true : false;

            if (buildingSelected != null)
            {
                // if initialy created building, then pass
                if (!buildingSelected.OnceLanded)
                {
                    return;
                }
                // building can't land, then pass
                if (!buildingSelected.Landed && !buildingSelected.Landable)
                {
                    return;
                }

                // land building
                BuildingLandUnselect();
                UICommand.Hide();
            }

            if (SelectSame)
            {
                return;
            }

            buildingSelected = buildingNew;

            if (buildingSelected != null)
            {
                //Debug.Log ("Building Selected:"+buildingNew.gameObject.name+" OnceLanded:"+buildingNew.OnceLanded.ToString ());
                // set scale animation to newly selected building
                BETween bt = BETween.scale(buildingSelected.gameObject, 0.1f, new Vector3(1.0f, 1.0f, 1.0f), new Vector3(1.4f, 1.4f, 1.4f));
                bt.loopStyle = BETweenLoop.pingpong;
                // se tbuilding state unland
                buildingSelected.Land(false, true);
            }
        }
Exemple #5
0
        // collect resources
        public void Collect()
        {
            string textColor = "";

            // increase resource count
            if (def.eProductionType == PayType.Elixir)
            {
                SceneTown.Elixir.ChangeDelta((double)Production);
                SceneTown.instance.CapacityCheck();
                textColor = "<color=purple>";
            }
            else if (def.eProductionType == PayType.Gold)
            {
                SceneTown.Gold.ChangeDelta((double)Production);
                SceneTown.instance.CapacityCheck();
                textColor = "<color=orange>";
            }
            else
            {
            }

            // show collect ui to show how many resources was collected
            UICollect script = UIInGame.instance.AddInGameUI(prefUICollect, transform, new Vector3(0, 1.5f, 0)).GetComponent <UICollect>();

            script.Name.text = textColor + ((int)Production).ToString() + "</color>";
            script.Init(transform, new Vector3(0, 1.0f, 0));

            // reset values related to production
            Collectable = false;
            Production  = 0;
            // hide collect dialog
            BETween.alpha(uiInfo.groupCollect.gameObject, 0.3f, 1.0f, 0.0f);
            BETween.enable(uiInfo.groupCollect.gameObject, 0.3f, true, false);
            // save game - save game when action is occured. not program quit moment
            SceneTown.instance.Save();
        }
Exemple #6
0
        public static BETween color(GameObject go, float _duration, Color _color)
        {
            BETween tween = add(go, _duration, BETweenType.color);

            Color color = Color.white;

            if (tween.image != null)
            {
                color = tween.image.color;
            }
            else if (tween.meshRender != null)
            {
                color = tween.meshRender.materials[0].GetColor("_TintColor");
            }
            else
            {
            }

            tween.from      = new Vector3(color.r, color.g, color.b);
            tween.to        = new Vector3(_color.r, _color.g, _color.b);
            tween.current   = tween.from;
            tween.applyFrom = false;
            return(tween);
        }
Exemple #7
0
        void _Show(ShopType type)
        {
            // if shop dialog called while new building is in creation,
            // delete new building
            if (SceneTown.buildingSelected != null)
            {
                if (!SceneTown.buildingSelected.OnceLanded)
                {
                    SceneTown.instance.BuildingDelete();
                }
            }

            gameObject.transform.localPosition = Vector3.zero;
            gameObject.SetActive(true);
            gameObject.GetComponent <Image>().color = new Color32(0, 0, 0, 0);
            SceneTown.isModalShow = true;
            eType = type;

            // delete old items of each content
            for (int i = 0; i < contents.Length; ++i)
            {
                for (int j = contents[i].transform.childCount - 1; j >= 0; j--)
                {
                    Destroy(contents[i].transform.GetChild(j).gameObject);
                }
            }

            // create shop items of each contents
            if (eType == ShopType.Normal)
            {
                List <BuildingType> bt = new List <BuildingType>();

                // fill first tab
                bt.Clear();
                bt.Add(TBDatabase.GetBuildingType(3));
                bt.Add(TBDatabase.GetBuildingType(4));
                bt.Add(TBDatabase.GetBuildingType(5));
                bt.Add(TBDatabase.GetBuildingType(6));
                FillContents(0, "Economy", bt);

                // fill second tab
                bt.Clear();
                bt.Add(TBDatabase.GetBuildingType(2));
                bt.Add(TBDatabase.GetBuildingType(7));
                bt.Add(TBDatabase.GetBuildingType(8));
                //bt.Add (TBDatabase.GetBuildingType(9));
                //bt.Add (TBDatabase.GetBuildingType(10));
                FillContents(1, "Defense", bt);

                // fill third tab
                bt.Clear();
                bt.Add(TBDatabase.GetBuildingbyName(name: "Hut"));
                bt.Add(TBDatabase.GetBuildingbyName(name: "wangtianshu"));
                bt.Add(TBDatabase.GetBuildingbyName(name: "apartment_mess"));
                bt.Add(TBDatabase.GetBuildingbyName(name: "apartment_huge"));
                FillContents(2, "Support", bt);

                BETween.anchoredPosition(rtDialog.gameObject, 0.3f, new Vector3(0, -500), new Vector3(0, 0)).method = BETweenMethod.easeOut;
            }
            else if (eType == ShopType.InApp)
            {
                FillInApp(0, "InApp");

                // if shop has only one tab, then change position to hide tab
                BETween.anchoredPosition(rtDialog.gameObject, 0.3f, new Vector3(0, -500), new Vector3(0, -50)).method = BETweenMethod.easeOut;
            }
            else if (eType == ShopType.House)
            {
                List <BuildingType> bt = new List <BuildingType>();

                // add house building
                bt.Clear();
                bt.Add(TBDatabase.GetBuildingType(1));
                FillContents(0, "House", bt);

                // if shop has only one tab, then change position to hide tab
                BETween.anchoredPosition(rtDialog.gameObject, 0.3f, new Vector3(0, -500), new Vector3(0, -50)).method = BETweenMethod.easeOut;
            }
            else
            {
            }

            toggleButtons[0].isOn = true;
            CategorySelected(0);
            rtDialog.anchoredPosition = new Vector3(0, -500);
            BETween.alpha(gameObject, 0.3f, 0, 0.5f).method = BETweenMethod.easeOut;
        }
Exemple #8
0
        void Update()
        {
            // get delta time from BETime
            float deltaTime = BETime.deltaTime;

            // if user pressed escape key, show quit messagebox
            if (!UIDialogMessage.IsShow() && !isModalShow && Input.GetKeyDown(KeyCode.Escape))
            {
                UIDialogMessage.Show("Do you want to quit this program?", "Yes,No", "Quit?", null, (result) => { MessageBoxResult(result); });
            }

            // if in camera animation
            if (InFade)
            {
                //camera zoom in
                FadeAge += Time.deltaTime * 0.7f;
                if (FadeAge > 1.0f)
                {
                    InFade      = false;
                    FadeAge     = 1.0f;
                    zoomCurrent = 64.0f;                       // 游戏开始时放大倍数(最终值)
                }

                goCameraRoot.transform.position  = Vector3.Lerp(new Vector3(-5.5f, 0, -5), Vector3.zero, FadeAge);
                goCamera.transform.localPosition = Vector3.Lerp(new Vector3(0, 0, -128.0f), new Vector3(0, 0, -64.0f), FadeAge);             // 游戏开始时放大倍数(中间值)
            }

            Exp.Update();
            Gold.Update();
            Elixir.Update();
            Gem.Update();
            Shield.ChangeTo(Shield.Target() - (double)deltaTime);
            Shield.Update();
            HouseInfo.text = BEWorkerManager.instance.GetAvailableWorkerCount().ToString() + "/" + BEGround.instance.GetBuildingCount(1).ToString();

            if (UIDialogMessage.IsShow() || isModalShow)
            {
                return;
            }
            //if(EventSystem.current.IsPointerOverGameObject()) return;

            if (Input.GetMouseButton(0))
            {
                if (EventSystem.current.IsPointerOverGameObject())
                {
                    //Debug.Log("left-click over a GUI element!");
                    return;
                }

                //Click MouseButton
                if (!bInTouch)
                {
                    bInTouch         = true;
                    ClickAfter       = 0.0f;
                    bTemporarySelect = false;
                    Dragged          = false;
                    mousePosOld      = Input.mousePosition;
                    mousePosLast     = Input.mousePosition;
                    vCamRootPosOld   = goCameraRoot.transform.position;

                    //when a building was selected and user drag mouse on the map
                    //check mouse drag start is over selected building or not
                    //if not do not move selected building
                    Ray        ray = Camera.main.ScreenPointToRay(mousePosOld);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit) && (hit.collider.gameObject.tag == "Building"))
                    {
                        MouseClickedBuilding = BuildingFromObject(hit.collider.gameObject);
                    }
                    else
                    {
                        MouseClickedBuilding = null;
                    }

                    //Debug.Log ("Update buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none"));
                }
                else
                {
                    //Mouse Button is in pressed
                    //if mouse move certain diatance
                    if (Vector3.Distance(Input.mousePosition, mousePosLast) > 0.01f)
                    {
                        // set drag flag on
                        if (!Dragged)
                        {
                            Dragged = true;

                            // show tile grid 显示建筑物降落网格(亮度变0.3)
                            if ((buildingSelected != null) && (MouseClickedBuilding == buildingSelected))
                            {
                                BETween.alpha(ground.gameObject, 0.1f, 0.0f, 0.3f);
                                //Debug.Log ("ground alpha to 0.1");
                            }
                        }

                        mousePosLast = Input.mousePosition;

                        // if selected building exist
                        if ((buildingSelected != null) && (MouseClickedBuilding == buildingSelected))
                        {
                            Ray   ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                            float enter;
                            xzPlane.Raycast(ray, out enter);
                            Vector3 vTarget = ray.GetPoint(enter);
                            // move selected building
                            buildingSelected.Move(vTarget);
                        }
                        // else camera panning
                        else
                        {
                            if (camPanningUse)
                            {
                                Vector3 vDelta   = (Input.mousePosition - mousePosOld) * 0.008f;
                                Vector3 vForward = goCameraRoot.transform.forward;      vForward.y = 0.0f; vForward.Normalize();
                                Vector3 vRight   = goCameraRoot.transform.right;          vRight.y = 0.0f; vRight.Normalize();
                                Vector3 vMove    = -vForward * vDelta.y + -vRight * vDelta.x;
                                goCameraRoot.transform.position = vCamRootPosOld + vMove;
                            }
                        }
                    }
                    // Not Move
                    else
                    {
                        if (!Dragged)
                        {
                            ClickAfter += Time.deltaTime;
                            if (!bTemporarySelect && (ClickAfter > 0.5f))
                            {
                                bTemporarySelect = true;
                                //Debug.Log ("Update2 buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none"));
                                Pick();
                            }
                        }
                    }
                }
            }
            else
            {
                //Release MouseButton
                if (bInTouch)
                {
                    bInTouch = false;

                    // if in drag state
                    if (Dragged)
                    {
                        // seleted building exist
                        if (buildingSelected != null)
                        {
                            // hide tile grid
                            if (MouseClickedBuilding == buildingSelected)
                            {
                                BETween.alpha(ground.gameObject, 0.1f, 0.3f, 0f);
                            }

                            if (buildingSelected.Landable && buildingSelected.OnceLanded)
                            {
                                BuildingLandUnselect();
                            }
                        }
                    }
                    else
                    {
                        if (bTemporarySelect)
                        {
                            // land building
                            if ((buildingSelected != null) && (MouseClickedBuilding != buildingSelected) && buildingSelected.OnceLanded)
                            {
                                BuildingLandUnselect();
                            }
                        }
                        else
                        {
                            // land building
                            if ((buildingSelected != null) && (MouseClickedBuilding != buildingSelected) && buildingSelected.OnceLanded)
                            {
                                BuildingLandUnselect();
                            }

                            //Debug.Log ("Update3 buildingSelected:"+((buildingSelected != null) ? buildingSelected.name : "none"));
                            Pick();
                        }
                    }
                }
            }

            //zoom
            if (!InFade)
            {
                zoomCurrent -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed;
                zoomCurrent  = Mathf.Clamp(zoomCurrent, zoomMin, zoomMax);
                goCamera.transform.localPosition = new Vector3(0, 0, -zoomCurrent);
            }

            // pinch zoom for mobile touch input
            if (Input.touchCount == 2)
            {
                // Store both touches.
                Touch touchZero = Input.GetTouch(0);
                Touch touchOne  = Input.GetTouch(1);

                // Find the position in the previous frame of each touch.
                Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
                Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

                // Find the magnitude of the vector (the distance) between the touches in each frame.
                float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
                float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

                // Find the difference in the distances between each frame.
                float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

                zoomCurrent += deltaMagnitudeDiff * perspectiveZoomSpeed;
                zoomCurrent  = Mathf.Clamp(zoomCurrent, zoomMin, zoomMax);
                goCamera.transform.localPosition = new Vector3(0, 0, -zoomCurrent);
            }
        }
Exemple #9
0
        public void Land(bool landed, bool animate)
        {
            if (Landed == landed)
            {
                return;
            }

            if (landed && !Landable)
            {
                if (((int)tilePosOld.x == -1) && ((int)tilePosOld.y == -1))
                {
                    return;
                }

                tilePos = tilePosOld;
                //Debug.Log ("Land RecoverOldPos: "+TilePosOldX.ToString()+","+TilePosOldY.ToString());
                ground.Move(gameObject, tilePos, tileSize);
                CheckLandable();

                if (!Landable)
                {
                    return;
                }
            }

            Landed = landed;
            ground.OccupySet(this);

            if (!Landed)
            {
                tilePosOld = tilePos;
                //Debug.Log ("Land Save OldPos: "+TilePosOldX.ToString()+","+TilePosOldY.ToString());
            }
            else
            {
                if (!OnceLanded)
                {
                    OnceLanded = true;
                }
            }

            CheckLandable();
            goGrid.SetActive(Landed ? false : true);
            if (goArrowRoot != null)
            {
                goArrowRoot.SetActive(Landed ? false : true);
            }

            if (uiInfo != null)
            {
                //uiInfo.groupProgress.alpha = 0;

                if (animate)
                {
                    if (Landed)
                    {
                        BETween.alpha(uiInfo.groupInfo.gameObject, 0.1f, 1.0f, 0.0f);
                        BETween.enable(uiInfo.groupInfo.gameObject, 0.1f, true, false);
                    }
                    else
                    {
                        BETween.alpha(uiInfo.groupInfo.gameObject, 0.1f, 0.0f, 1.0f);
                        uiInfo.groupInfo.gameObject.SetActive(true);
                    }
                }
                else
                {
                    uiInfo.groupInfo.alpha = Landed ? 0 : 1;
                    uiInfo.groupInfo.gameObject.SetActive(Landed ? false : true);
                }
            }

            // if building is wall, check neighbor
            if (Type == 2)
            {
                CheckNeighbor();
            }

            if (Landed && (goCenter != null))
            {
                SceneTown.instance.Save();
                BEUtil.SetObjectColor(goCenter, Color.white);
                BEUtil.SetObjectColor(goXInc, Color.white);
                BEUtil.SetObjectColor(goZInc, Color.white);
            }

            UpjustYByState();
            if (!SceneTown.instance.InLoading && (BEWorkerManager.instance != null))
            {
                BEWorkerManager.instance.OnTileInfoChanged();
            }
        }
Exemple #10
0
        void Update()
        {
            // use BETime to revise times
            float deltaTime = BETime.deltaTime;

            // if building is in selected state, keep color animation
            if (!Landed && (goCenter != null))
            {
                float fColor  = Mathf.PingPong(Time.time * 1.5f, 1) * 0.5f + 0.5f;
                Color clrTemp = new Color(fColor, fColor, fColor, 1);
                BEUtil.SetObjectColor(goCenter, clrTemp);
                BEUtil.SetObjectColor(goXInc, clrTemp);
                BEUtil.SetObjectColor(goZInc, clrTemp);
            }

            // if building can produce resources
            if (Landed && !InUpgrade && (def != null) && (def.eProductionType != PayType.None))
            {
                Production += (float)def.ProductionRate * deltaTime;

                // check maximum capacity
                if ((int)Production >= def.Capacity[(int)def.eProductionType])
                {
                    Production = def.Capacity[(int)def.eProductionType];
                }

                // is minimum resources generated, then ser collectable flagand show dialog
                if (((int)Production >= 10) && !uiInfo.groupCollect.gameObject.activeInHierarchy)
                {
                    Collectable = true;
                    uiInfo.CollectIcon.sprite = TBDatabase.GetPayTypeIcon(def.eProductionType);
                    BETween.alpha(uiInfo.groupCollect.gameObject, 0.2f, 0.0f, 1.0f);
                    uiInfo.groupCollect.gameObject.SetActive(true);
                    uiInfo.groupInfo.gameObject.SetActive(false);
                }

                if (Collectable)
                {
                    // when production count is reach to max count, then change dialog color to red
                    uiInfo.CollectDialog.color = (Production == def.Capacity[(int)def.eProductionType]) ? Color.red : Color.white;
                }
            }

            // if in upgrade
            if (InUpgrade)
            {
                // if upgrading proceed
                if (!UpgradeCompleted)
                {
                    // decrease left time
                    UpgradeTimeLeft -= deltaTime;

                    // if upgrading done
                    if (UpgradeTimeLeft < 0.0f)
                    {
                        UpgradeTimeLeft  = 0.0f;
                        UpgradeCompleted = true;

                        // if building is selected, then update command dialog
                        if (UICommand.Visible && (SceneTown.buildingSelected == this))
                        {
                            UICommand.Show(this);
                        }
                    }
                }

                // update ui info
                uiInfo.TimeLeft.text       = UpgradeCompleted ? "Completed!" : BENumber.SecToString(Mathf.CeilToInt(UpgradeTimeLeft));
                uiInfo.Progress.fillAmount = (UpgradeTimeTotal - UpgradeTimeLeft) / UpgradeTimeTotal;
                uiInfo.groupProgress.alpha = 1;
                uiInfo.groupProgress.gameObject.SetActive(true);
            }

            UnitGenUpdate(deltaTime);
        }