Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by rogiedodgie38 · Nov 08, 2015 at 06:32 AM · imagesaveloadipadwebcamtexture

Loading Images on iOS vs Standalone Build

Hi All,

I have a simple program for iOS that shows you what is on the webcam, and, when you click on one of 25 cubes, it maps that to the cube. When you return to the scene later in the game, your picture is still there. this works fine on a standalone build. However, when I connect my iPAD and play it there, i get a strange behavior. The pics map to the cubes when i click on them, but when I reload the scene later, the cubes are all back in their original, unmapped state with no pictures on them. Is there something different about how I should save and load the files in smartupdatepics() function. I feel it is a simple fix, but I can't for the life of me figure it out! Any suggestions? Thanks, Roger

 #pragma strict
     import System.IO;
     import UnityEngine.UI;
     //put this on an object like a cube
     //Then create a button that, when pressed, activates the takephoto function of this script
     //takes pic to Assets/MiscImages, cant seem to work anywhere else...
     var CubePlayers : GameObject[] = new GameObject[25];
     var PrefabCubePlayers : GameObject[] = new GameObject[25];
     var PrefabTextures: Texture[] = new Texture[25];
     var PhotoTextures: Texture[] = new Texture[25];
     var placeholder:int;
     var indicator: GameObject;
     var MajorCube: GameObject;
     var onpremade = false;
     var blankphototex: Texture;
     
     public static var webCamTexture: WebCamTexture;
     
     function Start() {
         
         //Get textures on object and write to persistent data path for easy access later on
         for(var cctr = 0; cctr < 25; cctr++){
             var AsTex = PrefabTextures[cctr] as Texture2D;
             var bytes = AsTex.EncodeToPNG();
             File.WriteAllBytes(Application.persistentDataPath + "/prefabnum"+cctr+".jpg", bytes);
             Debug.Log("Wrote File: "+Application.persistentDataPath + "/prefabnum"+cctr+".jpg");
         }
             
       webCamTexture = new WebCamTexture();
       this.GetComponent.<Renderer>().material.mainTexture = webCamTexture;
             
       webCamTexture.Play();
       smartupdatepics();
     }
         
     function Update(){
        detectobjecttouched();
     }
         
     function smartupdatepics() {
         
         //load photos and such
         var sboard2textures : Texture[] = new Texture[25];
         for(var tctr = 0; tctr < 25; tctr++)
             {
             Debug.Log("loaded: "+Application.persistentDataPath + "/num"+tctr+".jpg");
                 if (!System.IO.File.Exists(Application.persistentDataPath + "/num"+tctr.ToString+".jpg")){
                     CubePlayers[tctr].GetComponent.<Renderer>().material.mainTexture = blankphototex;    
                 }
                 if (System.IO.File.Exists(Application.persistentDataPath + "/num"+tctr+".jpg")){
                     var bytestorage = System.IO.File.ReadAllBytes(Application.persistentDataPath + "/num"+tctr+".jpg");
                     Debug.Log("loaded: "+Application.persistentDataPath + "/num"+tctr+".jpg");
                     var textoload = new Texture2D(1,1);
                     textoload.LoadImage(bytestorage);
                     CubePlayers[tctr].GetComponent.<Renderer>().material.mainTexture = textoload;    
                 }
             }
             
             //load up textures on cubes for prefab players
             var prefabtextures : Texture[] = new Texture[25];
             for(var pctr = 0; pctr < 25; pctr++){
                 PrefabCubePlayers[pctr].GetComponent.<Renderer>().material.mainTexture = PrefabTextures[pctr];
             }
     }
         
             
     function detectobjecttouched(){
                var hit : RaycastHit;
                var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
                if (Input.GetMouseButton(0)){
                    if ( Physics.Raycast( ray, hit, 1000 ) ){
                          var phoo = hit.collider.gameObject.transform.name;
                          var photo2 = new Texture2D(webCamTexture.width, webCamTexture.height);
                             photo2.SetPixels(webCamTexture.GetPixels());
                             TextureScale.Bilinear(photo2, 320, 190);
                             photo2.Apply();
                        
                             var i: int;
                         if (int.TryParse(phoo,i)){
                              hit.collider.gameObject.GetComponent.<Renderer>().material.mainTexture =  photo2;
                          
                          
                              var bytes = photo2.EncodeToPNG();
                             // File.WriteAllBytes(Application.persistentDataPath + "/" + someFilename, someTexture.EncodePNG());
                              File.WriteAllBytes(Application.persistentDataPath + "/num"+int.Parse(phoo)+".jpg", bytes);
                              Debug.Log("saved: "+Application.persistentDataPath + "/num"+int.Parse(phoo)+".jpg");
                             
                      }
                     }
         }
     }
     
     function RotatePics() {
         //transform.Rotate(Vector3 (0,90,0), 10 * Time.deltaTime);
         if (onpremade == false){
         MajorCube.transform.rotation.y=1;
         onpremade = true;
         }
         else if (onpremade == true){
         MajorCube.transform.rotation.y=0;
         onpremade = false;
         
         }
     }
     
     function TurnOffWebPlayerCamera(){
         webCamTexture.Stop();
     }



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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Save model from Blender in Unity and open it subsequently 0 Answers

How to make a save script in javascript. 1 Answer

Save/Load Player System 0 Answers

Save and load component values 0 Answers

Save/load not work on mobile phone 1 Answer


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