2017-02-10 6 views
0
  • 私は私がリンクから画像をロードする必要があり、そのイメージ(「キャンバスどのようにリンク

  • で画像を宣言しているシーンがあります。httpからユニティで画像をロードします

    urllll = "http://192.168.137.129/ooredoo/client_api/" + ConfirmPath; 
    WWW imgLink1 = new WWW (urllll); 
    img1 = imgLink1.texture; 
    
      :/資産/スクリーンセーバー」)

    は、私が実際に画像をロードするために何かを行っています

  • しかし、この負荷、私はキャンバスに宣言した画像の上に画像をロードする必要が完全に
  • シーン全体に画像

EDIT:完全なコード

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
using ZXing; 
using ZXing.Common; 
using ZXing.QrCode; 
using System.IO; 
using UnityEngine.Events; 
using LitJson; 
using System.Data; 
using Mono.Data.Sqlite; 
using System.Linq; 
using System.Collections.Generic; 
using System; 

public class ScreenSaverFromServer : MonoBehaviour 
{ 

public Text Tester; 
public int st = 0; 
public int TimerFrAdd = 30; 
public int OgTimerFrAdd; 
public int ImageSize = 5; 
public Image[] Imagez; 
public Image Imag; 
public int TimeToChangeImage = 10; 
public int TimeToChangeVideo= 10; 
public string imagePath = "Assets/Images/1K.png"; 
public Image photo; 
public Texture2D img1; 
public string urllll; 
public string ConfirmPath; 
public string[] paths = {"1","2","3","4","5","6","7","8","9","10"}; 
public string[] VedioPaths = { "Look at NEW Trump's 2-minute closing argument ad.mp4","The 2 minutes love story of TV Commercial for Canon 'You are my inspiration'.mp4"}; 
public string ConfirmPath1; 
public int PathNO1; 
public int PathNO ; 
public bool guitextureindi = true; 
public Image guitextureindFrame; 
public string screensavertype,ImageFrameIndic; 

void Start() 
{ 
    OgTimerFrAdd = TimerFrAdd; 
    Tester = GameObject.Find ("Tester").GetComponent<Text>(); 
    InvokeRepeating("touches1", 1, 1); 

    Imag = GameObject.Find("ImageFrame").GetComponent<Image>(); 

    Imag.enabled = false; 

    screensavertype = PlayerPrefs.GetString ("screensavertype"); 
    ImageFrameIndic = PlayerPrefs.GetString ("screensaverActive"); 
} 

void Update() 
{ 
    foreach (UnityEngine.Touch touch in Input.touches) 
    { 
     print ("touched"); 

     if (TimerFrAdd == 0) 
     { 
      InvokeRepeating("touches1", 1, 1); 
     } 

     TimerFrAdd = OgTimerFrAdd; 
     Imag.enabled = false; 
    } 

    if (guitextureindFrame.enabled) 
    { 
     guitextureindi = true; 
    } 

    if(screensavertype == "0") 
    { 
     Imag.enabled = false; 
    } 
} 

public void touches1() 
{ 
    TimerFrAdd = TimerFrAdd - 1; 
    Tester.text = TimerFrAdd.ToString(); 
    if (TimerFrAdd == 0) 
    { 
     if(ImageFrameIndic == "1") 
     { 
      Imag.enabled = true; 
     } 

     CancelInvoke (methodName : "touches1"); 

     string[] CallChange = {"ChangeImage","ChangeVideo" }; 
     System.Random random0 = new System.Random(); 
     int PathNO0 = random0.Next (CallChange.Length); 
     string ConfirmPath0 = CallChange[PathNO0]; 

     print (ConfirmPath0); 

     InvokeRepeating ("ChangeImage", 1, TimeToChangeImage); 
    } 
} 

public void ChangeImage() 
{ 
    //System.Random random = new System.Random(); 
    //PathNO = random.Next (paths.Length); 
    //ConfirmPath = paths[PathNO]; 
    //photo.sprite =Resources.Load<Sprite>("Images/"+ConfirmPath) as Sprite ; 
    print("aaaaaaaa"); 
    StartCoroutine (LoadImg1()); 
} 


public void ChangeVideo() 
{ 
    Imag.enabled = false; 
    CancelInvoke (methodName : "ChangeImage"); 
    CancelInvoke (methodName : "touches1"); 
    CancelInvoke (methodName : "ChangeVideo"); 

    System.Random random1 = new System.Random(); 
    PathNO1 = random1.Next (VedioPaths.Length); 
    ConfirmPath1 = VedioPaths[PathNO1]; 
    Handheld.PlayFullScreenMovie (ConfirmPath1,Color.black, FullScreenMovieControlMode.CancelOnInput); 

    if (TimerFrAdd == 0) 
    { 
     InvokeRepeating("touches1", 1, 1); 
     TimerFrAdd = OgTimerFrAdd; 
    } 
} 

IEnumerator LoadImg1() 
{ 
    yield return 0; 

    //List<string> Items13 = new List<string> (ScreenSaverCodesApi.Items12); 
    List<string> Items13 = ScreenSaverCodesApi.Items12; 

    print("aaaaaaaa2222222"); 
    System.Random random1 = new System.Random(); 
    print("aaaaaaaa333333"); 
    int PathNO = Items13.Count; 

    int num = UnityEngine.Random.Range(0,PathNO); 
    print(num); 

    foreach (string st in Items13) { 
     print (st); 
    } 
    print ("path-----"+Items13[num]); 
    string ConfirmPath = Items13[num]; 
    print(ConfirmPath); 
    print("aaaaaaaa555555"); 
    urllll = "http://hcfhfch/nn/client_api/" + ConfirmPath; // test with an image link 

    print("aaaaaaaa6666666"); 

    WWW imgLink1 = new WWW (urllll); 
    print("aaaaaaaa777777"); 
    print (urllll); 
    print("aaaaaaaa888888"); 
    yield return imgLink1; 
    print("aaaaaaaa999999"); 

    img1 = imgLink1.texture; 
} 

void OnGUI() 
{ 
    foreach (UnityEngine.Touch touch in Input.touches) 
    { 
     guitextureindi = false; 
    } 

    if (guitextureindi) 
    { 
     GUILayout.Label (img1); 
    } 
} 
} 
+0

