Skip to content

Commit 8547f80

Browse files
committedAug 2, 2020
Added pool
·
v3.0.2v3.0.0
1 parent 5e2a007 commit 8547f80

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
 

‎Editor/ConstrainedRectPool.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections.Generic;
2+
using UnityEngine;
3+
4+
namespace TNRD.Constraints
5+
{
6+
internal static class ConstrainedRectPool
7+
{
8+
private static List<ConstrainedRect> available = new List<ConstrainedRect>();
9+
10+
public static ConstrainedRect Create(Rect to)
11+
{
12+
if (available.Count == 0)
13+
{
14+
return CreateNew(to);
15+
}
16+
17+
var constrainedRect = available[0];
18+
available.Remove(constrainedRect);
19+
constrainedRect.Reset(to);
20+
return constrainedRect;
21+
}
22+
23+
private static ConstrainedRect CreateNew(Rect to)
24+
{
25+
var constrainedRect = new ConstrainedRect(to);
26+
return constrainedRect;
27+
}
28+
29+
public static void Return(ConstrainedRect constrainedRect)
30+
{
31+
available.Add(constrainedRect);
32+
}
33+
}
34+
}

‎Editor/ConstrainedRectPool.cs.meta

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

0 commit comments

Comments
 (0)
Please sign in to comment.