UNITY3D学习笔记10





using UnityEngine;
using System.Collections;

public class TestB2 : MonoBehaviour {

	public AudioSource music;
	public float musicVolume;

	// Use this for initialization
	void Start () {
		musicVolume = 0.5f;
	}
	
	// Update is called once per frame
	void Update () { }

	void OnGUI(){
		if(GUI.Button(new Rect(10,10,100,50),"播放音乐")){
			if(!music.isPlaying){
				music.Play();
			}
		}

		if(GUI.Button(new Rect(10,60,100,50),"停止音乐")){
			if(!music.isPlaying){
				music.Stop();
			}
		}

		if(GUI.Button(new Rect(10,110,100,50),"暂停音乐")){
			if(!music.isPlaying){
				music.Pause();
			}
		}

		musicVolume = GUI.HorizontalSlider(new Rect(160,10,100,50),musicVolume,0.0f,1.0f);

		GUI.Label(new Rect(160,50,300,20),"游戏音量"+(int)(musicVolume * 100)+"%");

		if(music.isPlaying){
			music.volume = musicVolume;
		}
	}
}



using UnityEngine;
using System.Collections;
using UnityEditor;

public class TestB3 : MonoBehaviour {

	public MovieTexture movTexture;

	// Use this for initialization
	void Start () {
		//movTexture = new MovieTexture();
		//movTexture = (MovieTexture)AssetDatabase.LoadAssetAtPath("Assets/Movie/1.mp4",typeof(MovieTexture));
		renderer.material.mainTexture = movTexture;
		movTexture.loop = true;
	}
	//texture = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Texture/0.png",typeof(Texture2D));  

	// Update is called once per frame
	void Update () { }

	void OnGUI(){
		if(GUILayout.Button("Play/Co..")){
			if(!movTexture.isPlaying){
				movTexture.Play();
			}
		}

		if(GUILayout.Button("pause")){
			movTexture.Pause();
		}

		if(GUILayout.Button("Stop")){
			movTexture.Stop();
		}
	}
}



using UnityEngine;
using System.Collections;

public class TestB4 : MonoBehaviour {

	public MovieTexture movTexture;

	// Use this for initialization
	void Start () {
		movTexture.loop = true;
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnGUI(){

		GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),movTexture,ScaleMode.StretchToFill);

		if(GUILayout.Button("Play/Co..")){
			if(!movTexture.isPlaying){
				movTexture.Play();
			}
		}
		
		if(GUILayout.Button("pause")){
			movTexture.Pause();
		}
		
		if(GUILayout.Button("Stop")){
			movTexture.Stop();
		}
	}
}



using UnityEngine;
using System.Collections;

public class TestB5 : MonoBehaviour {

	private Texture tex0;
	private Texture tex1;

	IEnumerator loadLocal(){
		if(tex0 == null){
			WWW date = new WWW("file://"+Application.dataPath+"/Image/pic1.png");
			yield return date;
			tex0 = date.texture;
		}
		renderer.material.mainTexture = tex0;
	}

	IEnumerator loadNetWork(){
		if(tex1==null){
			WWW date = new WWW("http://10.33.91.13/test3/1.jpg");

			yield return date;

			tex1 = date.texture;
		}
		renderer.material.mainTexture = tex1;
	}
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnGUI(){
		if(GUILayout.Button("local")){
			StartCoroutine(loadLocal());
		}

		if(GUILayout.Button("network")){
			StartCoroutine(loadNetWork());
		}
	}
}
//http://10.33.91.13/test3/1.jpg



using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;

public class TestB6 : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	[MenuItem("zidingyi/create res")]
	static void ExecCreateAssetBunles(){
		string targetDir = Application.dataPath +"/AssetBundles";

		Object[] SelectedAsset = Selection.GetFiltered(typeof(Object),SelectionMode.DeepAssets);

		if(!Directory.Exists(targetDir)){
			Directory.CreateDirectory(targetDir);
		}

		for(int i = 0;i<SelectedAsset.Length;i++){
			string filePath = targetDir + "/" + SelectedAsset[i].name +".unity3d";

			if(File.Exists(filePath)){
				File.Delete(filePath);
			}

			if(BuildPipeline.BuildAssetBundle(SelectedAsset[i],null,filePath,
			                                  BuildAssetBundleOptions.CollectDependencies))
			{
				Debug.Log ("OK");
				AssetDatabase.Refresh();
			}else{
				Debug.Log ("faild");
			}
		}
	}
}



using UnityEngine;
using System.Collections;

public class TestB7 : MonoBehaviour {

	IEnumerator loadBundleMat(string name){
		Material mat;
		WWW date = new WWW("file://"+Application.dataPath+"/AssetBundle/"+name+".unity3d");
		
		yield return date;
		mat = (Material)date.assetBundle.mainAsset;
		
		renderer.material = mat;
		date.assetBundle.Unload(false);
	}
	
	IEnumerator loadBundleObject(string name){
		WWW date = new WWW("file://"+Application.dataPath+"/AssetBundles/"+name+".unity3d");
		yield return Instantiate(date.assetBundle.mainAsset);
		
		date.assetBundle.Unload(false);
	}

	// Use this for initialization
	void Start () { }
	
	// Update is called once per frame
	void Update () { }

	public void OnGUI(){
		if(GUILayout.Button("down red")){
			StartCoroutine(loadBundleMat("red"));
		}

		if(GUILayout.Button("down black")){
			StartCoroutine(loadBundleMat("black"));
		}

		if(GUILayout.Button("down blue")){
			StartCoroutine(loadBundleMat("blue"));
		}

		if(GUILayout.Button("down and create Object")){
			StartCoroutine(loadBundleObject("Cube"));
		}
	}


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值