-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRobotStudioBreadboard.cs
More file actions
54 lines (46 loc) · 1.5 KB
/
RobotStudioBreadboard.cs
File metadata and controls
54 lines (46 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using UnityEngine;
namespace RobotTwin.UI
{
public class RobotStudioBreadboard : MonoBehaviour
{
public string Id;
public int PinCount;
public int Columns;
public int Rows;
public float Pitch;
public float Thickness;
public float Margin;
public float Width;
public float Depth;
public Renderer BoardRenderer;
// Owned resources created at runtime (e.g., texture/material for the base).
// These are not Unity asset references and must be cleaned up to avoid leaks.
public Material OwnedMaterial;
public Texture2D OwnedTexture;
public float TopSurfaceY => Thickness * 0.5f;
private void OnDestroy()
{
// If we authored the shared material/texture at runtime, we own lifetime.
if (BoardRenderer != null && OwnedMaterial != null && BoardRenderer.sharedMaterial == OwnedMaterial)
{
BoardRenderer.sharedMaterial = null;
}
DestroyOwnedResource(OwnedMaterial);
OwnedMaterial = null;
DestroyOwnedResource(OwnedTexture);
OwnedTexture = null;
}
private static void DestroyOwnedResource(Object resource)
{
if (resource == null) return;
if (Application.isPlaying)
{
Destroy(resource);
}
else
{
DestroyImmediate(resource);
}
}
}
}