ZMWSLI0-SL2021-GR11/cw2/Assets/Scripts/ContextTurtle.cs

29 lines
1.8 KiB
C#
Raw Normal View History

2021-04-15 00:07:29 +02:00
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
using ConsoleLSystem;
using System;
public class ContextTurtle : TurtleLSystem {
protected override void initLiteralInterpretation() {
turtleInterpretation = new Dictionary<string, Func<float[], Tuple<GameObject, Matrix4x4>>>();
//turtleInterpretation
//loading required objects
var path = "Assets/Models/{0}.fbx";
var bigL = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "bigL"), typeof(GameObject));
var bigR = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "bigR"), typeof(GameObject));
var l = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "l"), typeof(GameObject));
var r = (GameObject)AssetDatabase.LoadAssetAtPath(String.Format(path, "r"), typeof(GameObject));
//creating functions that are used for interpretation
turtleInterpretation.Add("A", (float[] args) => new Tuple<GameObject, Matrix4x4>(l, Matrix4x4.Translate(new Vector3(0.1f, 0, 0)) * Matrix4x4.Scale(new Vector3(0.1f, 0.1f, 0.1f))));
turtleInterpretation.Add("B", (float[] args) => new Tuple<GameObject, Matrix4x4>(r, Matrix4x4.Translate(new Vector3(0.1f, 0, 0)) * Matrix4x4.Scale(new Vector3(0.1f, 0.1f, 0.1f))));
turtleInterpretation.Add("D", (float[] args) => new Tuple<GameObject, Matrix4x4>(bigR, Matrix4x4.Translate(new Vector3(0.1f, 0, 0)) * Matrix4x4.Scale(new Vector3(0.1f, 0.1f * (args[0] * 0.2f + 0.01f), 0.1f))));
turtleInterpretation.Add("C", (float[] args) => new Tuple<GameObject, Matrix4x4>(bigR, Matrix4x4.Translate(new Vector3(0.1f, 0, 0)) * Matrix4x4.Scale(new Vector3(0.1f, 0.1f * (args[0] * 0.2f + 0.01f), 0.1f))));
}
}