コミュ障だから明日が僕らをよんだって返事もろくにしなかった

何かを創る人に憧れたからブログをはじめたんだと思うよ

おくりびと(※タイトルと記事内容は一切関係ありません)

僕はこういうテキスト送りを作りたいんだよ!

僕はバーバルコミュニケーションとかいうやつが致命的に苦手で口で説明することが出来ないのだ。だから、まずはこれを見てほしい。
f:id:andron:20191011002817g:plain
そう、僕は海外のインディーズゲームとかでよくでてくるこのふにゃふにゃ動きながら文字送りをするアニメーションが作りたかったんだよ!んでAviUtilいじっててようやく作れたわけだ。やっとできた。そして夜になってた。んでですね。僕は鳥頭に定評があるので、ここに記事投稿をしないとどうやって作るのか忘れてしまうので備忘録を兼ねた投稿をしようと思う。

つくりかた

まずAviUtilを起動して[メディアオブジェクトの追加 -> フィルタ効果の追加 -> スクリプト制御]を選択します。
f:id:andron:20191011003433p:plain

んでスクリプトに以下の記述をします。

l = 2.5
r = 360*obj.time/2
obj.ox = obj.ox + math.sin(r*math.pi/180)*l
obj.oy = obj.oy - math.cos(r*math.pi/180)*l

んでテキストの[文字毎の個別オブジェクト]にチェックします。
f:id:andron:20191011004414p:plain

これで先ほどの文字送りができます。やったぜ!


おわり。


今日は勢いだけでブログ書いてしまった……。むしゃくしゃしてやった。反省はしていない。

おくりびと [DVD]

おくりびと [DVD]

びぎなーいずふぉーえばー

おわらせた

はい、おはようございます。そんなわけでポエム投稿兼Unityチュートリアル進捗報告用に使っていた連続エントリーをみなさまの熱い声援(?)のおかげでおわらせることができました。

以前の記事
inujini.hatenablog.com


それではお作法の確認を

今回はただの終了報告なのでポエムはなしです。なしだけど終わらせたので早速やっていきたいと思います。

22. クラス
前回どこまで進んでたか分かりませんが、クラスの使い方についてのお話からはじめていきます。

using UnityEngine;
using System.Collections;

public class SingleCharacterScript : MonoBehaviour
{
    public class Stuff
    {
        public int bullets;
        public int grenades;
        public int rockets;
        
        public Stuff(int bul, int gre, int roc)
        {
            bullets = bul;
            grenades = gre;
            rockets = roc;
        }
    }
       
    public Stuff myStuff = new Stuff(10, 7, 25);
    public float speed;
    public float turnSpeed;
    public Rigidbody bulletPrefab;
    public Transform firePosition;
    public float bulletSpeed;
    
    
    void Update ()
    {
        Movement();
        Shoot();
    }
       
    void Movement ()
    {
        float forwardMovement = Input.GetAxis("Vertical") * speed * Time.deltaTime;
        float turnMovement = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
        
        transform.Translate(Vector3.forward * forwardMovement);
        transform.Rotate(Vector3.up * turnMovement);
    }
       
    void Shoot ()
    {
        if(Input.GetButtonDown("Fire1") && myStuff.bullets > 0)
        {
            Rigidbody bulletInstance = Instantiate(bulletPrefab, firePosition.position, firePosition.rotation) as Rigidbody;
            bulletInstance.AddForce(firePosition.forward * bulletSpeed);
            myStuff.bullets--;
        }
    }
}




using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour
{
    public class Stuff
    {
        public int bullets;
        public int grenades;
        public int rockets;
        public float fuel;
        
        public Stuff(int bul, int gre, int roc)
        {
            bullets = bul;
            grenades = gre;
            rockets = roc;
        }
        
        public Stuff(int bul, float fu)
        {
            bullets = bul;
            fuel = fu;
        }
        
        public Stuff ()
        {
            bullets = 1;
            grenades = 1;
            rockets = 1;
        }
    }
    
    // Stuffクラスより
    public Stuff myStuff = new Stuff(50, 5, 5);
    public Stuff myOtherStuff = new Stuff(50, 1.5f);
    void Start()
    {
        Debug.Log(myStuff.bullets); 
    }
}




