Skip to content

Commit 0b616e6

Browse files
committed
Merge remote-tracking branch 'remotes/origin/2017.1' into 2017.2
2 parents 1eef8c6 + 143e25c commit 0b616e6

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

Assets/Examples/Scripts/RandomInstancing.cs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class RandomInstancing : MonoBehaviour
1717
public float m_Size = 100.0f;
1818

1919
List<Transform> m_Instances = new List<Transform>();
20-
int m_Seed;
2120
int m_Used;
2221
int m_LocX, m_LocZ;
2322

@@ -26,6 +25,7 @@ void Awake()
2625
for (int i = 0; i < m_PoolSize; ++i)
2726
{
2827
var go = Instantiate(m_Prefab, Vector3.zero, Quaternion.identity) as GameObject;
28+
go.SetActive(false);
2929
m_Instances.Add(go.transform);
3030
}
3131
}
@@ -67,51 +67,62 @@ void UpdateInstances()
6767
{
6868
for (var j = z - 2; j <= z + 2; ++j)
6969
{
70-
if (m_Used >= m_PoolSize - 1)
70+
var count = UpdateTileInstances(i, j);
71+
if (count != m_InstancesPerTile)
7172
return;
72-
UpdateTileInstances(i, j);
7373
}
7474
}
75+
76+
// Deactivate the remaining active elements in the pool.
77+
// Here we assume all active elements are contiguous and first in the list.
78+
for (int i = m_Used; i < m_PoolSize && m_Instances[i].gameObject.activeSelf; ++i)
79+
m_Instances[i].gameObject.SetActive(false);
7580
}
7681

77-
void UpdateTileInstances(int i, int j)
82+
int UpdateTileInstances(int i, int j)
7883
{
79-
m_Seed = Hash2(i, j) ^ m_BaseHash;
80-
for (var k = 0; k < m_InstancesPerTile; ++k)
84+
var seed = Hash2(i, j) ^ m_BaseHash;
85+
var count = System.Math.Min(m_InstancesPerTile, m_PoolSize - m_Used);
86+
for (var end = m_Used + count; m_Used < end; ++m_Used)
8187
{
8288
float x = 0;
8389
float y = 0;
8490

8591
if (m_RandomPosition)
8692
{
87-
x = Random();
88-
y = Random();
93+
x = Random(ref seed);
94+
y = Random(ref seed);
8995
}
9096
var pos = new Vector3((i + x) * m_Size, m_Height, (j + y) * m_Size);
9197

9298
if (m_RandomOrientation)
9399
{
94-
float r = 360.0f * Random();
100+
float r = 360.0f * Random(ref seed);
95101
m_Instances[m_Used].rotation = Quaternion.AngleAxis(r, Vector3.up);
96102
}
97103
m_Instances[m_Used].position = pos;
98-
m_Used++;
104+
m_Instances[m_Used].gameObject.SetActive(true);
99105
}
106+
107+
if (count < m_InstancesPerTile)
108+
Debug.LogWarning("Pool exhausted", this);
109+
110+
return count;
100111
}
101112

102113
static int Hash2(int i, int j)
103114
{
104115
return (i * 73856093) ^ (j * 19349663);
105116
}
106117

107-
float Random()
118+
static float Random(ref int seed)
108119
{
109-
m_Seed = (m_Seed ^ 123459876);
110-
var k = m_Seed / 127773;
111-
m_Seed = 16807 * (m_Seed - k * 127773) - 2836 * k;
112-
if (m_Seed < 0) m_Seed = m_Seed + 2147483647;
113-
float ran0 = m_Seed * 1.0f / 2147483647.0f;
114-
m_Seed = (m_Seed ^ 123459876);
120+
seed = (seed ^ 123459876);
121+
var k = seed / 127773;
122+
seed = 16807 * (seed - k * 127773) - 2836 * k;
123+
if (seed < 0) seed = seed + 2147483647;
124+
float ran0 = seed * 1.0f / 2147483647.0f;
125+
seed = (seed ^ 123459876);
115126
return ran0;
116127
}
117128
}

Assets/NavMeshComponents/Editor/NavMeshModifierVolumeEditor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class NavMeshModifierVolumeEditor : Editor
1717
static Color s_HandleColor = new Color(187f, 138f, 240f, 210f) / 255;
1818
static Color s_HandleColorDisabled = new Color(187f * 0.75f, 138f * 0.75f, 240f * 0.75f, 100f) / 255;
1919

20-
static int s_HandleControlIDHint = typeof(NavMeshModifierVolumeEditor).Name.GetHashCode();
21-
BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle(s_HandleControlIDHint);
20+
BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle();
2221

2322
bool editingCollider
2423
{

Assets/NavMeshComponents/Editor/NavMeshSurfaceEditor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ struct AsyncBakeOperation
5656
static Color s_HandleColorSelected = new Color(127f, 214f, 244f, 210f) / 255;
5757
static Color s_HandleColorDisabled = new Color(127f * 0.75f, 214f * 0.75f, 244f * 0.75f, 100f) / 255;
5858

59-
static int s_HandleControlIDHint = typeof(NavMeshSurfaceEditor).Name.GetHashCode();
60-
BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle(s_HandleControlIDHint);
59+
BoxBoundsHandle m_BoundsHandle = new BoxBoundsHandle();
6160

6261
bool editingCollider
6362
{

ProjectSettings/ProjectVersion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
m_EditorVersion: 5.6.0f3
1+
m_EditorVersion: 2017.1.0f3

0 commit comments

Comments
 (0)