Unityでのゲーム開発において、デザインアセットの制作・管理・最適化は、プロダクション全体のパフォーマンスと開発スピードを左右する重要なプロセスです。しかし、3Dモデルのインポート、シェーダーの調整、テクスチャ管理、アセットバンドルの構築といった複数のタスクを手動で行うことは、時間がかかり、ヒューマンエラーも発生しやすい課題です。
Antigravity IDE を活用することで、これらのワークフロー全体を AI の力で自動化・最適化できます。ここで整理するのはAntigravity が提供する高度な開発支援機能を用いて、Unity プロジェクトのデザインアセット制作を効率化する実践的な方法を、段階を追って解説します。
Antigravity IDE による Unity ワークフロー革新
Antigravity IDE は、単なるコード補完ツールではなく、AI エージェントとして複雑なタスクを自動化できる Google の次世代開発環境です。Unity プロジェクトでの活用によって、以下のような価値が実現します:
シェーダー・マテリアルスクリプトの自動生成 : HLSL や ShaderLab コードを AI が記述
3D モデルパイプラインの自動化 : FBX/glTF インポート、LOD 自動生成、メッシュ最適化
テクスチャアセット管理の効率化 : アトラスパッキング、解像度最適化、スプライトシート生成
アセットバンドルビルド の CI/CD 統合 : バージョン管理と自動デプロイメント
これにより、エンジニアは単純作業から解放され、クリエイティブな判断と品質保証に注力できるようになります。
Antigravity で Unity プロジェクトをセットアップする
プロジェクト設定とアンチグラビティ設定ファイル
Antigravity で Unity プロジェクトを効率的に開発するには、プロジェクトルートに .antigravity 設定ファイルを配置し、Unity 環境への理解を深める必要があります。
以下は、Unity ゲーム開発向けの推奨設定です:
# プロジェクトルートの .antigravity ファイル
version : "2.0"
project-type : "unity-game"
sdk-version : "2022.3-LTS"
contexts :
- name : "unity-editor"
path : "Assets/"
language : "csharp"
features :
- shader-generation
- asset-automation
- ci-cd-integration
- name : "build-pipeline"
path : "BuildScripts/"
language : "csharp"
features :
- asset-bundle-management
- version-control
- size-optimization
rules :
- ignore : [ "Library/" , "Logs/" , "Temp/" , "UserSettings/" ]
- preserve-structure : true
- auto-format : "csharp"
agents :
shader-agent :
role : "シェーダーとマテリアルスクリプト生成"
capabilities : [ "hlsl" , "shaderlab" , "material-properties" ]
asset-agent :
role : "3D モデルとテクスチャ処理"
capabilities : [ "fbx-processing" , "lod-generation" , "mesh-optimization" ]
bundle-agent :
role : "アセットバンドルビルドと最適化"
capabilities : [ "bundle-packing" , "compression" , "version-management" ]
この設定により、Antigravity は Unity プロジェクト構造を理解し、適切なコンテキストで AI エージェントを活動させられます。
C# インテリセンスと型定義の統合
Antigravity の IntelliSense を Unity C# 開発で最大限活用するには、Unity のアセンブリ定義ファイル (.asmdef) と型情報をプリロードします:
// Assets/Plugins/AntigravityUnityBridge.cs
using UnityEngine ;
using UnityEngine . Rendering ;
/// < summary >
/// Antigravity エージェントが参照する Unity 型ブリッジ
/// IntelliSense と型チェックを強化
/// </ summary >
public static class AntigravityUnityBridge
{
// シェーダー・マテリアル関連
public static class ShaderAPI
{
public static Material CreateMaterialFromProperties (
string shaderName ,
ShaderPropertyInfo [] properties ) => null ;
}
// 3D モデル処理関連
public static class ModelAPI
{
public static void GenerateLOD (
Mesh originalMesh ,
float [] lodScreenHeights ) { }
}
// アセットバンドル関連
public static class BundleAPI
{
public static void BuildAssetBundles (
string outputPath ,
BuildAssetBundleOptions options ) { }
}
}
public class ShaderPropertyInfo
{
public string name ;
public string type ;
public float defaultValue ;
}
このブリッジにより、Antigravity は Unity の標準 API を完全に理解し、より正確で実行可能なコードを生成できるようになります。
AI 支援シェーダーとマテリアルスクリプト生成
Antigravity エージェントでシェーダーコードを作成
Unity のゲーム開発では、カスタムシェーダーはビジュアル品質を大きく左右します。Antigravity を使用すれば、複雑な HLSL や ShaderLab コードを AI エージェントが自動生成できます。
// Antigravity エージェント:shader-agent への指示プロンプト例
/*
Task: Generate a PBR (Physically Based Rendering) shader for Unity
Requirements:
- Support albedo, normal, roughness, metallic textures
- Implement specular highlights and environmental reflection
- Optimize for mobile (minimize texture samples)
- Include forward rendering path
- Support up to 4 directional lights
Output: Write to Assets/Shaders/PBRMobile.shader
Language: ShaderLab with HLSL
*/
生成されたシェーダーの例:
Shader "Custom/PBRMobile"
{
Properties
{
_MainTex ( "Albedo" , 2D) = "white" {}
_NormalMap ( "Normal Map" , 2D) = "bump" {}
_RoughnessMap ( "Roughness" , 2D) = "white" {}
_MetallicMap ( "Metallic" , 2D) = "black" {}
_Roughness ( "Roughness Override" , Range ( 0 , 1 )) = 0.5
_Metallic ( "Metallic Override" , Range ( 0 , 1 )) = 0.0
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }
LOD 200
Pass
{
Name "ForwardLit"
Tags { "LightMode" = "UniversalForward" }
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _ADDITIONAL_LIGHTS
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
// テクスチャとサンプラー
TEXTURE2D (_MainTex);
SAMPLER (sampler_MainTex);
TEXTURE2D (_NormalMap);
SAMPLER (sampler_NormalMap);
// プロパティ
CBUFFER_START (UnityPerMaterial)
float4 _MainTex_ST;
float _Roughness;
float _Metallic;
CBUFFER_END
struct Attributes
{
float4 positionOS : POSITION ;
float3 normalOS : NORMAL ;
float4 tangentOS : TANGENT ;
float2 uv : TEXCOORD0 ;
};
struct Varyings
{
float4 positionCS : SV_POSITION ;
float3 positionWS : TEXCOORD0 ;
float3 normalWS : TEXCOORD1 ;
float3 tangentWS : TEXCOORD2 ;
float3 bitangentWS : TEXCOORD3 ;
float2 uv : TEXCOORD4 ;
};
Varyings vert (Attributes input)
{
Varyings output = (Varyings) 0 ;
output.positionWS = TransformObjectToWorld (input.positionOS.xyz);
output.positionCS = TransformWorldToHClip (output.positionWS);
output.normalWS = TransformObjectToWorldNormal (input.normalOS);
output.tangentWS = TransformObjectToWorldDir (input.tangentOS.xyz);
output.bitangentWS = cross (output.normalWS, output.tangentWS) * input.tangentOS.w;
output.uv = TRANSFORM_TEX (input.uv, _MainTex);
return output;
}
float4 frag (Varyings input) : SV_Target
{
// アルベド読み込み
float4 albedo = SAMPLE_TEXTURE2D (_MainTex, sampler_MainTex, input.uv);
// ノーマルマップ読み込みと展開
float3 normalTS = UnpackNormal (
SAMPLE_TEXTURE2D (_NormalMap, sampler_NormalMap, input.uv)
);
float3x3 TBN = float3x3 (
input.tangentWS,
input.bitangentWS,
input.normalWS
);
float3 normalWS = normalize ( mul (normalTS, TBN));
// ライト計算(簡略版 - モバイル向け最適化)
float3 lightColor = _MainLightColor.rgb;
float3 lightDir = _MainLightPosition.xyz;
float lightAtten = MainLightRealtimeShadow (
TransformWorldToShadowCoord (input.positionWS)
);
float ndotl = max ( 0.0 , dot (normalWS, lightDir));
float3 diffuse = albedo.rgb * lightColor * ndotl * lightAtten;
return float4 (diffuse, albedo.a);
}
ENDHLSL
}
}
FallBack "Universal Render Pipeline/Lit"
}
実行結果例:
生成されたシェーダーは URP (Universal Render Pipeline) 対応
モバイル環境を想定した最適化済み
メインライトとシャドウ対応
マテリアルプロパティスクリプトの自動生成
シェーダーの生成と並行して、マテリアルのプロパティを C# スクリプトで管理するコードもエージェントが生成できます:
// Antigravity が生成した MaterialPropertyController.cs
using UnityEngine ;
[ RequireComponent ( typeof ( Renderer ))]
public class MaterialPropertyController : MonoBehaviour
{
[ SerializeField ] private Material material ;
// PBR プロパティ
[ Range ( 0f , 1f )] public float roughness = 0.5f ;
[ Range ( 0f , 1f )] public float metallic = 0f ;
private static readonly int RoughnessID = Shader. PropertyToID ( "_Roughness" );
private static readonly int MetallicID = Shader. PropertyToID ( "_Metallic" );
private void OnValidate ()
{
if (material == null )
material = GetComponent < Renderer >().material;
// インスペクタで値を変更するたびに即座にマテリアルに反映
UpdateMaterialProperties ();
}
public void UpdateMaterialProperties ()
{
if (material == null ) return ;
material. SetFloat (RoughnessID, roughness);
material. SetFloat (MetallicID, metallic);
}
// ランタイムでの動的変更
public void SetRoughness ( float value )
{
roughness = Mathf. Clamp01 (value);
material. SetFloat (RoughnessID, roughness);
}
public void SetMetallic ( float value )
{
metallic = Mathf. Clamp01 (value);
material. SetFloat (MetallicID, metallic);
}
}
3D モデルインポートパイプラインの自動化
FBX/glTF 処理スクリプトの自動生成
Antigravity は、複数の 3D モデルを一括処理するスクリプトを自動生成でき、LOD (Level of Detail) やメッシュ最適化を統一的に適用できます。
// Antigravity が生成した ModelImportPipeline.cs
using UnityEngine ;
using UnityEditor ;
using UnityEditor . AssetImporters ;
using System . Collections . Generic ;
public class ModelImportPipeline : AssetPostprocessor
{
void OnPreprocessModel ()
{
// FBX インポート設定の自動化
ModelImporter importer = assetImporter as ModelImporter ;
// インポート最適化
importer.meshCompression = ModelImporterMeshCompression.High;
importer.isReadable = false ; // ランタイムアクセスが不要な場合
importer.optimizeMeshPolygons = true ;
importer.optimizeMeshVertices = true ;
// ボーンウェイト設定(スキンメッシュ用)
importer.maxBoneWeights = 4 ;
importer.skinWeights = ModelImporterSkinWeights.Max4Bones;
// 法線と接線の自動生成
importer.importNormals = ModelImporterNormals.Import;
importer.importTangents = ModelImporterTangents.Import;
// アニメーション設定
importer.importAnimation = true ;
importer.animationType = ModelImporterAnimationType.Generic;
}
void OnPostprocessModel ( GameObject g )
{
// インポート後のメッシュ最適化処理
ProcessMeshes (g.transform);
}
private void ProcessMeshes ( Transform root )
{
foreach ( var meshFilter in root. GetComponentsInChildren < MeshFilter >())
{
Mesh mesh = meshFilter.sharedMesh;
if (mesh == null ) continue ;
// 頂点色の自動最適化
OptimizeMeshVertexColors (mesh);
// バウンディングボックス再計算
mesh. RecalculateBounds ();
}
}
private void OptimizeMeshVertexColors ( Mesh mesh )
{
// 不要な頂点属性を削除し、メモリ削減
var attributes = mesh. GetVertexAttributes ();
// 処理ロジック...
}
}
LOD (Level of Detail) 自動生成
複雑な 3D モデルに対して、自動的に複数の LOD レベルを生成することで、パフォーマンスを維持しながら視覚品質を保ちます:
// Antigravity が生成した LODGenerator.cs
using UnityEngine ;
public class LODGenerator : MonoBehaviour
{
[ SerializeField ] private Mesh originalMesh ;
[ SerializeField ] private float [] lodScreenHeights = { 0.5f , 0.25f , 0.1f };
public void GenerateLODs ()
{
LODGroup lodGroup = gameObject. AddComponent < LODGroup >();
LOD [] lods = new LOD [lodScreenHeights.Length];
for ( int i = 0 ; i < lodScreenHeights.Length; i ++ )
{
// 各 LOD レベルのメッシュを生成
Mesh lodMesh = GenerateSimplifiedMesh (originalMesh, GetReductionRatio (i));
var meshFilter = gameObject. AddComponent < MeshFilter >();
meshFilter.mesh = lodMesh;
var renderer = gameObject. AddComponent < MeshRenderer >();
lods[i] = new LOD (lodScreenHeights[i], new Renderer [] { renderer });
}
lodGroup. SetLODs (lods);
}
private Mesh GenerateSimplifiedMesh ( Mesh original , float reductionRatio )
{
// QuadricMeshSimplifier など外部ライブラリを使用して
// ポリゴン削減をシミュレート
Mesh simplified = new Mesh ();
// 実装の詳細...
// 頂点と三角形をreductionRatioに基づいて削減
return simplified;
}
private float GetReductionRatio ( int lodLevel )
{
// LOD レベルごとにポリゴン削減率を決定
// LOD 0: 元のメッシュ
// LOD 1: 50% 削減
// LOD 2: 75% 削減
return Mathf. Pow ( 0.5f , lodLevel);
}
}
テクスチャアトラスとスプライトシート管理
アトラスパッキング自動化スクリプト
複数のテクスチャを効率的に 1 枚のアトラスにパッキングすることで、ドローコールを削減できます:
// Antigravity が生成した TextureAtlasPacker.cs
using UnityEngine ;
using System . Collections . Generic ;
public class TextureAtlasPacker : MonoBehaviour
{
[ System . Serializable ]
public class AtlasConfig
{
public int atlasWidth = 2048 ;
public int atlasHeight = 2048 ;
public TextureFormat format = TextureFormat.RGBA32;
public FilterMode filterMode = FilterMode.Bilinear;
}
public void PackTexturesIntoAtlas (
List < Texture2D > sourceTextures ,
AtlasConfig config ,
string outputPath )
{
// テクスチャをサイズでソート(大きい順)
sourceTextures. Sort (( a , b ) =>
(b.width * b.height). CompareTo (a.width * a.height)
);
Texture2D atlas = new Texture2D (
config.atlasWidth,
config.atlasHeight,
config.format,
false
);
Dictionary < Texture2D , Rect > uvMap = new Dictionary < Texture2D , Rect >();
int currentX = 0 , currentY = 0 , rowHeight = 0 ;
// シンプルな矩形パッキングアルゴリズム
foreach ( var texture in sourceTextures)
{
if (currentX + texture.width > config.atlasWidth)
{
currentX = 0 ;
currentY += rowHeight;
rowHeight = 0 ;
}
if (currentY + texture.height > config.atlasHeight)
{
Debug. LogError ( "アトラスが満杯です。より大きなサイズで再試行してください。" );
return ;
}
// テクスチャをアトラスにコピー
Graphics. CopyTexture (
texture, 0 , 0 , 0 , 0 ,
texture.width, texture.height,
atlas, 0 , 0 , currentX, currentY
);
// UV マップを記録
Rect uvRect = new Rect (
( float )currentX / config.atlasWidth,
( float )currentY / config.atlasHeight,
( float )texture.width / config.atlasWidth,
( float )texture.height / config.atlasHeight
);
uvMap[texture] = uvRect;
currentX += texture.width;
rowHeight = Mathf. Max (rowHeight, texture.height);
}
// アトラスをファイルに保存
byte [] atlasBytes = atlas. EncodeToPNG ();
System.IO.File. WriteAllBytes (outputPath, atlasBytes);
Debug. Log ( $"アトラス生成完了: { outputPath } " );
}
// 元のテクスチャから UV マップを取得
public Rect GetUVRect ( Texture2D originalTexture )
{
// uvMap から取得...
return new Rect ();
}
}
解像度最適化とスプライトシート生成
異なる画面密度に対応するため、複数解像度のテクスチャを自動生成します:
// Antigravity が生成した ResolutionOptimizer.cs
using UnityEngine ;
public class ResolutionOptimizer : MonoBehaviour
{
public class ResolutionTier
{
public int width ;
public int height ;
public TextureFormat format ;
public int maxSize ;
}
private static readonly ResolutionTier [] Tiers = new []
{
new ResolutionTier { width = 4096 , height = 4096 , format = TextureFormat.RGBA32, maxSize = 4096 },
new ResolutionTier { width = 2048 , height = 2048 , format = TextureFormat.RGBA32, maxSize = 2048 },
new ResolutionTier { width = 1024 , height = 1024 , format = TextureFormat.RGB24, maxSize = 1024 },
new ResolutionTier { width = 512 , height = 512 , format = TextureFormat.RGB24, maxSize = 512 },
};
public void OptimizeTextureForPlatform (
Texture2D sourceTexture ,
RuntimePlatform targetPlatform )
{
ResolutionTier tier = SelectTierForPlatform (targetPlatform);
// テクスチャを目標サイズにリサイズ
TextureScale. Scale (sourceTexture, tier.width, tier.height);
// インポート設定を更新
// 実装詳細...
}
private ResolutionTier SelectTierForPlatform ( RuntimePlatform platform )
{
return platform switch
{
RuntimePlatform . Android => Tiers[ 2 ], // 1024x1024
RuntimePlatform . IPhonePlayer => Tiers[ 3 ], // 512x512
_ => Tiers[ 1 ] // デフォルト 2048x2048
};
}
}
アセットバンドルビルド自動化と CI/CD 統合
アセットバンドル構築スクリプト
Antigravity は複雑なアセットバンドル構築パイプラインを自動化できます:
// Antigravity が生成した AssetBundleBuilder.cs
using UnityEditor ;
using UnityEngine ;
using System . Collections . Generic ;
public class AssetBundleBuilder
{
[ System . Serializable ]
public class BundleConfig
{
public string bundleName ;
public string [] assetPaths ;
public BuildAssetBundleOptions options ;
public string [] dependencies ; // 依存する他のバンドル
}
public static void BuildAssetBundles (
List < BundleConfig > configs ,
string outputDirectory ,
BuildTarget buildTarget )
{
// AssetBundle 名を設定
foreach ( var config in configs)
{
foreach ( var assetPath in config.assetPaths)
{
var importer = AssetImporter. GetAtPath (assetPath);
importer.assetBundleName = config.bundleName;
}
}
// バンドルをビルド
var manifest = BuildPipeline. BuildAssetBundles (
outputDirectory,
BuildAssetBundleOptions.ChunkBasedCompression |
BuildAssetBundleOptions.StrictMode,
buildTarget
);
if (manifest == null )
{
Debug. LogError ( "AssetBundle ビルド失敗" );
return ;
}
// バージョン情報を記録
LogBuildInfo (manifest, configs, outputDirectory);
}
private static void LogBuildInfo (
AssetBundleManifest manifest ,
List < BundleConfig > configs ,
string outputPath )
{
var bundleNames = manifest. GetAllAssetBundles ();
foreach ( var bundleName in bundleNames)
{
var hash = manifest. GetAssetBundleHash (bundleName);
var crc = manifest. GetAssetBundleCrc (bundleName);
var deps = manifest. GetAllDependencies (bundleName);
Debug. Log ( $"Bundle: { bundleName } " );
Debug. Log ( $" Hash: { hash } " );
Debug. Log ( $" CRC: { crc } " );
Debug. Log ( $" Dependencies: { string . Join ( ", " , deps )} " );
}
}
}
CI/CD パイプラインへの統合
GitHub Actions や Jenkins などの CI/CD システムと統合し、自動ビルドと配布を実現:
# Antigravity が生成した .github/workflows/build-asset-bundles.yml
name : Build Asset Bundles
on :
push :
branches :
- main
pull_request :
branches :
- main
jobs :
build :
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@v3
- name : Set up Unity
uses : game-ci/unity-builder@v3
with :
unityVersion : 2022.3.0f1
- name : Build Asset Bundles
run : |
/opt/Unity/Editor/Unity -projectPath . \
-executeMethod AssetBundleBuilder.BuildAssetBundles \
-outputPath ./AssetBundles \
-buildTarget StandaloneLinux64 \
-batchmode -nographics -quit
- name : Compress Bundles
run : |
cd AssetBundles
tar -czf asset-bundles-${{ github.sha }}.tar.gz *.bundle
ls -lh asset-bundles-*.tar.gz
- name : Upload to Storage
run : |
# クラウドストレージ(Google Cloud Storage など)にアップロード
gsutil cp asset-bundles-*.tar.gz \
gs://your-bucket/releases/${{ github.ref }}/
- name : Generate Version Info
run : |
echo "Build: ${{ github.sha }}" > version.json
echo "Date: $(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> version.json
cat version.json
個人開発者の視点から(実体験メモ)
ここまでの要点
Antigravity IDE を活用することで、Unity でのデザインアセット制作ワークフローが大きく変わります。シェーダー・マテリアル、3D モデル処理、テクスチャ管理、アセットバンドル構築といった複雑で反復的なタスクが自動化されることで、エンジニアはより高度な問題解決やクリエイティブな判断に注力できるようになります。
本ガイドで紹介したワークフロー(.antigravity 設定の整備、エージェントの活用、CI/CD 統合)を参考に、自身のプロジェクトに段階的に導入することで、開発スピード向上と品質保証の両立が実現できます。Antigravity のポテンシャルを最大限活用し、次世代のゲーム開発を加速させましょう。