using UnityEngine;
using System.Collections;

public class MovementControls : MonoBehaviour
{
    public float speed;
    public float turnSpeed;
        
    void Update ()
    {
        Movement();
    }

    void Movement ()
    {
        float forwardMovement = Input.GetAxis("Vertical") * speed * Time.deltaTime;
        float turnMovement = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
        
        transform.Translate(Vector3.forward * forwardMovement);
        transform.Rotate(Vector3.up * turnMovement);
    }
}




using UnityEngine;
using System.Collections;

public class Shooting : MonoBehaviour
{
    public Rigidbody bulletPrefab;
    public Transform firePosition;
    public float bulletSpeed;   
    private Inventory inventory;
       
    void Awake ()
    {
        inventory = GetComponent<Inventory>();
    }
       
    void Update ()
    {
        Shoot();
    }
   
    void Shoot ()
    {
        if(Input.GetButtonDown("Fire1") && inventory.myStuff.bullets > 0)
        {
            Rigidbody bulletInstance = Instantiate(bulletPrefab, firePosition.position, firePosition.rotation) as Rigidbody;
            bulletInstance.AddForce(firePosition.forward * bulletSpeed);
            inventory.myStuff.bullets--;
        }
    }
}


雑にクラス図をつくってみる。多分こんな感じ、つながりがない……。Unity特有のStart()とかRigidbodyとかそういうのを加えた方がいいのだろうか……。それをやるとごちゃごちゃしてきて何をしたい設計なのか分からなくなる気がする……。まあ、大規模なもの作ったことないからいらぬ心配なんですけどね(笑)。


23. Instantiate

オブジェクトの生成とかにかかわるInstantiateな話。

using UnityEngine;
using System.Collections;
public class UsingInstantiate : MonoBehaviour
{
    public Rigidbody rocketPrefab;
    public Transform barrelEnd;
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Rigidbody rocketInstance;
            // オブジェクトの生成
            rocketInstance = Instantiate(rocketPrefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
            rocketInstance.AddForce(barrelEnd.forward * 5000);
        }
    }
}
using UnityEngine;
using System.Collections;

public class RocketDestruction : MonoBehaviour
{
    void Start()
    {
        // オブジェクトの破壊
        Destroy(gameObject, 1.5f);
    }
}

―と、おまけのデストロイ。


24. Array

なんで後半で配列の話なんだろう。

using UnityEngine;
using System.Collections;

public class Arrays : MonoBehaviour
{
    public GameObject[] players;
    void Start ()
    {
        players = GameObject.FindGameObjectsWithTag("Player");
        for(int i = 0; i < players.Length; i++)
        {
            Debug.Log("Player Number "+i+" is named "+players[i].name);
        }
    }
}

複雑なことをやろうとすると事故るやつだけど、この例だと特に話すことは多分ないです。


25. Invoke
僕の中ではJavaScriptsetTimeoutみたいな認識のやつ。個人的にInvokeって単語はPowerShellの方でよく見かける。あっちはこういう機能なかった気がするけど……。

using UnityEngine;
using System.Collections;
public class InvokeScript : MonoBehaviour
{
    public GameObject target;
    void Start()
    {
        // SpawnObject()
        Invoke("SpawnObject", 2);
    }
    void SpawnObject()
    {
        Instantiate(target, new Vector3(0, 2, 0), Quaternion.identity);
    }
}
using UnityEngine;
using System.Collections;

public class InvokeRepeating : MonoBehaviour
{
    public GameObject target;
    void Start()
    {
        // SpawnObject()
        InvokeRepeating("SpawnObject", 2, 1);
    }

    void SpawnObject()
    {
        float x = Random.Range(-2.0f, 2.0f);
        float z = Random.Range(-2.0f, 2.0f);
        Instantiate(target, new Vector3(x, 2, z), Quaternion.identity);
    }
}

