Example #1
0
 /**
  * Render 3D objects into the scene
  */
 IEnumerator RenderObjects(LatLngObject mapMiddlePoint, List <BuildingObject> buildings, List <RoadObject> roads, List <TreeObject> trees)
 {
     while (!CanRenderObjects)
     {
         yield return(new WaitForSeconds(0.1f));
     }
     //render terrain
     TerrainRender.Get().GenerateTerrain(mapMiddlePoint, transform);
     //render buildings
     BuildingRender.Get().Render(transform, buildings);
     //render roads
     RoadRender.Get().Render(mapMiddlePoint, transform, roads);
     //render trees
     TreeRender.Get().GenerateTrees(mapMiddlePoint, trees);
     //init address info game objects
     MenuController.Get().AddAddressGameObjects(AddressBackground, AddressText);
     CanRenderObjects = false;
 }
        /**
         * Nastavení kláves a myši pro rotaci objektu, jeho posun, načtení a jeho umístění
         */
        public static void PlaceNewBuildingListener()
        {
            if (customObject == null)
            {
                return;
            }

            var customObjectTransform = customObject.transform;

            //realtime object position update
            customObjectTransform.position = GetMousePos();

            //custom object ROTATION -- MOUSE
            if (Input.GetAxis("Mouse ScrollWheel") > 0f && activeAction == CanvasActionUtils.RotateAction)
            {
                customObjectTransform.Rotate(Vector3.up * Time.deltaTime * 150f);
            }

            if (Input.GetAxis("Mouse ScrollWheel") < 0f && activeAction == CanvasActionUtils.RotateAction)
            {
                customObject.transform.Rotate(Vector3.down * Time.deltaTime * 150f);
            }

            //custom object ROTATION -- GAMEPAD
            if (Input.GetAxisRaw("Horizontal") > 0 && activeAction == CanvasActionUtils.RotateAction)
            {
                customObjectTransform.Rotate(Vector3.up * Time.deltaTime * 150f);
            }

            if (Input.GetAxisRaw("Horizontal") < 0 && activeAction == CanvasActionUtils.RotateAction)
            {
                customObjectTransform.Rotate(Vector3.down * Time.deltaTime * 150f);
            }

            //custom object SIZE changing -- MOUSE
            if (Input.GetAxis("Mouse ScrollWheel") > 0f && activeAction == CanvasActionUtils.SizeAction)
            {
                customObjectSize = customObjectSize + defaultObjectSize * Time.deltaTime * 2;
                customObjectTransform.localScale = new Vector3(customObjectSize,
                                                               customObjectSize, customObjectSize);
            }

            if ((Input.GetAxis("Mouse ScrollWheel") < 0f && activeAction == CanvasActionUtils.SizeAction))
            {
                customObjectSize = customObjectSize - defaultObjectSize * Time.deltaTime * 2;
                customObjectTransform.localScale = new Vector3(customObjectSize,
                                                               customObjectSize, customObjectSize);
            }

            //custom object SIZE changing -- GAMEPAD
            if (Input.GetAxisRaw("Horizontal") > 0 && activeAction == CanvasActionUtils.SizeAction)
            {
                customObjectSize = customObjectSize + defaultObjectSize * Time.deltaTime * 2;
                customObjectTransform.localScale = new Vector3(customObjectSize,
                                                               customObjectSize, customObjectSize);
            }

            if (Input.GetAxisRaw("Horizontal") < 0 && activeAction == CanvasActionUtils.SizeAction)
            {
                customObjectSize = customObjectSize - defaultObjectSize * Time.deltaTime * 2;
                customObjectTransform.localScale = new Vector3(customObjectSize,
                                                               customObjectSize, customObjectSize);
            }


            //put custom object (with spacebar or gamepad A button)
            if (ControlUtils.ConfirmAction() && customObject != null)
            {
                putted = true;
                var objectFinalPosition = GetMousePos();
                //set terrain height as y coordinate
                objectFinalPosition.y = TerrainRender.Get().Terrain.SampleHeight(objectFinalPosition);
                //remove "clone" text in the name
                var customObjectName = customObject.name.Substring(0, customObject.name.LastIndexOf("("));
                //save added object into List
                var addedObject = new CustomObject
                {
                    Position   = objectFinalPosition,
                    ObjectName = customObjectName,
                    Rotation   = customObjectTransform.rotation.eulerAngles.y,
                    Size       = customObjectSize
                };
                Main.AddedObjects.Add(addedObject);

                //place custom object to the final position
                customObjectTransform.position = objectFinalPosition;
                customObject     = null;
                customObjectSize = defaultObjectSize;
            }
        }