Skip to content

Commit 1b406ae

Browse files
committed
InspectorにDeleteボタンを追加し、既存のPhysics Settingの複製機能を追加。
1 parent 2360079 commit 1b406ae

22 files changed

+297
-267
lines changed

Assets/PhysicsLayers/Editor/LayersManagerInspector.Drawers.cs

+8-10
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ namespace a3geek.PhysicsLayers.Editors
88
{
99
using Common;
1010
using Components;
11-
12-
using LayerDic = Dictionary<Components.LayerID, string>;
1311

1412
public partial class LayersManagerInspector
1513
{
1614
private List<bool> collInfosFolders = new List<bool>();
1715

1816

19-
private void DrawPhysicsLayers(LayerDic layers)
17+
private void DrawPhysicsLayers(Dictionary<int, string> layers)
2018
{
2119
EditorGUI.indentLevel += 1;
2220

@@ -32,21 +30,21 @@ private void DrawPhysicsLayers(LayerDic layers)
3230

3331
EditorGUILayout.Space();
3432

35-
var layerIDs = new List<LayerID>(layers.Keys);
33+
var layerIDs = new List<int>(layers.Keys);
3634
foreach(var layerID in layerIDs)
3735
{
3836
using(var hori = new EditorGUILayout.HorizontalScope())
3937
{
4038
var layerName = layers[layerID];
4139

42-
EditorGUILayout.PrefixLabel("Layer ID : " + layerID.ID);
40+
EditorGUILayout.PrefixLabel("Layer ID : " + layerID);
4341
layers[layerID] = EditorGUILayout.DelayedTextField(layerName);
4442

4543
if(string.IsNullOrEmpty(layers[layerID]) == true)
4644
{
4745
layers[layerID] = layerName;
4846
}
49-
47+
5048
if(GUILayout.Button("Delete"))
5149
{
5250
layers.Remove(layerID);
@@ -75,14 +73,14 @@ private void DrawCollInfos(PhysicsLayerInfos layerInfos)
7573
}
7674

7775
var collInfos = physicsLayer.CollisionInfos;
78-
76+
7977
EditorGUI.indentLevel += 1;
8078
using(var vert = new EditorGUILayout.VerticalScope())
8179
{
8280
var keys = collInfos.Keys.OrderBy(info => info);
8381
var unityKeys = keys.Where(key => key < LayersManager.UnityLayerCount);
8482
var physicsKeys = keys.Where(key => key >= LayersManager.UnityLayerCount);
85-
83+
8684
EditorGUILayout.LabelField("Layers");
8785
foreach(var key in unityKeys)
8886
{
@@ -112,11 +110,11 @@ private void DrawCollInfos(PhysicsLayerInfos layerInfos)
112110
EditorGUI.indentLevel -= 1;
113111
}
114112

115-
private bool DrawCollInfo(LayerID layerID, bool collision)
113+
private bool DrawCollInfo(int layerID, bool collision)
116114
{
117115
using(var hori = new EditorGUILayout.HorizontalScope())
118116
{
119-
EditorGUILayout.PrefixLabel(this.Target.LayerToName(layerID) + " : " + layerID.ID);
117+
EditorGUILayout.PrefixLabel(this.Target.LayerToName(layerID));
120118
return EditorGUILayout.Toggle(collision);
121119
}
122120
}

Assets/PhysicsLayers/Editor/LayersManagerInspector.cs

+17-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public override void OnInspectorGUI()
3939
this.UpdateLayer(physicsLayerInfos, physicsLayers);
4040
this.SetDirty();
4141
}
42+
else
43+
{
44+
this.UpdateLayer(physicsLayerInfos, physicsLayers);
45+
}
4246
}
4347

4448
if(physicsLayerInfos.LayerCount <= 0)
@@ -67,12 +71,22 @@ public override void OnInspectorGUI()
6771
Undo.IncrementCurrentGroup();
6872
}
6973

70-
private void UpdateLayer(PhysicsLayerInfos target, Dictionary<LayerID, string> physicsLayers)
74+
private void UpdateLayer(PhysicsLayerInfos infos, Dictionary<int, string> physicsLayers)
7175
{
72-
target.Update(physicsLayers);
76+
infos.Update(physicsLayers, true);
7377

78+
physicsLayers = infos.Layers;
7479
physicsLayers.AddRange(this.Target.UnityLayerInfos.Layers);
75-
target.GetEnumerable().ToList().ForEach(infos => infos.Update(physicsLayers.Keys.ToList()));
80+
81+
this.UpdateLayerCollision(infos, physicsLayers.Keys);
82+
}
83+
84+
private void UpdateLayerCollision(PhysicsLayerInfos infos, IEnumerable<int> layers)
85+
{
86+
foreach(var layer in infos.GetEnumerable())
87+
{
88+
layer.Update(layers);
89+
}
7690
}
7791
}
7892
}
8.06 KB
Binary file not shown.

Assets/PhysicsLayers/Scripts/Common/DictionaryExtension.cs

+5-10
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,26 @@ namespace a3geek.PhysicsLayers.Common
88
{
99
public static class DictionaryExtension
1010
{
11-
public static void ForEach<T1, T2>(this Dictionary<T1, T2> source, Action<KeyValuePair<T1, T2>> action)
11+
public static List<T3> ToList<T1, T2, T3>(this Dictionary<T1, T2> source, Func<KeyValuePair<T1, T2>, T3> converter)
1212
{
13+
var list = new List<T3>();
1314
foreach(var pair in source)
1415
{
15-
action(pair);
16+
list.Add(converter(pair));
1617
}
17-
}
18-
19-
public static List<T3> ToList<T1, T2, T3>(this Dictionary<T1, T2> source, Func<KeyValuePair<T1, T2>, T3> converter)
20-
{
21-
var list = new List<T3>();
22-
source.ForEach(pair => list.Add(converter(pair)));
2318

2419
return list;
2520
}
2621

2722
public static void AddRange<T1, T2>(this Dictionary<T1, T2> source, Dictionary<T1, T2> other)
2823
{
29-
other.ForEach(pair =>
24+
foreach(var pair in other)
3025
{
3126
if(source.ContainsKey(pair.Key) == false)
3227
{
3328
source.Add(pair.Key, pair.Value);
3429
}
35-
});
30+
}
3631
}
3732

3833
public static void SetCount<T1, T2>(this Dictionary<T1, T2> source, int count, Func<int, T1> defaultKey, Func<int, T2> defaultValue)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using System;
5+
using System.Linq;
6+
7+
namespace a3geek.PhysicsLayers.Components
8+
{
9+
[Serializable]
10+
public abstract class AbstractLayer : ILayer
11+
{
12+
public int LayerID
13+
{
14+
get { return this.layerID; }
15+
internal set { this.layerID = this.AdjustLayerID(value, this.IsPhysicsLayer()); }
16+
}
17+
18+
public abstract string LayerName { get; internal set; }
19+
20+
[SerializeField]
21+
private int layerID = 0;
22+
23+
24+
public abstract bool IsPhysicsLayer();
25+
26+
protected int AdjustLayerID(int layerID, bool isPhysicsLayer)
27+
{
28+
return isPhysicsLayer == true ?
29+
Mathf.Max(LayersManager.UnityLayerCount, layerID) : // 32 ~
30+
Mathf.Min(LayersManager.UnityLayerCount - 1, Mathf.Max(0, layerID)); // 0 ~ 31
31+
}
32+
}
33+
}

Assets/PhysicsLayers/Scripts/Components/LayerID.cs.meta Assets/PhysicsLayers/Scripts/Components/AbstractLayer.cs.meta

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/PhysicsLayers/Scripts/Components/AbstractLayerInfos.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public T this[string layerName]
1919
}
2020

2121
public abstract int LayerCount { get; }
22-
public abstract Dictionary<LayerID, string> Layers { get; }
23-
public abstract List<LayerID> LayerIDs { get; }
24-
public abstract List<string> LayerNames { get; }
22+
public abstract Dictionary<int, string> Layers { get; }
23+
public abstract IEnumerable<int> LayerIDs { get; }
24+
public abstract IEnumerable<string> LayerNames { get; }
2525

2626
[SerializeField]
2727
protected List<T> layers = new List<T>();
@@ -36,7 +36,7 @@ public virtual string LayerToName(int layerID)
3636
public virtual int NameToLayer(string layerName)
3737
{
3838
var layer = this[layerName];
39-
return layer == null ? -1 : layer.LayerID.ID;
39+
return layer == null ? -1 : layer.LayerID;
4040
}
4141

4242
public virtual IEnumerable<T> GetEnumerable()

Assets/PhysicsLayers/Scripts/Components/ILayer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace a3geek.PhysicsLayers.Components
88
{
99
public interface ILayer
1010
{
11-
LayerID LayerID { get; }
11+
int LayerID { get; }
1212
string LayerName { get; }
1313
}
1414
}

Assets/PhysicsLayers/Scripts/Components/ILayerInfos.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace a3geek.PhysicsLayers.Components
99
public interface ILayerInfos
1010
{
1111
int LayerCount { get; }
12-
Dictionary<LayerID, string> Layers { get; }
13-
List<LayerID> LayerIDs { get; }
14-
List<string> LayerNames { get; }
12+
Dictionary<int, string> Layers { get; }
13+
IEnumerable<int> LayerIDs { get; }
14+
IEnumerable<string> LayerNames { get; }
1515

1616
string LayerToName(int layerID);
1717
int NameToLayer(string layerName);

Assets/PhysicsLayers/Scripts/Components/LayerCollision.cs

+5-15
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,20 @@ namespace a3geek.PhysicsLayers.Components
99
[Serializable]
1010
public sealed class LayerCollision
1111
{
12-
public LayerID LayerID
12+
public int LayerID
1313
{
14-
get { return this.layerID == null ? -1 : this.layerID.ID; }
14+
get { return this.layerID; }
15+
internal set { this.layerID = Mathf.Max(0, value); }
1516
}
1617
public bool Collision
1718
{
1819
get { return this.collision; }
1920
internal set { this.collision = value; }
2021
}
21-
22+
2223
[SerializeField]
23-
private LayerID layerID = null;
24+
private int layerID = 0;
2425
[SerializeField]
2526
private bool collision = true;
26-
27-
28-
public LayerCollision(LayerID layerID)
29-
{
30-
this.layerID = layerID;
31-
}
32-
33-
public LayerCollision(LayerID layerID, bool collision) : this(layerID)
34-
{
35-
this.collision = collision;
36-
}
3727
}
3828
}

Assets/PhysicsLayers/Scripts/Components/LayerID.cs

-121
This file was deleted.

0 commit comments

Comments
 (0)