Skip to content

Commit d64bd87

Browse files
committed
GameObjectからPhysicsLayerにアクセスするための拡張メソッドを追加
1 parent 79ed595 commit d64bd87

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System;
5+
using UnityEngine;
6+
7+
namespace a3geek.PhysicsLayers
8+
{
9+
using Layers.Abstracts;
10+
11+
public static class GameObjectExtension
12+
{
13+
private static Dictionary<GameObject, AbstractLayer> Dic = new Dictionary<GameObject, AbstractLayer>();
14+
15+
16+
public static int PhysicsLayer(this GameObject obj, bool containsUnityLayer = true)
17+
{
18+
AbstractLayer layer = null;
19+
if(!(Dic.TryGetValue(obj, out layer) == true && layer != null))
20+
{
21+
layer = obj.GetComponent<AbstractLayer>();
22+
}
23+
24+
if(layer == null || (containsUnityLayer == false && layer.LayerID < LayersManager.UnityLayerCount))
25+
{
26+
return -1;
27+
}
28+
29+
Dic[obj] = layer;
30+
return layer.LayerID;
31+
}
32+
}
33+
}

Assets/PhysicsLayers/Scripts/Common/GameObjectExtension.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/PhysicsLayers/Version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.2
1+
2.4.2

0 commit comments

Comments
 (0)