public void SaveXml(string file, ref StarsSpaceGenerator gen)
        {
            Data          data       = new Data(gen);
            XmlSerializer serializer = new XmlSerializer(typeof(Data));
            FileStream    stream     = new FileStream(file, FileMode.Create);

            serializer.Serialize(stream, data);
            stream.Close();
        }
        static public void UpdateTexturesCubeMap(StarsSpaceGenerator target)
        {
            string[] founded = AssetDatabase.FindAssets("SunUtilities t:ComputeShader");
            if (founded.Length <= 0)
            {
                Debug.LogWarning("Can`t find SunUtilities.compute!");
                return;
            }
            string        path         = AssetDatabase.GUIDToAssetPath(founded[0]);
            ComputeShader SunUtilities = (ComputeShader)AssetDatabase.LoadAssetAtPath(path, typeof(ComputeShader));

            target.UpdateTexturesCubeMap(SunUtilities);
        }
        void SaveFiles(SaveType selected = SaveType.All)
        {
            StarsSpaceGenerator tTarget = ((StarsSpaceGenerator)target.target);

            StarsSpaceGeneratorEditor.UpdateTexturesCubeMap(tTarget);
            Texture2D[] textures = tTarget.GetTextures();
            for (int i = 0; i < 6; i++)
            {
                if (textures[i] == null)
                {
                    break;
                }
                string pref = prefix[i];
                if (NamePrefix == PrefixName.Num)
                {
                    pref = i.ToString();
                }
                string toPath = Path.Combine(basepath, basefilename + AddSpacer(pref) + "." + Type.ToString().ToLower());
                if (selected != SaveType.Material)
                {
                    byte[] bytes = new byte[0];
                    if (Type == ImageType.PNG)
                    {
                        bytes = textures[i].EncodeToPNG();
                    }
                    if (Type == ImageType.JPG)
                    {
                        bytes = textures[i].EncodeToJPG(quality);
                    }
                    File.WriteAllBytes(toPath, bytes);
                    AssetDatabase.Refresh();
                }
                toPath               = toPath.Replace(Application.dataPath, "Assets");
                textures[i]          = (Texture2D)AssetDatabase.LoadAssetAtPath(toPath, typeof(Texture2D));
                textures[i].wrapMode = TextureWrapMode.Clamp;
            }
            if (selected != SaveType.Textures)
            {
                Material mat = new Material(tTarget.GetMaterial());
                for (int i = 0; i < 6; i++)
                {
                    mat.SetTexture(StarsSpaceGenerator.MaterialTextureNames[i], textures[i]);
                }
                string toPathMaterial = Path.Combine(basepath, basefilename + ".mat");
                toPathMaterial = toPathMaterial.Replace(Application.dataPath, "Assets");
                AssetDatabase.CreateAsset(mat, toPathMaterial);
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
 public void LoadXml(string file, ref StarsSpaceGenerator gen)
 {
     try
     {
         XmlSerializer serializer = new XmlSerializer(typeof(Data));
         FileStream    stream     = new FileStream(file, FileMode.Open);
         Data          data       = serializer.Deserialize(stream) as Data;
         stream.Close();
         data.Get(ref gen);
         UpdateTexturesCubeMap((StarsSpaceGenerator)gen);
     }
     catch (Exception ex)
     {
         Debug.Log("Wrong xml format: " + ex.Message);
     }
 }
        public override void OnInspectorGUI()
        {
            StarsSpaceGenerator tTarget = (StarsSpaceGenerator)target;

            DrawDefaultInspector();
            GUILayout.BeginHorizontal();
            GUI.enabled = tTarget.UpdateType == StarsSpaceGenerator.EUpdateType.Manual;
            if (GUILayout.Button(new GUIContent("Update", "Rebuild Sky Box Textures"), GUILayout.Width(100)))
            {
                UpdateTexturesCubeMap((StarsSpaceGenerator)target);
            }
            GUI.enabled = true;
            if (GUILayout.Button(new GUIContent("Load Themplate", "Load parameters from XML")))
            {
                string path = EditorUtility.OpenFilePanel(
                    "Load template from XML",
                    "/Assets/SunShader/Temlpates",
                    "xml");
                if (path.Length != 0)
                {
                    LoadXml(path, ref tTarget);
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(new GUIContent("Save Sky Box", "Save all textures and material."
                                                + "When you are finished choose the settings, you can create a static skybox for high performance"), GUILayout.Width(100)))
            {
                SaveToTextureStarsSpaceWindow.ShowWindow(this);
            }
            if (GUILayout.Button(new GUIContent("Save Themplate", "Save parameters to XML")))
            {
                string path = EditorUtility.SaveFilePanel(
                    "Save template as XML",
                    "/Assets/SunShader/Temlpates",
                    target.name + ".xml",
                    "xml");
                if (path.Length != 0)
                {
                    SaveXml(path, ref tTarget);
                }
            }
            GUILayout.EndHorizontal();
        }
 public void Get(ref StarsSpaceGenerator targ)
 {
     targ.StarsColor1        = StringToColor(StarsColor1);
     targ.StarsColor2        = StringToColor(StarsColor2);
     targ.StarsPrimary       = StringToColor(StarsPrimary);
     targ.StarsBrightPrimary = StarsBrightPrimary;
     targ.StarsBrightSecond  = StarsBrightSecond;
     targ.StarsSeed          = StarsSeed;
     targ.CloudColor1        = StringToColor(CloudColor1);
     targ.CloudColor2        = StringToColor(CloudColor2);
     targ.CloudPrimary       = StringToColor(CloudPrimary);
     targ.Zoom          = Zoom;
     targ.VoronoiPerlin = VPMix;
     targ.LightStage    = LightStage;
     targ.ScaleStage    = ScaleStage;
     targ.Bright        = Bright;
     targ.CloudSeed     = CloudSeed;
     targ.TextureSize   = TextureSize;
     targ.Exposure      = Exposure;
 }
 public void Set(ref StarsSpaceGenerator targ)
 {
     StarsColor1        = ColorToString(targ.StarsColor1);
     StarsColor2        = ColorToString(targ.StarsColor2);
     StarsPrimary       = ColorToString(targ.StarsPrimary);
     StarsBrightPrimary = targ.StarsBrightPrimary;
     StarsBrightSecond  = targ.StarsBrightSecond;
     StarsSeed          = targ.StarsSeed;
     CloudColor1        = ColorToString(targ.CloudColor1);
     CloudColor2        = ColorToString(targ.CloudColor2);
     CloudPrimary       = ColorToString(targ.CloudPrimary);
     Zoom        = targ.Zoom;
     VPMix       = targ.VoronoiPerlin;
     LightStage  = targ.LightStage;
     ScaleStage  = targ.ScaleStage;
     Bright      = targ.Bright;
     CloudSeed   = targ.CloudSeed;
     TextureSize = targ.TextureSize;
     Exposure    = targ.Exposure;
 }
 public Data(StarsSpaceGenerator targ)
 {
     Set(ref targ);
 }