Example #1
0
 public static void Save()
 {
     //Debug.Log ("BESetting::Save Gold:"+Gold);
     PlayerPrefs.SetInt("MusicVolume", MusicVolume);
     PlayerPrefs.SetInt("SoundVolume", SoundVolume);
     PlayerPrefs.SetInt("StageRunCount", StageRunCount);
     PlayerPrefs.SetInt("ShowInstruction", ShowInstruction);
     PlayerPrefs.SetFloat("Credit", (float)Gold.Target());
 }
Example #2
0
        public void CapacityCheck()
        {
            int GoldCapacityTotal = BEGround.instance.GetCapacityTotal(PayType.Gold);
            //Debug.Log ("iGoldCapacityTotal:"+GoldCapacityTotal.ToString ());
            int ElixirCapacityTotal = BEGround.instance.GetCapacityTotal(PayType.Elixir);

            //Debug.Log ("ElixirCapacityTotal:"+ElixirCapacityTotal.ToString ());

            Gold.MaxSet(GoldCapacityTotal);
            if (Gold.Target() > GoldCapacityTotal)
            {
                Gold.ChangeTo(GoldCapacityTotal);
            }
            Elixir.MaxSet(ElixirCapacityTotal);
            if (Elixir.Target() > ElixirCapacityTotal)
            {
                Elixir.ChangeTo(ElixirCapacityTotal);
            }

            BEGround.instance.DistributeByCapacity(PayType.Gold, (float)Gold.Target());
            BEGround.instance.DistributeByCapacity(PayType.Elixir, (float)Elixir.Target());
        }
Example #3
0
        // Do not save town when script quit.
        // save when action is occured
        // (for example, when building created, when start upgrade, when colled product, when training start)
        public void Save()
        {
            if (InLoading)
            {
                return;
            }

            string      xmlFilePath = BEUtil.pathForDocumentsFile(configFilename);
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml("<item><name>wrench</name></item>");
            {
                xmlDocument.DocumentElement.RemoveAll();

                // Version
                { XmlElement ne = xmlDocument.CreateElement("ConfigVersion");           ne.SetAttribute("value", ConfigVersion.ToString());                     xmlDocument.DocumentElement.AppendChild(ne); }
                { XmlElement ne = xmlDocument.CreateElement("Time");                            ne.SetAttribute("value", DateTime.Now.ToString());                      xmlDocument.DocumentElement.AppendChild(ne); }
                { XmlElement ne = xmlDocument.CreateElement("ExpTotal");                        ne.SetAttribute("value", ExpTotal.ToString());                          xmlDocument.DocumentElement.AppendChild(ne); }
                { XmlElement ne = xmlDocument.CreateElement("Gem");                             ne.SetAttribute("value", Gem.Target().ToString());                      xmlDocument.DocumentElement.AppendChild(ne); }
                { XmlElement ne = xmlDocument.CreateElement("Gold");                            ne.SetAttribute("value", Gold.Target().ToString());                     xmlDocument.DocumentElement.AppendChild(ne); }
                { XmlElement ne = xmlDocument.CreateElement("Elixir");                          ne.SetAttribute("value", Elixir.Target().ToString());           xmlDocument.DocumentElement.AppendChild(ne); }
                { XmlElement ne = xmlDocument.CreateElement("Shield");                          ne.SetAttribute("value", Shield.Target().ToString());           xmlDocument.DocumentElement.AppendChild(ne); }

                Transform trDecoRoot = BEGround.instance.trDecoRoot;
                //List<GameObject> goTiles=new List<GameObject>();
                foreach (Transform child in trDecoRoot)
                {
                    Building script = child.gameObject.GetComponent <Building>();
                    if (script != null)
                    {
                        script.Save(xmlDocument);
                    }
                }

                // ####### Encrypt the XML #######
                // If you want to view the original xml file, turn of this piece of code and press play.
                if (xmlDocument.DocumentElement.ChildNodes.Count >= 1)
                {
                    if (UseEncryption)
                    {
                        string data = BEUtil.Encrypt(xmlDocument.DocumentElement.InnerXml);
                        xmlDocument.DocumentElement.RemoveAll();
                        xmlDocument.DocumentElement.InnerText = data;
                    }
                    xmlDocument.Save(xmlFilePath);
                }
                // ###############################
            }
        }
Example #4
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);
            }
        }