Tanoda
SwizzleGenerator.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System.IO;
10using System.Text;
11using System.Collections;
12using System.Collections.Generic;
13using UnityEngine;
15
17 using Query;
18
19 [CreateAssetMenu(menuName = "Generator/Swizzle", order = 900)]
21
22 public const string TEMPLATE_CODE_KEY = "//__SWIZZLE__";
23 public const string TEMPLATE_NAMESPACE = "Leap.Unity.Swizzle.Generation";
24 public const string TARGET_NAMESPACE = "Leap.Unity.Swizzle";
25
26 public TextAsset templateAsset;
28
29 public override void Generate() {
30 StringBuilder builder = new StringBuilder();
31
32 for (int i = 2; i <= 4; i++) {
33 string sourceType = "Vector" + i;
34
35 for (int j = 2; j <= 4; j++) {
36 string resultType = "Vector" + j;
37
38 int[] components = new int[j];
39 do {
40 builder.AppendLine();
41
42 builder.Append(" ");
43 builder.Append("public static " + resultType + " ");
44 for (int k = 0; k < components.Length; k++) {
45 builder.Append("xyzw"[components[k]]);
46 }
47 builder.Append("(this " + sourceType + " vector) {");
48 builder.AppendLine();
49
50 builder.Append(" ");
51 builder.Append("return new " + resultType + "(");
52 for (int k = 0; k < components.Length; k++) {
53 if (k != 0) {
54 builder.Append(", ");
55 }
56 builder.Append("vector." + "xyzw"[components[k]]);
57 }
58 builder.Append(");");
59 builder.AppendLine();
60
61 builder.Append(" ");
62 builder.Append("}");
63 builder.AppendLine();
64 } while (Utils.NextTuple(components, i));
65 }
66 }
67
68 File.WriteAllText(Path.Combine(destFolder.Path, "Swizzle.cs"),
70 Replace(TEMPLATE_CODE_KEY, builder.ToString()));
71 }
72 }
73}
A convenient serializable representation of an asset folder. Only useful for editor scripts since ass...
Definition: AssetFolder.cs:26
virtual string Path
Gets or sets the folder path. This path will always be a path relative to the asset folder,...
Definition: AssetFolder.cs:43
A Query object is a type of immutable ordered collection of elements that can be used to perform usef...
Definition: Query.cs:90