/// <summary> /// Handles post process on all assets within Unity Editor. Finds all meshes and creates /// a Unity prefab allowing easy instation at runtime. For more information about this Unity /// Message Handle: http://docs.unity3d.com/ScriptReference/AssetPostprocessor.OnPostprocessAllAssets.html /// </summary> /// <param name="importedAssets">List of paths to assets that have been imported</param> /// <param name="deletedAssets">List of paths to assets that have been deleted</param> /// <param name="movedAssets">List of paths to assets that have been moved</param> /// <param name="movedFromAssetPaths">List of paths to assets that have been moved from paths</param> static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { if (importedAssets.Length > 0) { FileType type = FileType.UNKNOWN; foreach (string assetPath in importedAssets) { string filename = FileManagerImpl.GetFileName(assetPath, false); type = FileManagerImpl.GetFileType(assetPath); UnityEngine.Object asset = AssetDatabase.LoadMainAssetAtPath(assetPath); // Creating prefab here will cause this function to be invoked again causing an infinite loop of // assets being generated. Proper Check of the Object is of type GameObject, isn't part of a prefab // and that the asset is a proper model that can become a prefab. if (asset.GetType() == typeof(GameObject) && PrefabUtility.GetPrefabParent(asset) == null && PrefabUtility.GetPrefabType(asset) == PrefabType.ModelPrefab) { // To properly create a prefab of the object we need to instantiate it into // the game world and save that object as a prefab. GameObject go = GameObject.Instantiate <GameObject>((GameObject)asset); go.name = asset.name; // remove the (clone) within the name. PrefabUtility.CreatePrefab(string.Format(prefabItemPathFormat, go.name), go); GameObject.DestroyImmediate(go); } else if (type == FileType.URDF || type == FileType.XACRO) { string prefabName = CreateUrdfRobot(assetPath); if (!String.IsNullOrEmpty(prefabName)) { UrdfItemModel item = new UrdfItemModel(); item.name = filename; item.urdfFilename = assetPath; item.prefabFilename = prefabName; item.visibility = 1; UrdfDb db = new UrdfDb(); db.AddSensor(item); } } } } }
/// <summary> /// This save function, grabs all the inputs and preforms the appropriate /// action according to the state it ccurrently is in. /// </summary> public void SaveForm_click() { UrdfItemModel item = null; Sensor sensor = null; if (this.currSelectedSensor != null) { sensor = this.currSelectedSensor.GetComponent <Sensor>(); } if (sensor != null) { item = sensor.item; } else { item = new UrdfItemModel(); } item.name = this.inputs["txtName"].text; item.modelNumber = this.inputs["txtModel"].text; item.notes = this.inputs["txtNotes"].text; item.prefabFilename = this.inputs["txtPrefabPath"].text; item.fk_category_id = this.dropdowns["ddCategory"].value; item.fk_type_id = this.dropdowns["ddTypes"].value; item.visibility = (this.toggles["toggleVisibility"].isOn ? 1 : 0); if (!float.TryParse(this.inputs["txtInternalCost"].text, out item.internalCost)) { Debug.Log("[internalCost] Invalid float detected. Did you change the context type?"); } if (!float.TryParse(this.inputs["txtExternalCost"].text, out item.externalCost)) { Debug.Log("[externalCost] Invalid float detected. Did you change the context type?"); } if (!float.TryParse(this.inputs["txtPower"].text, out item.powerUsage)) { Debug.Log("[power] Invalid float detected. Did you change the context type?"); } if (!float.TryParse(this.inputs["txtWeight"].text, out item.weight)) { Debug.Log("[weight] Invalid float detected. Did you change the context type?"); } if (!float.TryParse(this.inputs["txtTime"].text, out item.time)) { Debug.Log("[time] Invalid float detected. Did you change the context type?"); } switch (currState) { case UIState.Create: urdf.AddSensor(item); break; case UIState.Delete: urdf.DeleteSensor(item); GameObject.Destroy(this.currSelectedSensor); GameObject.Destroy(this.currSelectedSensorGoModel); SetUiState(UIState.Create); clearForm(); break; case UIState.Update: urdf.UpdateSensor(item); this.currSelectedSensor.GetComponent <Sensor>().item = item; UpdateVisuals(item); break; } }