
æ å ±æº
ããã«ããšã³ãžã³ã«ãŸã£ãã粟éããŠããªã人ããŸãã¯ãšã³ãžã³ãç¥ãå§ããã°ããã®äººã®ããã«ã Unity3dã®æçšãªæ å ±æºã«ã€ããŠæžããŸãã
- Unity3d.com-å
¬åŒãšã³ãžã³ãµã€ãã 䟿å©ãªããŒãžã¯æ¬¡ã®ãšããã§ãã
- UnityãŠãŒã¶ãŒããã¥ã¢ã« -å ¬åŒãŠãŒã¶ãŒã¬ã€ãã ããããæ¢çŽ¢ãå§ããŸãããã
- Unityãªãã¡ã¬ã³ã¹ããã¥ã¢ã« -ãã詳现ãªèª¿æ»ã
- ã¹ã¯ãªãããªãã¡ã¬ã³ã¹ -ãµããŒããããŠãã3ã€ã®èšèªãã¹ãŠïŒBooãJavaScriptãCïŒïŒã®Unity3dã©ã€ãã©ãªã«ã€ããŠèª¬æããŸãã
- UnityãªãœãŒã¹ -ããã§ã¯ããããªãã¥ãŒããªã¢ã«ãäŸããã¬ãŒã³ããŒã·ã§ã³ãèŠã€ããããšãã§ããŸãã
- Unity Answers-ããã§è³ªåã«çããããæ¢æã®çããèŠã€ããããšãã§ããŸãã å€ãã®å Žåããã®ãªãœãŒã¹ã䜿çšããŸããã
- Unityã³ãã¥ããã£ãã©ãŒã©ã ã
- ãã·ã¢èªã®Unity3d-ãã·ã¢èªã®Unity3dã®éçºè åããµã€ãã è±èªãæ°ã«ããªãå Žåã¯ããã·ã¢èªã®ããã¥ã¢ã«ãããããã©ãŒã©ã ã§èå³ã®ãã質åãžã®åçãåŸãããšãã§ããŸãã
- Unity3d Wikiã¯éåžžã«äŸ¿å©ãªãªãœãŒã¹ã§ãã å€ãã®æšå¥šäºé ãç¡æã®äŸ¿å©ãªã¹ã¯ãªããããããŸãã

å¿ èŠãªãã®
䜿çšããããšã³ãžã³ã®ããŒãžã§ã³ã¯3.3ã§ãããã¹ãŠã®ã³ãŒãã¯CïŒã§èšè¿°ãããŠããããã¹ãŠã®Unityã©ã€ã»ã³ã¹ã§åäœããŸãã Unityã®ç¡æããŒãžã§ã³ãããŠã³ããŒãããã ãã§ãã MonoDevelop-.NETçšã®ç¡æã®éçºç°å¢ãå«ãŸããŠããŸãïŒ Visual Studioããªãå ŽåïŒã ãã®ç°å¢ã¯ãããªãã®ããã«ãç°¡åã«ã«ã¹ã¿ãã€ãºã§ããéçºã«å¿ èŠãªãã®ããã¹ãŠæã£ãŠãããèªåè£å®ãã³ãŒã眮æãã¿ãŒã³ãªã©ã®äŸ¿å©ãªæ©èœããµããŒãããŠããŸãã ç§èªèº«ã¯Visual StudioãResharperãšçµã¿åãããŠäœ¿çšââããŠããŸã -ãã䟿å©ã§ãã Unity Editorã¯äž¡æ¹ã®ç°å¢ããµããŒãããŠããŸãã
ã³ãŒãèŠçŽ
å·çæç¹ã§ã³ãŒããæåããäœæããã®ã§ãæé ãç¹°ãè¿ããŠãåé¡ã¯ãªãã¯ãã§ãã ã³ãŒãã¯èªç±ã«äœ¿çšãç·šéãæ¹åã§ããŸãã
å¯äžã®æ¡ä»¶ããããŸã ïŒåçšãããžã§ã¯ãã§ã³ãŒãïŒå€æŽããããã®ãå«ãïŒã䜿çšããå Žåãäœæè ïŒã€ãŸãã fischer -meïŒãžã®ãªã³ã¯ãæå®ããå¿ èŠããããŸãã
ãã®èšäºã§äœ¿çšãããŠããäŸã®ã³ãŒãã¯ã ããããããŠã³ããŒãã§ããŸã ã
ã«ã¡ã©ã®ã»ããã¢ãã
ãŸãããªããžã§ã¯ãã®ãªã空ã®ã·ãŒã³ãäœæããŸãã ããã©ã«ãã®MainCameraãªããžã§ã¯ããåé€ããŸã ã
2dã«ãé©åãã«ãªãããã«ã«ã¡ã©ãèšå®ããå¿ èŠããããŸãã Unityã§ã¯ãã«ã¡ã©ã¯Cameraã¯ã©ã¹ãæããŸãã ããã䜿çšããã«ã¯ã次ã®ãã®ãå¿ èŠã§ãã
- 空ã®ãªããžã§ã¯ããäœæããŸãïŒ GameObject-> Create Empty ïŒã
- ãããéžæããããã«Cameraã³ã³ããŒãã³ããè¿œå ããŸãïŒ Component-> Rendering-> Camera ïŒã
2Dã°ã©ãã£ãã¯ã¹ã®å Žåã空éå ã®ã¹ãã©ã€ãã®äœçœ®ã¯éèŠã§ã¯ãããŸããã ããã«éèŠãªã®ã¯ãã¹ãã©ã€ããäºãã«éãªãåãæ¹æ³ã§ãã ã«ã¡ã©ã¯ãé è¿æ³ïŒ é è¿æ³ ïŒãšçŽäº€æ³ ïŒ æ£å°æ³ ïŒã®2ã€ã®ã¢ãŒãïŒæ圱ã®çš®é¡ïŒããµããŒãããŠããŸãã 1ã€ã¯ãã¹ãŠã®3Dã²ãŒã ã§äœ¿çšãããŸããã«ã¡ã©ããé ãã«ãããªããžã§ã¯ãã¯å°ããèŠããŸãã ããã¯ã»ãšãã©ç§ãã¡ã®äžçãèŠãæ¹æ³ã§ãã 2çªç®ã®ã¢ãŒãã§ããOrthographicãå¿ èŠã§ã-ãªããžã§ã¯ãã¯åžžã«å®éã®ãµã€ãºã§æç»ãããã«ã¡ã©ãŸã§ã®è·é¢ã«å¿ããŠäºãã«éãªããŸãã 2Dããã³ã¢ã€ãœã¡å³ã«æé©ãªã«ã¡ã©ã¢ãŒãã æ°ããäœæããããªããžã§ã¯ãã®ã«ã¡ã©ã³ã³ããŒãã³ãã®[ ã€ã³ã¹ãã¯ã¿ãŒ]ãŠã£ã³ããŠã®[ æ圱]ãã£ãŒã«ãã§ã[ çŽäº€ æ圱æ³]ãéžæããŸãã åæã«ãããã€ãã®ãã©ã¡ãŒã¿ãŒïŒ ããŒã¹ãã¯ãã£ãã¢ãŒãã«å¯Ÿå¿ïŒã¯æ¶ããŸããã ãµã€ãºãã©ã¡ãŒã¿ãŒïŒçŽäº€ã«ã¡ã©ã®ãµã€ãºïŒã衚瀺ãããŸãã

次ã«ãç»é¢äžã®åãã¯ã»ã«ãUnityã®ã¹ããŒã¹ã®1åäœã«å¯Ÿå¿ããããã«ã«ã¡ã©ãæ§æããŸãã å°æ¥çã«ã¯ãã¹ãã©ã€ãã移åãããµã€ãºããã¯ã»ã«åäœã§èšå®ãããšãã«äŸ¿å©ã§ãã ãããè¡ãã«ã¯ãçŽäº€ã«ã¡ã©ã®ãµã€ãº ïŒ ãµã€ãºãã©ã¡ãŒã¿ãŒïŒãç»é¢ã®é«ãã®ååïŒãã¯ã»ã«åäœïŒã«çããããå¿ èŠããããŸãã ããšãã°ããããããŒãã¬ãŒãã¢ãŒãã®iPhone 3Gç»é¢ã§ãç»é¢è§£å床ã320x480ã®å Žåã ãµã€ãº= h / 2 = 480/2 = 240ã§ãã
æ¯åããããã¹ãŠæåã§è¡ããªãããã«ãã¹ã¯ãªãããäœæããŸãã
using UnityEngine; [ExecuteInEditMode] [RequireComponent(typeof(Camera))] internal class Ortho2dCamera : MonoBehaviour { [SerializeField] private bool uniform = true; [SerializeField] private bool autoSetUniform = false; private void Awake() { camera.orthographic = true; if (uniform) SetUniform(); } private void LateUpdate() { if (autoSetUniform && uniform) SetUniform(); } private void SetUniform() { float orthographicSize = camera.pixelHeight/2; if (orthographicSize != camera.orthographicSize) camera.orthographicSize = orthographicSize; } }
ãã®ã¹ã¯ãªãããã²ãŒã ãªããžã§ã¯ãïŒ GameObject ïŒã«è¿œå ãããšã次ã®ããã«ãªããŸãã
- ã«ã¡ã©ã³ã³ããŒãã³ãããã®ãªããžã§ã¯ãã«èªåçã«è¿œå ãããŸãã RequireComponentå±æ§ããããæ åœããŸãã
- ã¢ãŠã§ã€ã¯æ©èœãå®è¡ãããŸãã å±æ§ExecuteInEditModeããããæ åœããŸããããã«ããããšãã£ã¿ãŒã§ã¹ã¯ãªãããçŽæ¥å®è¡ãããŸãã
- ãã®é¢æ°ãåŒã³åºããçµæãã«ã¡ã©ã¯çŽäº€ããŸãã
- ãã®ãµã€ãºã¯ãç»é¢äžã®1ãã¯ã»ã«ã1ã€ã®UnityãŠãããã«å¯Ÿå¿ããããã«èšå®ãããŸãïŒ SetUniformé¢æ°ãåŒã³åºããŸãïŒã ããã¯ã©ã®ç»é¢ã§ãèªåçã«è¡ãããŸãã

æ©èœåŒ·å
- å®è¡æã«ç»é¢ãµã€ãºãå€æŽã§ããå ŽåïŒã¹ããŒããã©ã³ã®ç»é¢ãå転ããããŠãŒã¶ãŒã解å床ãå€æŽããå ŽåïŒãã«ã¡ã©ã®ãµã€ãºãèªåçã«å€æŽãããšäŸ¿å©ã§ãã ããã¯ã LateUpdateé¢æ°ã§å®è¡ã§ããŸãã
- ç §æã䜿çšãããªãå ŽåïŒã»ãšãã©ã®2Dã²ãŒã ã§èµ·ããããã«ïŒããããžã§ã¯ãèšå®ïŒ ãã¡ã€ã«->ãã«ãèšå®->ãã¬ãŒã€ãŒèšå®->ãã®ä»ã®èšå® ïŒã§Rendering Pathãã©ã¡ãŒã¿ãŒãVertex Litã«èšå®ããããšããå§ãããŸãã ããã¯ãã»ãšãã©ã®ããã€ã¹ã§ãµããŒããããŠãããªããžã§ã¯ãïŒãã¹ãŠã®å æºã«å¯ŸããŠ1ã€ã®ã¹ãããã§åãªããžã§ã¯ãïŒãæç»ããæãç°¡åãªæ¹æ³ã§ãã ç§ã®iOSããã€ã¹ã®å Žåãããã«ããããã©ãŒãã³ã¹ãé£èºçã«åäžããŸããã åãããšãç¹å®ã®ã«ã¡ã©ã«å¯ŸããŠãå®è¡ã§ããŸãã ããã©ã«ãã§ã¯ãã«ã¡ã©ã¯Player Settingsã®å€ã䜿çšããŸãã
ã¹ãã©ã€ã
ã¹ãã©ã€ãã¯ããã¯ã¹ãã£ããªãŒããŒã¬ã€ãããé·æ¹åœ¢ã§ãã ããã©ã«ãã§ã¯ãXOYãã¬ãŒã³ã«é 眮ãããããšã«åæããŸãã 次ã«ãã¹ãââã©ã€ãïŒã¬ã€ã€ãŒïŒã®çžäºé 眮ã«ã€ããŠãZ座æšã責任ãè² ããŸãã
ãã³ã ïŒã¹ãã©ã€ããèŠãããããããã«ãå³äžã®ã·ãŒã³ã®è»žãã¯ãªãã¯ããŠåº§æšè»žãå転ããé©åãªåœ¢ïŒãã®å Žåã¯Backäœçœ®ïŒã«ãªããŸã§å転ãããããšãã§ããŸãã

ã¹ãã©ã€ãã¯ãããã€ãã®ãã©ã¡ãŒã¿ãŒã«ãã£ãŠèšå®ãããŸãã
[SerializeField] private Vector2 size = Vector2.one; [SerializeField] private Vector2 zero = Vector2.one / 2; [SerializeField] private Rect textureCoords = Rect.MinMaxRect(0, 0, 1, 1); [SerializeField] private bool pixelCorrect = true;
ãããã解èªããïŒ
- zero-å·Šäžé
ã«å¯Ÿããã¹ãã©ã€ãã®ãŒãç¹ã®äœçœ®ã ã¹ãã©ã€ãã®äžéšã§æž¬å®ãããŸãã ïŒ0.5ã0.5ïŒã¯ã¹ãã©ã€ãã®äžå¿ã§ãã ãã¯ã¹ãã£äžã§ã®ã¹ãã©ã€ãã®é
眮ã«é¢ä¿ãªããã¹ãã©ã€ãã®æ£ãããã£ã¹ãã¬ã€ã¹ã¡ã³ããå¿
èŠã§ãã
ãã³ã ïŒãšãã£ã¿ãŒã®å転軞/å€äœè»žãäžå¿ã§ã¯ãªãïŒããã©ã«ãã§ã¯ïŒãŒããã€ã³ãã§è¡šç€ºããã«ã¯ãããŒã«ããŒã®Transform Gizmo Togglesã³ã³ãããŒã«ã§ Pivotãéžæããå¿ èŠããããŸã ã
- textureCoords-ãã¯ã¹ãã£åº§æšã ãããã¯ãå·Šäžé ã®åº§æšãšãã¯ã¹ãã£äžã®é åã®ãµã€ãºã§ãã ãããã¯ãOpenGLãšåãæ¹æ³ã§æž¬å®ãããŸã-ãã¯ã¹ãã£ã®å²åã§ã ãã¯ã¹ãã£ããšã«ã[0ã1]ã»ã°ã¡ã³ããé¢ãããšãã«åº§æšãåãåããããããã¯ã¹ãã£ãç¹°ãè¿ããããã©ããã瀺ããã©ã¡ãŒã¿ãèšå®ãããŸãïŒ ã©ããã¢ãŒããã¯ã¹ãã£ã€ã³ããŒããã©ã¡ãŒã¿ïŒã
- pixelCorrectã¯ãã¹ãã©ã€ãã®åãã¯ã»ã«ãç»é¢äžã®ãã¯ã»ã«ã«å¯Ÿå¿ããããã«ãã¹ãã©ã€ããããã¯ã»ã«éãã§è¡šç€ºããããã©ããã®ããŒã«å€ã§ãã
- ããŒã¯ã®ãªã¹ã
- é·æ¹åœ¢ãæ§æããäžè§åœ¢ã®é ç¹ãæ§æããé ç¹ã€ã³ããã¯ã¹ã®ãªã¹ãã
- é ç¹ã«å¯Ÿå¿ãããã¯ã¹ãã£åº§æšã®ãªã¹ãã
äžèšã®ã¹ãã©ã€ããã©ã¡ãŒã¿ãèæ ®ããŠã次ã®ãããªMeshã¯ã©ã¹ã®ãªããžã§ã¯ããäœæããŸãã
private static Mesh CreateMesh(Vector2 size, Vector2 zero, Rect textureCoords) { var vertices = new[] { new Vector3(0, 0, 0), // 1 ___ 2 new Vector3(0, size.y, 0), // | | new Vector3(size.x, size.y, 0),// | | new Vector3(size.x, 0, 0) // 0 ---- 3 }; Vector3 shift = Vector2.Scale(zero, size); for (int i = 0; i < vertices.Length; i++) { vertices[i] -= shift; } var uv = new[] { new Vector2(textureCoords.xMin, 1 - textureCoords.yMax), new Vector2(textureCoords.xMin, 1 - textureCoords.yMin), new Vector2(textureCoords.xMax, 1 - textureCoords.yMin), new Vector2(textureCoords.xMax, 1 - textureCoords.yMax) }; var triangles = new[] { 0, 1, 2, 0, 2, 3 }; return new Mesh { vertices = vertices, uv = uv, triangles = triangles }; }
ã¡ãã·ã¥ãæç»ããã«ã¯ã MeshRendererããã³MeshFilterã³ã³ããŒãã³ããå¿ èŠã§ã ã æåã®ã³ã³ããŒãã³ãã«ã¯ãã¹ãã©ã€ãã®ãã¯ã¹ãã£ãããªã¢ã«ãžã®ãªã³ã¯ãå«ãŸããŠããŸãã 2çªç®ã®ãªããžã§ã¯ãã«ã¯ã圌ãæãMeshFilter.meshãªããžã§ã¯ããå«ãŸããŠããŸãã ã¹ãã©ã€ããå€æŽããã«ã¯ãããã«å¿ããŠãã®ãªããžã§ã¯ããå€æŽããå¿ èŠããããŸãã ã¹ãã©ã€ãèªäœã¯ã SampleSpriteã³ã³ããŒãã³ããä»ããŠå®è£ ãããŸãã ã¹ãã©ã€ããåžžã«ããã2ã€ã®ã³ã³ããŒãã³ããæã€ããã«ããã«ã¯ã察å¿ããRequireComponentå±æ§ãè¿œå ããŸãïŒ
using UnityEngine; [ExecuteInEditMode] [AddComponentMenu("Sprites/Sample Sprite")] [RequireComponent (typeof(MeshFilter))] [RequireComponent (typeof(MeshRenderer))] public class SampleSprite : MonoBehaviour { ⊠}
AddComponentMenuå±æ§ã¯ã Sprites-> Sample Spriteããšãã£ã¿ãŒã®ã³ã³ããŒãã³ãã¡ãã¥ãŒã«è¿œå ããŸãã ããã䜿çšããŠã SampleSpriteã³ã³ããŒãã³ããä»»æã®Unityãªããžã§ã¯ãã«è¿œå ã§ããŸãã

ç·šéäžã«ã¹ãã©ã€ãã衚瀺ã§ããããã«ããã«ã¯ã ExecuteInEditModeå±æ§ã䜿çšã㊠ã SampleSpriteã¯ã©ã¹ã®Awakeããã³Starté¢æ°ããšãã£ã¿ãŒã§çŽæ¥åŒã³åºãããšãã§ããŸã ã ãããã®é¢æ°å ã«ã¡ãã·ã¥ãäœæãããŸãã
private MeshFilter meshFilter; private MeshRenderer meshRenderer; #region Unity messages // Use this for initialization private void Awake() { meshFilter = GetComponent<MeshFilter>(); meshRenderer = GetComponent<MeshRenderer>(); } private void Start() { // NOTE: initializing mesh here because our camera is initialized in Awake() InitializeMesh(); } #endregion
ã¡ãã·ã¥ãåæåãããšãã pixelCorrectãã©ã°ãèæ ®ããå¿ èŠããããŸãã ã¹ã¯ãªãŒã³ã®é«ããã«ã¡ã©ã®ãµã€ãºãšç°ãªãåæ°ã確èªããŸã-éåžžã®ããŒãžã§ã³ïŒã¹ã¯ãªãŒã³ã®é«ããçŽäº€ã«ã¡ã©ã®ãµã€ãºã®2åã«çããïŒã§ãã¡ãã·ã¥ã®ãµã€ãºãã¹ãã©ã€ãã®ãã¯ã¹ãã£é åã®ãµã€ãºã«çããå Žåãã¡ãã·ã¥ãå¢ããå¿ èŠãããåæ°ïŒ
private void InitializeMesh() { Camera cam = Camera.main; if (pixelCorrect && cam != null) { float ratio = cam.pixelHeight / (2 * cam.orthographicSize); size.x = NonNormalizedTextureCoords.width * ratio; size.y = NonNormalizedTextureCoords.height * ratio; } meshFilter.mesh = CreateMesh(size, zero, textureCoords); }
NonNormalizedTextureCoords-ãã¯ã»ã«åäœã®ãã¯ã¹ãã£åº§æšã æ£èŠåããããã¯ã¹ãã£åº§æšïŒã¹ãã©ã€ããã©ã¡ãŒã¿ïŒãšTextureSizeãã¯ã¹ãã£èªäœã®ãµã€ãºã«ãã£ãŠå®çŸ©ãããŸãïŒ
private Rect NonNormalizedTextureCoords { get { Rect coords = textureCoords; Vector2 texSize = TextureSize; if (texSize != Vector2.zero) { coords.xMin *= texSize.x; coords.xMax *= texSize.x; coords.yMin *= texSize.y; coords.yMax *= texSize.y; } return coords; } } private Vector2 TextureSize { get { if (meshRenderer == null) return Vector2.zero; Material mat = meshRenderer.sharedMaterial; if (mat == null) return Vector2.zero; Texture tex = mat.mainTexture; if (tex == null) return Vector2.zero; return new Vector2(tex.width, tex.height); } }
ã¡ãã·ã¥ã¯ã Starté¢æ°ã§åæåãããããšã«æ³šæããŠãã ãããåæåããããšãã«ã¡ã©ããã®æ å ±ã䜿çšããã Awakeã§åæåãããŸãã Startã§ã¯ããã®æ å ±ã¯ãã§ã«ä»ã®ãªããžã§ã¯ãã§å©çšã§ããŸãïŒUnityã§ã¯ããã¹ãŠã®Awakeãæåã«åŒã³åºããã次ã«ãã¹ãŠã®StartãåŒã³åºãããŸãããç°ãªããªããžã§ã¯ãã«å¯ŸããŠåãé¢æ°ãåŒã³åºãé åºã¯å®çŸ©ãããŠããŸããïŒã ãŸãããã®äŸã§ã¯ã Camera.mainã䜿çšãããŸã-ã¹ããŒãžäžã®ã¡ã€ã³ã«ã¡ã©ã§ãã ã€ãŸã ã«ã¡ã©ã«MainCameraã®ã¿ã°ãä»ããå¿ èŠããããŸãã

ååãšããŠããã®æ®µéã§ã¹ãã©ã€ããæäœããããšã¯ãã§ã«å¯èœã§ãã ãããè¡ãã«ã¯ã SampleSpriteã³ã³ããŒãã³ããä»»æã®ãªããžã§ã¯ãã«ã¢ã¿ããããå¿ èŠããããŸãïŒããšãã°ã[ ã³ã³ããŒãã³ã ]ã¡ãã¥ãŒããããŸãã¯ã¹ã¯ãªãããã¡ã€ã«ããã®äžã«ãã©ãã°ããŠïŒã MeshFilterããã³MeshRendererã³ã³ããŒãã³ããèªåçã«è¿œå ãããŸãã ããã§ããã¯ã¹ãã£ãããªã¢ã«ããã©ãã°ïŒãŸãã¯ãã¯ã¹ãã£ããã®ãªããžã§ã¯ãã«ãã©ãã°ãããšããããªã¢ã«ãèªåçã«äœæãããŸãïŒããŠãã©ã¡ãŒã¿ã調æŽãããšãå®æãã2Dç»åãèŠãããšãã§ããŸãã

ãã¯ã¹ãã£èšå®ã調æŽãã
ã¹ãã©ã€ããæ£ãã衚瀺ããã«ã¯ããã¯ã¹ãã£ããããã£ã®æ¬¡ã®ãã©ã¡ãŒã¿ãŒãå€æŽããå¿ èŠããããŸãã
- ã¹ãã©ã€ãã®åããæ»ããã«ãªãããã«ãã¹ãã©ã€ãã®ãµã€ãºãå€æŽããããšãã«æ»ããã«èŠããããã«ããã«ã¯ããã¯ã¹ãã£ãšã¯ã¹ããŒããã©ã¡ãŒã¿ãŒã®ãã£ã«ã¿ãŒã¢ãŒããBilinearãŸãã¯Trilinearã«èšå®ããå¿ èŠããããŸãã
- Texture TypeãGUIå€ã«èšå®ããŸãã
- Formatãã©ã¡ãŒã¿ãŒã®å€ãTruecolorã«èšå®ããŠãå§çž®ãåé€ããããšãå¿ããªãã§ãã ããã

ç §æ
éåžžã2Dã²ãŒã ã¯ç §æã䜿çšããŸããã ãããã®ãšãã§ã¯ãã¯ãã¢ãŒãã£ã¹ãããã¯ã¹ãã£ãããŒãã£ã¯ã«ã·ã¹ãã ãããã³ãã®ä»ã®æ¹æ³ã§äºåã«å®çŸ©ããŠããŸãã ããã«ãç §æã¯ã¬ã³ããªã³ã°ã®é床ã«åœ±é¿ããŸãã ãããã£ãŠã䜿çšãããããªã¢ã«ã®ã¹ãã©ã€ãã®å Žåãé©åãªã·ã§ãŒããŒãéžæããå¿ èŠããããŸãã
- ããŒãžã§ã³3.3ã«ã¯ãç §æããªãã«ããUnlitã·ã§ãŒããŒã®ã°ã«ãŒãããããŸãã éæãªã¹ãã©ã€ãã®å Žåãèæ¯Unlit-> Textureã«ã¯Unlit-> Transparentã·ã§ãŒããŒãé©ããŠããŸãã
- Unityã®å€ãããŒãžã§ã³ã§ã¯ã Transparent-> Diffuseã·ã§ãŒããŒã䜿çšã§ããŸãã ãããããã¹ãŠã®ã¹ãã©ã€ããèªç¶ãªè²ã«ãªãããã«ã ç·šé->ã¬ã³ããªã³ã°èšå®ã§ç°å¢å ãçœã«ããããšãå¿ããªãã§ãã ããã ãã以å€ã®å Žåã ã¢ã³ããšã³ãã©ã€ãã®ããã©ã«ãèšå®ã¯ã°ã¬ãŒã®åœ±ãªã®ã§ããããã¯æããªããŸãã
- ç §æããªãã«ããç¬èªã®ã·ã§ãŒããŒãäœæã§ããŸãã Unityã®å ¬åŒã·ã§ãŒããŒãã¥ãŒããªã¢ã«ã§ãããè¡ãæ¹æ³ã確èªã§ããŸãã
ãšãã£ã¿ãŒæ©èœã䜿çšãã
Unityã䜿çšãããšããšãã£ã¿ãŒã®æ©èœãæ¡åŒµã§ããŸãã ããã«ã¯ãããšãã°æ¬¡ã®ãã®ã䜿çšãããŸãã
- EditorOnlyã¿ã°ã
- Editorã¯ã©ã¹ããç¶æ¿ããŠã ã³ã³ããŒãã³ãã€ã³ã¹ãã¯ã¿ãŒã§ã²ãŒã ãªããžã§ã¯ããšãã£ã¿ãŒãäœæããŸãã
- EditorWindowã¯ã©ã¹ãç¶æ¿ããŠãšãã£ã¿ãŒãŠã£ã³ããŠãäœæããŸãã
ãŠãŒã¶ãŒã«ããã䟿å©ãªåäœã§ããã€ãã®ã¹ãã©ã€ããã©ã¡ãŒã¿ãŒãèšå®ããããã«çµæã衚瀺ããæ©èœãæäŸã§ããŸãã ããšãã°ããŒãç¹ã¯æ£èŠåãããç¶æ ãç¶æããã®ãæé©ã§ãããªããªãã ãã¯ã¹ãã£äžã®ãªããžã§ã¯ãã®ãµã€ãºãå€æŽãããå Žåããã³ã§åºå®ããå¿ èŠã¯ãããŸããã ããããããããšãã£ã¿ãŒã§èšå®ããæ¹ããã¹ãã©ã€ãã®ãµã€ãºã«çžå¯ŸããŠé 眮ãããæ¹æ³ãè¡šãããã«ãã¯ã»ã«åäœã§ãã䟿å©ã§ãã Editorã¯ã©ã¹ã®ãã®ãããªå®è£ ã¯ãããããã¹ãŠã®ããŒãºã«é©ããŠããŸãã
using UnityEditor; using UnityEngine; [CustomEditor(typeof(SampleSprite))] public class SampleSpriteEditor : Editor { public override void OnInspectorGUI() { Target.Size = EditorGUILayout.Vector2Field("Size", Target.Size); Target.Zero = EditorGUILayout.Vector2Field("Zero Point", Target.Zero); Target.TextureCoords = EditorGUILayout.RectField("Texture Coordinates", Target.TextureCoords); Target.PixelCorrect = EditorGUILayout.Toggle("Pixel Correct", Target.PixelCorrect); if (GUI.changed) { Target.UpdateMesh(); EditorUtility.SetDirty(target); } } private SampleSprite Target { get { return target as SampleSprite; } } [MenuItem("Sprites/Create/Sample")] private static void CreateSprite() { var gameObject = new GameObject("New Sample Sprite"); gameObject.AddComponent<SampleSprite>(); Selection.activeObject = gameObject; } }
泚 ïŒãšãã£ã¿ãŒã«é¢é£ä»ããããŠãããã¹ãŠã®ã¹ã¯ãªããã¯ã Assets / Editorãã©ã«ããŒã«é
眮ããå¿
èŠããããŸãã
CustomEditorå±æ§ã¯ããã®ã¯ã©ã¹ãSampleSpriteã³ã³ããŒãã³ãã¯ã©ã¹ã®ãšãã£ã¿ãŒãšããŠã³ã³ããŒãã³ãã€ã³ã¹ãã¯ã¿ãŒã§äœ¿çšãããããšã瀺ããŸãã Targetããããã£ã¯ãç·šéããããªããžã§ã¯ãã®ãã£ãŒã«ãã«ã¢ã¯ã»ã¹ããããããã«å°å ¥ãããŸããã ããã©ã«ãã®ã¿ãŒã²ãããªããžã§ã¯ãã¯Objectåã§ãã ãªãŒããŒã©ã€ããããOnInspectorGUIé¢æ°ã¯ ã Inspectorã«è¡šç€ºãããSampleSpriteã³ã³ããŒãã³ããã©ã¡ãŒã¿ã®ãªã¹ããèšå®ããŸãã ãããã®ãã©ã¡ãŒã¿ãŒã®å°ãªããšã1ã€ãå€æŽããããšïŒ GUI.changed ïŒãã¹ãã©ã€ããæŽæ°ãããç»é¢äžã®å€æŽã®çµæãšã¹ãã©ã€ãã®å€æŽããããã©ã¡ãŒã¿ãŒïŒ EditorUtility.SetDirty ïŒã衚瀺ãããŸãã
ç·šéå¯èœãªãã©ã¡ãŒã¿ãŒãSampleSpriteã¯ã©ã¹ã«è¿œå ããæ¡ä»¶ä»ãã§ã³ã³ãã€ã«ããŸãïŒãã®ã³ãŒããæçµè£œåã«å ¥ããããšãã£ã¿ãŒã§ã®ã¿æ©èœããããã«ïŒã
#if UNITY_EDITOR public Vector2 Size { get { return size; } set { size = value; } } public Vector2 Zero { get { return Vector2.Scale(zero, size); } set { if (size.x != 0 && size.y != 0) { zero = new Vector2(value.x / size.x, value.y / size.y); } } } public Rect TextureCoords { get { return NonNormalizedTextureCoords; } set { textureCoords = value; Vector2 texSize = TextureSize; if (texSize != Vector2.zero) { textureCoords.xMin /= texSize.x; textureCoords.xMax /= texSize.x; textureCoords.yMin /= texSize.y; textureCoords.yMax /= texSize.y; } } } public bool PixelCorrect { get { return pixelCorrect; } set { pixelCorrect = value; } } public void UpdateMesh() { InitializeMesh(); } #endif
ãã®å Žåã Zeroãã©ã¡ãŒã¿ãŒã¯sizeãšåãåäœã§æž¬å®ããã TextureCoordsã¯ãã¯ã¹ãã£ã®ãã¯ã»ã«åäœã§æž¬å®ãããŸãã
æé©åãæ¹åãªã©
ãããŒã³ãŒã«ãæžãã
ãããè¡ãã«ã¯ããã€ãã®æ¹æ³ããããŸãã
- éçãããåŠç ã ãªããžã§ã¯ããå€æŽãããªãå Žåã¯ã éçãšããŠããŒã¯ããããšãã§ããŸãïŒ ã€ã³ã¹ãã¯ã¿ãŒã® éçãã§ãã¯ããã¯ã¹ïŒã ãã®ãããªãªããžã§ã¯ãã¯ãã¹ãŠ1ã€ã®å€§ããªãªããžã§ã¯ãã«çµåããã1ã€ã®Draw Callã§æç»ãããŸãã æ®å¿µãªããã éçãããæ©èœã¯Unity ProããŒãžã§ã³ã§ã®ã¿å©çšå¯èœã§ãã
- åçãããåŠç ã è€æ°ã®ãªããžã§ã¯ããåããããªã¢ã«ã䜿çšããå ŽåãUnityã¯ãããã1ã€ã«ãŸãšããŠããæç»ãããã¹ãŠã®ãªããžã§ã¯ãã1ã€ã®Draw Callã§æç»ãããŸãã ãã®å¹æãå®çŸããã«ã¯ããã¯ã¹ãã£ã1ã€ã®ã¢ãã©ã¹ã«çµåããå¿
èŠããããŸãã1ã€ã®å€§ããªãã¯ã¹ãã£ã§ãã ã¢ãã©ã¹ã䜿çšãã-ïŒ åçãããåŠçã«ãã ïŒDraw Callã®æ°ãšããã¯ã¹ãã£ãå æããã¡ã¢ãªéïŒã¢ãã€ã«ãã©ãããã©ãŒã ã«ãšã£ãŠéåžžã«éèŠïŒã®äž¡æ¹ãæžããããšãã§ããŸãã
ãã³ã ïŒäžéšã®ãã©ãããã©ãŒã ã§ãããåŠçã¿ã€ãã®æå¹å/ç¡å¹åã¯ã [ãã¡ã€ã«]-> [ãã«ãèšå®]-> [ãã¬ãŒã€ãŒèšå®]ã§è¡ããŸãã - ã¹ãã©ã€ããããŒãžã£ãŒ å®è£ ã®1ã€ã¯SpriteManagerã§ãã ã¹ãã©ã€ãã¯ã1ã€ã®ã¢ãã©ã¹ãã¯ã¹ãã£ïŒ MeshRendererã³ã³ããŒãã³ãå ïŒã䜿çšããã¹ãã©ã€ããããŒãžã£ãŒã«è¿œå ãããã¹ãã©ã€ãçšã®ã¡ãã·ã¥ãäœæããŸãïŒ MeshFilterã³ã³ããŒãã³ãå ïŒãåã¹ãã©ã€ãã«1ã€ãã€ãå€ãã®é·æ¹åœ¢ã§æ§æãããŸãïŒèè ã¯ãã®å®è£ ã«ãšãã£ã¿ãŒã®å©äŸ¿æ§ããã蟌ãã§SM2ãååŸããŸããïŒ ïŒ ãŸããã¹ãã©ã€ãã䜿çšãããããªã¢ã«ãžã®ãªã³ã¯ã«èšå®ããŠã¹ãã©ã€ããããŒãžã£ãŒãæ¹åãããã¹ãŠã®ãããªã¢ã«ãã¹ãã©ã€ããããŒãžã£ãŒã®MeshRendererã³ã³ããŒãã³ãã«ä¿åã ã Mesh.CombineMeshes ã Mesh.SetTriangles ã Meshã®æ©èœã䜿çšããŠãã¡ãã·ã¥ãå°ããªã¡ãã·ã¥ã®ã³ã¬ã¯ã·ã§ã³ïŒãããªã¢ã«ããšã«1ã€ïŒãšããŠæç»ããããšãã§ããŸãã GetTriangles ã Mesh.subMeshCount ã ããã«ãããåãããªã¢ã«ã«å¯ŸããŠã¹ãã©ã€ããããŒãžã£ãèµ·åããªãããã«ã§ããŸãã
ããã€ãã®ã³ãŒãã®æ¹å
- ãã¡ããã CreateMeshé¢æ°ã®çµ¶ãéãªãåŒã³åºããåãé€ãã»ããè¯ãã§ããããã¯æ°ããã¡ãã·ã¥ã®äœæã«ã€ãªãããŸãïŒãã®å ŽåãéèŠãªããšã¯ãããŸããããã¹ãŠããšãã£ã¿ãŒã§è¡ãããå®éã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ã¹ãã©ã€ããäžåºŠäœæãããããå€æŽãããªãããã§ãïŒã 代ããã«ããã©ã¡ãŒã¿Mesh.vertices ã Mesh.uv ã Mesh.trianglesãå€æŽããã ãã§ã ã é ç¹é åãå€æŽãããå Žåã mesh.RecalculateBoundsïŒïŒãåŒã³åºãããšãå¿ããªãã§ãã ããã äžè§åœ¢ã®é åãå€æŽããããšããã®é¢æ°ãèªåçã«åŒã³åºãããŸãã
- Camera.mainã®ä»£ããã«ãã«ã¡ã©ãã¹ã¯ãªãããã©ã¡ãŒã¿ãŒãšããŠèšå®ããããšããå§ãããŸãã
ã¢ãã¡ãŒã·ã§ã³ã®äœãæ¹
æ¬æ Œçãªã¹ãã©ã€ãã¢ãã¡ãŒã·ã§ã³ã®äœææ¹æ³ã¯ã SpriteManagerã®äŸã§èŠãããšãã§ããŸãã
ãããã³ã®ã³ã²ãŒã ã«ã¯ã¹ãã©ã€ãã¢ãã¡ãŒã·ã§ã³ã¯ãããŸããã§ããã 代ããã«ãããšãã°ããã³ã®ã³ã¯ããŒãããã¹ãã©ã€ãã®ãŒããã€ã³ãã«åºå®ããããããã®ããŒãã®ç§»åã¯Animationã³ã³ããŒãã³ãã䜿çšããŠå®è¡ãããŸããã ããã§ååã§ããã Unityã§ã¯ãããã¯éåžžã«åŒ·åãªããŒã«ã§ãã ããšãã°ãã¢ãã¡ãŒã·ã§ã³ã§ã¯ãã¹ã¯ãªããããé¢æ°åŒã³åºããæ¿å ¥ããããšãã§ããŸãã

2Dç©çåŠ
Colliderã¿ã€ãã®ã³ã³ããŒãã³ããä»»æã®ã¹ãã©ã€ãã«ã¢ã¿ããã§ããŸããé·æ¹åœ¢ãªããžã§ã¯ãã®å Žåã¯Component-> Physics-> BoxCollider ãç圢ãªããžã§ã¯ãã®å Žåã¯Component-> Physics-> SphereColliderã§ãã ãããã®ã³ã³ããŒãã³ãã¯ã2ã€ã®ç®çã«äœ¿çšã§ããŸãã
- ãªããžã§ã¯ããããªã¬ãŒã«ããŸãïŒ ãããªã¬ãŒããã§ãã¯ããã¯ã¹ïŒã
- ãªããžã§ã¯ãã«ç©ççãªè¡æãäžããŸãã ãããè¡ãã«ã¯ã ã³ã³ããŒãã³ã->ç©ç->ãªãžããããã£ã³ã³ããŒãã³ãããªããžã§ã¯ãã«è¿œå ã§è¿œå ããŸãã

Unity3dç©çåŠã¯ ãä»ã®è±å¯ãªå¯èœæ§ãæäŸããŸãïŒãªããžã§ã¯ãã®ç¹å®ã®ãã€ã³ãã«é©çšãããåãéåãæ¥ç¶ãã€ã³ãïŒ Fixed Joint ã Spring Joint ïŒã ããããã¹ãŠã䜿çšããŠãç©çåŠã«åºã¥ããåªããã²ãŒã ãäœæã§ããŸãã
代æ¿æ¡
- EZSpriteã¯ãUnityã§2Dã¢ãã¡ãŒã·ã§ã³ãäœæããããã®ã·ã³ãã«ãªææã·ã¹ãã ã§ãïŒå·çæç¹ã§ã¯ããã©ã°ã€ã³ã®äŸ¡æ Œã¯35ãã«ã§ãïŒã
- SpriteManagerã¯ãã¹ãã©ã€ãã¢ãã¡ãŒã·ã§ã³ãäœæããããã®ã¯ã©ã¹ã·ã¹ãã ã§ãã 1ã€ã®Draw Callã§ã®ã¹ãã©ã€ãã®æç»ãã¹ãã©ã€ããã¢ãã¡ãŒã·ã§ã³ãããã³ã¢ãã©ã¹ã®ãããŒãžã£ãŒããµããŒãããŸãã èšå®ããã®ã¯ããªãäžäŸ¿ã§ãããäºç®ãéãããŠããå Žåã¯ã䜿çšã«éåžžã«é©ããŠããŸãã
- SM2 ïŒSprite Manager 2ïŒã¯ããšãã£ã¿ãŒããµããŒãããææã®ã¹ãã©ã€ããããŒãžã£ãŒã§ãã ç¡æçã«å ããŠãå€ãã®äŸ¿å©ãªæ©èœããµããŒãããŠããŸããã¢ãã©ã¹ã®äœæããšãã£ã¿ãŒã䜿çšãããã¯ã¹ãã£ãŒé åã®åŒ·èª¿è¡šç€ºãã¢ãã¡ãŒã·ã§ã³ã®èªåäœæãªã©ã ã¹ãã©ã€ããæåã§å®è£ ããããªãå Žåãç§ã®æèŠã§ã¯ãSM2ãæè¯ã®éžæã§ãã æ°ã«å ¥ããªãå Žåã¯ãè¿éãã60æ¥éã®æ©äŒã§150ãã«ããããŸãã
- RageSpline ã50ãã«ã ãã®ãã©ã°ã€ã³ã¯å®å
šã«ã¹ãã©ã€ãã§ã¯ãªãããã¯ã¿ãŒã®ãã®ã§ãã ãã©ã°ã€ã³ã«ã¯å€ãã®èå³æ·±ãæ©èœããããŸãïŒ
- ããžã§æ²ç·ã«åºã¥ããŠ2Dã¡ãã·ã¥ãšã©ã€ã³ãäœæããŸãã
- ããŸããŸãªå¹ ã®ãªããžã§ã¯ãã®èŒªéã
- åè²å¡ãã€ã¶ã/ã°ã©ããŒã·ã§ã³;
- ãã¯ã¹ãã£ãªããžã§ã¯ã;
- ãªã©ãªã©ã
ãããã«
ç§ãæžããããšã¯ã2Dã·ã¹ãã ãäœæãã2次å ã®ã²ãŒã ãäœæãããšãã«äœ¿çšããããšã§ååã§ãã ãšã³ãžã³ã®3次å æ§ãšç©çåŠã®ãµããŒãã«ãããæ°ããè±å¯ãªæ©äŒãåŸãããUnityïŒãšã³ãžã³ã®å€§ããªãã©ã¹ïŒã§ã®é«ãéçºé床ãã³ã¹ããåæžããŸãã
PS誰ãæ°ã«ãããç§ã®ä»¥åã®æçš¿ãèªãã§ãã ããã 2æ¥é ã®ã²ãŒã ãšãå°ããªåã§ã²ãŒã ã®ããã¢ãŒã·ã§ã³ãããªãäœæããæ¹æ³ ã 次ã®èšäºã§ã¯ãUnityã§ã®æé©åã«ã€ããŠèª¬æããŸãã Unityåãã®ã²ãŒã ãéçºãããšããç§ã¯ç¹°ãè¿ãæé©åã®å¿ èŠæ§ã«çŽé¢ããŠããŸããããã®ä»¶ã§ç§ã®çµéšãããªããšå ±æããããšæããŸãã