// Creates an asset for a given file GameObject createFileShapeAsset(string fullFileName, string identifier) { string[] pathLst = fullFileName.Split(new string[] { "/" }, StringSplitOptions.None); string fileName = pathLst[pathLst.Length - 1]; pathLst = fileName.Split(new string[] { "." }, StringSplitOptions.None); string fileNameNoEnding = pathLst[0]; Debug.Log("TYPE FILENAME " + fileName + " fileNameNoEnding " + fileNameNoEnding); string destPath = "Assets/Resources/" + fileName; if (!System.IO.Directory.Exists("Assets/Resources"))// dir doesn't exists { System.IO.Directory.CreateDirectory("Assets/Resources"); } if (!System.IO.File.Exists(destPath))//file does not exist { FileUtil.CopyFileOrDirectory(fullFileName, destPath); } else { //FileUtil.ReplaceFile(fullFileName, destPath); } AssetDatabase.ImportAsset(destPath); UnityEngine.Object prefab = Resources.Load(fileNameNoEnding); if (GameObject.Find(identifier) != null) //it does exist { Debug.Log("There is already a GameObject named " + fileNameNoEnding); DestroyImmediate(GameObject.Find(identifier)); } GameObject go = (GameObject)Instantiate(prefab, new Vector3(0, 0, 0), Quaternion.identity); go.name = identifier; FMUshapeBehaviour script = go.AddComponent <FMUshapeBehaviour>(); script.meshID = makeFirstCharUpperCase(fileNameNoEnding); //go.transform.rotation = Quaternion.AngleAxis(180,new Vector3(0,1,0)); return(go); }
void FixedUpdate() { //Debug.Log("Time " + (Time.time/speedUP)); simulateToTime(simulator, (Time.time / speedUP)); //simulateToTime(simulator, 0); float val; for (int i = 0; i < fmuVarRefs.Count; i++) { val = getRealValueForVarRef(simulator, fmuVarRefs[i]); //Debug.Log("get "+val.ToString()+" for var reference " + fmuVarRefs[i].ToString()); FMUshapeBehaviour shapeGO = GameObject.Find(goIDs[i]).GetComponent <FMUshapeBehaviour>(); shapeGO.setVarAttribute(attrIDs[i], val); } for (int i = 0; i < allFMUShapes.Count; i++) { FMUshapeBehaviour shapeGO = GameObject.Find(allFMUShapes[i]).GetComponent <FMUshapeBehaviour>(); shapeGO.updateShapes(); } }
void analyseShapeAttribute(GameObject shapeGO, XmlNode nodeIn, string shapeName, int attr) { // the vraiables attributes have to be put in the simulator FMU_Simulation fmuSim = simulatorGO.GetComponent <FMU_Simulation>(); // the constant attributes have to go in the gameObject directly FMUshapeBehaviour fmuShape = shapeGO.GetComponent <FMUshapeBehaviour>(); if (nodeIn.Name == "exp") { float val = Single.Parse(nodeIn.InnerText); //Debug.Log("constant exp "+attr.ToString()+" VAL: "+val.ToString()); fmuShape.setVarAttribute(attr, val); } else if (nodeIn.Name == "cref") { fmuSim.goIDs.Add(shapeName); fmuSim.attrIDs.Add(attr); fmuSim.varNames.Add(nodeIn.InnerText); //FMU_Simulation.varAttr v = new FMU_Simulation.varAttr(shapeName,attr, nodeIn.InnerText, -1); //Debug.Log("THE VARATTR " + v1.debugString()); } }