• unity+Android+PC加载本地图片


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class LoadImage : MonoBehaviour {
        Texture2D tempImage;
        private RawImage RawImageRef;
        // Use this for initialization
        void Start () {
            RawImageRef = gameObject.GetComponent<RawImage>();
            StartCoroutine(OnLoadImage("uploadFile/projectImg/22.jpg", RawImageRef));
        }
        
        // Update is called once per frame
        void Update () {
            
        }
        IEnumerator OnLoadImage(string path, RawImage image)
        {
    
            string filePath = "file://" + Application.persistentDataPath + "/document/" + path;
            //string filePath = "file://" + "/sdcard/TKData/SaveData/" + "document/" + path;//手机
            WWW www = new WWW(filePath);
            yield return www;
            if (www.error != null)
            {
                Debug.LogError(filePath + www.error);
    
                image.gameObject.SetActive(false);
            }
            else
            {
                Debug.LogError(filePath);
                image.gameObject.SetActive(true);
                tempImage = www.texture;
                image.texture = tempImage;
            }
    
        }
    }

    将图片放入本地指定文件夹即可

    unity设置如下

  • 相关阅读:
    css3圆形轨迹动画
    css3动画
    3D效果
    css3基础下
    css3基础
    HTML5 表单 中
    HTML5 表单
    面向对象的三大特性、七大原则、类与类间的关系
    四种事务的隔离级别
    线程池(二)
  • 原文地址:https://www.cnblogs.com/WalkingSnail/p/10997657.html
Copyright © 2020-2023  润新知