public static void BuildObjects(CreateObjectModel[] objects) { ObjectsBuilderWindow window = GetWindow <ObjectsBuilderWindow>(true, "Building objects", true); window.minSize = new Vector2(350, 110); window.Show(); window.RunBuildObjects(objects); }
public static void BuildOnlyZip(VarwinObjectDescriptor varwinObj) { ObjectsBuilderWindow window = GetWindow <ObjectsBuilderWindow>(true, "Building VWO for " + varwinObj.Name, true); window.minSize = new Vector2(350, 110); window.Show(); window.BuildOnlyZip(new ObjectBuildDescription(varwinObj)); }
public static void BuildVarwinObject(VarwinObjectDescriptor varwinObj) { ObjectsBuilderWindow window = GetWindow <ObjectsBuilderWindow>(true, "Building object: " + varwinObj.Name, true); window.minSize = new Vector2(350, 110); window.Show(); window.RunBuildVarwinObject(varwinObj); }
public static void BuildAll() { if (!EditorUtility.DisplayDialog("Confirm Build All Objects", "Building all objects might take some time, do you want to proceed?", "Yes", "Cancel")) { return; } ObjectsBuilderWindow window = GetWindow <ObjectsBuilderWindow>(true, "Building all objects", true); window.minSize = new Vector2(350, 110); window.Show(); window.RunBuildAllObjects(); }
private static void OnScriptsReloaded() { try { GetWindow <ImportModelsWindow>().Close(); int createdNum = 0; if (File.Exists(CreateObjectTempModel.TempFilePath)) { string config = File.ReadAllText(CreateObjectTempModel.TempFilePath); CreateObjectTempModel temp = JsonConvert.DeserializeObject <CreateObjectTempModel>(config); File.Delete(CreateObjectTempModel.TempFilePath); if (temp == null) { Debug.LogError("Temp build file is broken! Can't finish objects creation."); return; } _modelsList = temp.Objects; _buildNow = temp.BuildNow; foreach (CreateObjectModel fileModel in _modelsList) { Debug.Log("Creating prefab for " + fileModel.ObjectName); GameObject gameObject, prefab; //Check if it's model import if (fileModel.ModelImportPath != null) { if (fileModel.Skip) { continue; } GameObject modelPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(fileModel.ModelImportPath); if (modelPrefab == null) { Debug.LogError("Can't create object " + fileModel.ObjectName + ". Imported file is incorrect: " + fileModel.Path); Directory.Delete(fileModel.ObjectFolder, true); continue; } gameObject = Instantiate(modelPrefab, new Vector3(0, 0, 0), Quaternion.identity); //Calculate bounds Bounds bounds = GetBounds(gameObject); float maxBound = Mathf.Max(bounds.size.x, bounds.size.y, bounds.size.z); float scale = fileModel.BiggestSideSize / maxBound; gameObject.transform.localScale = Vector3.one * scale; Rigidbody objectBody = gameObject.AddComponent <Rigidbody>(); objectBody.isKinematic = !fileModel.IsPhysicsOn; objectBody.mass = fileModel.Mass; InteractableObjectBehaviour objectBehaviour = gameObject.AddComponent <InteractableObjectBehaviour>(); objectBehaviour.SetIsGrabbable(fileModel.IsGrabbable); objectBehaviour.SetIsUsable(false); objectBehaviour.SetIsTouchable(false); CreateObjectUtils.AddObjectId(gameObject); MeshFilter[] meshes = gameObject.GetComponentsInChildren <MeshFilter>(); foreach (MeshFilter meshFilter in meshes) { MeshCollider collider = meshFilter.gameObject.AddComponent <MeshCollider>(); collider.sharedMesh = meshFilter.sharedMesh; collider.convex = true; } if (meshes == null || meshes.Length == 0) { BoxCollider box = gameObject.AddComponent <BoxCollider>(); box.center = bounds.center; box.size = bounds.size; } prefab = CreatePrefab(gameObject, fileModel.PrefabPath, fileModel.Guid, fileModel.ObjectName, fileModel.ClassName, fileModel.Extras); } else { gameObject = AssetDatabase.LoadAssetAtPath <GameObject>(fileModel.PrefabPath); if (gameObject == null) { Debug.LogError("Can't create " + fileModel.ObjectName + ": no prefab and no model. How did it happen? Please try again."); return; } CreateNew(gameObject, fileModel.PrefabPath, fileModel.Guid, fileModel.ObjectName, fileModel.ClassName, fileModel.Extras, true, true); } AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); if (fileModel.ModelImportPath != null) { DestroyImmediate(gameObject); } createdNum++; gameObject = AssetDatabase.LoadAssetAtPath <GameObject>(fileModel.PrefabPath); var instance = PrefabUtility.InstantiatePrefab(gameObject); instance.name = instance.name.Replace("(Clone)", ""); EditorGUIUtility.PingObject(instance); } EditorUtility.DisplayDialog("Done!", createdNum + " objects were created!", "OK"); if (temp.BuildNow) { ObjectsBuilderWindow.BuildObjects(_modelsList.ToArray()); } GetWindow <CreateObjectWindow>().Close(); } } catch (Exception e) { EditorUtility.DisplayDialog("Error!", $"{e.Message}:\nProblem when creating an objects", "OK"); Debug.LogException(e); } }