sanukin39 / UniAndroidPermission

Android Runtime Permission for Unity
MIT License
136 stars 30 forks source link

CS0103: The name 'UniAndroidPermission' does not exist in the current context #25

Open LearningByPlay opened 5 years ago

LearningByPlay commented 5 years ago

Hi I need to publish a game another developer has created and we need to work further on. I have upgraded to Unity 2019 and can't build to Android. The game works fine in Unity.

This is the error comming from 3 different scripts.

I have tried to import the latest package but it still fails and i'm a bit lost here, thanks for your input.

Her is the part that fails:

if UNITY_ANDROID && !UNITY_EDITOR

    if (!UniAndroidPermission.IsPermitted (AndroidPermission.CAMERA)) {
        UniAndroidPermission.RequestPremission (AndroidPermission.CAMERA, () => {
            StartCoroutine ("GoCam");
        }, () => {
            StartCoroutine ("NoGoCam");
        });
    }else
        StartCoroutine ("GoCam");

else

    StartCoroutine("GoCam");

endif

And here the whole script for that part: using System.Collections; using System.Collections.Generic; using System.Runtime.InteropServices; using UnityEngine; using UnityEngine.UI;

public class ScreenGamePicture : MonoBehaviour {

// list references

public AudioClip shutter;

private PageManager PGMNGR;
private GameObject cam;
private GameObject camOn;
private GameObject camOff;
private GameObject accept;
private Animator flash;

private bool camAvailable;
private WebCamTexture deviceCam;
private RawImage holder;
private AspectRatioFitter fit;
private WebCamDevice[] devices;

void Awake() // bind references
{
    PGMNGR = PageManager.Instance;
    cam = transform.Find("Screen/ToggleCamera").gameObject;
    camOn = cam.transform.Find("On").gameObject;
    camOff = cam.transform.Find("Off").gameObject;
    accept = transform.Find("Screen/ButtonAccept").gameObject;
    flash = transform.Find("Screen/Flash").GetComponent<Animator>();
    holder = transform.Find("Screen/Mask/Holder").GetComponent<RawImage>();
    fit = holder.transform.GetComponent<AspectRatioFitter>();
}

if UNITY_IOS && !UNITY_EDITOR

[DllImport ("__Internal")] public static extern bool HasCameraPermissions();

endif

/*private bool simbuild = true;
IEnumerator GoSim(){
    yield return new WaitForSeconds (.5f);
    data = new Color32[1 * 1];
    tex = new Texture2D (1, 1);
    tex.SetPixels32 (data);
    tex.Apply ();
    PGMNGR.playerimage[PGMNGR.newuid] = tex as Texture2D;
    yield return new WaitForEndOfFrame ();
    PGMNGR.GoTo ("GameSkill", true);
}*/

private bool capture;
private Texture2D tex;
private Color32[] data;
private string uid;
private void Start()
{
    PGMNGR.StartCoroutine("ShufflePages");

    /*if(simbuild){
        StartCoroutine ("GoSim");
        return;
    }*/

if UNITY_ANDROID && !UNITY_EDITOR

    if (!UniAndroidPermission.IsPermitted (AndroidPermission.CAMERA)) {
        UniAndroidPermission.RequestPremission (AndroidPermission.CAMERA, () => {
            StartCoroutine ("GoCam");
        }, () => {
            StartCoroutine ("NoGoCam");
        });
    }else
        StartCoroutine ("GoCam");

else

    StartCoroutine("GoCam");

endif

}

IEnumerator NoGoCam()
{
    yield return new WaitForSeconds(.5f);
    PGMNGR.GoTo("NoCamera", true);
}

IEnumerator GoCam()
{

    devices = WebCamTexture.devices;

    // find frontfacing cam
    foreach (WebCamDevice device in devices)
    {
        if (device.isFrontFacing)
        {
            deviceCam = new WebCamTexture(device.name, 1024, 768);
            break;
        }
    }
    if (deviceCam == null && devices.Length > 0)
        deviceCam = new WebCamTexture(devices[0].name, 1024, 768);

    camAvailable = false;

    if (devices.Length == 0 || deviceCam == null)
    {
        yield return new WaitForSeconds(.5f);
        PGMNGR.GoTo("NoCamera", true);
        yield break;
    }

    if (string.IsNullOrEmpty(PGMNGR.newuid))
    {
        capture = true;
        uid = PGMNGR.player["uid"].str;
    }
    else
    {
        uid = PGMNGR.newuid;
        capture = PGMNGR.playerimage[PGMNGR.newuid] == null ? true : false;
    }

    accept.SetActive(!capture);
    camOff.SetActive(!capture);
    camOn.SetActive(capture);
    cam.SetActive(false);

    deviceCam.Play();

    while (deviceCam.height < 480 || !deviceCam.isPlaying)
        yield return new WaitForEndOfFrame();

if UNITY_IOS && !UNITY_EDITOR

    if(!HasCameraPermissions ()){
        deviceCam.Stop ();
        while(deviceCam.isPlaying)
            yield return  new WaitForEndOfFrame ();

        yield return new WaitForSeconds (.5f);
        PGMNGR.GoTo ("NoCamera",true);
        yield break;
    }

endif

    float scaleY = deviceCam.videoVerticallyMirrored ? -1f : 1f;
    holder.rectTransform.localScale = new Vector3(1f, scaleY, 1f);
    if (!capture)
    {
        fit.aspectRatio = (float)PGMNGR.playerimage[uid].width / (float)PGMNGR.playerimage[uid].height;
        holder.color = new Color(1, 1, 1, 1);
        holder.texture = PGMNGR.playerimage[uid] as Texture2D;
    }

    if (!forceQuit)
    {
        tex = new Texture2D(deviceCam.width, deviceCam.height);
        data = new Color32[deviceCam.width * deviceCam.height];
        fit.aspectRatio = (float)deviceCam.width / (float)deviceCam.height;

        camAvailable = true;
        holder.color = new Color(1, 1, 1, 1);
        holder.texture = capture ? deviceCam as Texture : holder.texture;
        cam.SetActive(true);
    }

    while (camAvailable && deviceCam.isPlaying)
    {
        while (capture && deviceCam.didUpdateThisFrame && deviceCam.isPlaying)
        {
            scaleY = deviceCam.videoVerticallyMirrored ? -1f : 1f;
            holder.rectTransform.localScale = new Vector3(1f, scaleY, 1f);
            holder.rectTransform.localEulerAngles = new Vector3(0, 0, -deviceCam.videoRotationAngle);
            //deviceCam.GetPixels32 (data);

            yield return null;
        }
        yield return null;
    }
    //deviceCam.Stop ();
}

private bool triggered = false;
public void ToggleCamera()
{
    camOn.SetActive(!camOn.activeInHierarchy);
    camOff.SetActive(!camOn.activeInHierarchy);

    if (camOn.activeInHierarchy)
    {
        accept.GetComponent<Animator>().SetTrigger("vanish");
        capture = true;
        holder.texture = deviceCam;
        if (PGMNGR.newuid!=null && PGMNGR.playerimage.ContainsKey(PGMNGR.newuid))
            PGMNGR.playerimage[PGMNGR.newuid] = null;

    }
    else
    {
        triggered = true;
        capture = false;
        accept.SetActive(true);
        deviceCam.GetPixels32(data);
        tex.SetPixels32(data);
        tex.Apply();

        if (deviceCam.videoVerticallyMirrored)
        {
            tex = rotateTexture(tex as Texture2D);
            tex = rotateTexture(tex as Texture2D);
            holder.texture = FlipHorizontal(tex);
        }
        else
            holder.texture = tex;

        PGMNGR.SoundUI(shutter);
        flash.SetTrigger("flash");
    }
}

private GameObject syncs;
private bool forceQuit = false;
public void Navigate(bool forward)
{
    transform.Find("Screen/ButtonBack").GetComponent<Animator>().SetTrigger("vanish");
    transform.Find("Screen/ButtonAccept").GetComponent<Animator>().SetTrigger("vanish");
    transform.Find("Screen/ToggleCamera").GetComponent<Animator>().SetTrigger("vanish");
    forceQuit = true;
    camAvailable = false;
    capture = false;
    StartCoroutine("NavigateDo", forward);
}
private IEnumerator NavigateDo(bool forward)
{
    while (deviceCam.isPlaying)
    {

if UNITY_IOS

        deviceCam.Stop();

else

        deviceCam.Pause();

endif

        yield return null;
    }

    Destroy(deviceCam);
    deviceCam = null;
    Destroy(holder);
    yield return new WaitForEndOfFrame ();

    if (forward) {
        if(triggered)
            PGMNGR.playerimage [uid] = tex as Texture2D;
        if(PGMNGR.player!=null && PGMNGR.player["uid"].str==uid && triggered){
            System.IO.File.WriteAllBytes (PGMNGR.saveURL + "/"+uid+".jpg", tex.EncodeToJPG ());
            yield return new WaitForEndOfFrame ();
            PGMNGR.GoBack ();
        }else
            PGMNGR.GoTo ("GameSkill", true);
    }else
        PGMNGR.GoBack ();

    tex = null;
}

private Texture2D rotateTexture(Texture2D image )
{
    Texture2D target = new Texture2D(image.height, image.width, image.format, false);
    Color32[] pixels = image.GetPixels32(0);
    pixels = rotateTextureGrid(pixels, image.width, image.height);
    target.SetPixels32(pixels);
    target.Apply();

    return target;
}

private Color32[] rotateTextureGrid(Color32[] tex, int wid, int hi)
{
    Color32[] ret = new Color32[wid * hi];
    for (int y = 0; y < hi; y++)
        for (int x = 0; x < wid; x++)
            ret[(hi-1)-y + x * hi] = tex[x + y * wid]; 

    return ret;
}

Texture2D FlipHorizontal(Texture2D original)
{
    Texture2D flipped = new Texture2D(original.width,original.height);

    int xN = original.width;
    int yN = original.height;

    for(int i=0;i<xN;i++){
        for(int j=0;j<yN;j++){
            flipped.SetPixel(xN-i-1, j, original.GetPixel(i,j));
        }
    }
    flipped.Apply();

    return flipped;
}

/*private Texture2D snap;
        snap = new Texture2D (deviceCam.height,deviceCam.height);
        snap.SetPixels (deviceCam.GetPixels (Mathf.RoundToInt(((float)deviceCam.width - (float)deviceCam.height) * .5f), 0, deviceCam.height, deviceCam.height));
        snap.Apply ();
        snap = FlipTexture (snap);

        image.sprite = Sprite.Create (snap, new Rect (0, 0, snap.width, snap.height),new Vector2(.5f,.5f),100);
        snap = null;

*/

}

LearningByPlay commented 5 years ago

Any input to this problem ?