/// <summary> /// Loads the entity. /// </summary> /// <returns>The entity.</returns> /// <param name="name">Name.</param> static public ZEntity LoadEntity(string name, int ID = -1) { string strFileName = name + ".json"; string sl = ""; //create the entity ZEntity newEntity = new ZEntity(); newEntity.Name = name; newEntity.ID = ID; string entityPath = Application.dataPath + GetCurPoolEntityPath(); if (!System.IO.File.Exists(entityPath + strFileName)) { return(newEntity); } try { StreamReader sr = new StreamReader(entityPath + strFileName, Encoding.Default); if (sr == null) { return(newEntity); } //get entity ID sl = sr.ReadLine(); //newEntity.ID = Convert.ToInt32(sl); //read type sl = sr.ReadLine(); newEntity.EType = (EntityType)Enum.Parse(typeof(EntityType), sl); //Debug.Log("EType is " + newEntity.EType); while (sl != null) { sl = sr.ReadLine(); if (sl != null && sl.CompareTo(ComponentPrefix) == 0) { var c = LoadAComponent(sr); if (c != null) { newEntity.AddComponent(c); } } } sr.Close(); } catch (Exception e) { Console.WriteLine(e.Message); throw new Exception("Load Entity Error " + name + e.Message); //return null; } return(newEntity); }
/// <summary> /// Draws the entity. /// </summary> void DrawEntity() { EditorGUI.BeginChangeCheck(); var componentColor = Color.HSVToRGB(0.5f, 0.7f, 1f); componentColor.a = 0.15f; entityStyle = new GUIStyle(GUI.skin.box); entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor); List <IZComponent> coms = curEntity.GetComponents <IZComponent> (); //draw current selected entity EditorGUILayout.BeginVertical(entityStyle); //show the entity name EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Entity Name: " + curEntity.Name); //curEntity.Name = EditorGUILayout.TextField (curEntity.Name); EditorGUILayout.EndHorizontal(); //show component info EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Component x " + coms.Count, GUILayout.MaxWidth(100)); GUILayout.FlexibleSpace(); //show the component menu IZComponent c = curEntity.EType == EntityType.Entity ? ComponentsPool <IZComponent> .DrawAddComponentMenu() : ComponentsPool <IZComponent> .DrawAddSystemMenu(); if (c != null) { var com = ComponentsPool <IZComponent> .CreateComponent(c.GetType()); curEntity.AddComponent(com); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Draw Component componentColor = Color.HSVToRGB(0.9f, 0.1f, 0.9f); componentColor.a = 0.15f; entityStyle = new GUIStyle(GUI.skin.box); entityStyle.normal.background = InspectorDrawer.createTexture(2, 2, componentColor); ///EditorGUILayout.Space(); foreach (IZComponent com in coms) { DrawComponent(com); } if (EditorGUI.EndChangeCheck()) { // Code to execute if GUI.changed // was set to true inside the block of code above. if (poolConfig != null && poolConfig.CurPool != null) { //Debug.Log("EndChangeCheck"); EntityPoolEditorBuildUtils.SaveEntity(curEntity); serializedObject.SetIsDifferentCacheDirty(); EditorApplication.DirtyHierarchyWindowSorting(); EditorApplication.RepaintProjectWindow(); //AssetDatabase.Refresh (); //EditorApplication. } } }