Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Error en Script ocultar Canvas

Iniciado por dgmegias, Noviembre 25, 2015, 08:10:39 PM

Tema anterior - Siguiente tema
Noviembre 25, 2015, 08:10:39 PM Ultima modificación: Noviembre 27, 2015, 01:29:36 PM por dgmegias
Un saludo a todostengo este scritp que funciona perfectamente, pero necesito que cuando se va a hacer la screenshot el canvas pase a false y una vez hecha vuelva a mostrarse.he utilizado las sentencias  yield return null; y yield return new WaitForEndOf Frame(); y entre medio localizo el objeto canvas y lo pongo a false pero el error que me indica es que no puedo usar esEl cuerpo de Photoshare.ShareImage() no puede ser un bloque de iteradores porque 'void' no es un tipo de interfaz de iteradores.Podría alguien por favor indicarme como poner el código correctamente o si puedo hacer desaparecer el Canvas de otro modo ante de la screenshot y que se muestre luego ?Agradezco cualquier ayuda, muchas gracias. using UnityEngine;
using System.Collections;
using System;public class photoshare : MonoBehaviour {    
    private SharePlugin sharePlugin;
    private UtilsPlugin utilsPlugin;    void Start (){
        //androidUltimatePluginController = AndroidUltimatePluginController.GetInstance ();
        sharePlugin = SharePlugin.GetInstance();
        utilsPlugin = UtilsPlugin.GetInstance();
        sharePlugin.SetDebug(0);
        
        
}
    public  void ShareImage(){      
        string screenShotName = "T" + System.DateTime.Now.ToString ("ddMMyyyHHmmss")+ ".jpg";
        string folderPath = utilsPlugin.CreateFolder("MyScreenShots",0);
        string path ="";
        GameObject.Find("Canvas").GetComponent<Canvas>().enabled = false;
        if(!folderPath.Equals("",StringComparison.Ordinal)){
            path = folderPath + "/" + screenShotName;
            
            //note: we added new required variable to pass which is screenShotName to determined what image format to use
            //jpg or png, if format is not given set default to jpg format
            yield return null; // Wait till the las possible momento before screen rendering to hide de UI
            GameObject.Find("Canvas").GetComponent<Canvas>().enabled = false; //oculta el UI
            StartCoroutine(AUP.Utils.TakeScreenshot(path,screenShotName)); //toma la foto
            yield return new WaitForEndOfFrame();//Waint for screen rendering to complete           GameObject.Find("Canvas").GetComponent<Canvas>().enabled = true;
            sharePlugin.ShareImage("Titulo","-",path);
        }
            
    }
    
    public void close (){
        Application.Quit ();
    }
    
    public void app(){
        Application.Quit ();
    }
    
    public void escena(){
        Application.LoadLevel ("Visor");
        
    }}

Noviembre 25, 2015, 10:17:04 PM #1 Ultima modificación: Noviembre 25, 2015, 10:17:43 PM por brok
using UnityEngine;
using System.Collections;
using System;

public class photoshare : MonoBehaviour {



void Start (){

   StartCoroutine (ShareImage ());
        sharePlugin = SharePlugin.GetInstance();
        utilsPlugin = UtilsPlugin.GetInstance();
        sharePlugin.SetDebug(0);
   
}
public  IEnumerator ShareImage(){      
   string screenShotName = "T" + System.DateTime.Now.ToString ("ddMMyyyHHmmss")+ ".jpg";
   string folderPath = utilsPlugin.CreateFolder("MyScreenShots",0);
   string path ="";
   GameObject.Find("Canvas").GetComponent<Canvas>().enabled = false;
   if(!folderPath.Equals("",StringComparison.Ordinal)){
      path = folderPath + "/" + screenShotName;

      GameObject.Find("Canvas").GetComponent<Canvas>().enabled = false;
      yield return new WaitForEndOfFrame(1f);
      StartCoroutine(AUP.Utils.TakeScreenshot(path,screenShotName));
      GameObject.Find("Canvas").GetComponent<Canvas>().enabled = true;
      sharePlugin.ShareImage("Titulo","-",path);
      yield return null;
   }
   
}

public void close (){
   Application.Quit ();
}

public void app(){
   Application.Quit ();
}

public void escena(){
   Application.LoadLevel ("Visor");
   
}

}
mira si asin te va

