A game about forced loneliness, made by TACStudios
1using System;
2using UnityEngine;
3
4namespace UnityEditor.ShaderGraph
5{
6 [GenerationAPI]
7 [Serializable]
8 internal class IncludeDescriptor : IConditional
9 {
10 public IncludeDescriptor(string guid, string path, IncludeLocation location, FieldCondition[] fieldConditions, bool shouldIncludeWithPragmas = false)
11 {
12 _guid = guid;
13 _path = path;
14 _location = location;
15 this.fieldConditions = fieldConditions;
16 _shouldIncludeWithPragmas = shouldIncludeWithPragmas;
17 }
18
19 [SerializeField]
20 string _guid;
21 public string guid => _guid;
22
23 // NOTE: this path is NOT guaranteed to be correct -- it's only the path that was given to us when this descriptor was constructed.
24 // if the file was moved, it may not be correct. use the GUID to get the current REAL path via AssetDatabase.GUIDToAssetPath
25 [SerializeField]
26 string _path;
27 public string path => _path;
28
29 [SerializeField]
30 IncludeLocation _location;
31 public IncludeLocation location => _location;
32
33 [SerializeField]
34 bool _shouldIncludeWithPragmas;
35 public bool shouldIncludeWithPragmas => _shouldIncludeWithPragmas;
36
37 // NOTE: this is not serialized at the moment.. as it's not needed.
38 // (serialization only used for subgraph includes, coming from nodes, which can't have conditions)
39 public FieldCondition[] fieldConditions { get; }
40
41 public string value
42 {
43 get
44 {
45 // we must get the path from asset database to ensure it is correct after file moves
46 var realPath = AssetDatabase.GUIDToAssetPath(guid);
47 if (string.IsNullOrEmpty(realPath))
48 return $"// missing include file: {path} ({guid})";
49 else if (_shouldIncludeWithPragmas)
50 return $"#include_with_pragmas \"{realPath}\"";
51 else
52 return $"#include \"{realPath}\"";
53 }
54 }
55 }
56}