Created
February 20, 2015 19:05
-
-
Save RH2/2c8bbda423c29da43cea to your computer and use it in GitHub Desktop.
play up tools // "instantiate"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A modified script based on one created by PlayUp Tools - www.playuptools.com | |
//source at https://github.com/RH2/TD_B3D-UDK/tree/Unity feel free to fork and improve/expand this plugin ^__^ | |
using UnityEngine; | |
using UnityEditor; | |
using System.Collections; | |
using System.IO; | |
using System.Text; | |
using System; | |
using System.Xml; | |
public class B3DInstanceToolImport { | |
public static void FiletoObj(string levelName){ | |
char[] delimiterChars = { ',' }; | |
GameObject level = new GameObject(Path.GetFileNameWithoutExtension(levelName)); | |
//Create the XmlDocument. | |
XmlDocument doc = new XmlDocument(); | |
string path = "Assets/B3DInstanceTool/Editor/lvl/" + levelName; | |
FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite); | |
doc.Load(fs); | |
XmlNodeList node = doc.GetElementsByTagName("OBJECT"); | |
for (int i=0; i<node.Count; i++) | |
{ | |
GameObject prefab = null; | |
GameObject clone = null; | |
XmlAttributeCollection attrc = node[i].Attributes; | |
for (int j=0; j<attrc.Count; j++) | |
{ | |
if (attrc[j].Name == "NAME"){ | |
prefab = Resources.LoadAssetAtPath("Assets/B3DInstanceTool/objects/" + attrc[j].Value + ".fbx", typeof(GameObject)) as GameObject; | |
clone = PrefabUtility.InstantiatePrefab(prefab) as GameObject; | |
} | |
if (attrc[j].Name == "POSITION"){ | |
string[] vals = attrc[j].Value.Split(delimiterChars); | |
Vector3 pos; | |
pos.x = float.Parse(vals[0]); | |
pos.y = float.Parse(vals[1]); | |
pos.z = float.Parse(vals[2]); | |
clone.transform.position = pos; | |
} | |
if (attrc[j].Name == "ROTATION"){ | |
string[] vals = attrc[j].Value.Split(delimiterChars); | |
float qX, qY, qZ, qW; | |
qW = float.Parse(vals[0]); | |
qX = float.Parse(vals[1]); | |
qY = float.Parse(vals[2])*-1f; | |
qZ = float.Parse(vals[3])*-1f; | |
clone.transform.rotation = new Quaternion(qX,qY,qZ,qW); | |
} | |
if (attrc[j].Name == "SCALE"){ | |
string[] vals = attrc[j].Value.Split(delimiterChars); | |
Vector3 scale; | |
scale.x = float.Parse(vals[0]); | |
scale.y = float.Parse(vals[1]); | |
scale.z = float.Parse(vals[2]); | |
clone.transform.localScale = scale; | |
} | |
} | |
clone.transform.parent = level.transform; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment