ãã®èšäºãæžããçç±ã¯ãããã«ã·ãã§ããã«é¢ãããã®åºçç©ã§ããã Unityã§ã®ããã°ã©ã ã¡ãã·ã¥çæã«é¢ããèå³æ·±ããããã¯ãåãäžããŸããã
ç§ã®èšäºã¯ãUnityã«é·å¹Žåãçµãã§ãã人ã察象ãšãããã®ã§ã¯ãããŸãããUnityã®è€éãã«ç²ŸéããŠãã人ã«ãšã£ãŠæ°ãããã®ã¯ãªãã§ãããã ãŸããå®å šã«æ°åè ã®å Žåãããã§ã¯æçœãªãå°é£ããçºçããå¯èœæ§ãããããã¹ãŠããšãã£ã¿ãŒã«ãããšãã«äœããçºæããå¿ èŠãããã®ã¯ãªãã§ããã ç§ãã¡ã®èŽè¡ã¯ãUnityã§æ¢ã«äœãã§ããéçºè ã«æãé©ããŠããŸããããšãã£ã¿ãŒã§ã¡ãã·ã¥ãåçã«å€æŽããåé¡ããŸã 解決ããŠããŸããã ãŸããç§ãã¡ã®äœäººãã¯ãæ€æ»å®ãšã®çµéšããå©çãåŸããããããŸããã
èè ã¯ããµããžã§ã¯ãé åã®çµ¶å¯Ÿçãªç¥èãæã£ãŠãããšäž»åŒµããŠããŸãããç§ã¯èªåã®èšèã§ãã¢ã»ãããäœæãããšãã«çŸããããã€ãã®ã¿ã¹ã¯ã®è§£æ±ºçãäŒãããã ãã§ãã
äžèšã®èšäºãèªãã åŸãç§ã¯ããã«ããããããžã§ã¯ãã«å¿ èŠãªãã®ã§ããããšã«æ°ä»ããŸããã æåã¯ããšã¯ã¹ããŒããããfbxãã¡ã€ã«ãã家ãäœæããŠããŸããã ãã¡ããã説æãããŠããããã«1察1ã§è¡ãã®ã§ã¯ãªããåºæ¬çãªã¢ã€ãã¢ãæŒãåºããŠãããã«ã¿ã¹ã¯ãèšå®ããŸãããå®è¡äžã®ã²ãŒã ã¢ãŒãã«åãæ¿ããããšãªããUnityãšãã£ã¿ãŒã§å»ºç©ãçŽæ¥ç·šéããã³è¡šç€ºããŸãã åã®ã¢ã€ãã¢ã®çµæãšããŠããã¹ãŠã®å»ºç©ã®èšå®ã1ã€ã®ã¹ã¯ãªããã«åããããšãå€æãããã®çµæããªããžã§ã¯ãã€ã³ã¹ãã¯ã¿ãŒã§æ§é å šäœã1ãæã§ç·šéããããšãå€æããŸããã
å°ããªäœè«
èªå·±ç®èããå§ããŸãã ç§ãã¡ã®å°ããªããŒã ã¯å°ãåã«ãã¢ãã€ã«ãã©ãããã©ãŒã åãã®ã²ãŒã ã®éçºãåŒãåããŸããã ç¬èªã®ã²ãŒã ãšã³ãžã³ãäœæãããšããéå¿çãªã¿ã¹ã¯ããå§ããŠãäœæ¥ãéå§ããŸããã ä»ã®æŽ»ååéãéçºããã²ãŒã ãšã³ãžã³ã®äœæã«é¢ããæ¬ãèªãã ç§èªèº«ã®çµéšã«ãããšããã¹ãŠãçŽç²ãªsi ïŒ PureC ïŒã§æžãããšã決å®ãããŸããã ãšã³ãžã³ã®ããã€ãã®äž»èŠãªåºæ¬ãµãã·ã¹ãã ãå®è£ ãããŸãããæé©åãããã¡ã¢ãªãããŒãžã£ã ã°ã©ãã£ãã¯ã¬ã³ãã©ãŒã è€åã¢ãã«ã®äœæã«å¯Ÿããã³ã³ããŒãã³ãã¢ãããŒãïŒ ããã§ã®å ¬é ïŒã«åºã¥ããªããžã§ã¯ãã®éå±€ã LUAãäœæããã²ãŒã ã®ã¹ã¯ãªããäœææ©èœã«é¢é£ä»ããŸããã SQLiteã«åºã¥ããããŒã«ã«ããŒã¿ããŒã¹ã«ããããããã®ïŒLuaã®ã¹ã¯ãªãããå«ãïŒãªã©ãä¿åããæ©èœãå®è£ ããŸããã äžèšã®ãã¹ãŠãå®è£ ããOpenGLãæäŸããã€ã³ã¿ãŒãã§ã€ã¹ãç¿åŸããŠããªãé·ãæéãçµéããåŸãæ®å¿µãªçµè«ã«éããŸãããæ¬æ Œçãªãšã³ãžã³ãäœæã§ããŸãããããã«ã§ããŸãã
Unityãžã®ç§»è¡
åœç¶ãç¬èªã®ãšã³ãžã³ã®äœæãšäžŠè¡ããŠãã²ãŒã æ¥çã®ææã«èå³ããããŸããã ç§ãã¡ã¯ã¢ã³ãªã¢ã«ãšã³ãžã³ã«éåžžã«é åãæããŠããŸããããã¢ãã€ã«ãã©ãããã©ãŒã çšã®30ã45MBã®æå°éã®ãããžã§ã¯ãã¯ããã«å·éã«ãªããä»ã®ãœãªã¥ãŒã·ã§ã³ãæ¢ãããšã«ããŸããã
æåŸã«ãUnityã§æè¿è©ŠããŸããã Unity CïŒæ§æã¯éšåçã«ãã¹ã¿ãŒãããŠããŸããããã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã·ã¹ãã ïŒ GC ïŒã®ãããã§ãäœæããããªãœãŒã¹ã解æŸããå¿ èŠãå¿ ããããªããšããäºå®ã«æ £ããã®ã¯ããªãå°é£ã§ããã
ä»äºã®ããã«éžã°ãããããã¯
ããã«äœæ¥ã説æããåã«ãå¶éã«ã€ããŠããã«èª¬æããŸããUnity5ãããã«å匷ãå§ããŸãããã€ãŸãããã¹ãŠã®äŸã¯ãUnityã®5çªç®ã®ããŒãžã§ã³ãåã®4çªç®ãããã«3çªç®ã®ããŒãžã§ã³ã§åäœããã¯ãã§ããä¿èšŒã¯ã§ããŸããã ç§èªèº«ã®çµéšãããããŒãžã§ã³4ã§åºäŒã£ãã¬ãã¹ã³/ã¹ã¯ãªããã®äžéšã¯ããŒãžã§ã³5ã§å®è¡ãããããšãå€æããäžéšã¯æ°ããããŒãžã§ã³ã«åãã©ãŒãããããŠæ£åžžã«éå§ããå¿ èŠããããäžéšã¯éå§ã§ããªãã£ããããã³ãã³ãæ§æãå€æŽããå¿ èŠããããŸããã ããŒãžã§ã³ã®äžäœäºææ§ã«ã€ããŠã¯äœãç¥ããŸããïŒå°ããªè¿œå ïŒã¢ã»ãããå ¬éããåã«ãUnity 4.5.0ã§ä»¥äžã«ãªã¹ããããã¹ã¯ãªãããæ£åžžã«ãã¹ãããŸããïŒã
ã²ãŒã ãèŠèŠçã«æºããããã«ãåšå²ã®èæ¯ãããŸããŸãªå»ºç©ã§é£œåãããããšã決å®ãããŸããã ãšãã£ã¿ã§å»ºç©ã®ããããã®å€èŠ³ãããã«èŠãããšæããŸããã ãšãã£ã¿ãŒã§çŽæ¥ã¹ã¯ãªããããå®è¡ãã§ããããã«ããã«ã¯ãMonoBehaviourããç¶æ¿ããã¯ã©ã¹ã®åã«ã[ExecuteInEditMode]ãšããè¡ãèšè¿°ããå¿ èŠããããŸãã ãããžã§ã¯ãã§MyTest.csã¹ã¯ãªãããäœæãã次ã®ãã³ãã¬ãŒãã«åŸã£ãŠå€æŽããŸãã
using UnityEngine; [ExecuteInEditMode] public class MyTest : MonoBehaviour { // , // // }
ã€ã³ã¹ãã¯ã¿ãŒã®ãã£ãŒã«ããå€æŽãããšãã¹ã¯ãªããã¡ãœããïŒå®è£ ãããŠããå ŽåïŒUpdateïŒïŒãåŒã³åºãããŸãã ã²ãŒã çšã«åéãããã¹ã¯ãªããã®ãµã€ãºãç¯çŽããããã«ããã®ã¡ãœããã¯#if UNITY_EDITOR ... #endifãã£ã¬ã¯ãã£ãã®ãã¢ã§ããšã¹ã±ãŒããã§ããŸãããããã£ãŠãã€ã³ã¹ãã¯ã¿ãŒã§çŽæ¥å€æŽã§ããã¹ã¯ãªããã®ããããã®ãã³ãã¬ãŒããã³ã³ããŒãã³ãã«å¯ŸããŠè¡šç€ºãããŸãã
using UnityEngine; [ExecuteInEditMode] public class MyTest : MonoBehaviour { public int i=10; #if UNITY_EDITOR void Update () { Debug.Log ("Update"); } #endif }
ãã®ã¹ã¯ãªãããã¹ããŒãžäžã®ä»»æã®ã³ã³ããŒãã³ãã«æ·»ä»ããã€ã³ã¹ãã¯ã¿ãŒã®iãã£ãŒã«ãã®å€ãå€æŽãããšãã³ã³ãœãŒã«ã¯ããã«ãæŽæ°ãã衚瀺ãïŒããæ£ç¢ºã«ã¯ãæŽæ°ãã¡ãã»ãŒãžã®æ°ãå¢å ããŸãïŒãæ®ãã®æéã¯ã¹ã¯ãªããããããªãã¯ãã£ãŒã«ãã®å€æŽããåŸ æ©ãããŸãã
ãã®ã¹ã¯ãªããã䜿çšããŠã·ãŒã³ã«å€æ°ã®ã³ã³ããŒãã³ããããå Žåãã·ãŒã³ã®é床ãèããäœäžããããšã«æ³šæããŠãã ããã ãããåãé€ãã«ã¯ãã€ã³ã¹ãã¯ã¿ãŒã®å€æŽããã»ããµãŒãç¹å¥ãªãšãã£ã¿ãŒãã©ã«ããŒã®ã¹ã¯ãªããã«ç§»åããå¿ èŠããããŸãã ãã®ãã©ã«ããŒã®å 容ã¯ãå®æãããããžã§ã¯ãã«åé¡ãããŸããã Editorãã©ã«ããŒãšããã®äžã«ã¹ã¯ãªããMyTestInspector.csãäœæããŸãããã
using UnityEngine; using UnityEditor; using System.Collections; [CustomEditor(typeof(MyTest))] public class MyTestInspector : Editor { // public override void OnInspectorGUI() { // DrawDefaultInspector (); // MyTest mt = target as MyTest; // , // mt.DoRefresh(); } }
å€æŽãããMyTestã¹ã¯ãªãããèŠãŠã¿ãŸãããã
using UnityEngine; [ExecuteInEditMode] public class MyTest : MonoBehaviour { public int i=10; public void DoRefresh () { Debug.Log ("Update"); } }
ãã䟿å©ãªäœæ¥ã®ããã®ã€ã³ã¹ãã¯ã¿ãŒã®ã»ããã¢ãã
å ¬åŒæ å ±ãšã°ãŒã°ã«ãç 究ããåŸããŸããã€ã³ã¹ãã¯ã¿ãŒã®ãããªãã¯ããããã£ã®åæç»ãšã¹ã¯ãªããå ã®é©åãªæ¹æ³ã«ããå€æŽãžã®å¯Ÿå¿ãæäŸããããªã¢ã³ãã決å®ããŸãããããã®åŸãç·šéçšã®ãœãŒã¹ããŒã¿ãã倱ããã«æäœããããçžäºæ¥ç¶ãããããŒã¿æ§é ã«åå²ããããšã«ããŸãã建ç©ãæ§ç¯ããããã®çŽ130ã®åæ衚瀺èšå®ã ãã®åŸããå人æ€æ»å®ãã®å¿ èŠæ§ã¯ãªããªããŸããã ãã ããã³ã³ããŒãã³ããäœæããã³ç·šéããå Žåã¯ãä»åŸãã®ã¢ãããŒãã«æ»ããããšèããŠããŸãã 誰ããèå³ãæã£ãŠãããªããç§ã¯ãªã³ã¯ãäžããããšãã§ããŸãïŒ ãããšãã
ã€ã³ã¿ãŒãã§ã€ã¹äœæã®åŸ®åŠãªç¹
ããšãã°ãåintãŸãã¯floatã®ãããªãã¯å€æ°ãéåžžäœæãããšã次ã®ããã«ãªããŸãã
public int iterator=2; public float dx=0.5f;
ã€ã³ã¹ãã¯ã¿ãŒã§ã¯ãåçŽãªç·šéãã£ãŒã«ããšããŠè¡šç€ºãããŸãããäœæ¥äžã«ãããã®å€ãé »ç¹ã«å€æŽãããããããŠã¹ã«ãŒãœã«ãåžžã«ãã£ãŒã«ãã«ç§»åããäºãã«ã»ãšãã©æå³ã®ãªãæå³ã®ããæ°åãå ¥åããåãåã£ãå€æŽã確èªããã®ã¯éåžžã«éå±ã§ããç°ãªãã¢ãããŒããã¯ããã«äŸ¿å©ã§ãã å€æ°ïŒäžèšã®è¡ïŒã®çŽåã«ãã£ãŒã«ãã宣èšããå Žåãå ¥åãããå€ã®æå¹ãªç¯å²ã瀺ããŸãã
[Range(-10, 10)] public int iterator=2; [Range(0.0f, 1.0f)] public float dx=0.5f;
å€æ°ã®åã«ãã®ãããªè¿œå ãè¡ã£ãåŸãã€ã³ã¹ãã¯ã¿ãŒã§ã¹ã©ã€ããŒãåãããŠå€ãã¹ã ãŒãºã«ããŸãã¯çªç¶å€æŽããã ãã§ååã§ãã
ã¹ã¯ãªããå ã®ãã¹ãŠã®ãã£ãŒã«ããåæã«è¡šç€ºããªãããã«ããããã«ãçŽ130åã®ãã£ãŒã«ãããããŸããäºãã«åŒ·ãé¢é£ããå€ã1ã€ã®ã¯ã©ã¹ã«ã°ã«ãŒãåããŠããã®ã¯ã©ã¹ãã¹ã¯ãªããå ã®ãããªãã¯ãã£ãŒã«ããšããŠå®£èšããããšãã§ããŸãã ã¯ã©ã¹ã®å¥ã ã®ã€ã³ã¹ã¿ã³ã¹ã§ãã£ãŒã«ãã®å€æŽãä¿åããã€ã³ã¹ãã¯ã¿ãŒã§ãã£ãŒã«ãã衚瀺ã§ããããã«ããã«ã¯ãã¯ã©ã¹ã宣èšããåã«[System.Serializable]ã®è¡ãèšè¿°ããå¿ èŠããããŸãïŒäžèšã®è¡ïŒã
[System.Serializable] public class LeftRightSide { [Range(0, 100)] public int leftSide=3; [Range(0, 100)] public int rightSide=20; }
ãã®ã¯ã©ã¹ãã¹ã¯ãªããã§ãããªãã¯ãã£ãŒã«ããšããŠå®£èšãããšãäžèšã®ã¯ã©ã¹ã®ã³ã³ãã³ããç·šéããããã®ãã£ãŒã«ãã®é衚瀺/å±éå¯èœãªãããã¯ãã€ã³ã¹ãã¯ã¿ãŒã«è¡šç€ºãããŸãã ããŸããŸãªã¯ã©ã¹ãäºãã«éå±€çã«ãã¹ãããããšãã§ããåžžèã«ãã£ãŠã®ã¿å¶éãããŸãã ãã®ãããªåçŽãªææ³ã«ããããŸãïŒé¢é£ããŒã¿ãã°ã«ãŒãåã§ãã次ã«ïŒã€ã³ã¹ãã¯ã¿ãŒã§ã®ããã²ãŒã·ã§ã³ãç°¡åã«ãªããŸãã ã¹ã¯ãªããå šäœã«ã€ããŠèª¬æããŸãã
using UnityEngine; [ExecuteInEditMode] public class MyTest : MonoBehaviour { public LeftRightSide leftRight=new LeftRightSide(); public void DoRefresh () { Debug.Log ("Update"); } } [System.Serializable] public class LeftRightSide { [Range(0, 100)] public int leftSide; [Range(0, 100)] public int rightSide; }
ã¡ãã·ã¥ãšãã£ã¿ãŒã§çŽæ¥ç·šéå¯èœ
ã¡ãã·ã¥ãæç»ããããã®ã³ã³ããŒãã³ãã®æºåã ã¡ãã·ã¥ãç·šéããã³è¡šç€ºã§ããããã«ããã«ã¯ããšãã£ã¿ãŒã®æ©èœã䜿çšã§ããŸããããšãã°ãã¹ããŒãžäžã§ç©ºã®ãªããžã§ã¯ããäœæããã¡ãã¥ãŒé ç®Component-> Mesh-> Mesh Filter and Component-> Mesh-> Mesh RendererããMeshFilterãšMeshRendererãè¿œå ããŸãããã«å¿ããŠã æåã®ã³ã³ããŒãã³ãã¯ãå éšãã¡ãã·ã¥ãžãªã¡ããªãæ åœãã2çªç®ã¯ã¹ã¯ãªãŒã³äžã®ã¡ãã·ã¥ã®æç»ã«é¢é£ä»ããããŠããŸãã ãããã®ã³ã³ããŒãã³ããè¿œå ããå¥ã®ããä¿¡é Œæ§ã®é«ãæ¹æ³ããããŸãã ã¹ã¯ãªãããäœæãããšããã¹ã¯ãªãããæ¥ç¶ãããŠããã³ã³ããŒãã³ãäžã«ãªãå Žåãäžèšã®2ã€ã®ã³ã³ããŒãã³ããè¿œå ããããã«æ瀺ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ãMonoBehaviourã®äžäœã¯ã©ã¹ã宣èšããåã«ãæåå[RequireComponentïŒtypeofïŒMeshFilterïŒãtypeofïŒMeshRendererïŒïŒ]ãèšè¿°ããŸãã ãµã³ãã«ã¹ã¯ãªããã®æºåïŒ
using UnityEngine; using System.Collections; [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] [ExecuteInEditMode] public class MyTest : MonoBehaviour { //... }
å°ãã®çè«ïŒUnityã§ã¡ãã·ã¥ãæäœããæ¹æ³ãç¥ã£ãŠãã人ã¯ããã®ã»ã¯ã·ã§ã³ãã¹ãããã§ããŸãïŒ
ã³ã³ããŒãã³ãã®ã¡ãã·ã¥ã«äœãã衚瀺ããã«ã¯ãå¿ èŠãªããŒã¿ã§ã¡ãã·ã¥ãå¡ãã€ã¶ãå¿ èŠããããŸãã æå°ã¯ãé ç¹ã®ã»ãããšãããããã¡ã»ããïŒãã®ååã«ã¯å矩èªããããŸããããšãã°ãäžè§åœ¢ãé¢ããã¡ã»ãããã€ã³ããã¯ã¹ã®é åïŒãã€ãŸããé ç¹ãçžäºã«ãªã³ã¯ããããã®ã«ãŒã«ã§æ§æãããŸãã ããã«ããã¯ã¹ãã£ãæç»ããå¯èœæ§ãèæ ®ãããŸããã€ãŸããUV座æšã䜿çšããå¿ èŠããããŸãã æ³ç·ãçæé衚瀺ãããŸãã ããã«äºçŽããŸããããã§ã¯ãããŒãã£ã¯ã«ã·ã¹ãã ã®æäœãã¡ãã·ã¥ã¢ãŒãã®æäœãªã©ãèæ ®ããã«ãã·ã§ãŒããŒã®ãå€å žçãªãäœæ¥ã®ã¿ãèæ ®ããŸãã ã€ãŸããé ç¹ãšãããã®ããã³ãã«ãã®ã«ãŒã«ã«åºã¥ããŠäžè§åœ¢ãæç»ããã¢ãŒããèæ ®ãããŸãã äžè¬çã«ããã®ãããã¯ã®è©³çŽ°ãªè°è«ãããªãã¡ ã¡ãã·ã¥ãã·ã§ãŒããŒãå€æ°ã®é ç¹ããã¡ã»ãããæ³ç·ããã¯ã¹ãã£åº§æšãé ç¹ãããã¡ãŒããããªãã¯ã¹ãªã©ã¯ãæ°åã®æ¬ã®ããªã¥ãŒã ãå æããå¯èœæ§ããããŸãïŒãããã¹ãã§ãïŒã®ã§ãçŽæ¥è¡šç€ºãããåçã¡ãã·ã¥ãæ§ç¯ããã®ã«ååãªæå°éã®æ å ±éã«å¶éããŸããšãã£ã¿ãŒã
äžè§åœ¢ãæãããšãã§ããã®ã§ãäžè§åœ¢ãäºãã«çµã¿åãããããšã«ãããä»»æã®è€éãªå³åœ¢ãæãããšãã§ããŸãã ããšãã°ãæ£æ¹åœ¢ãè±åœ¢ãå¹³è¡å é¢äœãå°åœ¢ãããã³äžè¬çã«åè§åœ¢ã®å Žåã2ã€ã®äžè§åœ¢ã§ååã§ãã ããè€éãªåœ¢ç¶ãæãã«ã¯ãããå€ãã®äžè§åœ¢ãå¿ èŠã§ãããååã¯å€ãããŸããã ã€ãŸããä»ã®ãã¹ãŠãæç»ããããã®æå°ãã€ååãªããªããã£ãã§ãããäžè§åœ¢ãèæ ®ããããšã«åæããŸãã
ã·ã§ãŒããŒã«ã€ããŠç°¡åã«èª¬æããŸããã·ã§ãŒããŒã¯ãç¹å®ã®ã«ãŒã«ã«åŸã£ãŠäžè§åœ¢ãæãç¹å¥ã«äœæããã³ã³ã³ãã€ã«ãããããã°ã©ã ã§ãã å®éããã¹ãŠã¯ããè€éã§ãããç°¡æœã«ããããã«ãã®è§£éãåãå ¥ããŸãã å¥ã®äžè§åœ¢ãæç»ãããšããã·ã§ãŒããŒã¯é£æ¥ããäžè§åœ¢ã«ã€ããŠäœãç¥ããªãããšãèšåããŸãã
ã³ã³ãã¥ãŒã¿ãŒã®ã¡ã¢ãªã¯ç·åœ¢ã§ããã倧èŠæš¡ãª/è€åããŒã¿ãããã¯ïŒæ§é ãã¯ã©ã¹ãé åãªã©ïŒãããå Žåã¯åžžã«ããã®å 容ã¯ããåŸãã«ããããã®èŠçŽ ãžã®ã¢ã¯ã»ã¹ãç·åœ¢ã«é 眮ããã®ãæé©ã§ãã ãŸããã¡ãã·ã¥ã¯éåžžã«å€§éã®ç°ãªãããŒã¿ãå«ãããšãã§ããè€éãªæ§é ã§ãããç¹å®ã®ããŒã¿ã®ã¿ã€ãã«ãã£ãŠçµåãããããããã®ããŒã¿ã®ç®¡çãç·åœ¢ã¢ã¯ã»ã¹ã«ãã£ãŠæ£ããç·šæãããŸãã ã€ãŸããé åãäœæããŠé©åãªããŒã¿ãå ¥åãããããã®é åãã¡ãã·ã¥ã«ã¢ã¿ããããå¿ èŠããããŸãã
ã¡ãã·ã¥ãæ§ç¯ããããã«å¿ èŠãªããã€ãã®ããŒã¿åããªã¹ãããŸãã
é ç¹ïŒé ç¹ïŒ-Vector3åã®ããŒã¿ã®é åãã€ãŸããxãyãz軞ã«æ²¿ã£ã1ã€ã®é ç¹ã®ç©ºé座æšã«ãããªããfloatåã®3ã€ã®é£ç¶ããããŒã¿ãå«ãæ§é äœã®é åã§æ§æãããŸãã
é ç¹ã€ã³ããã¯ã¹ãŸãã¯ãã¡ã»ããïŒäžè§åœ¢ïŒ-intããŒã¿åã®é åã§æ§æãããŸãããããã§ã¯æŽæ°ã3ã§1ã€ã®äžè§åœ¢ã«ã°ã«ãŒãåããå¿ èŠãããããšãèæ ®ããå¿ èŠããããŸãã ãã®ç¹ããã詳现ã«æ€èšãããšãå®éã«ã¯ã1ã€ã®äžè§åœ¢ïŒã€ãŸããæå°éã®æç»ããªããã£ãïŒãèšè¿°ããããã«ã3ã€ã®é ç¹ã€ã³ããã¯ã¹ãæå®ããå¿ èŠããããŸãã æåã®3ã€ã®æ°åã¯ãæåã®äžè§åœ¢ã®æç»ã決å®ãã2çªç®ã®3ã€ã®æ°åã¯2çªç®ã®äžè§åœ¢ãæç»ããŸã ãŸããäžè§åœ¢å ã®é ç¹ã®ãã©ããŒã¹ã®é åºã«èšåããããšãéèŠã§ãã é ç¹ïŒã€ãŸããé ç¹ã®ã€ã³ããã¯ã¹ïŒãæèšåãã«ãªã¹ããããšãäžè§åœ¢ããããªããèŠãããã€ãŸãèŠããããããªããã°ãäžè§åœ¢ã¯æç»ãããã衚瀺ãããŸããããèŠèŠçã«å察åŽãããåããå Žåãããã¯ããªãã«èŠããããã«ãªããŸãïŒã€ãŸããæ°ããè§åºŠãããé ç¹ã®åæã¯ãå€åãããæèšåãã«ãªããŸãïŒã ãæ³åã®ãšãããé åå šäœã®å šé·ã¯ãäžè§åœ¢ã®æ°ã«3ãæãããã®ã«çãããªããŸãã
æ³ç·-Vector3åã®ããŒã¿ã®é åã§æ§æãããŸããããã¯ãé ç¹ã«å¯ŸãããåçŽãã®é åã§ãããæ³ç·ã®é åãšé ç¹ã®é åã®æ¬¡å ã¯åãã§ãã åæ³ç·ãã¯ãã«ã®çµ¶å¯Ÿé·ã¯1ã«çãããå®éãé ç¹ã®ãå転è§ãã圢æãããŸãã ãªããããã®æ³ç·ãå¿ èŠãªã®ã§ããïŒ ãããã¯ãäžè§åœ¢ã®ç §æãæ£ããèæ ®ããããã«å¿ èŠã§ãã æ³ç·ãå æºã®ããŒã ãããã³èŠ³å¯è ã®ç®ã®éã®è§åºŠãç¥ã£ãŠãç §æãèšç®ã§ããŸãã æ³ç·ã¯ãæ³å®ãããããã«äžè§åœ¢ã§ã¯ãªããé ç¹ããšã«äœæããã³èšç®ãããŸãã æ³ç·ãäžè§åœ¢ã®ã¿ã«èšå®ãããŠããå Žåãã·ã§ãŒããŒã¯æ³ç·ãäžè§åœ¢ããäžè§åœ¢ã«ã©ã®ããã«å€åããããç¥ããŸããïŒã·ã§ãŒããŒã¯é£æ¥ããäžè§åœ¢ã«ã€ããŠäœãç¥ããªãããïŒããããããæç»ãããã·ã§ã€ãã¯æããèŠããŸãããéåžžã«ãè§åŒµã£ãŠããŸãã å®éãã·ã§ãŒããŒã¯ãåäžè§åœ¢ãåŠçãããšãã«ãé ç¹éã®æ³ç·ãå«ããé ç¹éã®ãã©ã¡ãŒã¿ãäžæ§ã«å€æŽããŸãã ããã«ãããåãäžè§åœ¢å ã§ãç §æã®æ»ãããªå€åãåŸãããŸãã äžè§åœ¢ã®é ç¹ã®æ³ç·ãäºãã«çºæ£ããå Žåãäžè§åœ¢ã¯ãåžãã«èŠããæ³ç·ãåæããå Žåãäžè§åœ¢ã¯ãå¹ãã«ãªããæ³ç·ãå¹³è¡ã®å Žåãäžè§åœ¢ã¯å¹³ãã«ãªããŸãã é£æ¥ããäžè§åœ¢ã¯åãåçã«åºã¥ããŠæ§ç¯ããã察å¿ããé ç¹ã¯æ³ç·ãšäžèŽããŸããäžè§åœ¢ãç°ãªãããè§åºŠã倧ããç°ãªãå Žåãäžè§åœ¢éã®ç§»è¡ã¯æ»ããã«ãªãããããã®éã®å¢çã¯åºå¥ã§ããªããªããŸã
UV座æšïŒuvïŒ-Vector2åã®ããŒã¿ã®é åã§æ§æãããŸããã€ãŸãããã¯ã¹ãã£ã®ãå éšãã®xããã³y座æšã§ããfloatåã®2ã€ã®å€æ°ãå«ãæ§é äœã§ãã ããã§ããã詳现ã«äŒããå¿ èŠããããŸãã ãã¯ã¹ãã£ã®å·Šäžé ã¯ãUV座æšïŒ0ã0ïŒãå·Šäž-ïŒ0ã1ïŒãå³äž-ïŒ1ã1ïŒãããã³å³äž-ïŒ1ã0ïŒã«å¯Ÿå¿ããŠããŸãã [0 ... 1]ã®ç¯å²ã®åº§æšãååŸãããšãæå®ããå€ã«å¿ããŠããã¯ã¹ãã£å šäœãéšåçãŸãã¯å®å šã«æç»ãããŸãã æå®ãããç¯å²å€ã®å€ãåãããšãã§ããæå®ããåæ°ã ããã¯ã¹ãã£ãç¹°ãè¿ãããŸããããšãã°ãuv座æšïŒ2ã3.5ïŒãéžæãããx軞ããã¯ã¹ãã£ã2åãy軞ã3.5åç¹°ãè¿ãããŸãã ãã¯ã¹ãã£ãç¹°ãè¿ãããã«ãããã«å¿ èŠãªãã©ã°ãèšå®ããå¿ èŠããããŸãã å€ãã®å Žåããã©ã°ã¯ããã©ã«ãã§èšå®ãããŠããŸãã uv座æšé åã®æ¬¡å ã¯ãé ç¹é åã®æ¬¡å ãšåãã§ããã€ãŸããåé ç¹ã¯ãã¯ã¹ãã£åº§æšuvã«å¯Ÿå¿ããŸãã
以äžããŸãšããŸãã ã¡ãã·ã¥ãäœæããã³æç»ããã«ã¯ãé ç¹ãé ç¹ã€ã³ããã¯ã¹ãUV座æšãããã³æ³ç·ã®é åãäœæããå¿ èŠããããŸãã
äžã®å³ãèŠããšã座æšã®äžå¿ãåºæºã«ããé·æ¹åœ¢ã®é ç¹ã®é 眮ãæš¡åŒçã«ç€ºããŠããŸãã é·æ¹åœ¢ã®è§ã®è¿ãã«ã¯ãé ç¹ã®ã€ã³ããã¯ã¹ãã€ãŸãé ç¹é åå ã®ã€ã³ããã¯ã¹ããããŸãã å³åœ¢ãäœæãããšãã¯ãåç¹ã«ã幟äœåŠçäžå¿ããæã€å³åœ¢ãäœæããããšããå§ãããŸãã ããã¯ãäºæž¬å¯èœãªçµæã§åœ¢ç¶ãå転ããã³/ãŸãã¯æ¡å€§çž®å°ããå¿ èŠãããå Žåã«äŸ¿å©ã§ãã ã¡ãã·ã¥ãäœæããããå¿ èŠãªæ¹åã«ãã¹ãŠã®é ç¹ãç°¡åã«ç§»åã§ããŸãã
é ç¹ãšã€ã³ããã¯ã¹ã®ã¿ããã¡ãã·ã¥ã®äœæãå§ããŸããããäžèšã®ã¹ã¯ãªãããäŸãšããŠå€æŽããŠãã ããïŒ
ãã¡ã€ã«MyTest.cs
using UnityEngine; using System.Collections; [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] [ExecuteInEditMode] public class MyTest : MonoBehaviour { // public Banner banner = new Banner(); void Start () { } // public void DoRefresh() { // 3 // // 3*1=3 Vector3[] v=new Vector3[3]; // int[] f=new int[3]; // // Mesh tmpMesh; // float w2 = banner.bWidth / 2; // float h2 = banner.bHeight / 2; // // , z v [0] = new Vector3 (-w2, -h2, 0); //0- v [1] = new Vector3 (-w2, h2, 0); //1- v [2] = new Vector3 (w2, h2, 0); //2- // // , // f [0] = 0; f [1] = 1; f [2] = 2; // tmpMesh = new Mesh (); // tmpMesh.vertices = v; // tmpMesh.triangles = f; // , //"" GetComponent<MeshFilter> ().mesh = tmpMesh; } } [System.Serializable] public class Banner { [Range(0.0f, 1.0f)] public float bWidth=0.5f; [Range(0.0f, 1.0f)] public float bHeight=0.5f; }
ã¹ããŒãžäžã«ã空ã®ãã³ã³ããŒãã³ããäœæãïŒGameObject-> Create Emptyã¡ãã¥ãŒïŒãã¹ã¯ãªãããæ·»ä»ããŸãããã³ã¯ã®äžè§åœ¢ã衚瀺ãããã¯ãã§ããäžè§åœ¢ãèŠããªãå Žåã¯ãã³ã³ããŒãã³ãã®åšãã§ã«ã¡ã©ãå転ãããŸãã ã€ã³ã¹ãã¯ã¿ãŒã§ãããŒã®å¹ ãšé«ããå€æŽããŠã¿ãŠãã ãããããã«äžè§åœ¢ã®å€åãèŠããã¯ãã§ãã é·æ¹åœ¢ãäœããŸãããã ãããè¡ãã«ã¯ãDoRefreshïŒïŒã¡ãœããã®å 容ã次ã®ããã«å€æŽããŸãã
MyTest.cs
public void DoRefresh () { // 4 // 0-, 1- 2- // 0-, 2- 3- // 2 , // 3*2=6 Vector3[] v=new Vector3[4]; int[] f=new int[6]; Mesh tmpMesh; float w2 = banner.bWidth / 2; float h2 = banner.bHeight / 2; v [0] = new Vector3 (-w2, -h2, 0); v [1] = new Vector3 (-w2, h2, 0); v [2] = new Vector3 (w2, h2, 0); v [3] = new Vector3 (w2, -h2, 0); //3- // // , // //1- f [0] = 0; f [1] = 1; f [2] = 2; //2- f [3] = 0; f [4] = 2; f [5] = 3; tmpMesh = new Mesh (); tmpMesh.vertices = v; tmpMesh.triangles = f; GetComponent<MeshFilter> ().mesh = tmpMesh; }
ã¹ã¯ãªãããç·šéããUnityç°å¢ã«åãæ¿ããåŸãäžè§åœ¢ã¯é·æ¹åœ¢ã«ãå®æãããŸãã 次ã«ãé·æ¹åœ¢ã®è²ãå€æŽããŸãããã ãããè¡ãã«ã¯ã2ã€ã®å Žæã§ã¹ã¯ãªãããå€æŽããå¿ èŠããããŸãããããªãã¯ã¯ã©ã¹Bannerãäœæãããæäžéšã§ãè¡public Material bannerMaterialãè¿œå ããå¿ èŠããããŸãã ã€ãŸã
public Banner banner = new Banner(); // public Material bannerMaterial;
ãŸããDoRefreshïŒïŒã¡ãœããã®æåŸã«ãGetComponent <MeshRenderer>ïŒïŒ.material = bannerMaterial;ãšããè¡ãè¿œå ããŸãã ã€ãŸã
GetComponent<MeshFilter> ().mesh = tmpMesh; // , GetComponent<MeshRenderer> ().material = bannerMaterial;
ãã®åŸããããªã¢ã«ã¿ã€ãã®å€æ°ãã€ã³ã¹ãã¯ã¿ãŒã«è¡šç€ºããããããªã¢ã«ãå²ãåœãŠãããšãã§ããŸããå€ãå€æŽãããšãé·æ¹åœ¢ã¯ãããªã¢ã«ã®å€æŽãrepaintãã«ããã«å¿çããŸããã1ã€ã®è²ã§å¡ãã€ã¶ãããŸãïŒUnity 4.5.0ã§ã¯ããã¯ã¹ãã£ã®ã·ãã座æšïŒã ããã¯ãUV座æšãã¡ãã·ã¥ã«äžããããªãã£ãããã§ãããããä¿®æ£ããŸãããã DoRefreshïŒïŒã¡ãœããã次ã®ããã¹ãã«å床眮ãæããå¿ èŠããããŸãã
MyTest.cs
public void DoRefresh() { Vector3[] v=new Vector3[4]; int[] f=new int[6]; // uv 4 Vector2[] uv=new Vector2[4]; Mesh tmpMesh; float w2 = banner.bWidth / 2; float h2 = banner.bHeight / 2; v [0] = new Vector3 (-w2, -h2, 0); v [1] = new Vector3 (-w2, h2, 0); v [2] = new Vector3 (w2, h2, 0); v [3] = new Vector3 (w2, -h2, 0); f [0] = 0; f [1] = 1; f [2] = 2; f [3] = 0; f [4] = 2; f [5] = 3; // uv uv [0] = new Vector2 (0, 0); //0- , uv [1] = new Vector2 (0, 1); //1- , uv [2] = new Vector2 (1, 1); //2- , uv [3] = new Vector2 (1, 0); //3- , tmpMesh = new Mesh (); tmpMesh.vertices = v; tmpMesh.triangles = f; tmpMesh.uv = uv; // GetComponent<MeshFilter> ().mesh = tmpMesh; GetComponent<MeshRenderer> ().material = bannerMaterial; }
ããã§ããããªã¢ã«ã«ç»åãæ·»ä»ãããŠããå Žåãé·æ¹åœ¢å šäœã«æ¡å€§ãããŸãã ãããããŸã ãªã¢ãªãºã ã«æ¬ ããŠããŸãã ãªã¢ãªãºã ãè¿œå ããã«ã¯ãã€ã«ãããŒã·ã§ã³ãèæ ®ããå¿ èŠããããŸãããã®ããã«ã¯ãæ³ç·ãäœæããŠã¡ãã·ã¥ã«è¿œå ããå¿ èŠããããŸãã ç¹å®ã®ã±ãŒã¹ã§ã¯ãããã¯ç°¡åã§ãã ã¡ãã·ã¥ã¯XOYå¹³é¢ã«æç»ãããŸããã€ãŸããZ軞ã«åçŽã§ãæ³ç·ã®z座æšã決å®ããããã«æ®ããŸãã æ³ç·ã¯ãé ç¹ãã衚瀺ãããå空éïŒäžè§åœ¢ã®åé¢ã®å空éãæå³ããïŒã«å°éããå¿ èŠããããŸãã DoRefreshïŒïŒã¡ãœãããå床線éããŸãã
MyTest.cs
public void DoRefresh() { Vector3[] v=new Vector3[4]; int[] f=new int[6]; Vector2[] uv=new Vector2[4]; // Vector3[] n = new Vector3[4]; Mesh tmpMesh; float w2 = banner.bWidth / 2; float h2 = banner.bHeight / 2; v [0] = new Vector3 (-w2, -h2, 0); v [1] = new Vector3 (-w2, h2, 0); v [2] = new Vector3 (w2, h2, 0); v [3] = new Vector3 (w2, -h2, 0); f [0] = 0; f [1] = 1; f [2] = 2; f [3] = 0; f [4] = 2; f [5] = 3; uv [0] = new Vector2 (0, 0); uv [1] = new Vector2 (0, 1); uv [2] = new Vector2 (1, 1); uv [3] = new Vector2 (1, 0); // , , // , Z for (int i=0; i<4; i++) { n[i]=new Vector3(0, 0, -1); } tmpMesh = new Mesh (); tmpMesh.vertices = v; tmpMesh.triangles = f; tmpMesh.uv = uv; tmpMesh.normals = n; // GetComponent<MeshFilter> ().mesh = tmpMesh; GetComponent<MeshRenderer> ().material = bannerMaterial; }
ããã§ãå æºã®åŒ·åºŠãç §æã®æ¹åãå€æŽãããšãããã«é·æ¹åœ¢ã®çµæãèŠãããšãã§ããŸãã
ã·ã ã®å Žåãç§ã¯ãèŸåãããŸããèšäºã¯ããªã倧ããããšãå€æããŸãããéç¥ããããã¹ãŠã®ãšã©ãŒããã³äžæ£ç¢ºãªæ å ±ãéä¿¡ããèŠæ±ã
PSïŒã¢ãŒãã£ã¹ãã¯ç§ããã¯åŒ±ãã®ã§ãåè·¯å³ã®æç»ã¯å®å šã«ã¯æããã§ã¯ãªãããšãå€æããŸããããŸãããããžã§ã¯ãã¯åçšã§ããããã建ç©ã®å»ºèšã®å®å šãªãœãŒã¹ã³ãŒããå ¬éããããšã¯ã§ããŸããã