Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Heromoga2000 · Jun 22, 2020 at 03:00 PM · unity4.3

The IEnumerator with voice command function

Hi All

I have a project where I use only voice command to perform some different function and one of them is to take a photo using Hololens .So I use the StartCoroutine(photoshoot()); function to call the IEnumerator photoshoot(). The IEnumerator photoshoot() call the TakePhotosnap();.

It takes the photo perfectly but I have issue after taking the photo it does not go back to IEnumerator.

It stops the code and can not perform any other function.


As you can see in my code ( I put some numbers to help me explain the function )

I call StartCoroutine(photoshoot()); line 11 and in IEnumerator photoshoot() called the TakePhotosnap(); line 12 and it performs taking photo till line 13 Debug.Log("we finish taking photo successfully "); and then stop. It should go to line 14 in IEnumerator photoshoot().

Please what is wrong with my code. and is there any other way to solve it, please .

Please help me. My deadline is very soon.

Regards,

Here is some of my code



private void Takephoto()

{

// this function is to call to take a photo and save it in a special folder

Debug.Log("Take Photo function call is started");

11 StartCoroutine(photoshoot());

Debug.Log("Take Photo for Hololens");

}

IEnumerator photoshoot()

{

Debug.Log(" The taking photo coroutine is started ");

yield return new WaitForEndOfFrame();

Debug.Log("Take Photo");

12 TakePhotosnap();

14 Debug.Log("Finish taking Hi again ");

yield return new WaitForEndOfFrame();

GameObject.Find("Cube").transform.localPosition = new Vector3(Random.Range(-1, 1), 0, Random.Range(1, 3));

GameObject.Find("Cube").SetActive(true);

}


private void TakePhotosnap()

{

Debug.Log("TakePhoto Call StartPhotoModeAsync () method to start the photo mode");

Debug.Log("snap pic taken");

PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);

}

void OnPhotoCaptureCreated(PhotoCapture captureObject)

{

//Store objects, configure shooting parameters and start shooting mode.

Debug.Log("Start taking photo calling function");

photoCaptureObject = captureObject;

Debug.Log("set camera parameters");

Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

CameraParameters c = new CameraParameters();

/// c= CameraParameters

c.hologramOpacity = 1.0f;

c.cameraResolutionWidth = cameraResolution.width;

c.cameraResolutionHeight = cameraResolution.height;

c.pixelFormat = CapturePixelFormat.BGRA32;

Debug.Log("camera parameters finish");

captureObject.StartPhotoModeAsync(c, OnPhotoModeStarted);

}

private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)

{

if (result.success)

{

//string filename = string.Format(@"CapturedImage{0}_n.jpg", Time.time);

string filename = string.Format(@"alc.jpg", Time.time);

Debug.Log("FileName: =" + filename);

string filePath = System.IO.Path.Combine(Application.persistentDataPath, filename);

Debug.Log("filePath: =" + filePath);

/////

string targetPath = @"C: \Users\ABC\Pictures\Camera Roll";

string destFile = System.IO.Path.Combine(targetPath, filename);

Debug.Log("destFile: =" + destFile);

if (!System.IO.File.Exists(filePath))

{

//System.IO.File.Create(filePath);

System.IO.File.Create(filePath).Dispose();

}

// https://blog.csdn.net/Lee_gc/java/article/details/79919042

Debug.Log("filePath filePath: =" + filePath);

string filePath2 = System.IO.Path.Combine(Application.dataPath, filename);

Debug.Log("filePath2: =" + filePath2);

Debug.Log("finish to set photo file path and name");

//photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);

Debug.LogError("Saved That Image Somewhere" + "FileName: =" + filename + " FilePath: = " + filePath + " FilePath2: = " + filePath2);

Debug.Log("finish to copy photo to new directory");

Debug.Log("finish photo");

photoCaptureObject.TakePhotoAsync(filePath, PhotoCaptureFileOutputFormat.JPG, OnCapturedPhotoToDisk);

13 Debug.Log("we finish taking photo successfuly ");

}

else

{

Debug.LogError("Unable to start photo mode!");

}

}

// clean up

void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)

{

Debug.Log("result=" + result);

photoCaptureObject.Dispose();

photoCaptureObject = null;

}

void OnCapturedPhotoToDisk(PhotoCapture.PhotoCaptureResult result)

{

if (result.success)

{

Debug.Log("Saved Photo to disk!");

photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);

}

else

{

Debug.Log("Failed to save Photo to disk");

}

}

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

126 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Music Slider hookup? 1 Answer

Change object's clone tag after creation. 1 Answer

Scene Loading Question 1 Answer

Waves of birds 0 Answers

Screen record in unity3d 7 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges