Gamerch
あかさ

スマホタッチFX

最終更新日時 :
1人が閲覧中
作成者: ユーザー98083
最終更新者: ユーザー98083

キーボード応用

using System.Collections.Generic;

using UnityEngine;

public class スマホタッチFX : MonoBehaviour

{

void Start()

{タッチボタン管理.初期化();}


void Update()

{ タッチボタン管理.更新(); }

}



public static class 指押すFX

{


public static bool タッチ1, タッチ2, タッチ3, タッチ4, タッチ5;

}


public static class 指入力FX

{

public static bool タッチ1, タッチ2, タッチ3, タッチ4, タッチ5;

}


public static class 指離すFX

{

public static bool タッチ1, タッチ2, タッチ3, タッチ4, タッチ5;

}




public static class タッチ位置

{

public static Vector2 タッチ1, タッチ2, タッチ3, タッチ4, タッチ5;

}



public static class タッチボタン管理

{

const int 最大タッチ数 = 5;

static int[] エリア担当指 = new int[最大タッチ数 + 1];




static int エリアからタッチ番号(Vector2 pos)

{

float w = Screen.width;

float h = Screen.height;


if (pos.y > h * 0.66f)

return 3;


if (pos.x < w * 0.5f)

return 1;


return 2;

}



public static void 初期化()

{

for (int i = 1; i <= 最大タッチ数; i++)

{

string 名 = $"タッチ{i}";

設定(typeof(指押すFX), 名, false);

設定(typeof(指入力FX), 名, false);

設定(typeof(指離すFX), 名, false);

設定位置(typeof(タッチ位置),名, Vector2.zero);

エリア担当指[i] = -1;

}

}


public static void リセット()

{

for (int i = 1; i <= 最大タッチ数; i++)

{

string 名 = $"タッチ{i}";

設定(typeof(指押すFX), 名, false);

設定(typeof(指入力FX), 名, false);

設定(typeof(指離すFX), 名, false);

}

}




public static void 更新()

{

int count = Input.touchCount;


for (int i = 0; i < count; i++)

{

Touch t = Input.GetTouch(i);

int 指ID = t.fingerId;

int 番号 = エリアからタッチ番号(t.position);

string 名 = $"タッチ{番号}";

設定位置(typeof(タッチ位置),名, t.position);


if (エリア担当指[番号] != -1 && エリア担当指[番号] != 指ID)

{continue; }

if (エリア担当指[番号] == -1)

{エリア担当指[番号] = 指ID;}



if (t.phase == TouchPhase.Began)

設定(typeof(指押すFX), 名, true);

if (t.phase == TouchPhase.Began||t.phase == TouchPhase.Moved || t.phase == TouchPhase.Stationary)

設定(typeof(指入力FX), 名, true);

if (t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled)

{設定(typeof(指離すFX), 名, true);エリア担当指[番号] = -1; }

}

}



static void 設定(System.Type クラス, string 名, bool 値)

{

クラス.GetField(名).SetValue(null, 値);

}


static void 設定位置(System.Type クラス,string 名, Vector2 値)

{

クラス.GetField(名).SetValue(null, 値);

}

}


最後

using System.Collections;

using System.Collections.Generic;

using UnityEngine;



public class スマホタッチFX最後 : MonoBehaviour

{

void Start()

{ }


void FixedUpdate()

{

タッチボタン管理.リセット();

}

}

コメント (スマホタッチFX)
  • 総コメント数0
この記事を作った人
やり込み度

Wikiにゲームが紐づいていません

編集者紹介

未登録

注目記事
ページトップへ