Code error.
Make a procedural generator of the planets, wrote the code and gives an error
Here is a mistake that will unity:
Assets/Scripts/PlanetGenneratorUI.cs(113,38): error CS1061: Type object' does not contain a definition for
TryGetValue’ and no extension method TryGetValue' of type
object’ could be found (are you missing a using directive or an assembly reference?)
Here is the code:
// Decompile from assembly: Assembly-CSharp.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using UnityEngine;
public class PlanetGenUI : MonoBehaviour
{
public class FeatureUI
{
public IPlanetFeature feature;
public bool expand;
public bool remove;
public FeatureUI(IPlanetFeature feature)
{
this.feature = feature;
this.expand = true;
this.remove = false;
}
}
public GUISkin skin;
public GameObject PlanetPrefab;
public bool showUI;
public GameObject spawned;
private Type sampler;
private bool selectSampler = true;
private IPlanetSampler aSampler;
public List<PlanetGenUI.FeatureUI> features;
private static Func<Assembly, IEnumerable> __f__am_cacheA;
private static Func<Assembly, IEnumerable> __f__am_cacheB;
private static Predicate<PlanetGenUI.FeatureUI> __f__am_cacheC;
private static object __f__switch_map1;
private int reference;
private IPlanetFeature component;
private object num;
private void Start()
{
this.features = new List<PlanetGenUI.FeatureUI>();
}
private void Update()
{
}
private void OnGUI()
{
GUI.skin = this.skin;
if (this.showUI)
{
GUILayout.Window(0, new Rect(10f, 10f, 400f, 800f), new GUI.WindowFunction(this.NewPlanetWindow), “New Planet”, new GUILayoutOption[0]);
}
else
{
GUILayout.Space(64f);
if (GUILayout.Button(“Click me!”, new GUILayoutOption[0]))
{
this.showUI = !this.showUI;
}
}
}
private void FieldToUI(FieldInfo fieldInfo, object target)
{
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUILayout.Label(fieldInfo.Name, new GUILayoutOption[ ]
{
GUILayout.MaxWidth(120f)
});
if (fieldInfo.GetCustomAttributes(typeof(RangeAttribute), false).Length > 0)
{
RangeAttribute rangeAttribute = (RangeAttribute)fieldInfo.GetCustomAttributes(typeof(RangeAttribute), false)[0];
GUILayout.Label(rangeAttribute.min.ToString(), new GUILayoutOption[ ]
{
GUILayout.MaxWidth(32f)
});
string text = fieldInfo.FieldType.ToString();
if (text != null)
{
if (PlanetGenUI.__f__switch_map1 == null)
{
PlanetGenUI.__f__switch_map1 = new Dictionary<string, int>(2)
{
{
“System.Single”,
0
},
{
“System.Int32”,
1
}
};
}
int x = Num();
if (__f__switch_map1.TryGetValue(text, out num))
{
{
fieldInfo.SetValue(target, GUILayout.HorizontalSlider((float)fieldInfo.GetValue(target), rangeAttribute.min, rangeAttribute.max, new GUILayoutOption[0]));
goto IL_175;
}
}
}
UnityEngine.Debug.Log("UnkType: " + fieldInfo.FieldType.ToString());
IL_175:
GUILayout.Label(fieldInfo.GetValue(target).ToString(), new GUILayoutOption[ ]
{
GUILayout.MaxWidth(64f)
});
GUILayout.Label(rangeAttribute.max.ToString(), new GUILayoutOption[ ]
{
GUILayout.MaxWidth(32f)
});
}
else
{
string text = fieldInfo.FieldType.ToString();
switch (text)
{
case “System.Single”:
fieldInfo.SetValue(target, Convert.ToSingle(GUILayout.TextField(fieldInfo.GetValue(target).ToString(), new GUILayoutOption[0])));
goto IL_30C;
case “System.Int32”:
fieldInfo.SetValue(target, Convert.ToInt32(GUILayout.TextField(fieldInfo.GetValue(target).ToString(), new GUILayoutOption[0])));
goto IL_30C;
case “System.Boolean”:
fieldInfo.SetValue(target, Convert.ToBoolean(GUILayout.Toggle((bool)fieldInfo.GetValue(target), “!”, new GUILayoutOption[0])));
goto IL_30C;
case “UnityEngine.GameObject”:
GUILayout.Label(“GameObj”, new GUILayoutOption[0]);
goto IL_30C;
}
UnityEngine.Debug.Log("UnkType: " + fieldInfo.FieldType.ToString());
}
IL_30C:
GUILayout.EndHorizontal();
}
private int Num()
{
throw new NotImplementedException();
}
private static int ToInteger()
{
throw new NotImplementedException();
}
private void NewPlanetWindow(int id)
{
if (GUILayout.Button(“Hide me!”, new GUILayoutOption[0]))
{
this.showUI = !this.showUI;
}
GUILayout.Label(“Pick a sampler:”, new GUILayoutOption[0]);
IEnumerable arg_5B_0 = AppDomain.CurrentDomain.GetAssemblies();
if (PlanetGenUI.__f__am_cacheA == null)
{
PlanetGenUI.__f__am_cacheA = new Func<Assembly, IEnumerable>(PlanetGenUI._NewPlanetWindow_m__B);
}
List list = arg_5B_0.SelectMany(PlanetGenUI.__f__am_cacheA).Where(new Func<Type, bool>(typeof(IPlanetSampler).IsAssignableFrom)).ToList();
IEnumerable arg_A8_0 = AppDomain.CurrentDomain.GetAssemblies();
if (PlanetGenUI.__f__am_cacheB == null)
{
PlanetGenUI.__f__am_cacheB = new Func<Assembly, IEnumerable>(PlanetGenUI._NewPlanetWindow_m__C);
}
List list2 = arg_A8_0.SelectMany(PlanetGenUI.__f__am_cacheB).Where(new Func<Type, bool>(typeof(IPlanetFeature).IsAssignableFrom)).ToList();
if (this.selectSampler)
{
foreach (Type current in list)
{
if (current != typeof(IPlanetSampler))
{
if (GUILayout.Button(current.ToString(), new GUILayoutOption[0]))
{
this.selectSampler = false;
this.sampler = current;
}
}
}
}
else
{
if (GUILayout.Button(“Select a sampler?”, new GUILayoutOption[0]))
{
this.selectSampler = true;
}
FieldInfo[ ] fields = this.sampler.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo[ ] array = fields;
for (int i = 0; i < array.Length; i++)
{
FieldInfo fieldInfo = array*;*
if (!fieldInfo.IsPrivate || fieldInfo.GetCustomAttributes(typeof(SerializeField), true).Length != 0)
{
this.FieldToUI(fieldInfo, this.aSampler);
}
}
GUILayout.Space(4f);
GUILayout.Label(“Features:”, new GUILayoutOption[0]);
foreach (Type current2 in list2)
{
if (current2 != typeof(IPlanetFeature))
{
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
if (GUILayout.Button(“+”, new GUILayoutOption[ ]
{
GUILayout.ExpandWidth(false)
}))
{
this.selectSampler = false;
this.features.Add(new PlanetGenUI.FeatureUI((IPlanetFeature)component));
}
GUILayout.Label(current2.ToString(), new GUILayoutOption[0]);
GUILayout.EndHorizontal();
}
}
foreach (PlanetGenUI.FeatureUI current3 in this.features)
{
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
if (GUILayout.Button(“-”, new GUILayoutOption[ ]
{
GUILayout.ExpandWidth(false)
}))
{
this.selectSampler = false;
current3.remove = true;
}
GUILayout.Label(current3.feature.GetType().ToString(), new GUILayoutOption[0]);
GUILayout.EndHorizontal();
FieldInfo[ ] fields2 = current3.feature.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo[ ] array2 = fields2;
for (int j = 0; j < array2.Length; j++)
{
FieldInfo fieldInfo2 = array2[j];
if (!fieldInfo2.IsPrivate || fieldInfo2.GetCustomAttributes(typeof(SerializeField), true).Length != 0)
{
this.FieldToUI(fieldInfo2, current3.feature);
}
}
}
List<PlanetGenUI.FeatureUI> arg_3E8_0 = this.features;
if (PlanetGenUI.__f__am_cacheC == null)
{
PlanetGenUI.__f__am_cacheC = new Predicate<PlanetGenUI.FeatureUI>(PlanetGenUI._NewPlanetWindow_m__D);
}
arg_3E8_0.RemoveAll(PlanetGenUI.__f__am_cacheC);
GUILayout.Space(4f);
}
GUILayout.Space(4f);
if (GUILayout.Button(“Generate!”, new GUILayoutOption[0]))
{
if (this.spawned != null)
{
UnityEngine.Object.Destroy(this.spawned);
this.spawned = null;
}
this.spawned = (GameObject)UnityEngine.Object.Instantiate(this.PlanetPrefab);
IPlanetSampler planetSampler = (IPlanetSampler)this.spawned.AddComponent(this.sampler);
FieldInfo[ ] fields3 = this.sampler.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo[ ] array3 = fields3;
for (int k = 0; k < array3.Length; k++)
{
FieldInfo fieldInfo3 = array3[k];
if (!fieldInfo3.IsPrivate || fieldInfo3.GetCustomAttributes(typeof(SerializeField), false).Length != 0)
{
fieldInfo3.SetValue(planetSampler, fieldInfo3.GetValue(this.aSampler));
}
}
foreach (PlanetGenUI.FeatureUI current4 in this.features)
{
IPlanetFeature planetFeature = (IPlanetFeature)this.spawned.AddComponent(current4.feature.GetType());
FieldInfo[ ] fields4 = current4.feature.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FieldInfo[ ] array4 = fields4;
for (int l = 0; l < array4.Length; l++)
{
FieldInfo fieldInfo4 = array4[l];
UnityEngine.Debug.Log(fieldInfo4.FieldType.Name);
UnityEngine.Debug.Log(fieldInfo4.FieldType.Name);
UnityEngine.Debug.Log(fieldInfo4);
fieldInfo4.SetValue(planetFeature, fieldInfo4.GetValue(current4.feature));
}
planetFeature.Create();
}
planetSampler.Awake();
}
}
private static void AddComponent(GameObject gameObject, string v1, string v2)
{
throw new NotImplementedException();
}
private static IEnumerable _NewPlanetWindow_m__B(Assembly s)
{
return s.GetTypes();
}
private static IEnumerable _NewPlanetWindow_m__C(Assembly s)
{
return s.GetTypes();
}
private static bool _NewPlanetWindow_m__D(PlanetGenUI.FeatureUI x)
{
return x.remove;
}
}