/// <summary> /// Creates a new prefab based on the currently selected primitive type. /// </summary> /// <param name="gridMapEditor">A reference to a grid map editor.</param> /// <returns>Returns a reference to the prefab that was created.</returns> public static GameObject CreatePrimitivePrefab(GridMapEditor gridMapEditor) { GameObject prefab = null; var gridMappingService = GridMappingService.Instance; // if current prefab is not null if (gridMappingService.CurrentPrefab != null) { prefab = GridMapping.Helpers.PerformInstantiation(gridMappingService.CurrentPrefab); } // set material if one specified & there is a mesh renderer & apply material is checked if (!gridMapEditor.SelectingCustomPrefab && gridMappingService.CurrentMaterial != null && prefab != null && prefab.renderer != null && gridMapEditor.ApplyMaterial) { // clear material references before assigning new material prefab.renderer.material = null; prefab.renderer.sharedMaterial = gridMappingService.CurrentMaterial; } return(prefab); }
/// <summary> /// Creates a new prefab based on the currently selected primitive type. /// </summary> /// <param name="gridMapEditor">A reference to a grid map editor.</param> /// <returns>Returns a reference to the prefab that was created.</returns> public static GameObject CreatePrimitivePrefab(GridMapEditor gridMapEditor) { GameObject prefab = null; var gridMappingService = GridMappingService.Instance; // if current prefab is not null if (gridMappingService.CurrentPrefab != null) { prefab = GridMapping.Helpers.PerformInstantiation(gridMappingService.CurrentPrefab); } // set material if one specified & there is a mesh renderer & apply material is checked if (!gridMapEditor.SelectingCustomPrefab && gridMappingService.CurrentMaterial != null && prefab != null && prefab.renderer != null && gridMapEditor.ApplyMaterial) { // clear material references before assigning new material prefab.renderer.material = null; prefab.renderer.sharedMaterial = gridMappingService.CurrentMaterial; } return prefab; }