/// <summary> /// Check if the suers has the proper android permissions to use the photo gallery /// </summary> void CheckPermissions() { if (NativeGallery.CheckPermission() == NativeGallery.Permission.ShouldAsk) { NativeGallery.RequestPermission(); } }
private IEnumerator TakeScreenshotAndSave() { NativeGallery.Permission permission = NativeGallery.CheckPermission(); if (permission == NativeGallery.Permission.ShouldAsk) { permission = NativeGallery.RequestPermission(); } else { } takingScreenshot = true; yield return(new WaitForEndOfFrame()); Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false); ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); ss.Apply(); fotos = Random.Range(10000, 99999); // Save the screenshot to Gallery/Photos string name = string.Format("foto_" + fotos + ".png", Application.productName, "{0}", System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")); //Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(ss, Application.productName + " Captures", name)); takingScreenshot = false; string stringX = "Permission result: " + NativeGallery.SaveImageToGallery(ss, Application.productName + " Captures", name); //textorefleja.text+=stringX; todo.SetActive(true); camaraimage.sprite = camarasprite; }
public void OnClickUploadImageButton() { //NativeGallery.PermisionType permisionType = new NativeGallery.PermissionType(); NativeGallery.Permission per = NativeGallery.RequestPermission(new NativeGallery.PermissionType()); // probably should do some permissions checking here NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) => { if (path != null) { // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, 2073600, false); if (texture == null) { return; } //StartCoroutine(UploadImage(texture)); UploadImage(texture); } }, "Select an image", "image/*"); }
/// <summary> /// Open window for image pick. Work on IOS/Android /// </summary> public void UploadAvatarFromGallery() { if (NativeGallery.CheckPermission() != NativeGallery.Permission.Granted) { NativeGallery.RequestPermission(); } NativeGallery.GetImageFromGallery(OnImagePicked); }
/// <summary> /// Init easy profile solution /// </summary> private void Init() { EasyProfileManager.Instance.VIEW_CONTROLLER.ShowLoading(); EasyProfileManager.Instance.InitFirebase(OnFirebaseInited); EasyProfileManager.Instance.AddOnLogOutAction(OnLogOut); NativeCamera.RequestPermission(); NativeGallery.RequestPermission(); }
private void PickImage(NativeAction actionPick) { #if UNITY_ANDROID NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetImageFromGalleryForAndroid((path) => { if (path.IsNotNullAndEmpty()) { mPhotoPath = path; ImageDownloadUtils.Instance.SetAsyncImage("file://" + path, ImgPhoto); BtnDel.gameObject.SetActive(true); } Debug.Log("Image path: " + path); }, "选择图片", "image/*", false, action); } }, (int)actionPick); #elif UNITY_IOS // NativeGallery.Permission rest; if (actionPick == NativeAction.Album) { NativeGallery.Permission rest = NativeGallery.RequestIPhonePermission(1); if (rest == NativeGallery.Permission.Granted) { NativeGallery.GetImageFromGallery((backPath) => { if (backPath.IsNotNullAndEmpty()) { mPhotoPath = backPath; ImageDownloadUtils.Instance.SetAsyncImage("file://" + backPath, ImgPhoto, false); BtnDel.gameObject.SetActive(true); } }, "选择图片", "image/*"); } } else if (actionPick == NativeAction.Camera) { NativeGallery.Permission rest = NativeGallery.RequestIPhonePermission(4); if (rest == NativeGallery.Permission.Granted) { NativeGallery.GetIPhoneCameraImageFromGallery((backPath) => { if (backPath.IsNotNullAndEmpty()) { mPhotoPath = backPath; ImageDownloadUtils.Instance.SetAsyncImage("file://" + backPath, ImgPhoto, false); BtnDel.gameObject.SetActive(true); } }, "选择图片", "image/*"); } } #else #endif }
public void Select() { var permission = NativeGallery.CheckPermission(); if (permission == NativeGallery.Permission.Granted) { NativeGallery.GetImageFromGallery(OnImageSelected); } else { NativeGallery.RequestPermission(); } }
public void OnClick() { if (key == "") { //UIController.Instance.Push(uiName); NativeGallery.Permission p = NativeGallery.CheckPermission(); // Debug.Log(p); if (p == NativeGallery.Permission.Granted) { PickImage(maxSize); } else if (p == NativeGallery.Permission.ShouldAsk) { if (NativeGallery.RequestPermission() == NativeGallery.Permission.Granted) { PickImage(maxSize); } } else { //UIController.Instance.Pop("PhotoPermission"); if (NativeGallery.CanOpenSettings()) { UIController.Instance.PushSelectHint("PhotoPermission", PhotoPermission, "提示开启相册权限", null, "设置", "取消"); } else { UIController.Instance.PushHint("PhotoPermission", "提示开启相册权限"); } } } else if (key == "origin") { DataManager.Instance.getData("GameStatus").SetStringValue("PhotoName", ""); UIController.Instance.Pop("PhotoSelect"); EncryptionManager.SetString("PhotoName", ""); EncryptionManager.Save(); } else { DataManager.Instance.getData("GameStatus").SetStringValue("PhotoName", key); UIController.Instance.Pop("PhotoSelect"); EncryptionManager.SetString("PhotoName", key); EncryptionManager.Save(); } }
public void CaptureScreenshot() { camaraimage.sprite = transparentesprite; todo.SetActive(false); NativeGallery.Permission permission = NativeGallery.CheckPermission(); if (permission == NativeGallery.Permission.ShouldAsk) { permission = NativeGallery.RequestPermission(); //Debug.Log("Asking"); } /**PERMISION CAMERA ANDROID * https://stackoverflow.com/questions/50875097/c-sharp-unity-script-to-take-and-save-screenshot-in-android-gallery-with-library */ StartCoroutine(TakeScreenshotAndSave()); }
/// <summary> /// Ajoute une interface de calque en demandant de choisir une nouvelle texture. /// </summary> public void AddLayer(Action <Texture2D> callback_) { #if !UNITY_EDITOR if (NativeGallery.CheckPermission() != NativeGallery.Permission.Granted) { if (NativeGallery.RequestPermission() != NativeGallery.Permission.Granted && NativeGallery.CanOpenSettings()) { NativeGallery.OpenSettings(); } else { Application.Quit(); } } if (!NativeGallery.IsMediaPickerBusy()) { var workerObjAFCW_ = AugmentedFaceCreatorWorker.Instance_; var maxSize_ = Mathf.Max(workerObjAFCW_.TextureWidth_, workerObjAFCW_.TextureHeight_); NativeGallery.GetImageFromGallery((path_) => { var texture_ = NativeGallery.LoadImageAtPath(path_, maxSize: maxSize_, markTextureNonReadable: false, generateMipmaps: false); AddLayer(texture_, false, false, true); callback_?.Invoke(texture_); }, title: "Select a texture"); } #else var workerAFCW_ = WorkerObj_.GetComponent <AugmentedFaceCreatorWorker>(); var texture_ = Texture2D.whiteTexture; texture_.Resize(1024, 512); texture_.Apply(); AddLayer(texture_, false, false, true); callback_?.Invoke(texture_); #endif }
void RequestPermissions() { if (useAppCamera) { if (Application.platform == RuntimePlatform.Android) { List <string> cameraPermissions = new List <string>(); cameraPermissions.Add(Permission.Camera); cameraPermissions.Add(Permission.Microphone); StartAndroidPermissionRequest(cameraPermissions); } if (Application.platform == RuntimePlatform.IPhonePlayer) { Application.RequestUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone); } NativeGallery.RequestPermission(); } }
void Start() { if (Application.internetReachability != NetworkReachability.NotReachable) { NativeGallery.Permission permission = NativeGallery.RequestPermission(); permission = NativeGallery.Permission.ShouldAsk; NativeGallery.RequestPermission(); if (NativeGallery.CheckPermission() == NativeGallery.Permission.Granted) { SceneManager.LoadScene(sceneName); } } else { NativeGallery.Permission permission = NativeGallery.RequestPermission(); permission = NativeGallery.Permission.ShouldAsk; NativeGallery.RequestPermission(); if (NativeGallery.CheckPermission() == NativeGallery.Permission.Granted) { SceneManager.LoadScene(sceneName); } } }
public void RetrieveImage() { if (NativeGallery.CheckPermission() != NativeGallery.Permission.Granted) { NativeGallery.Permission permission = NativeGallery.RequestPermission(); CodelabUtils._ShowAndroidToastMessage("Please Grant the permission before you continue"); } //else //{ NativeGallery.Permission permissionr = NativeGallery.GetImageFromGallery((path) => { if (path != null) { CodelabUtils._ShowAndroidToastMessage($"Image path {path}"); // Create Texture from selected image Texture2D texture = NativeGallery.LoadImageAtPath(path, 512); if (texture == null) { CodelabUtils._ShowAndroidToastMessage($"Could not load texturee from {path}"); CodelabUtils._ShowAndroidToastMessage($"Could not load texturee from {path}"); return; } // add to the list of texture item AddItem(new Item(texture, path)); refreshList(); /*StartCoroutine(StoreImages(new Item(texture, path), * path.Substring(path.Length - 10, path.Length)));*/ } }, "Select an Image", "image/*"); //} }
protected override void OnInit(QFramework.IUIData uiData) { mData = uiData as BindWIFIMessagePanelData ?? new BindWIFIMessagePanelData(); if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { isSendMessage = true; Log.I("RequestPermission: " + result); if (result == (int)NativeGallery.Permission.Granted) { // InvokeRepeating("GetWifiInfo",1,1); 可以实时更新wifi,但无法修改wifi密码,暂时舍弃 NativeGallery.GetSomethingFromNative((json, action1) => { if (json.IsNotNullAndEmpty()) { isSSIDContains5G(json); InputFieldSSID.text = json; string pwd = PlayerPrefsUtil.GetWiFiPWD(json); if (pwd.IsNotNullAndEmpty()) { InputFieldPWD.text = pwd; } else { InputFieldPWD.text = string.Empty; } } Log.I("GetSomethingFromNative: " + json); }, (int)NativeAction.Location); } }, (int)NativeAction.Location); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { if (NativeGallery.RequestIPhonePermission(2) == NativeGallery.Permission.Granted) { NativeGallery.GetSomethingFromIPhone(result => { if (result.IsNotNullAndEmpty()) { InputFieldSSID.text = result; isSSIDContains5G(result); string pwd = PlayerPrefsUtil.GetWiFiPWD(result); if (pwd.IsNotNullAndEmpty()) { InputFieldPWD.text = pwd; } else { InputFieldPWD.text = String.Empty; } } }, 1); } } var submit = Observable.Merge( InputFieldSSID.OnEndEditAsObservable().Where(_ => Input.GetKeyDown(KeyCode.Return)), BtnCommit.OnClickAsObservable().Select(_ => InputFieldSSID.text) ); submit.Where(s => s != "") .Subscribe(s => { AudioManager.PlaySound("Button_Audio"); isSendMessage = false; if (saveWiFipwd) { // 保存 WiFi ssid 和 pwd 到本地 PlayerPrefsUtil.SetWiFiSSIDPWD(InputFieldSSID.text, InputFieldPWD.text); } else { PlayerPrefsUtil.SetWiFiSSIDPWD(InputFieldSSID.text, String.Empty); } Debug.Log("submit-确定 " + "ssid=" + s + " pwd=" + InputFieldPWD.text); UIMgr.OpenPanel <BindDevicePanel>(new BindDevicePanelData() { pwdStr = InputFieldPWD.text, ssidStr = InputFieldSSID.text }, UITransitionType.CIRCLE, this); }).AddTo(this); BtnClearPWD.OnClickAsObservable().Subscribe(_ => { AudioManager.PlaySound("Button_Audio"); InputFieldPWD.text = String.Empty; }).AddTo(this); BtnSSIDList.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); #if UNITY_ANDROID NativeGallery.RequestPermission((result, action) => { Log.I("RequestPermission: " + result); if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.OpenWifiSettings(); } }, (int)NativeAction.Location); #elif UNITY_IOS NativeGallery.OpenSettings(); #else #endif }); InputFieldSSID.OnValueChangedAsObservable().Subscribe((s => { var texture2D = mResLoader.LoadSync <Texture2D>("ic_bindDetermine"); if (s.Length > 0) { texture2D = mResLoader.LoadSync <Texture2D>("ic_bindDetermine"); } else { texture2D = mResLoader.LoadSync <Texture2D>("btn_code_sel"); } ImgDetermine.sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f); })).AddTo(this); BtnShow.OnClickAsObservable().Subscribe(_ => { AudioManager.PlaySound("Button_Audio"); var texture2D = mResLoader.LoadSync <Texture2D>("ic_savepwd"); showWiFipwd = !showWiFipwd; if (showWiFipwd) { texture2D = mResLoader.LoadSync <Texture2D>("btn_show_pwd"); InputFieldPWD.contentType = InputField.ContentType.EmailAddress; } else { texture2D = mResLoader.LoadSync <Texture2D>("btn_hide_pwd"); InputFieldPWD.contentType = InputField.ContentType.Password; } var image = BtnShow.transform.Find("Image").GetComponent <Image>(); image.sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f); InputFieldPWD.MyUpdateLabel(); }).AddTo(this); BtnConnectTips.OnClickAsObservable().Subscribe(_ => { AudioManager.PlaySound("Button_Audio"); UIMgr.OpenPanel <BindCheckWIFIPanel>(new BindCheckWIFIPanelData(), UITransitionType.NULL); }).AddTo(this); BtnBack.OnClickAsObservable().Subscribe(_ => { AudioManager.PlaySound("Button_Audio"); Debug.Log("WiFi 返回"); Back(); }).AddTo(this); BtnSavepwd.OnClickAsObservable().Subscribe(_ => { AudioManager.PlaySound("Button_Audio"); Debug.Log("记住密码"); saveWiFipwd = !saveWiFipwd; var texture2D = mResLoader.LoadSync <Texture2D>("ic_savepwd"); if (saveWiFipwd) { texture2D = mResLoader.LoadSync <Texture2D>("ic_savepwd"); } else { texture2D = mResLoader.LoadSync <Texture2D>("ic_unsavepwd"); } ImageSavePWD.sprite = Sprite.Create(texture2D, new Rect(0, 0, texture2D.width, texture2D.height), Vector2.one * 0.5f); }).AddTo(this); SimpleEventSystem.GetEvent <TipConfirmClick>() .Subscribe(_ => { if (_.GetAction == TipAction.Contains5GAlter) { if (Application.platform == RuntimePlatform.IPhonePlayer) { NativeGallery.RequestPermission((result, action) => { Log.I("RequestPermission: " + result); if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.OpenWifiSettings(); } }, (int)NativeAction.Location); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { NativeGallery.OpenSettings(); } } }).AddTo(this); // please add init code here }
protected override void OnInit(QFramework.IUIData uiData) { if (Application.platform == RuntimePlatform.Android) { AudioManager.SetMusicOn(); AudioManager.PlayMusic("Main_BG_Music"); AndroidForUnity.CallAndroidHideSplash(); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> param = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); param.Add("method", IOSClientUtil.MainPanelOnInit); param.Add("params", subParam); IOSClientUtil.CommonMethodCallIOSClient(param.ToJson()); if (App.IsFirstInitialize == 1) { AudioManager.SetMusicOn(); AudioManager.PlayMusic("Main_BG_Music"); } } else { AudioManager.SetMusicOn(); AudioManager.PlayMusic("Main_BG_Music"); } mTexture2DHBoy = mResLoader.LoadSync <Texture2D>("ic_head_boy"); mTexture2DHGirl = mResLoader.LoadSync <Texture2D>("ic_head_girl"); mMainAnimationGo = mResLoader.LoadSync <GameObject>("MainAnimation") .Instantiate() .transform .LocalScale(1.4f, 1.4f, 1.4f) .Position(-11.0f, -5.0f, 0) .gameObject; mData = uiData as MainPanelData ?? new MainPanelData(); BtnGift.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); UIMgr.OpenPanel <GiftListPanel>(new GiftListPanelData(), UITransitionType.CLOUD, this); }); BtnSetting.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); UIMgr.OpenPanel <SettingPanel>(new SettingPanelData(), UITransitionType.CLOUD, this); }); BtnListen.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); StartRequestForGetResourcePageUrl(); }); BtnMessage.onClick.AddListener(() => { // UIMgr.OpenPanel<AttendanceAddAudioPanel>(); }); BtnRobot.OnClickAsObservable().Subscribe((unit => { AudioManager.PlaySound("Button_Audio"); UIMgr.OpenPanel <DeviceStatusPanel>(new DeviceStatusPanelData(), UITransitionType.CLOUD, this); })).AddTo(this); BtnIntegral.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); Debug.Log("每日任务"); UIMgr.OpenPanel <DailyTaskPanel>(new DailyTaskPanelData(), UITransitionType.CLOUD, this); }); BtnMedal.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); Debug.Log("勋章"); UIMgr.OpenPanel <DailyTaskPanel>(new DailyTaskPanelData() { showMedal = 2, }, UITransitionType.CLOUD, this); }); BtnScan.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { Dictionary <string, object> param = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); param.Add("target", AppConst.SCAN); param.Add("params", subParam); AndroidForUnity.CallAndroidStartActivityForAnim(param.ToJson(), AppConst.ANIM_CLOUD); } }, (int)NativeAction.Camera); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> param = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); param.Add("target", AppConst.SCAN_IOS); param.Add("params", subParam); IOSClientUtil.CallIOSClient(param.ToJson()); } }); BtnChineseShop.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (UserInfo.chPlanId != 0) { StartRequestForGetPlanInfo(UserInfo.chPlanId, 0); } else { UIMgr.OpenPanel <TipPanel>(new TipPanelData() { action = TipAction.PlanScan, message = "该计划未解锁\n需扫描盒子二维码进行解锁!", strConfirm = "去扫描", strTitle = "解锁提示" }); LoadingManager.GetInstance().DismissLoading(); } }); BtnEnglishShop.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (UserInfo.enPlanId != 0) { StartRequestForGetPlanInfo(UserInfo.enPlanId, 0); } else { UIMgr.OpenPanel <TipPanel>(new TipPanelData() { action = TipAction.PlanScan, message = "该计划未解锁\n需扫描盒子二维码进行解锁!", strConfirm = "去扫描", strTitle = "解锁提示" }); LoadingManager.GetInstance().DismissLoading(); } }); BtnLearningShop.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (UserInfo.qgPlanId != 0) { StartRequestForGetPlanInfo(UserInfo.qgPlanId, 0); } else { StartRequestForDrawPowerSpecialPlan(); } }); BtnPhotoWall.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); UIMgr.OpenPanel <WorksWallPanel>(new WorksWallPanelData(), UITransitionType.CLOUD, this); }); BtnAddRobot.onClick.AddListener(() => { UIMgr.OpenPanel <BindConfirmBootPanel>(new BindConfirmBootPanelData() { }, UITransitionType.CLOUD, this); }); SimpleEventSystem.GetEvent <ScanQRResult>() .Subscribe(_ => { if (_.ScanResult.IsNotNullAndEmpty()) { StartRequestForScanQR(_.ScanResult); } }).AddTo(this); //扫码动画关闭监听 SimpleEventSystem.GetEvent <CollectGiftBoxPanelClosed>() .Subscribe(_ => { if (_.CollectGiftBoxType == CollectGiftBoxType.ChineseLearningPlan || _.CollectGiftBoxType == CollectGiftBoxType.EnglishLearningPlan) { StartRequestForGetPlanInfo(ScanQrCodePlanId, ScanQrCodeMonth); } }).AddTo(this); SimpleEventSystem.GetEvent <TipConfirmClick>() .Subscribe(_ => { if (_.GetAction == TipAction.PlanScan) { if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { Dictionary <string, object> param = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); param.Add("target", AppConst.SCAN); param.Add("params", subParam); AndroidForUnity.CallAndroidStartActivityForAnim(param.ToJson(), AppConst.ANIM_CLOUD); } }, (int)NativeAction.Camera); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> param = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); param.Add("target", AppConst.SCAN_IOS); param.Add("params", subParam); IOSClientUtil.CallIOSClient(param.ToJson()); } } }).AddTo(this); /** * 展示完引导页 的事件 */ SimpleEventSystem.GetEvent <MainPanelGuideDismiss>().Subscribe(_ => { this.gameObject.SetActive(true); }).AddTo(this); SimpleEventSystem.GetEvent <LottieAnimationFinish>().Subscribe(_ => { if (Application.platform == RuntimePlatform.IPhonePlayer) { if (App.IsFirstInitialize == 1) { AudioManager.SetMusicOn(); AudioManager.PlayMusic("Main_BG_Music"); } } }).AddTo(this); /** * 勋章领取成功 */ SimpleEventSystem.GetEvent <MedalDrawSuccess>() .Subscribe(_ => { string medalCount = TvMedal.text; TvMedal.text = (medalCount.ToInt() + 1).ToString(); if (mMedalList.Count > 0) { mMedalList.RemoveAt(0); } ShowMedalAnimationPanel(); }).AddTo(this); setUserInfoData(); StartResquestForGetUserInfo(); RequestBabyMedalFindList(); if (Application.platform == RuntimePlatform.Android) { NativeGallery.GetSomethingFromNative((json, action1) => { if (json.IsNotNullAndEmpty()) { AppInfo model = SerializeHelper.FromJson <AppInfo>(json); StartResquestForFindReleaseInfo("2", model.build); } }, (int)NativeAction.VersionJson); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { NativeGallery.GetSomethingFromIPhone(result => { Debug.Log("IOS - build = " + result); StartResquestForFindReleaseInfo("1", result.ToInt()); }, 4); } if (mData.ShopAction >= 1) { LoadingManager.GetInstance().CreatLoading(); StartCoroutine(WaitMainPanelAnimationCompleted(mData.ShopAction)); } }
protected override void OnInit(QFramework.IUIData uiData) { mData = uiData as AttendanceAddPanelData ?? new AttendanceAddPanelData(); mPath = mData.Path; mThumbnailPath = mData.ThumbnailPath; texture2DAddPhoto = mResLoader.LoadSync <Texture2D>("attendance_main_add"); BtnBack.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); Back(); }); BtnCancel.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); Back(); }); BtnPush.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); // if (InputContent.text.IsNullOrEmpty()) // { // CommonUtil.toast("请输入内容"); // Log.I("请输入内容"); // return; // } if (mPath.IsNullOrEmpty()) { if (mData.Action == AttendanceAdd.Pic) { CommonUtil.toast("请添加图片"); Log.I("请添加图片"); } else if (mData.Action == AttendanceAdd.Audio) { CommonUtil.toast("请添加音频"); Log.I("请添加音频"); } else if (mData.Action == AttendanceAdd.Video) { CommonUtil.toast("请添加视频"); Log.I("请添加视频"); } return; } LoadingManager.GetInstance().CreatLoading(); BtnPush.enabled = false; if (mData.Action == AttendanceAdd.Pic) { string fileType = mPath.Substring(mPath.LastIndexOf(".")); Log.I("mPath: " + mPath + " fileType: " + fileType); StartRequestForUpload("attendance" + fileType, mPath); } else if (mData.Action == AttendanceAdd.Audio) { MicrophoneManager.GetInstance().StopPlay(); string fileType = mPath.Substring(mPath.LastIndexOf(".")); Log.I("mPath: " + mPath + " fileType: " + fileType); StartRequestForUpload("attendance" + fileType, mPath); } else if (mData.Action == AttendanceAdd.Video) { if (Application.platform == RuntimePlatform.Android) { // CommonUtil.toast("视频压缩上传中,请稍等"); AndroidForUnity.CallAndroidForVideoCompress(mPath); } else { StartCoroutine(IPhonePlayerCompressFinished()); } } }); BtnAdd.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (mData.Action == AttendanceAdd.Audio) { UIMgr.OpenPanel <AttendanceAudioRecordPanel>(new AttendanceAudioRecordPanelData(), UITransitionType.CIRCLE); } else { //unityForPlayVideo if (mPath.IsNullOrEmpty()) { if (mData.Action == AttendanceAdd.Pic) { UIMgr.OpenPanel <ChoosePhotoPanel>(new ChoosePhotoPanelData() { action = ChoosePhotoAction.AttendancePic, }); } else if (mData.Action == AttendanceAdd.Video) { // UIMgr.OpenPanel<ChoosePhotoPanel>(new ChoosePhotoPanelData() // { // action = ChoosePhotoAction.AttendanceVideo, // showTip = true // // }); if (Application.platform == RuntimePlatform.IPhonePlayer) { IPhonePlayerMakeVideoOpenCamera(); } else if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetVideoFromGalleryForAndroid((json) => { if (json.IsNotNullAndEmpty()) { NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json); if (model.IsNotNull()) { if (model.status == 1) { mPath = model.videoPath; mThumbnailPath = model.imagePath; AudioContent.gameObject.SetActive(false); if (model.imagePath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + model.imagePath, ImagePic); BtnVideo.gameObject.SetActive(true); BtnDel.gameObject.SetActive(true); } } else if (model.status == 0) { mPath = null; mThumbnailPath = null; ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(false); } } } }, "选择视频", "video/*", action); } }, (int)NativeAction.Camera); } } } else { if (mData.Action == AttendanceAdd.Pic) { if (Application.platform == RuntimePlatform.Android) { AndroidForUnity.CallAndroidForShowPic(mPath); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { UIMgr.OpenPanel <PhotoBrowserPanel>(new PhotoBrowserPanelData() { ImageUrl = mPath, }, UITransitionType.NULL); } } else if (mData.Action == AttendanceAdd.Video) { if (Application.platform == RuntimePlatform.Android) { AndroidForUnity.CallAndroidForPlayVideo(mPath); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> paramDic = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); subParam.Add("url", mPath); paramDic.Add("target", AppConst.VIDEO_IOS); paramDic.Add("method", IOSClientUtil.VideoMediaPlay); paramDic.Add("params", subParam); IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson()); } } } } }); BtnVideo.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (mData.Action == AttendanceAdd.Video) { if (Application.platform == RuntimePlatform.Android) { AndroidForUnity.CallAndroidForPlayVideo(mPath); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> paramDic = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); subParam.Add("url", mPath); paramDic.Add("target", AppConst.VIDEO_IOS); paramDic.Add("method", IOSClientUtil.VideoMediaPlay); paramDic.Add("params", subParam); IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson()); } } }); if (mData.Action == AttendanceAdd.Audio) { UpdateTvTime("0"); AddContent.gameObject.SetActive(mPath.IsNullOrEmpty()); AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty()); TextAdd.text = "添加语音"; } else { if (mData.Action == AttendanceAdd.Pic) { TextAdd.text = "添加图片"; AudioContent.gameObject.SetActive(false); if (mPath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(true); } } else { TextAdd.text = "添加视频"; AudioContent.gameObject.SetActive(false); if (mPath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic); BtnVideo.gameObject.SetActive(true); BtnDel.gameObject.SetActive(true); } } } BtnPlayAndPause.onClick.AddListener(() => { if (mPath.IsNotNullAndEmpty()) { if (mPlayStatus == PlayStatus.NoPlaying || mPlayStatus == PlayStatus.Stop) { MicrophoneManager.GetInstance().PlayRecord(); } else if (mPlayStatus == PlayStatus.Playing) { MicrophoneManager.GetInstance().PausePlay(); } else if (mPlayStatus == PlayStatus.Pause) { MicrophoneManager.GetInstance().PlayRecord(MicrophoneManager.GetInstance().mPlayingTime.Value); } } }); BtnClose.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); mPath = null; MicrophoneManager.GetInstance().StopPlay(); AddContent.gameObject.SetActive(mPath.IsNullOrEmpty()); AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty()); }); BtnDel.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); // 弹窗 UIMgr.OpenPanel <TipPanel>(new TipPanelData() { action = TipAction.DelAttendance, message = "确定要删除当前内容吗?", }); }); InputContent.onValueChange.AddListener(EditChange); if (mData.Action == AttendanceAdd.Audio) { MicrophoneManager.GetInstance().mPlayStatus.Subscribe(status => { mPlayStatus = status; if (mPlayStatus == PlayStatus.Playing) { // var soundOnTexture = mResLoader.LoadSync<Texture2D>("ic_audio_playing"); // ImgPlayAndPause.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); ImgPlayAndPause.gameObject.SetActive(false); ImgPlaying.gameObject.SetActive(true); } else { // var soundOnTexture = mResLoader.LoadSync<Texture2D>("ic_audiio_pause"); // ImgPlayAndPause.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); ImgPlayAndPause.gameObject.SetActive(true); ImgPlaying.gameObject.SetActive(false); } if (mPlayStatus == PlayStatus.Stop) { UpdateTvTime("0"); } }).AddTo(this); } SimpleEventSystem.GetEvent <RecordPath>().Subscribe(Path => { mPath = Path.Path; UpdateTvTime("0"); AddContent.gameObject.SetActive(mPath.IsNullOrEmpty()); AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty()); }).AddTo(this); SimpleEventSystem.GetEvent <ChoosePhotoClick>() .Subscribe(_ => { if (_.GetPhotoAction == ChoosePhotoAction.AttendancePic) { if (Application.platform == RuntimePlatform.IPhonePlayer) { if (_.GetAction == NativeAction.Camera) { IPhonePlayerSelectPictureOpenCamera(); } else if (_.GetAction == NativeAction.Album) { IPhonePlayerSelectPictureOpenAlbum(); } } else if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetImageFromGalleryForAndroid((path) => { if (path.IsNotNullAndEmpty()) { mPath = path; mThumbnailPath = path; AudioContent.gameObject.SetActive(false); if (mPath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(true); } } Debug.Log("Image path: " + path); }, "选择图片", "image/*", true, action); } }, (int)_.GetAction); } } // 视频不需要了 else if (_.GetPhotoAction == ChoosePhotoAction.AttendanceVideo) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetVideoFromGalleryForAndroid((json) => { if (json.IsNotNullAndEmpty()) { NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json); if (model.IsNotNull()) { if (model.status == 1) { mPath = model.videoPath; mThumbnailPath = model.imagePath; AudioContent.gameObject.SetActive(false); if (model.imagePath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + model.imagePath, ImagePic); BtnVideo.gameObject.SetActive(true); BtnDel.gameObject.SetActive(true); } } else if (model.status == 0) { mPath = null; mThumbnailPath = null; ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(false); } } } }, "选择视频", "video/*", action); } }, (int)_.GetAction); } }).AddTo(this); SimpleEventSystem.GetEvent <TipConfirmClick>() .Subscribe(_ => { if (_.GetAction == TipAction.DelAttendance) { mPath = null; mThumbnailPath = null; ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(false); } }).AddTo(this); SimpleEventSystem.GetEvent <VideoCompressResult>().Subscribe(res => { VideoCompressModel model = res.Model; if (Application.platform == RuntimePlatform.Android) { if (model.status == 1) { string fileType = model.path.Substring(model.path.LastIndexOf(".")); Log.I("mPath: " + model.path + " fileType: " + fileType); StartRequestForUpload("attendance" + fileType, model.path); } else { CommonUtil.toast("视频压缩失败"); } } else if (Application.platform == RuntimePlatform.IPhonePlayer) { } }).AddTo(this); }
private void StartResquestForSharePoster(ShareAction shareAction) { Dictionary <string, object> paramDict = new Dictionary <string, object>(); paramDict.Add("babyId", PlayerPrefsUtil.GetBabyId()); paramDict.Add("shareType", 2); paramDict.Add("medalGrade", mData.medalModel.medalGrade); HttpUtil.PostWithSign <string>(UrlConst.SharePoster, paramDict) .Subscribe(response => { Log.I("图片地址: " + response); if (shareAction == ShareAction.Save) { if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { AndroidForUnity.CallAndroidForSavePicToAlbum(response); CommonUtil.toast("保存成功"); } }, (int)NativeAction.Album); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { IOSClientUtil.SaveImageToAlubmCallIOSClient(response); } } else if (shareAction == ShareAction.Wechat) { if (Application.platform == RuntimePlatform.Android) { ShareModel shareModel = new ShareModel(); shareModel.imageUrl = response; shareModel.platformName = AppConst.SHARE_WECHAT; shareModel.type = AppConst.SHARE_IMAGE_TYPE; shareModel.title = AppConst.SHARE_TITLE; if (mData.medalModel.isShare == 0) { shareModel.toastMessage = "分享成功+" + mData.medalModel.medalShareScore + "积分"; } AndroidForUnity.CallAndroidForShare(SerializeHelper.ToJson(shareModel)); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> sharParmsDic = new Dictionary <string, object>(); sharParmsDic.Add("platformType", "WechatSession"); sharParmsDic.Add("shareType", "image"); sharParmsDic.Add("image", response); if (mData.medalModel.isShare == 0) { string shareToastMessage = "分享成功+" + mData.medalModel.medalShareScore + "积分"; sharParmsDic.Add("shareToastMsg", shareToastMessage); } IOSClientUtil.ShareObjectCallIOSClient(SerializeHelper.ToJson(sharParmsDic)); } } else if (shareAction == ShareAction.WechatMoments) { if (Application.platform == RuntimePlatform.Android) { ShareModel shareModel = new ShareModel(); shareModel.imageUrl = response; shareModel.platformName = AppConst.SHARE_WECHAT_MOMENTS; shareModel.type = AppConst.SHARE_IMAGE_TYPE; shareModel.title = AppConst.SHARE_TITLE; if (mData.medalModel.isShare == 0) { shareModel.toastMessage = "分享成功+" + mData.medalModel.medalShareScore + "积分"; } AndroidForUnity.CallAndroidForShare(SerializeHelper.ToJson(shareModel)); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> sharParmsDic = new Dictionary <string, object>(); sharParmsDic.Add("platformType", "WechatTimeLine"); sharParmsDic.Add("shareType", "image"); sharParmsDic.Add("image", response); if (mData.medalModel.isShare == 0) { string shareToastMessage = "分享成功+" + mData.medalModel.medalShareScore + "积分"; sharParmsDic.Add("shareToastMsg", shareToastMessage); } IOSClientUtil.ShareObjectCallIOSClient(SerializeHelper.ToJson(sharParmsDic)); } } } , e => { if (e is HttpException) { HttpException http = e as HttpException; Log.E("弹吐司" + http.Message); } }).AddTo(this); }
IEnumerator CaptureCor(bool share) { yield return(new WaitForEndOfFrame()); byte[] imageByte; Texture2D tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, true); //RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 24); //foreach (Camera cam in cams) //{ // RenderTexture prev = cam.targetTexture; // cam.targetTexture = rt; // cam.Render(); // cam.targetTexture = prev; //} //RenderTexture.active = rt; tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); tex.Apply(); imageByte = tex.EncodeToPNG(); DestroyImmediate(tex); #if UNITY_ANDROID if (share) { try { string filePath = Path.Combine(Application.temporaryCachePath, "shared img.png"); File.WriteAllBytes(filePath, imageByte); new NativeShare().AddFile(filePath).SetSubject("소녀전선 제대 시뮬레이터").SetText("- Made By Cosmos0").Share(); SingleTon.instance.msg.SetMsg("공유"); } catch { SingleTon.instance.msg.SetMsg("공유 에러"); } } else { try { var permission = NativeGallery.SaveImageToGallery(imageByte, "GFSIM", "HOXY {0}.png"); if (permission == NativeGallery.Permission.ShouldAsk) { NativeGallery.RequestPermission(); SingleTon.instance.msg.SetMsg("캡쳐 실패!"); } else if (permission == NativeGallery.Permission.Denied) { SingleTon.instance.msg.SetMsg("캡쳐 실패!"); } else { SingleTon.instance.msg.SetMsg("캡쳐 됨!"); } } catch { SingleTon.instance.msg.SetMsg("캡쳐 에러"); } } #elif UNITY_EDITOR if (share) { SingleTon.instance.msg.SetMsg("PC버전에서 공유기능은 지원되지 않습니다.(캡쳐됨)"); } var path = Application.persistentDataPath + "/screenshot"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.WriteAllBytes(path + "/HOXY" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".PNG", imageByte); SingleTon.instance.msg.SetMsg("screenshot 폴더에 캡쳐 됨!"); #elif UNITY_STANDALONE if (share) { SingleTon.instance.msg.SetMsg("PC버전에서 공유기능은 지원되지 않습니다.(캡쳐됨)"); } var path = Application.dataPath + "/screenshot"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.WriteAllBytes(path + "/HOXY" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".PNG", imageByte); SingleTon.instance.msg.SetMsg("screenshot 폴더에 캡쳐 됨!"); #endif }
protected override void OnInit(QFramework.IUIData uiData) { mData = uiData as AttendanceMainPanelData ?? new AttendanceMainPanelData(); BtnBack.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); Back(); }); BtnPicture.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); UIMgr.OpenPanel <ChoosePhotoPanel>(new ChoosePhotoPanelData() { action = ChoosePhotoAction.AttendancePic, }); }); BtnAudio.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { UIMgr.OpenPanel <AttendanceAudioRecordPanel>(new AttendanceAudioRecordPanelData(), UITransitionType.CIRCLE); } }, (int)NativeAction.Audio); } else { UIMgr.OpenPanel <AttendanceAudioRecordPanel>(new AttendanceAudioRecordPanelData(), UITransitionType.CIRCLE); } }) ; BtnVideo.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); // UIMgr.OpenPanel<ChoosePhotoPanel>(new ChoosePhotoPanelData() // { // action = ChoosePhotoAction.AttendanceVideo, // showTip = true // }); if (Application.platform == RuntimePlatform.IPhonePlayer) { IPhonePlayerMakeVideoOpenCamera(); } else if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetVideoFromGalleryForAndroid((json) => { if (json.IsNotNullAndEmpty()) { NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json); if (model.IsNotNull()) { if (model.status == 1) { UIMgr.OpenPanel <AttendanceAddPanel>(new AttendanceAddPanelData() { BoxId = mData.BoxId, BoxDay = mData.BoxDay, Path = model.videoPath, ThumbnailPath = model.imagePath, Action = AttendanceAdd.Video, }, UITransitionType.CIRCLE); Close(); } } } }, "选择视频", "video/*", action); } }, (int)NativeAction.Camera); } }); SimpleEventSystem.GetEvent <RecordPath>().Subscribe(Path => { UIMgr.OpenPanel <AttendanceAddPanel>(new AttendanceAddPanelData() { BoxId = mData.BoxId, BoxDay = mData.BoxDay, Action = AttendanceAdd.Audio, Path = Path.Path }, UITransitionType.CIRCLE); Close(); }).AddTo(this); SimpleEventSystem.GetEvent <ChoosePhotoClick>() .Subscribe(_ => { if (_.GetPhotoAction == ChoosePhotoAction.AttendancePic) { if (Application.platform == RuntimePlatform.IPhonePlayer) { if (_.GetAction == NativeAction.Camera) { IPhonePlayerSelectPictureOpenCamera(); } else if (_.GetAction == NativeAction.Album) { IPhonePlayerSelectPictureOpenAlbum(); } else { } } else if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetImageFromGalleryForAndroid((path) => { if (path.IsNotNullAndEmpty()) { UIMgr.OpenPanel <AttendanceAddPanel>(new AttendanceAddPanelData() { BoxId = mData.BoxId, BoxDay = mData.BoxDay, Path = path, ThumbnailPath = path, Action = AttendanceAdd.Pic }, UITransitionType.CIRCLE); Close(); } Debug.Log("Image path: " + path); }, "选择图片", "image/*", true, action); } }, (int)_.GetAction); } } // 视频不需要了 else if (_.GetPhotoAction == ChoosePhotoAction.AttendanceVideo) { if (Application.platform == RuntimePlatform.IPhonePlayer) { if (_.GetAction == NativeAction.Album) { IPhonePlayerSelectVideoOpenAlbum(); } else if (_.GetAction == NativeAction.Camera) { IPhonePlayerMakeVideoOpenCamera(); } } else if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetVideoFromGalleryForAndroid((json) => { if (json.IsNotNullAndEmpty()) { NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json); if (model.IsNotNull()) { if (model.status == 1) { UIMgr.OpenPanel <AttendanceAddPanel>(new AttendanceAddPanelData() { BoxId = mData.BoxId, BoxDay = mData.BoxDay, Path = model.videoPath, ThumbnailPath = model.imagePath, Action = AttendanceAdd.Video, }, UITransitionType.CIRCLE); Close(); } } } }, "选择视频", "video/*", action); } }, (int)_.GetAction); } } }).AddTo(this); }
public void StartSaveProcessWithGrabber() { logger.text = "Permission 111: " + NativeGallery.RequestPermission(); StartCoroutine(TakeScreenshotAndSave()); }