unity3d 改变物体位置图集里的所有图片以相对位置全部拉到场景中

Unity3D调用摄像头并保持为图片然后加载到场景中代码&拍照照相代码
using UnityE
using System.C
using System.IO;
public class CameraController : MonoBehaviour {
& & public string
&&public&&WebCamTexture
&&public GameObject
objCameraC
&&public GameObject
&&public GameObject
&&public string
strTempTime="";
& & // Use this for
initialization
& & void Start () {
& & // Update is called once per
& & void Update () {
&&&if(strTempTime!="")
&GameObject.Find("pig5").GetComponent().mainTexture
= Resources.Load(strTempTime.ToString(), typeof(Texture)) as
& print("44444:"+strTempTime);
& & /// 调用摄像机
& & IEnumerator
CallTheCamera()
&&&yield return
Application.RequestUserAuthorization(UserAuthorization.WebCam);
&&&if(Application.HasUserAuthorization(UserAuthorization.WebCam))
&WebCamDevice[] devices =
WebCamTexture.
&& &deviceName =
devices[0].
&//摄像机摄像的区域
&& &webTex = new
WebCamTexture(deviceName, 400, 300, -112);
&GameObject.Find("CameraTexture").GetComponent().mainTexture
&webTex.Play();
& & /// 获取并保存texture
& & IEnumerator
GetTexture2D()
&&&print(GameObject.Find("CameraTexture").transform.localPosition);
&&&yield return
new WaitForEndOfFrame();
&&&Texture2D t =
Texture2D(GameObject.Find("CameraTexture").GetComponent().mainTexture.width,
GameObject.Find("CameraTexture").GetComponent().mainTexture.height);
&&&t.ReadPixels(new
Rect(15, 177, 406.5f, 281.6f), 0, 0, false);
&&&t.Apply();
&&&//把图片数据转换为byte数组
&&&byte[] byt =
t.EncodeToPNG();
&&&//然后保存为图片
&& &strTempTime
= Time.time.ToString();
&&&print("11111:"+strTempTime);
&File.WriteAllBytes(Application.dataPath +
"/Resources/" + strTempTime + ".jpg", byt);
&&&print("22222"+strTempTime);
&&&//GameObject
atlasPrefab = Resources.Load("TempAtlas") as GameO
& // Instantiate(ImgAtlas) as GameO
& tempA.GetComponent().spriteList.Add(
&&&UnityEditor.AssetDatabase.Refresh();
&&&//yield
return new WaitForSeconds(1);
&&&GameObject.Find("pig5").GetComponent().mainTexture
= Resources.Load(strTempTime.ToString(), typeof(Texture)) as
&&&print("33333"+strTempTime);
&&&NGUITools.AddSprite(tempA,
tempA.GetComponent(), "tempSprite");
&UIAtlas atlas = (Instantiate(ImgAtlas) as
GameObject).GetComponent();
&Texture text =
Resources.Load(Application.dataPath + "/Resources/" + strTempTime +
".jpg", typeof(Texture)) as T
&//&&print(atlas.ToString());
&&&//UISlicedSprite
ssprite = NGUITools.AddWidget(Game);
GameObject.Find("pig5").GetComponent().s
&&&//UIAtlas
atlas = Resources.Load(Application.dataPath + "/test/" + "Camera
Atlas", typeof(UIAtlas)) as UIA
&&&//print(atlas.ToString());
&//&&objAvatar.GetComponent().spriteName
= atlas.//this.gameObject.GetComponent().spriteN
&&&//objCameraController.SetActive(false);
& & void CameraStart()
&&&StartCoroutine("CallTheCamera");
& & void CameraSStart()
&&&StartCoroutine("GetTexture2D");
& & void CameraRestart()
&&&webTex.Play();
& & void CameraPause()
&&&webTex.Pause();
ClickCameraBtn()
&&&objCameraController.SetActive(true);
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。unity3d png图片不能直接拖入project里_百度知道
unity3d png图片不能直接拖入project里
我有更好的答案
有什么错误提示?
不是project。。是hierarchy里。
图片要放到材质球上才可以,不能直接把图片放到场景中比如创建一个基本体cube,再创建一个材质球material并赋予cube,然后就可以在这个cube上使用这张贴图了
采纳率:36%
如果你希望用这张图片做贴图的话,你需要先把他做成一个材质球,再将材质球拖上去即可
为您推荐:
其他类似问题
png图片的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。> Unity3D实现全景图
Unity3D实现全景图
时间:     来源:移动互联网学院
全景图是我们非常实用的场景,会增加显示的场景效果,现在我们就来查看全景图的添加方法。
首先 我们准备一张全景图图片。 这个图片怎么做的呢, 这个要问你们的美术了,他们会做的的。 我本来想给准备一张, 奈何, 蛮牛上图大小限制, 我没办法上传了。&
然后呢 ,我们在场景中创建一个 球体。&
然后再创建一个空的物体 ,名字你随便起,我就起了个很长的名字, 毕竟一寸长一寸强
第三部,我们就要把一个摄像机放在这个 新建的空的物体里面,作为子物体。
然后 把 球体, 摄像机, 和这个空的物体 都reset 下 位置, 也就是位置都是 0,0,0 &
这样 摄像机就在球体里面了。
下面就是写脚本和shader了&
[code]phpcode:
01 Shader &Unlit/Pano360Shader&
& &Properties
& &_MainTex(&Base(RGB)&, 2D) = &white&{}
& &_Color(&Main Color&, Color) = (1,1,1,0.5)
08 SubShader
& &Tags{ &RenderType& = &Opaque& }
& &//This is used to print the texture inside of the sphere
& &Cull Front
& &CGPROGRAM
14 #pragma surface surf SimpleLambert
& &half4 LightingSimpleLambert(SurfaceOutput s, half3 lightDir, half atten)
& &c.rgb = s.A
22 sampler2D _MainT
23 struct Input
& &float2 uv_MainT
& &float4 myColor : COLOR;
29 fixed3 _C
30 void surf(Input IN, inout SurfaceOutput o)
& &//This is used to mirror the image correctly when printing it inside of the sphere
& &IN.uv_MainTex.x= 1-IN.uv_MainTex.x;
& &fixed3 result = tex2D(_MainTex,IN.uv_MainTex)*_C
& &o.Albedo = result.
& &o.Alpha = 1;
40 Fallback &Diffuse&
这个shader 意思就是把图片做一个翻转 ,这样在球体内部看到图片也是正的。&
下面写一个控制摄像机旋转脚本
[code]csharpcode:
01 using UnityE
02 using System.C
04 public class Move : MonoBehaviour {
& &// Use this for initialization
& &void Start () {
& &// Update is called once per frame
& &void Update () {
& & & &if(Input.GetKey(KeyCode.A))
& & & & & &transform.Rotate(new Vector3(0,1,0));
& & & &if (Input.GetKey(KeyCode.D))
& & & & & &transform.Rotate(new Vector3(0, -1, 0));
【推荐阅读】&鍔犺浇涓

我要回帖

更多关于 unity3d 图集 的文章

 

随机推荐