万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

git ハッシュ値指定で対象のファイルを見る

長いけどこんな感じ

git diff-tree --no-commit-id --name-only -r 71dc1bfd0

Go言語のテンプレートで文字列比較

hoge変数がbarという文字と比較。 {{ if $hoge eq “bar” }}ではない。ポーランド記法

{{ if eq $hoge "bar" }}

{{else}}

{{end}}

ja.stackoverflow.com

Animator.ResetTrigger

Unity - スクリプトリファレンス: Animator.ResetTrigger

全てのトリガーをリセットしたいのに、1つをピンポイントで指定。面倒。 Animatorの拡張メソッドがあるといい。

    /// <summary>
    /// Triggger全てリセット.
    /// </summary>
    /// <param name="self">Self.</param>
    public static void ResetTriggers(this Animator self)
    {
        foreach(AnimatorControllerParameter animatorControllerParameter in self.parameters) {
            if(animatorControllerParameter.type == AnimatorControllerParameterType.Trigger)
            {
                self.ResetTrigger(animatorControllerParameter.name);
            }
        }
    }

これでthis.animator.ResetTriggers();

Vector3.Angle Unity実行

     public static float Angle(Vector3 from, Vector3 to)
        {
            return Mathf.Acos(Mathf.Clamp(Vector3.Dot(from.normalized, to.normalized), -1f, 1f)) * 57.29578f;
        }
            float judgeAngle = Vector3.Angle(Vector3.zero, Vector3.zero);
            Debug.Log(judgeAngle);

            judgeAngle = Vector3.Angle(Vector3.right, Vector3.zero);
            Debug.Log(judgeAngle);

            judgeAngle = Vector3.Angle(Vector3.zero, Vector3.right);
            Debug.Log(judgeAngle);

            judgeAngle = Vector3.Angle(Vector3.zero, Vector3.right);
            Debug.Log(judgeAngle);

            judgeAngle = Vector3.Angle(Vector3.zero, new Vector3(13, 441, 45));
            Debug.Log(judgeAngle);

            judgeAngle = Vector3.Angle(new Vector3(13, 441, 45), Vector3.zero);
            Debug.Log(judgeAngle);

            judgeAngle = Vector3.Angle(Vector3.forward, Vector3.zero);
            Debug.Log(judgeAngle);

            judgeAngle = Vector3.Angle(Vector3.back, Vector3.zero);
            Debug.Log(judgeAngle);

            judgeAngle = Vector3.Angle(Vector3.zero, Vector3.up);
            Debug.Log(judgeAngle);
// => ここまで90

            judgeAngle = Vector3.Angle(Vector3.right, Vector3.left);
            Debug.Log(judgeAngle);
// => 180

            judgeAngle = Vector3.Angle(Vector3.left, Vector3.left);
            Debug.Log(judgeAngle);
// => 0

            judgeAngle = Vector3.Angle(Vector3.right, Vector3.right);
            Debug.Log(judgeAngle);
// => 0