SetImage in PictureController

The PictureController will expose a method, SetImage(), that takes a game object as a parameter using a texture that should be in the picture. And while you're at it, also add the IMAGE command to activate the menu from the toolbar, and handle saving the initial texture to Cancel, as we just did for Frames.

Make the following additions to the PictureController.cs script:

File: PictureController.cs

At the top of the class, add a public variable for the imageMenu and a private variable for the image renderer:

    public GameObject imageMenu; 
    private Texture startTexture; 
    private Renderer imageRenderer; 

In the Start() function, initialize the imageRenderer:

        Transform image = framedImage.Find("Image"); 
        imageRenderer = image.gameObject.GetComponent<Renderer>(); 

In the Execute() function, add a case for the IMAGE command:

            case PictureCommand.IMAGE: 
                OpenImageMenu(); 
                break; 

Then add the corresponding function to open the menu:

    private void OpenImageMenu() { 
        imageMenu.SetActive(true); 
    } 

Then add the public SetTexture function, which sets the picture Image texture based on the current menu selection:

    public void SetTexture(Texture texture) { 
        imageRenderer.material.mainTexture = texture; 
    } 

Add the following line to SavePictureProperties for when we cancel the edit:

        startTexture = imageRenderer.material.mainTexture; 

Then add this line to RestorePictureProperties:

        imageRenderer.material.mainTexture = startTexture; 

The next step is to build the menu itself.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset