Upgrade to Pro — share decks privately, control downloads, hide ads and more …

StudyUnityFromAnti-pattern

Cova8bitdots
November 20, 2019

 StudyUnityFromAnti-pattern

Unity の使い方のアンチパターンを紹介。
そこからどう解消すべきかを紹介しています

Cova8bitdots

November 20, 2019
Tweet

More Decks by Cova8bitdots

Other Decks in Programming

Transcript

  1. PUBLICม਺໰୊ ໰୊఺ ▸ MonoBehaviour ܧঝΫϥεͰ͸Serializeର৅ʹͳΔ ▸ Unity Ͱ͸ Serialize ର৅ʹͳΔͨΊInspector͔Βฤू͕Մೳ

    ▸ উखʹฤूͤͨ͘͞ͳ͍࣌΋͋Δ
 ▸ ֎෦ʹΑΓ؆୯ʹॻ͖׵͑Մೳ ▸ ϓϩύςΟͰpublic ͳSetter Λఏڙ͍ͯ͠Δ৔߹΋ಉ༷ ▸ ΧϓηϧԽ(৘ใӅṭ)తʹඇৗʹϚζΠ
 جຊతʹ֎෦ΫϥεʹΑΔ௚઀ૢ࡞͸ةݥ
  2. PUBLICม਺໰୊ ղফ๏ ▸ MonoBehaviour ܧঝΫϥεͰ͸Serializeର৅ʹͳΔ ▸ [SerializeField] private / protected

    ʹ͠·͠ΐ͏ ▸ Public ม਺ఆٛ͸ۃྗආ͚Δ ▸ SDKͱ͔Ͱ͸ฏؾͰ࢖ͬͯͨΓ͠·͢ΑͶ…(খ੠) 
 ▸ ֎෦ʹΑΓ؆୯ʹॻ͖׵͑Մೳ ▸ Getter ͷެ։͸OK ▸ Setter ͸ϝιουͰදݱ ▸ τϨʔαϏϦςΟͷ؍఺ΑΓ
 ϓϩύςΟΑΓϝιουͷํ͕Φεεϝ
  3. PUBLICม਺໰୊ PUBLICม਺ͷར༻έʔε ▸ σʔλߏ଄ (ΤϯςΟςΟ) ͷදݱ ▸ ग़དྷΕ͹Getter/Setter ܦ༝͕๬·͍͕͠
 ৔߹ʹΑͬͯ͸ެ։͠ͳ͚Ε͹͍͚ͳ͍͜ͱ΋͋Δ

    ▸ ΠϯλʔϑΣʔεܦ༝΋OK ▸ μϛʔίʔυ/αϯϓϧίʔυ࡞੒࣌ʹ༻͍Δ ▸ ग़དྷΕ͹࢖Θͳ͍ํ͕ྑ͍ ▸ αΫοͱઆ໌͢Δ෼ʹ͸࢖͏͜ͱ΋͋Δ
  4. PUBLICม਺໰୊ ໰୊఺ ▸ ԿͰ΋͔ΜͰ΋ࢀরΛInspector Ͱͷઃఆͯ͠͠·͏ ▸ ࣗ਎ͷPrefabҎ֎ͷཁૉ ▸ ґଘؔ܎͕ΊͪΌͪ͘Ό ▸

    ॳظԽʹऑ͍
 ▸ PrefabԽͨ͠ͱ͖ʹґଘ͕ണ͕ΕΔ ▸ ϖλϖλషΔཁૉ͕ଟ͍ͱΞλον΋Ұۤ࿑
  5. PUBLICม਺໰୊ ղܾ๏ ▸ Inspector Ͱొ࿥͢΂͖΋ͷ ▸ ࣗ਎ҎԼͷཁૉ ▸ ಈతੜ੒͢ΔPrefab ▸

    ґଘੑͷղܾ ▸ ͪΌΜͱઃܭ͢Δʂ ▸ Ͳ͏ͯ͠΋ݫ͍͠৔߹͸Zenject ͳͲͷDI ίϯςφΛ༻͍Δ
  6. AWAKE / START ໰୊ ▸ ͱΓ͋͑ͣॳظԽ͸Awake/StartͰߦ͏ ▸ ֤ॴͰݺͼ͗ͯ͢Awake ͷ
 ࣮ߦॱʹґଘੑ͕ੜ͡Δ


    
 
 ▸ ࢖Θͳ͍Awake()/Start()/Update() ▸ ਺͕ଟ͍ͱݺͼग़͠ίετ͕
 അࣛʹͳΒͳ͍(ಛʹUpdate) ໰୊఺
  7. AWAKE / START ໰୊ ▸ ґଘੑͷ͋ΔॳظԽ ▸ ॳظԽؔ਺Λ༻ҙ͢Δ
 
 


    
 
 ▸ ॳظԽॲཧΛ؅ཧ͢Δ
 
 
 ໰୊఺ͷղফ๏
  8. Ξϯνύλʔϯྫ Public ม਺໰୊ Prefab ͷ SerializeField ໰୊ Awake / Start

    ໰୊ ิؒؔ਺ ໰୊ ໊લۭؒ ໰୊ Shader ໰୊
  9. ิؒؔ਺ ໰୊ ▸ Ґஔߋ৽Ͱ͜Μͳίʔυ͕
 
 
 
 ▸ Lerp/Slerp ͸਺ֶతʹ͸ʮ಺෼఺ʯΛܭࢉ͢Δؔ਺

    ▸ ͔֬ʹdeltaTime ͷׂ߹Ͱগͣͭ͠໨ඪʹۙͮ͘ ▸ ແݶ͔͚࣌ؒͳ͍ͱ࠷ऴ஋ʹ͸ͳΒͳ͍ ▸ ͦ΋ͦ΋0.033/0.016 ͣͭۙͮ͘ॲཧ͸ద੾͔ʁ ▸ ॲཧམͪͳͲ͢Δͱׂۙͮ͘߹΋ಈతʹมΘͬͯ͠·͏ ໰୊఺
  10. SHADER ໰୊ ▸ ϐΫηϧγΣʔμʔ಺Ͱͷॲཧͷॏ͍ؔ਺ ▸ ifจ ▸ ܰྔͳ਺ֶؔ਺Ͱ୅ΘΓͷදݱ
 ex) ceil(clamp(_value,

    0, 1)) _value ͕ෛ:0, ਖ਼:1
 uvͰv ͕0.5 Ҏ্͔Ͳ͏͔ˠ ceil(clamp(i.uv.y - 0.5, 0, 1)) ▸ ࡾ֯ؔ਺( Sin,Cos,Tan ) ▸ ࡾ֯ؔ਺ςʔϒϧΛ࡞੒/ςΫενϟʹॻ͖ࠐΜͰ͓͘ ▸ r=Sin, g=Cos, b = Tan ▸ Log, Sqrt ͳͲ ▸ ۃྗ࢖Θͳ͍ ▸ Sqrt ͷ୅ΘΓʹೋ৐ͰൺֱͳͲ ղফ๏
  11. ࠷ޙʹ ▸ υΩϡϝϯτ͸ͪΌΜͱಡΈ·͠ΐ͏ ▸ Θ͔Βͳ͍͚Ͳ࢖ͬͯΈͨ͸NG
 ▸ ઃܭΛͪΌΜͱߟ͑·͠ΐ͏ ▸ ಛʹӡ༻ίϯςϯπͳͲ͸ޙʑͰͬ͠΃ฦ͕͖͠·͢ ▸

    ٕज़తෛ࠴ͱ޲͖߹͍·͠ΐ͏ ▸ ύϑΥʔϚϯεΛؾʹ͠·͠ΐ͏ ▸ ৭ʑݕূهࣄͳͲΛ୳ͯ͠Έ·͠ΐ͏ ▸ ͳ͚Ε͹ࣗ෼Ͱܭଌͯ͠Έ·͠ΐ͏ ▸ ग़དྷΕ͹ͦͷ݁ՌΛγΣΞͯ͠΋Β͑Δͱ
 ΈΜͳ͕޾ͤʹͳΓ·͢ ·ͱΊ