No, el Canvas sigue apareciendo en cada screenshot y 
yield return new WaitForEndOfFrame(1f); no admite valores, da error.

Noviembre 26, 2015, 12:17:32 AM #3 Ultima modificación: Noviembre 26, 2015, 12:17:54 AM por brok
me confundifo
using UnityEngine;
using System.Collections;
using System;

public class photoshare : MonoBehaviour {



void Start (){

   
        sharePlugin = SharePlugin.GetInstance();
        utilsPlugin = UtilsPlugin.GetInstance();
        sharePlugin.SetDebug(0);
   
}
public void ShareImageCoroutine()
{
StartCoroutine (ShareImage ());
}

public  IEnumerator ShareImage(){      
   string screenShotName = "T" + System.DateTime.Now.ToString ("ddMMyyyHHmmss")+ ".jpg";
   string folderPath = utilsPlugin.CreateFolder("MyScreenShots",0);
   string path ="";
   GameObject.Find("Canvas").GetComponent<Canvas>().enabled = false;
   if(!folderPath.Equals("",StringComparison.Ordinal)){
      path = folderPath + "/" + screenShotName;

      GameObject.Find("Canvas").GetComponent<Canvas>().enabled = false;
      yield return new WaitForEndOfFrame();
      StartCoroutine(AUP.Utils.TakeScreenshot(path,screenShotName));
      GameObject.Find("Canvas").GetComponent<Canvas>().enabled = true;
      sharePlugin.ShareImage("Titulo","-",path);
      yield return null;
   }
   
}

public void close (){
   Application.Quit ();
}

public void app(){
   Application.Quit ();
}

public void escena(){
   Application.LoadLevel ("Visor");
   
}

}
 

No, continua apareciendo el Canvas
Este era el scritp antiguo que funcionaba con la versión anterior del plugin y funciona en el proyecto en el que está. using UnityEngine;
using System.Collections;
using System.IO;
public class SnapshotShare : MonoBehaviour
{
    private AndroidUltimatePluginController androidUltimatePluginController;
    
    Camera mainCamera;
    RenderTexture renderTex;
    Texture2D screenshot;
    Texture2D LoadScreenshot;
    int width = Screen.width;   // for Taking Picture
    int height = Screen.height; // for Taking Picture
    string fileName;
    string screenShotName = "T" + System.DateTime.Now.ToString ("ddMMyyyHHmmss")+ ".png";    void Start ()
    {
        androidUltimatePluginController = AndroidUltimatePluginController.GetInstance ();    }    public void Snapshot ()
    {
        StartCoroutine (CaptureScreen ());
    }
    
    public IEnumerator CaptureScreen ()
    {
        yield return null; // Wait till the last possible moment before screen rendering to hide the UI
        GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = false;
        yield return new WaitForEndOfFrame (); // Wait for screen rendering to complete        if (Screen.orientation == ScreenOrientation.LandscapeLeft || Screen.orientation == ScreenOrientation.LandscapeRight) {
            mainCamera = Camera.main.GetComponent<Camera> (); // for Taking Picture
            renderTex = new RenderTexture ( width,height, 24);
            mainCamera.targetTexture = renderTex;
            RenderTexture.active = renderTex;
            mainCamera.Render ();
            screenshot = new Texture2D ( width,height, TextureFormat.RGB24, false);
            screenshot.ReadPixels (new Rect (0, 0,  width,height), 0, 0);
            screenshot.Apply (); //false
            RenderTexture.active = null;
            mainCamera.targetTexture = null;
        }
        // on Win7 - C:/Users/Username/AppData/LocalLow/CompanyName/GameName
        // on Android - /Data/Data/com.companyname.gamename/Files
        File.WriteAllBytes (Application.persistentDataPath + "/" + screenShotName, screenshot.EncodeToPNG ());          
        GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = true; // Show UI after we're done
    }    public void ShareImage ()
    {
        androidUltimatePluginController.SetDebug(0);
        string path = Application.persistentDataPath + "/" + screenShotName;
        androidUltimatePluginController.ShareImage ("Nombre", "-", path);
    }    
    public void close ()
    {
        Application.Quit ();
    }    public void escena()
    {
        Application.LoadLevel ("Visor");
        
    }
}

