zoukankan      html  css  js  c++  java
  • 批量创建prefab

    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;
    using System.IO;
    using UnityEditor;
    
    public class Test : MonoBehaviour {
    
    	public string dicStr="";
    	// Use this for initialization
    	void Start () {
    		NewSpriteRender ();
    	}
    		
    	public void NewSpriteRender()
    	{
    		if(dicStr.Equals("")==true)
    			return;
    
    		Sprite [] sp = Resources.LoadAll<Sprite> (dicStr+"/");
    		Debug.Log (sp.Length);
    
    		string allpath = Application.dataPath +"/Resources/"+dicStr+"Prefab";
    		Debug.LogError("_________allpath:"+allpath);
    		if (Directory.Exists (allpath) == false) 
    		{
    			Directory.CreateDirectory (allpath);
    		}
    
    		for(int i=0;i<sp.Length;i++)
    		{
    			GameObject obj = new GameObject (sp[i].name); 
    			obj.layer = LayerMask.NameToLayer ("Default");
    			obj.AddComponent<SpriteRenderer> ().sprite = sp [i];
    			string prefabPath = allpath +"/"+sp[i].name+".prefab";
    			string prefabpath = prefabPath.Substring (prefabPath.IndexOf("Assets"));
    			Debug.Log (prefabpath);
    			#if UNITY_EDITOR
    			PrefabUtility.CreatePrefab(prefabpath,obj);
    			#endif
    		}
    
    	}
    	
    	// Update is called once per frame
    	void Update () {
    	
    	}
    }
    

      

  • 相关阅读:
    ESP8266 A0的使用
    电脑总是被乱装各种软件怎么办?那就设置一个密码吧!
    笔记本光驱位改装固态系统硬盘教程
    任务管理器无法呼出
    Python stomp 介绍与代码
    Power(x,y)
    旋转图像
    字符串相乘
    缺失的正数
    外观数列
  • 原文地址:https://www.cnblogs.com/602147629/p/5190664.html
Copyright © 2011-2022 走看看