/// <summary> /// Loads the station module from a XmlNode. /// </summary> /// <param name="node">The Xml node.</param> public override void LoadXml(XmlElement node) { base.LoadXml(node); XmlDocument doc = node.OwnerDocument; XmlElement el; StoreMaterials.Clear(); StoreItems.Clear(); LoadItemTemplates(); el = node["StoreMaterials"]; foreach (XmlNode xMat in el.ChildNodes) { StoreMaterials[xMat.Name] = int.Parse(xMat.InnerText); } el = node["StoreItems"]; foreach (XmlNode xIt in el.ChildNodes) { StoreItems[xIt.Name] = int.Parse(xIt.InnerText); } }
public void Deserialize(byte[] data, Component instance) { var renderer = (Renderer)instance; renderer.enabled = false; UnitySerializer.AddFinalAction(() => { Store = renderer.GetComponent <StoreMaterials> (); using (new UnitySerializer.SerializationSplitScope()) { var si = UnitySerializer.Deserialize <StoredInformation> (data); if (si == null) { Debug.LogError("An error occured when getting the stored information for a renderer"); return; } renderer.enabled = si.Enabled; if (si.materials.Count > 0) { if (Store != null) { renderer.materials = si.materials.ToArray(); } } } Store = null; } ); }
public override void OnInspectorGUI() { script = (StoreMaterials)target; if ((show.Count - 1 - script.MaterialProperties.Count) != 0) { Rebuild(); } show[0] = EditorGUILayout.Foldout(show[0], "Material properties"); if (show[0]) { int i = 1; foreach (string mat in script.MaterialProperties.Keys) { show[i] = EditorGUILayout.Foldout(show[i], mat); if (show[i]) { foreach (StoreMaterials.MaterialProperty property in script.MaterialProperties[mat]) { string type = ""; switch (property.type) { case ShaderUtil.ShaderPropertyType.Color: type = "COLOR"; break; case ShaderUtil.ShaderPropertyType.Float: type = "FLOAT"; break; case ShaderUtil.ShaderPropertyType.Range: type = "FLOAT"; break; case ShaderUtil.ShaderPropertyType.TexEnv: type = "TEXTURE"; break; case ShaderUtil.ShaderPropertyType.Vector: type = "VECTOR"; break; } GUILayout.Label("[" + type + "]\t" + property.description); } } i++; } EditorGUILayout.Space(); if (GUILayout.Button("Refresh")) { script.ForceRefresh(); } } }
public override void OnInspectorGUI() { script = (StoreMaterials)target; if (!EditorApplication.isPlaying) { Renderer renderer = script.GetComponent <Renderer>(); foreach (Material mat in renderer.sharedMaterials) { if (mat) { if (StoreMaterials.ShaderDatabase.ContainsKey(mat.shader.name)) { using (new Horizontal()) { using (new Vertical()) { EditorGUILayout.LabelField("Status:"); EditorGUILayout.LabelField("Material name:"); EditorGUILayout.LabelField("Shader name:"); } using (new Vertical()) { Color c = GUI.color; GUI.color = Color.green; EditorGUILayout.LabelField("Storing", EditorStyles.boldLabel); GUI.color = c; EditorGUILayout.LabelField(mat.name); string[] s = mat.shader.name.Split('/'); EditorGUILayout.LabelField(s[s.Length - 1]); } } } else { EditorGUILayout.HelpBox(string.Format("Shader \"{0}\" wasn't found in the shader database!\nMake sure you open the Unity Serializer wizard, go to the Materials tab and rebuild it.", mat.shader.name) , MessageType.Warning); if (!StoreMaterials.Dirty) { StoreMaterials.Dirty = true; } } } } } else { EditorGUILayout.HelpBox("Not available in play mode.", MessageType.Info); } EditorGUILayout.Space(); if (GUILayout.Button("Refresh")) { script.SendMessage("OnEnable"); } }
/// <summary> /// Loads the item templates. /// </summary> void LoadItemTemplates() { foreach (var item in (Game as Game).StoreItemManager.StoreItems) { if (item.Value.Type == ItemType.Mineral) { StoreMaterials.Add(item.Key, 0); } else { StoreItems.Add(item.Key, 0); } } }
public byte[] Serialize(Component component) { using (new UnitySerializer.SerializationSplitScope()) { var renderer = (Renderer)component; var si = new StoredInformation(); si.Enabled = renderer.enabled; if ((Store = renderer.GetComponent <StoreMaterials> ()) != null) { si.materials = renderer.materials.ToList(); } var data = UnitySerializer.Serialize(si); Store = null; return(data); } }
public override void OnInspectorGUI() { script = (StoreMaterials)target; if (!EditorApplication.isPlaying) { Renderer renderer = script.GetComponent<Renderer>(); foreach (Material mat in renderer.sharedMaterials) { if (mat) { if (StoreMaterials.ShaderDatabase.ContainsKey(mat.shader.name)) { using (new Horizontal()) { using (new Vertical()) { EditorGUILayout.LabelField("Status:"); EditorGUILayout.LabelField("Material name:"); EditorGUILayout.LabelField("Shader name:"); } using (new Vertical()) { Color c = GUI.color; GUI.color = Color.green; EditorGUILayout.LabelField("Storing", EditorStyles.boldLabel); GUI.color = c; EditorGUILayout.LabelField(mat.name); string[] s = mat.shader.name.Split('/'); EditorGUILayout.LabelField(s[s.Length - 1]); } } } else { EditorGUILayout.HelpBox(string.Format("Shader \"{0}\" wasn't found in the shader database!\nMake sure you open the Unity Serializer wizard, go to the Materials tab and rebuild it.", mat.shader.name) , MessageType.Warning); if (!StoreMaterials.Dirty) { StoreMaterials.Dirty = true; } } } } } else { EditorGUILayout.HelpBox("Not available in play mode.", MessageType.Info); } EditorGUILayout.Space(); if (GUILayout.Button("Refresh")) { script.SendMessage("OnEnable"); } }
public byte[] Serialize(Component component) { byte[] result; using (new UnitySerializer.SerializationSplitScope()) { Renderer renderer = (Renderer)component; SerializeRenderer.StoredInformation storedInformation = new SerializeRenderer.StoredInformation(); storedInformation.Enabled = renderer.enabled; if ((SerializeRenderer.Store = renderer.GetComponent <StoreMaterials>()) != null) { storedInformation.materials = renderer.materials.ToList <Material>(); } byte[] array = UnitySerializer.Serialize(storedInformation); SerializeRenderer.Store = null; result = array; } return(result); }
public byte[] Serialize(Component component) { byte[] result; using (new UnitySerializer.SerializationSplitScope()) { Renderer renderer = (Renderer)component; SerializeRenderer.StoredInformation storedInformation = new SerializeRenderer.StoredInformation(); storedInformation.Enabled = renderer.enabled; if ((SerializeRenderer.Store = renderer.GetComponent<StoreMaterials>()) != null) { storedInformation.materials = renderer.materials.ToList<Material>(); } byte[] array = UnitySerializer.Serialize(storedInformation); SerializeRenderer.Store = null; result = array; } return result; }
public override object Load(object[] data, object instance) { if ((bool)data[0]) { return(SaveGameManager.Instance.GetAsset((SaveGameManager.AssetReference)data[1])); } Shader shader = Shader.Find((string)data[1]); Material material = new Material(shader); material.name = (string)data[2]; StoreMaterials store = this.GetStore(); material.renderQueue = (int)data[3]; if (data[4] != null && store != null) { store.SetValues(material, (List <StoreMaterials.StoredValue>)data[4]); } return(material); }
public override IEnumerable <object> Save(Material target) { StoreMaterials store = this.GetStore(); if (target.GetInstanceID() >= 0) { return(new object[] { true, SaveGameManager.Instance.GetAssetId(target) }); } return(new object[] { false, target.shader.name, target.name, target.renderQueue, (!(store != null)) ? null : store.GetValues(target) }); }
public void Deserialize(byte[] data, Component instance) { Renderer renderer = (Renderer)instance; renderer.enabled = false; UnitySerializer.AddFinalAction(delegate { SerializeRenderer.Store = renderer.GetComponent<StoreMaterials>(); using (new UnitySerializer.SerializationSplitScope()) { SerializeRenderer.StoredInformation storedInformation = UnitySerializer.Deserialize<SerializeRenderer.StoredInformation>(data); if (storedInformation == null) { Debug.LogError("An error occured when getting the stored information for a renderer"); return; } renderer.enabled = storedInformation.Enabled; if (storedInformation.materials.Count > 0 && SerializeRenderer.Store != null) { renderer.materials = storedInformation.materials.ToArray(); } } SerializeRenderer.Store = null; }); }