¿Que plugin es?
no se mas como ayudarte espero que alguien mas experto en unity te ayude

Diría que el canvas no vas a poder desactivarlo. Pon un gameobject que cuelgue del canvas, y de éste todos los elementos del canvas. Entonces desactiva el gameobject.

iRobb podría ser un poco más concreto ? es para entender exactamente como proponer hacerloEn el último script que he puesto, que está en un proyecto, si se desactiva. El plugín que uso es el AndroidUltimatePlugin 

Asin pruebalo.
public class photoshare : MonoBehaviour {

public GameObject canvasUI;
private SharePlugin sharePlugin;
private UtilsPlugin utilsPlugin;

void Start (){
   //androidUltimatePluginController = AndroidUltimatePluginController.GetInstance ();
   sharePlugin = SharePlugin.GetInstance();
   utilsPlugin = UtilsPlugin.GetInstance();
   sharePlugin.SetDebug(0);
   
   
}
    public void ShareImagePhoto()
    {
        StartCoroutine(ShareImage());
    }
public  IEnumerator ShareImage(){      
   string screenShotName = "T" + System.DateTime.Now.ToString ("ddMMyyyHHmmss")+ ".jpg";
   string folderPath = utilsPlugin.CreateFolder("MyScreenShots",0);
   string path ="";
            canvasUI.gameObject.SetActive(false);
   if(!folderPath.Equals("",StringComparison.Ordinal)){
      path = folderPath + "/" + screenShotName;

            //note: we added new required variable to pass which is screenShotName to determined what image format to use
            //jpg or png, if format is not given set default to jpg format
            yield return null;// Wait till the las possible momento before screen rendering to hide de UI
            canvasUI.gameObject.SetActive(false); //oculta el UI
            StartCoroutine(AUP.Utils.TakeScreenshot(path,screenShotName)); //toma la foto
      yield return new WaitForEndOfFrame();//Waint for screen rendering to complete

            canvasUI.gameObject.SetActive(true);
            sharePlugin.ShareImage("Titulo","-",path);
            yield return null;
        }
   
}

public void close (){
   Application.Quit ();
}

public void app(){
   Application.Quit ();
}

public void escena(){
   Application.LoadLevel ("Visor");
   
}

}
 

Noviembre 26, 2015, 11:31:46 AM #9 Ultima modificación: Noviembre 26, 2015, 11:47:54 AM por dgmegias
Brok con tu script ahora no aparece la pantalla de compartir....Os estoy agradeciendo sinceramente el esfuerzo que ambos haceis, creo que al ocultar el canvasUI no deja ver la pantalla automática que debe aparecer cuando quieres compartir cualquier imagen en un telefono android.lo que debe desaparecer es el Canvas que tengo creado donde están los botones...si, ya se que pertenece al UI pero quizás por ese lado sea más sencillopor eso usaba GameObject.Find ("Canvas").GetComponent<Canvas> ().enabled = false; y funcionaba en la versión anterior del pluging.También se me ocurre si se podría hacer que al pulsar el boton de hacer foto el Canvas baje....quedando fuera de la vista del screen y al terminar de la rutina que suba para poder continuar. 

SolucionadoGracias a iRobb y a brok

Etiquetas: