예제 #1
0
            /// <summary>
            /// Renders the Window
            /// </summary>
            protected override void Render(Int32 id)
            {
                // Scroll
                BeginScrollView(240, 345);

                // Current Body
                DependencyButton(Localization.LOC_KITTOPIATECH_PLANETWINDOW_CURRENT + ": " + Current?.displayName.Replace("^N", ""), Localization.LOC_KITTOPIATECH_PLANETWINDOW_NOCURRENT, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Selector, Current ?? new CelestialBody(), b => Current = b); UIController.Instance.EnableWindow(KittopiaWindows.Selector); }, () => Current != null);
                index++;

                // Editors
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_AFG_EDITOR, () => { EditorController.SetEditedObject(KittopiaEditors.Atmosphere, Current); EditorController.EnableWindow(KittopiaEditors.Atmosphere); });
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_CB_EDITOR, () => { EditorController.SetEditedObject(KittopiaEditors.CelestialBody, Current); EditorController.EnableWindow(KittopiaEditors.CelestialBody); });
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_PQS_EDITOR, () => { EditorController.SetEditedObject(KittopiaEditors.Terrain, Current); EditorController.EnableWindow(KittopiaEditors.Terrain); });
                Enabled(() => Current?.orbitDriver != null, () => { Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_ORBIT_EDITOR, () => { EditorController.SetEditedObject(KittopiaEditors.Orbit, Current.orbitDriver); EditorController.EnableWindow(KittopiaEditors.Orbit); }); });
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_SCALED_EDITOR, () => { EditorController.SetEditedObject(KittopiaEditors.ScaledSpace, Current.scaledBody); EditorController.EnableWindow(KittopiaEditors.ScaledSpace); });
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_LIGHT_EDITOR, () => { EditorController.SetEditedObject(KittopiaEditors.Starlight, Current); EditorController.EnableWindow(KittopiaEditors.Starlight); });
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_RING_EDITOR, () => { EditorController.SetEditedObject(KittopiaEditors.Ring, Current); EditorController.EnableWindow(KittopiaEditors.Ring); });
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_PARTICLES_EDITOR, () => { EditorController.SetEditedObject(KittopiaEditors.Particles, Current); EditorController.EnableWindow(KittopiaEditors.Particles); });

                // Space
                index++;

                // Special Stuff
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_SAVE, () => PlanetExporter.SaveCelestial(Current));
                Button(Localization.LOC_KITTOPIATECH_PLANETWINDOW_INSTANTIATE, () => Utils.Instantiate(Utility.FindBody(PSystemManager.Instance.systemPrefab.rootBody, Current.transform.name), "Body" + new Random().Next(1000)));

                // Scroll
                EndScrollView();

                // Index
                index = 230 / distance + 2;

                // Design Hack
                Boolean e = isError;

                isError = false;
                HorizontalLine(8f);
                isError = e;

                // Render the EditorControler
                EditorController.RenderUI();
            }
예제 #2
0
            /// <summary>
            /// Renders an editor for the object
            /// </summary>
            protected void RenderObject(Object @object)
            {
                // Null check
                if (@object == null)
                {
                    return;
                }

                // Get all parseable MemberInfos
                MemberInfo[] infos = @object.GetType().GetMembers()
                                     .Where(m => m.MemberType == MemberTypes.Field || m.MemberType == MemberTypes.Property)
                                     .Where(m => !(m as FieldInfo)?.IsLiteral ?? true)
                                     .Where(m => m is PropertyInfo ? (m as PropertyInfo).CanRead && (m as PropertyInfo).CanWrite : true)
                                     .ToArray();

                // Loop through all fields and display them
                foreach (MemberInfo info in infos)
                {
                    // Get the type and the value of the member
                    Type   FieldType = info.GetMemberType();
                    Object value     = info.GetValue(@object);

                    if (FieldType == typeof(String))
                    {
                        Label(info.Name); index--;
                        TextField(value.ToString(), v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Boolean))
                    {
                        Label(info.Name); index--;
                        TextField((Boolean)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Int32))
                    {
                        Label(info.Name); index--;
                        TextField((Int32)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Single))
                    {
                        Label(info.Name); index--;
                        TextField((Single)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Double))
                    {
                        Label(info.Name); index--;
                        TextField((Double)value, v => info.SetValue(@object, v), new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (value is Enum)
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Enum, value, c => info.SetValue(@object, c));
                            UIController.Instance.EnableWindow(KittopiaWindows.Enum);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Color))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_COLOR, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Color, (Color)value, c => info.SetValue(@object, c));
                            UIController.Instance.EnableWindow(KittopiaWindows.Color);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Vector3))
                    {
                        Label(info.Name); index--;
                        Vector3 value_ = (Vector3)value;
                        TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--;
                        TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(260, index * distance + 10, 50, 20)); index--;
                        TextField(value_.z, f => { value_.z = f; info.SetValue(@object, value_); }, new Rect(320, index * distance + 10, 50, 20));
                    }
                    else if (FieldType == typeof(Vector3d))
                    {
                        Label(info.Name); index--;
                        Vector3d value_ = (Vector3d)value;
                        TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--;
                        TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(260, index * distance + 10, 50, 20)); index--;
                        TextField(value_.z, f => { value_.z = f; info.SetValue(@object, value_); }, new Rect(320, index * distance + 10, 50, 20));
                    }
                    else if (FieldType == typeof(Vector2))
                    {
                        Label(info.Name); index--;
                        Vector2 value_ = (Vector2)value;
                        TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--;
                        TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(285, index * distance + 10, 50, 20));
                    }
                    else if (FieldType == typeof(Vector2d))
                    {
                        Label(info.Name); index--;
                        Vector2d value_ = (Vector2d)value;
                        TextField(value_.x, f => { value_.x = f; info.SetValue(@object, value_); }, new Rect(200, index * distance + 10, 50, 20)); index--;
                        TextField(value_.y, f => { value_.y = f; info.SetValue(@object, value_); }, new Rect(285, index * distance + 10, 50, 20));
                    }
                    else if (FieldType == typeof(CBAttributeMapSO))
                    {
                        // Load the MapSO
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_LOAD_CBMAP, () =>
                        {
                            FileWindow.type = FieldType;
                            UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location =>
                            {
                                if (File.Exists(location))
                                {
                                    String path             = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, "");
                                    Texture2D texture       = Utility.LoadTexture(path, false, false, false);
                                    texture.name            = path.Replace("\\", "/");
                                    CBAttributeMapSO mapSO  = ScriptableObject.CreateInstance <CBAttributeMapSO>();
                                    mapSO.exactSearch       = false;
                                    mapSO.nonExactThreshold = 0.05f;
                                    mapSO.CreateMap(MapSO.MapDepth.RGB, texture);
                                    mapSO.Attributes = (value as CBAttributeMapSO).Attributes;
                                    mapSO.name       = path.Replace("\\", "/");
                                    info.SetValue(@object, mapSO);
                                }
                                else
                                {
                                    info.SetValue(@object, Resources.FindObjectsOfTypeAll <CBAttributeMapSO>().FirstOrDefault(m => m.name == location));
                                }
                            });
                            UIController.Instance.EnableWindow(KittopiaWindows.Files);
                        }, new Rect(200, index * distance + 10, 170, 20));


                        // Edit the Biome-Definitions
                        Button(Localization.LOC_KITTOPIATECH_EDIT_BIOMES, () => { UIController.Instance.SetEditedObject(KittopiaWindows.Biome, (value as CBAttributeMapSO).Attributes, att => { (value as CBAttributeMapSO).Attributes = att; info.SetValue(@object, value); }); UIController.Instance.EnableWindow(KittopiaWindows.Biome); });
                    }
                    else if (FieldType == typeof(Texture2D) || FieldType == typeof(Texture))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_LOAD_TEXTURE, () =>
                        {
                            FileWindow.type = FieldType;
                            UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location =>
                            {
                                if (File.Exists(location))
                                {
                                    String path       = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, "");
                                    Texture2D texture = Utility.LoadTexture(path, false, false, false);
                                    texture.name      = path.Replace("\\", "/");
                                    info.SetValue(@object, texture);
                                }
                                else
                                {
                                    info.SetValue(@object, Resources.FindObjectsOfTypeAll <Texture>().FirstOrDefault(m => m.name == location));
                                }
                            });
                            UIController.Instance.EnableWindow(KittopiaWindows.Files);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(PQSLandControl.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSLandControl.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSMod_VertexPlanet.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_VertexPlanet.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSMod_HeightColorMap.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMap.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSMod_HeightColorMap2.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMap2.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSMod_HeightColorMapNoise.LandClass[]))
                    {
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LANDCLASSES, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LandClass, (PQSMod_HeightColorMapNoise.LandClass[])value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LandClass);
                        });
                    }
                    else if (FieldType == typeof(PQSLandControl.LerpRange))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_LERPRANGE, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.LerpRange, (PQSLandControl.LerpRange)value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.LerpRange);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(PQSMod_VertexPlanet.SimplexWrapper))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_SIMPLEX, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Simplex, (PQSMod_VertexPlanet.SimplexWrapper)value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.Simplex);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(PQSMod_VertexPlanet.NoiseModWrapper))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_NOISEMOD, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.NoiseMod, (PQSMod_VertexPlanet.NoiseModWrapper)value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.NoiseMod);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(MapSO))
                    {
                        // Depth
                        if (mapDepth == 5 && value != null)
                        {
                            mapDepth = (Int32)(value as MapSO).Depth;
                        }
                        else if (mapDepth == 5 && value == null)
                        {
                            mapDepth = 0;
                        }

                        // Load the MapSO
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_LOAD_MAPSO, () =>
                        {
                            FileWindow.type = FieldType;
                            UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location =>
                            {
                                if (File.Exists(location))
                                {
                                    String path       = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, "");
                                    Texture2D texture = Utility.LoadTexture(path, false, false, false);
                                    texture.name      = path.Replace("\\", "/");
                                    MapSO mapSO       = ScriptableObject.CreateInstance <MapSO>();
                                    mapSO.CreateMap((MapSO.MapDepth)mapDepth, texture);
                                    mapSO.name = path.Replace("\\", "/");
                                    info.SetValue(@object, mapSO);
                                }
                                else
                                {
                                    info.SetValue(@object, Resources.FindObjectsOfTypeAll <MapSO>().FirstOrDefault(m => m.name == location));
                                }
                            });
                            UIController.Instance.EnableWindow(KittopiaWindows.Files);
                        }, new Rect(200, index * distance + 10, 170, 20));
                        mapDepth = GUI.SelectionGrid(new Rect(20, index * distance + 10, 350, 20), mapDepth, new [] { "Greyscale", "HeightAlpha", "RGB", "RGBA" }, 4);
                        index++;
                    }
                    else if (FieldType == typeof(PQS))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_SPHERE, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Selector, value as PQS ?? new PQS(), s => info.SetValue(@object, s));
                            UIController.Instance.EnableWindow(KittopiaWindows.Selector);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(CelestialBody))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_BODY, () =>
                        {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Selector, value ?? new CelestialBody(), b => info.SetValue(@object, b));
                            UIController.Instance.EnableWindow(KittopiaWindows.Selector);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (value is Material) // Kopernicus creates Wrappers for the Materials, so key.FieldType == typeof(Material) would return false. :/
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_MATERIAL, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Material, value as Material, m => info.SetValue(@object, m));
                            UIController.Instance.EnableWindow(KittopiaWindows.Material);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(FloatCurve))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_CURVE, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Curve, (FloatCurve)value, lc => info.SetValue(@object, lc));
                            UIController.Instance.EnableWindow(KittopiaWindows.Curve);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(AnimationCurve))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_CURVE, () => {
                            UIController.Instance.SetEditedObject(KittopiaWindows.Curve, new FloatCurve(((AnimationCurve)value).keys), lc => info.SetValue(@object, lc.Curve));
                            UIController.Instance.EnableWindow(KittopiaWindows.Curve);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                    else if (FieldType == typeof(Mesh))
                    {
                        Label(info.Name); index--;
                        Button(Localization.LOC_KITTOPIATECH_EDIT_MESH, () =>
                        {
                            FileWindow.type = FieldType;
                            UIController.Instance.SetEditedObject(KittopiaWindows.Files, value == null ? "" : PlanetExporter.Format(value as UnityEngine.Object), location =>
                            {
                                if (File.Exists(location))
                                {
                                    String path       = location.Replace(Path.Combine(Directory.GetCurrentDirectory(), "GameData") + Path.DirectorySeparatorChar, "");
                                    MeshParser parser = new MeshParser(value as Mesh);
                                    parser.SetFromString(path);
                                    parser.value.name = path.Replace("\\", "/");
                                    info.SetValue(@object, parser.value);
                                }
                                else
                                {
                                    info.SetValue(@object, Resources.FindObjectsOfTypeAll <Mesh>().FirstOrDefault(m => m.name == location));
                                }
                            });
                            UIController.Instance.EnableWindow(KittopiaWindows.Files);
                        }, new Rect(200, index * distance + 10, 170, 20));
                    }
                }
            }