-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathEnvironmentVariable.cs
More file actions
34 lines (28 loc) · 1.31 KB
/
Copy pathEnvironmentVariable.cs
File metadata and controls
34 lines (28 loc) · 1.31 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
using System;
using ThunderKit.Core.Pipelines;
using UnityEngine;
namespace ThunderKit.Core.Paths.Components
{
public class EnvironmentVariable : PathComponent
{
[Tooltip("Name only, without % or $. Names differ per platform; prefer SpecialFolder for a portable location")]
public string VariableName;
[Tooltip("Used when the variable is not set. Leave empty to require it")]
public string Fallback;
protected override string GetPathInternal(PathReference output, Pipeline pipeline)
{
if (string.IsNullOrEmpty(VariableName))
throw new InvalidOperationException(
$"{PathDiagnostics.Link(output, this)} has no variable name assigned.");
var value = Environment.GetEnvironmentVariable(VariableName);
if (!string.IsNullOrEmpty(value))
return value;
if (!string.IsNullOrEmpty(Fallback))
return Fallback;
throw new InvalidOperationException(
$"{PathDiagnostics.Link(output, this)} requires environment variable \"{VariableName}\", " +
"which is not set for the Editor process. The Editor reads the environment it was " +
"launched with, so a newly added variable needs an Editor restart.");
}
}
}