-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoreService.cs
More file actions
66 lines (52 loc) · 2.01 KB
/
Copy pathCoreService.cs
File metadata and controls
66 lines (52 loc) · 2.01 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
55
56
57
58
59
60
61
62
63
64
65
66
using System.Collections.Generic;
using UnityEngine;
namespace BasementExperiments.ScriptIconCustomiser
{
public class CoreService
{
private IconGenerator iconGenerator;
private IconSaver iconSaver;
private IconApplier iconApplier;
private TargetScriptsPersistence targetsPersistence;
public Texture2D DefaultIconTexture => iconGenerator?.DefaultIcon;
public TargetScriptsPersistence TargetsPersistence => targetsPersistence;
public CoreService()
{
iconGenerator ??= new IconGenerator();
iconSaver ??= new IconSaver();
iconApplier ??= new IconApplier();
targetsPersistence ??= new TargetScriptsPersistence();
}
public void ApplyIcon(Texture2D iconTexture, Color tintColor, List<Object> targetScripts)
{
if (targetScripts == null || targetScripts.Count == 0)
return;
targetsPersistence?.SaveGuidsToPrefs(targetScripts);
IconContext iconContext = iconGenerator?.GenerateIconAndGetContext(iconTexture, tintColor);
// Skip if trying to apply the default icon (no changes).
if (iconContext != null
&& iconContext.IconType == IconType.DEFAULT
&& iconContext.TintColor == Color.white)
{
return;
}
string iconPath = iconSaver?.SaveIcon(iconContext);
iconApplier?.ChangeIcon(iconPath, targetScripts);
}
public void ResetIcon(List<Object> targetScripts)
{
if (targetScripts == null || targetScripts.Count == 0)
return;
targetsPersistence?.SaveGuidsToPrefs(targetScripts);
iconApplier?.ResetIcon(targetScripts);
}
public void CleanUp()
{
iconGenerator = null;
iconSaver = null;
iconApplier = null;
targetsPersistence?.DeleteSavedGuids();
targetsPersistence = null;
}
}
}