とりあえず該当部分にコメントを入れてはみたものの語ることがない。細かい仕様はリファレンス見ておけばいいような気がする。
MonoBehaviour-Invoke - Unity スクリプトリファレンス
MonoBehaviour-InvokeRepeating - Unity スクリプトリファレンス



26. Enumerations

僕の中ではIDEに任意の文字列を紐づけて補間させるためのタグみたいな認識。次に出てくるSwitch文と併用して使用すると良い感じに使えるって思ってる。IDE使わなければ不要な存在なのでとも思ってたりする……、補間しないし。

using UnityEngine;
using System.Collections;

public class EnumScript : MonoBehaviour 
{
    enum Direction {North, East, South, West};
        void Start () 
    {
        Direction myDirection;
        
        myDirection = Direction.North;
    }   
    Direction ReverseDirection (Direction dir)
    {
        if(dir == Direction.North)
            dir = Direction.South;
        else if(dir == Direction.South)
            dir = Direction.North;
        else if(dir == Direction.East)
            dir = Direction.West;
        else if(dir == Direction.West)
            dir = Direction.East;       
        return dir;     
    }
}


27. Switch Statements

なぜか最後はSwitch文。僕の中ではラベル付きif文。

using UnityEngine;
using System.Collections;

public class ConversationScript : MonoBehaviour 
{
    public int intelligence = 5;
    void Greet()
    {
        switch (intelligence)
        {
        case 5:
            print ("Why hello there good sir! Let me teach you about Trigonometry!");
            break;
        case 4:
            print ("Hello and good day!");
            break;
        case 3:
            print ("Whadya want?");
            break;
        case 2:
            print ("Grog SMASH!");
            break;
        case 1:
            print ("Ulg, glib, Pblblblblb");
            break;
        default:
            print ("Incorrect intelligence level.");
            break;
        }
    }
}

例文のintelligence分岐、文章内容酷すぎるんだけど元ネタあったりするんですかね?

てことで終了です。
f:id:andron:20191009211434p:plain


今回はポエムはなしのでこれで終了です。おそまつさまでした!

ずしゅ

ずしゅらねば生き残れない

突然だけど今日はこれについての雑談をしようと思う。
www.zsh.org
そう "ずしゅ"(ズィーシェル、Z shell、zsh)。ズィーシェルとか横に表記しているけども正しい読み方はずしゅ(僕調べ)だ!誰が何と言おうと「ずしゅ」だ!

ということで、まずこいつが何かですが。

Z shell(ズィーシェル、zsh)はUnixのコマンドシェルの1つである。 対話的なログインコマンドシェルとしても、強力なシェルスクリプトコマンドのインタープリターとしても使うことができる。

zsh は数多くの改良を含んだBourne Shellの拡張版という見方もできる。のみならず、bashkshtcshの非常に有用な機能も一部取り込まれている。また、Windows上でネイティブUnix環境を提供する Interix サブシステム上ではUnix版のソースコードをビルドしてWindows上で使用することができる。

はい、シェル方言の一つです。そのほかの深いことは知らないです。なのでこれから触っていきます。


さわってみる

てなわけでインストールだけしてみます。こまかい便利カスタマイズは多分やさしい有識者的な人がコメント欄でアドバイスしたり、これが最強の設定ファイルだって言ってコメント欄に貼り付けるだろうからそれまでは適当に扱います(他力本願)。

# インストール
$ sudo apt install zsh

# 利用と初回利用メッセージ
$ zsh
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses ---

Aborting.
The function will be run again next time.  To prevent this, execute:
  touch ~/.zshrc

#バージョン確認
% zsh --version
zsh 5.4.2

インストールとかはこれで、初期起動時の画面ですとかカスタマイズとかは.zshrcしましょうってこと書いてます。

んで、カスタマイズはしないって言ったけども自分で細かいカスタマイズしたければArch LinuxWikiだけどこの辺みればいいんじゃないかなって思う。あと使い方とか公式のユーザガイドで(丸投げ)。
Zsh - ArchWiki
A User's Guide to the Z-Shell

結局のところカスタマイズして使わない場合はそんなにbashとそこまで気にしなくても良いような気がする……。

おわり