void MakeTemplateChildOfPallette(VoxelPallette targetPallette, VoxelTemplate voxelTemplate) { AssetDatabase.AddObjectToAsset(voxelTemplate, targetPallette); voxelTemplate.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(voxelTemplate)); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(targetPallette)); }
VoxelTemplate CopyVoxelTemplate(VoxelPallette voxelPallette, VoxelTemplate original) { VoxelTemplate newVoxelTemplate = ScriptableObject.CreateInstance <VoxelTemplate>(); newVoxelTemplate.shouldDraw = original.shouldDraw; newVoxelTemplate.name = original.name; newVoxelTemplate.atlasScale = original.atlasScale; newVoxelTemplate.voxelPallette = voxelPallette; newVoxelTemplate.drawFacesInCenter = original.drawFacesInCenter; newVoxelTemplate.color = original.color; newVoxelTemplate.UVOffsetFront = original.UVOffsetFront; newVoxelTemplate.UVOffsetBack = original.UVOffsetBack; newVoxelTemplate.UVOffsetTop = original.UVOffsetTop; newVoxelTemplate.UVOffsetBottom = original.UVOffsetBottom; newVoxelTemplate.UVOffsetLeft = original.UVOffsetLeft; newVoxelTemplate.UVOffsetRight = original.UVOffsetRight; newVoxelTemplate.SpriteFront = original.SpriteFront; newVoxelTemplate.SpriteBack = original.SpriteBack; newVoxelTemplate.SpriteTop = original.SpriteTop; newVoxelTemplate.SpriteBottom = original.SpriteBottom; newVoxelTemplate.SpriteLeft = original.SpriteLeft; newVoxelTemplate.SpriteRight = original.SpriteRight; newVoxelTemplate.drawFront = original.drawFront; newVoxelTemplate.drawBack = original.drawBack; newVoxelTemplate.drawLeft = original.drawLeft; newVoxelTemplate.drawRight = original.drawRight; newVoxelTemplate.drawTop = original.drawTop; newVoxelTemplate.drawBottom = original.drawBottom; MakeTemplateChildOfPallette(voxelPallette, newVoxelTemplate); newVoxelTemplate.GenerateAssetPreview(); EditorUtility.SetDirty(newVoxelTemplate); return(newVoxelTemplate); }
void AddNewVoxelTemplate(VoxelPallette voxelPallette, Sprite sprite) { VoxelTemplate newVoxelTemplate = ScriptableObject.CreateInstance <VoxelTemplate>(); newVoxelTemplate.shouldDraw = true; newVoxelTemplate.name = sprite.name; newVoxelTemplate.atlasScale = new Vector2(sprite.rect.width / voxelPallette.AtlasMaterial.mainTexture.width, sprite.rect.height / voxelPallette.AtlasMaterial.mainTexture.height); newVoxelTemplate.voxelPallette = voxelPallette; newVoxelTemplate.SpriteFront = sprite; newVoxelTemplate.SpriteBack = sprite; newVoxelTemplate.SpriteLeft = sprite; newVoxelTemplate.SpriteRight = sprite; newVoxelTemplate.SpriteTop = sprite; newVoxelTemplate.SpriteBottom = sprite; var offset = new Vector2(sprite.rect.x / voxelPallette.AtlasMaterial.mainTexture.width, sprite.rect.y / voxelPallette.AtlasMaterial.mainTexture.height); newVoxelTemplate.UVOffsetFront = offset; newVoxelTemplate.UVOffsetBack = offset; newVoxelTemplate.UVOffsetTop = offset; newVoxelTemplate.UVOffsetBottom = offset; newVoxelTemplate.UVOffsetLeft = offset; newVoxelTemplate.UVOffsetRight = offset; AssetDatabase.AddObjectToAsset(newVoxelTemplate, voxelPallette); voxelPallette.voxelTemplateList.Add(newVoxelTemplate); newVoxelTemplate.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newVoxelTemplate)); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(voxelPallette)); newVoxelTemplate.GenerateAssetPreview(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newVoxelTemplate)); EditorUtility.SetDirty(newVoxelTemplate); }
void AddNewVoxelTemplate(VoxelPallette voxelPallette) { VoxelTemplate newVoxelTemplate = ScriptableObject.CreateInstance <VoxelTemplate>(); newVoxelTemplate.shouldDraw = true; newVoxelTemplate.name = "New Voxel Template"; newVoxelTemplate.voxelPallette = voxelPallette; newVoxelTemplate.DisplayOrder = voxelPallette.voxelTemplatesSorted.Count(); AssetDatabase.AddObjectToAsset(newVoxelTemplate, voxelPallette); voxelPallette.voxelTemplateList.Add(newVoxelTemplate); newVoxelTemplate.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newVoxelTemplate)); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(voxelPallette)); newVoxelTemplate.GenerateAssetPreview(); EditorUtility.SetDirty(newVoxelTemplate); }