@Programmer。 ..私は元のサイズよりも小さいサイズにスケーリングしてイメージを表示する必要があり、私のコードはフルスクリーンでイメージを表示します。 –

+0

"html in unity3d"を検索してください。私はあなたが望むものを手に入れようとしているソリューションのひとつに賭けています。 –

+0

私の問題は、私がネットからロードした画像を拡大縮小することができないことです。 –

答えて

1

ますテクスチャをダウンロードして、のタイプの変数img1に格納しています。テクスチャ2D画像は、OnGUI機能でGUILayout.Labelと表示されます。問題は、画像のサイズを変更しています...

OnGUIの機能を使用します。 を入力しないOnGUI関数を必要とするUnity APIを使用してください。エディタプラグインを作成している場合を除きます。あなたの関数で

void OnGUI() 
{ 
    foreach (UnityEngine.Touch touch in Input.touches) 
    { 
     guitextureindi = false; 
    } 

    if (guitextureindi) 
    { 
     GUILayout.Label (img1); 
    } 
} 

渡しwidthlengthあなたがGUILayout.Label関数にしたいです。例えば

public float textureWidth = 400; 
public float textureHeight = 400; 

public Texture2D img1; 
void OnGUI() 
{ 
    GUILayout.Label(img1, GUILayout.Width(textureWidth), GUILayout.Height(textureHeight)); 
} 

ユニティに画像を表示するための正しい/適切な方法:

RawImageコンポーネントと

public float textureWidth = 400; 
public float textureHeight = 400; 

public Texture2D img1; 
public Image textureDisplayer; 

void SomeFunction() 
{ 
    textureDisplayer.sprite = Sprite.Create(img1, new Rect(0, 0, textureWidth, textureHeight), new Vector2()); 
} 

Imageコンポーネントと

public int textureWidth = 400; 
public int textureHeight = 400; 

public Texture2D img1; 
public RawImage textureDisplayer; 

void SomeFunction() 
{ 
    img1.Resize(textureWidth, textureHeight); 
    textureDisplayer.texture = img1; 
} 

またして画面上のImageまたはRawImageのサイズを変更することができます

textureDisplayer.GetComponent<RectTransform>().sizeDelta = new Vector2(textureWidth, textureHeight); 

簡単なダウンロード、サイズを変更し、表示画像サンプル:私は、インターネットから画像を表示する必要が

public int textureWidth = 400; 
public int textureHeight = 400; 

public RawImage textureDisplayer; 

void Start() 
{ 
    string imageUrl = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg"; 
    StartCoroutine(LoadImg(imageUrl)); 
} 

void displayImage(Texture2D imgToDisp) 
{ 
    //Resize Image 
    textureDisplayer.GetComponent<RectTransform>().sizeDelta = new Vector2(textureWidth, textureHeight); 
    textureDisplayer.texture = imgToDisp; 
} 


IEnumerator LoadImg(string url) 
{ 
    yield return null; 
    WWW www = new WWW(url); 
    yield return www; 

    displayImage(www.texture); 
} 
関連する問題