static public void Button_Select(int i)
        {
            List <string> FileNames = new List <string>();

            DirectoryInfo directory = new DirectoryInfo("GameInfo/KittopiaSpace/Textures/" + PlanetName + "/PQS/");
            var           files     = directory.GetFiles("*.png");

            foreach (FileInfo f in files)
            {
                FileNames.Add(f.Name);
            }
            FileNames.Add("Filler");

            Texture2D texture = Utils.LoadTexture("GameInfo/KittopiaSpace/Textures/" + PlanetName + "/PQS/" + FileNames[i]);

            ReturnedMapSo = (MapSO)ScriptableObject.CreateInstance(typeof(MapSO));
            ReturnedMapSo.CreateMap(MapSO.MapDepth.RGBA, texture);
        }
        public static void Button_Select( int i )
        {
            List<string> FileNames = new List<string>();

            DirectoryInfo directory = new DirectoryInfo( "GameInfo/KittopiaSpace/Textures/"+ PlanetName +"/PQS/" );
            var files = directory.GetFiles("*.png");
            foreach( FileInfo f in files )
            {
                FileNames.Add( f.Name );
            }
            FileNames.Add( "Filler" );

            Texture2D texture = Utils.LoadTexture( "GameInfo/KittopiaSpace/Textures/"+ PlanetName +"/PQS/" + FileNames[i] );

            ReturnedMapSo = (MapSO) ScriptableObject.CreateInstance(typeof (MapSO));
            ReturnedMapSo.CreateMap( MapSO.MapDepth.RGBA, texture );
        }
Beispiel #3
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));
                    }
                }
            }