A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using UnityEngine;
6
7namespace UnityEditor.ShaderGraph
8{
9 // Required for Unity to handle nested array serialization
10 [Serializable]
11 struct IntArray
12 {
13 public int[] array;
14
15 public int this[int i]
16 {
17 get => array[i];
18 set => array[i] = value;
19 }
20
21 public static implicit operator IntArray(int[] array)
22 {
23 return new IntArray { array = array };
24 }
25
26 public static implicit operator int[](IntArray array)
27 {
28 return array.array;
29 }
30 }
31
32 [Serializable]
33 class GraphCompilationResult
34 {
35 public string[] codeSnippets;
36
37 public int[] sharedCodeIndices;
38
39 public IntArray[] outputCodeIndices;
40
41 public string GenerateCode(int[] outputIndices)
42 {
43 var codeIndexSet = new HashSet<int>();
44
45 foreach (var codeIndex in sharedCodeIndices)
46 {
47 codeIndexSet.Add(codeIndex);
48 }
49
50 foreach (var outputIndex in outputIndices)
51 {
52 foreach (var codeIndex in outputCodeIndices[outputIndex].array)
53 {
54 codeIndexSet.Add(codeIndex);
55 }
56 }
57
58 var codeIndices = new int[codeIndexSet.Count];
59 codeIndexSet.CopyTo(codeIndices);
60 Array.Sort(codeIndices);
61
62 var charCount = 0;
63 foreach (var codeIndex in codeIndices)
64 {
65 charCount += codeSnippets[codeIndex].Length;
66 }
67
68 var sb = new StringBuilder();
69 sb.EnsureCapacity(charCount);
70
71 foreach (var codeIndex in codeIndices)
72 {
73 sb.Append(codeSnippets[codeIndex]);
74 }
75
76 return sb.ToString();
77 }
78 }
79}