Skip to content

Instantly share code, notes, and snippets.

@keijiro
Created September 27, 2022 07:00
Show Gist options
  • Save keijiro/a798c3d34045940789a78e27910f7490 to your computer and use it in GitHub Desktop.
Save keijiro/a798c3d34045940789a78e27910f7490 to your computer and use it in GitHub Desktop.

Revisions

  1. keijiro created this gist Sep 27, 2022.
    72 changes: 72 additions & 0 deletions TupleTest.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    using UnityEngine;

    sealed class Test : MonoBehaviour
    {
    float life;

    void Test1()
    {
    (float, int) attack = (3.5f, 8);
    life -= attack.Item1 * attack.Item2;
    }

    void Test2()
    {
    (float power, int count) attack = (3.5f, 8);
    life -= attack.power * attack.count;
    }

    void Test3()
    {
    var (power, count) = (3.5f, 8);
    life -= power * count;
    }

    void Test4()
    {
    var attack = (power: 3.5f, count: 8);
    life -= attack.power * attack.count;
    }

    bool CheckCollision(Vector3 c, float r, out Vector3 point)
    {
    point = Vector3.zero;
    return true;
    }

    (bool hit, Vector3 point) CheckCollision(Vector3 c, float r)
    {
    return (true, c);
    }

    struct Data { public bool hit; public Vector3 point; }

    bool Test5()
    {
    Data obj1, obj2;
    (obj1.hit, obj2.point) = CheckCollision(Vector3.zero, 1);
    return obj1.hit;
    }

    bool Test6()
    {
    var (hit, _) = CheckCollision(Vector3.zero, 1);
    return hit;
    }

    void Swap1(ref int a, ref int b)
    {
    var temp = a;
    a = b;
    b = a;
    }

    void Swap2(ref int a, ref int b)
    {
    (a, b) = (b, a);
    }

    void Start()
    {
    }
    }