Пример #1
0
        public TextSceneManager(
            TextDisplayController textDisplayController,
            BackgroundDisplayController backgroundDisplayController,
            ImageDisplayController imageDisplayController,
            GameLoop gameLoop,
            NextEventRaiser nextInputEventRaiser)
        {
            _textDisplayController       = textDisplayController;
            _backgroundDisplayController = backgroundDisplayController;
            _imageDisplayController      = imageDisplayController;

            _displays = new IDisplay[] { _textDisplayController, _backgroundDisplayController, _imageDisplayController };

            _gameLoop        = gameLoop;
            _nextEventRaiser = nextInputEventRaiser;
        }
    // transform position vector,
    // scale position vector,
    // create image object at position vector,
    // scale image object
    // add new position to nthNode of JSON.
    private GameObject createGameObject(JSONNode nthNode, string key, int i)
    {
        Vector3    pos;
        Quaternion quat;

        if (nthNode ["new_position"] != null)                          // if node is updated
        {
            pos  = JSONNodeToVector3(nthNode ["new_position"] [0]);    // because "new_position is JSONArray"
            quat = JSONNodeToQuaternion(nthNode ["new_rotation"] [0]); // because "new_rotation is JSONArray"
            print(quat.ToString());
        }
        else
        {
            pos = transformCoordinates(nthNode ["coordinates"] [i]);
            pos.Scale(new Vector3(this.scaleFactor, this.scaleFactor, this.scaleFactor));
            quat = Quaternion.identity;
        }
        GameObject imageInstance = Instantiate(ImageDisplayPrefab);

        imageInstance.transform.SetParent(this.transform);
        imageInstance.transform.SetPositionAndRotation(pos, quat);
        ImageDisplayController controller = imageInstance.GetComponent <ImageDisplayController> ();

        string imagePath = this.imageFolder + key;

        int cropping_x      = nthNode ["croppings"] [i] ["x"].AsInt;
        int cropping_y      = nthNode ["croppings"] [i] ["y"].AsInt;
        int cropping_width  = nthNode ["croppings"] [i] ["width"].AsInt;
        int cropping_height = nthNode ["croppings"] [i] ["height"].AsInt;

        controller.loadImage(imagePath, cropping_x, cropping_y, cropping_width, cropping_height);

        //scale the sprite Renderer so that all the sprint have same size
        float sprite_x = imageInstance.GetComponent <SpriteRenderer> ().sprite.bounds.extents.x;
        float sprite_y = imageInstance.GetComponent <SpriteRenderer> ().sprite.bounds.extents.y;



        Vector3 scale = new Vector3(displayimage_width / sprite_x, displayimage_height / sprite_y, 1);

        imageInstance.transform.localScale = scale;

        return(imageInstance);
    }
Пример #3
0
    public IEnumerator loadData(string coordFile)
    {
        if (this.busy)
        {
            yield break;
        }

        this.busy = true;

        findMaxAndMin(coordFile);
        // load coordinates
        string dataAsJson = File.ReadAllText(coordFile);

        var N = JSON.Parse(dataAsJson);
        int j = 0;

        foreach (var key in N.Keys)
        {
            var coordinates = N [key] ["coordinates"];
            //print ("key: " + key.ToString ());
//			for (int i = 0; i < coordinates.Count; i++) {
            for (int i = 0; i < 1 && coordinates.Count > 0; i++)
            {
                Vector3 pos = transformCoordinates(coordinates [i]);
                //Vector3 pos = new Vector3 (coordinates [i] ["x"], coordinates [i] ["y"], coordinates [i] ["z"]);
                pos.Scale(new Vector3(this.scaleFactor, this.scaleFactor, this.scaleFactor));
                //set position
                //GameObject imageInstance = Instantiate (ImageDisplayPrefab, pos, Quaternion.identity);
                GameObject imageInstance = Instantiate(ImageDisplayPrefab);

                imageInstance.transform.SetParent(this.transform);
                imageInstance.transform.SetPositionAndRotation(pos, Quaternion.identity);

                ImageDisplayController controller = imageInstance.GetComponent <ImageDisplayController> ();

                string imagePath = this.imageFolder + key;

                int cropping_x      = N [key] ["croppings"] [i] ["x"].AsInt;
                int cropping_y      = N [key] ["croppings"] [i] ["y"].AsInt;
                int cropping_width  = N [key] ["croppings"] [i] ["width"].AsInt;
                int cropping_height = N [key] ["croppings"] [i] ["height"].AsInt;

                controller.loadImage(imagePath, cropping_x, cropping_y, cropping_width, cropping_height);
                //controller.loadImage(imagePath);
                //scale the sprite Renderer so that all the sprint have same size
                float sprite_x = imageInstance.GetComponent <SpriteRenderer> ().sprite.bounds.extents.x;
                float sprite_y = imageInstance.GetComponent <SpriteRenderer> ().sprite.bounds.extents.y;



                Vector3 scale = new Vector3(displayimage_width / sprite_x, displayimage_height / sprite_y, 1);

                imageInstance.transform.localScale = scale;
                //float diff = imageInstance.GetComponent<SpriteRenderer> ().bounds.max.x - imageInstance.GetComponent<SpriteRenderer> ().bounds.min.x;
                GetNormalVector(imageInstance.GetComponent <SpriteRenderer> ().bounds);
                objs.Add(imageInstance);

                //print ("bounds.min: " + imageInstance.GetComponent<SpriteRenderer> ().bounds.min.ToString ("F3"));
                //conlision
                //	Vector2 S = imageInstance.GetComponent<SpriteRenderer>().sprite.bounds.size;
                //	imageInstance.GetComponent<BoxCollider2D>().size = S;
                //imageInstance.GetComponent<BoxCollider2D>().offset = new Vector2 ((S.x / 2), 0);


                yield return(null);
            }
            j++;
            if (j >= 100)
            {
                break;
            }
            yield return(null);
        }

        this.busy = false;
    }