public static T DeepCopyNorm <T>(T norm) where T : MNorm { string type = norm.GetType().ToString(); // Debug.Log("Now deep copying action " + type); T n = Activator.CreateInstance(norm.GetType()) as T; // Debug.Log("Now deep copying action " + typeof(T)); foreach (mEntity e in norm.context) { mEntity newE = new mEntity(); newE = e.copy(); //Debug.Log(g); n.context.Add(newE); } if (norm.targetAction != null) { n.targetAction = DeepCopyAction(norm.targetAction); } if (norm.targetGoal != null) { n.targetGoal = DeepCopyGoal(norm.targetGoal); } return(n as T); }
public NodeMEntity(mEntity entity, Node node, PortOrientation orientation) { this.orientation = orientation; entityName = entity.entityName; parent = node; foreach (IComponent c in entity.components) { NodeIComponent comp = new NodeIComponent(c, node, orientation); comp.parentEntity = this; components.Add(comp); } // tree = PropertyTree.Create(components); // if (nodeName=="") { if (orientation == PortOrientation.Out) { port = node.AddDynamicOutput(typeof(bool)); } else { port = node.AddDynamicInput(typeof(bool)); } nodeName = port.fieldName; } Debug.Log(port.fieldName); style = new NodeMEntityStyle(); style.unfolded = false; style.portVisible = false; }
public IEnumerator goFish() { Debug.Log("Grid " + grid); Debug.Log("ResourceTiles " + grid.resourceTiles.Count); ResourceTile mostTile = grid.resourceTiles.ElementAt(UnityEngine.Random.Range(0, grid.resourceTiles.Count)).Value; int stagger = UnityEngine.Random.Range(5, 30); for (int i = 0; i < stagger; i++) { yield return(null); } yield return(StartCoroutine(moveBoat(mostTile.tileIndex()))); mostTile.isHere(gameObject); //fish(mostTile.tileIndex()); mostTile.fishingHere(gameObject); yield return(null); entCatch = mostTile.getFish(gameObject); yield return(null); mostTile.leftHere(gameObject); }
public override void AddItem(mEntity Item) { if (ValidateItem(Item)) { items.Add(Item); } }
public static T DeepCopyAction <T>(T action) where T : MAction { string type = action.GetType().ToString(); // Debug.Log("Now deep copying action " + type); T act = Activator.CreateInstance(action.GetType()) as T; // Debug.Log("Now deep copying action " + typeof(T)); foreach (mEntity e in action.inFilter) { mEntity newE = new mEntity(); newE = e.copy(); // Debug.Log(act); act.inFilter.Add(newE); } foreach (mEntity e in action.outFilter) { mEntity newE = new mEntity(); newE = e.copy(); act.outFilter.Add(newE); } return(act as T); }
public override void initCached(BaseAgentBehavior owner) { base.initCached(owner); destination = cachedOutFilter.getEntity <Destination>(); map = (cachedInFilter.getEntity <ResourceTileMap>()).getComponent <ResourceTileMap>().map; }
public override void initCached(BaseAgentBehavior owner) { base.initCached(owner); tile = owner.entities.getEntity <Destination>().getComponent <Destination>().destination; currentCatch = owner.entities.getEntity <Catch>(); }
public virtual void init() { foreach (mEntity e in filter) { mEntity ent = ECUtils.getMatchingEntity(e, owner.entities); cachedFilter.Add(ent); } }
public void init() { //populate lists from profile. Profile has archetypes. //DO NOT USE ARCHETYPES. I will hurt you! //Make copies for use Debug.Log("Initializing agent"); List <Inventory> inventories = profile.getComponents <Inventory>(); List <MAction> acts = profile.getComponent <ActionListComponent>().list; List <MGoal> gls = profile.getComponent <GoalListComponent>().list; List <MNorm> nrms = profile.getComponent <NormListComponent>().list; List <mEntity> ents = new List <mEntity>(); foreach (Inventory inv in inventories) { if (inv.name.Contains("Entities")) { ents = inv.list; } } entities.Clear(); Debug.Log("Populating entities"); foreach (mEntity entity in ents) { Debug.Log("Copying " + entity.entityName); mEntity e = ECUtils.DeepCopyEntity(entity);//entity.copy(); entities.Add(e); } actions.Clear(); Debug.Log("Populating actions"); foreach (MAction action in actions) { // MAction act = ECUtils.DeepCopy<MAction>(action); // actions.Add(act); } goals.Clear(); Debug.Log("Populating goals"); foreach (MGoal goal in gls) { //goals.Add(ECUtils.DeepCopy<MGoal>(goal)); } norms.Clear(); Debug.Log("Populating norms"); foreach (MNorm norm in nrms) { // norms.Add(ECUtils.DeepCopy<MNorm>(norm)); } }
public void makeArchetype() { mEntity asset = CreateInstance <mEntity>(); AssetDatabase.CreateAsset(asset, "Assets/Model base/Data/Entities/Archetypes/" + "New Archetype" + ".asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
public static T GetComponent <T>(mEntity item) where T : IComponent //move to UTILS { foreach (IComponent c in item.components) { if (c is T) { return(c as T); } } return(null); }
public static void AddEntity(List <mEntity> list, string folderName) { AssetDatabase.Refresh(); // string folderName = nameof(list); string targetpath = AssetDatabase.GetAssetPath(Selection.activeObject); string[] folders = targetpath.Split('/'); string path = ""; string assetPath = ""; for (int i = 0; i < folders.Length - 1; i++) { path += folders[i] + "/"; } Debug.Log(targetpath); Debug.Log(path); //make new entity, make entity asset, name it something useful if (!path.Contains(Selection.activeObject.name)) { System.IO.DirectoryInfo objectPath = System.IO.Directory.CreateDirectory(path); System.IO.DirectoryInfo newObjectPath = System.IO.Directory.CreateDirectory(path + Selection.activeObject.name); System.IO.DirectoryInfo subObjectPath = System.IO.Directory.CreateDirectory(path + Selection.activeObject.name + "/" + folderName); assetPath = path + Selection.activeObject.name + "/" + folderName + "/" + Selection.activeObject.name + list.Count + "Entity.asset"; } else { assetPath = path + folderName + "/" + Selection.activeObject.name + list.Count + "Entity.asset"; } mEntity asset = new mEntity(); AssetDatabase.CreateAsset(asset, assetPath); // Debug.Log(path + Selection.activeObject.name + "/" + Selection.activeObject.name + ".asset"); if (!path.Contains(Selection.activeObject.name)) { AssetDatabase.MoveAsset(AssetDatabase.GetAssetPath(Selection.activeObject), path + Selection.activeObject.name + "/" + Selection.activeObject.name + ".asset"); } AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); // Selection.activeObject = asset; list.Add(asset); // AssetDatabase.MoveAsset(AssetDatabase.GetAssetPath(Selection.activeObject), "Assets/Model base/Data/Actions/Assets/" + Selection.activeObject.name + "/" + folderName + "/" + ".asset"); AssetDatabase.Refresh(); }
// Start is called before the first frame update void Start() { initResource(); initCommunities(); othertest = ECUtils.DeepCopyEntity(test); othertest.components.Add(new ColorComponent()); Debug.Log(test.components.Count); Debug.Log(othertest.components.Count); }
void initAgents(mEntity agentProfile, GameObject comGO, mEntity comProfile, mEntity vesselProfile) { GameObject agentGO = Instantiate(ECUtils.GetComponent <Prefab>(agentProfile).prefab); agentGO.GetComponent <AgentBehavior>().profile = agentProfile; agentGO.GetComponent <AgentBehavior>().communityProfile = comProfile; agentGO.GetComponent <AgentBehavior>().init(); agentGO.transform.parent = comGO.transform; agents.Add(agentGO); initVessels(vesselProfile, agentGO); }
public static List <T> GetComponents <T>(mEntity item) where T : IComponent //move to UTILS { List <T> list = new List <T>(); foreach (IComponent c in item.components) { if (c is T) { list.Add(c as T); } } return(list); }
public static mEntity getMatchingEntity(mEntity entity, List <mEntity> entities) { mEntity e = null; foreach (mEntity ent in entities) { if (entitiesMatch(entity, ent)) { e = ent; } } return(e); }
void addEntity(List <mEntity> list, string folderName) { // EntityAdder.AddEntity(list, folderName); mEntity entity = CreateInstance <mEntity>(); EditorGUIUtility.ShowObjectPicker <mEntity>(entity, false, "", 0); entity = (mEntity)EditorGUIUtility.GetObjectPickerObject(); AssetDatabase.AddObjectToAsset(entity, this); AssetDatabase.SaveAssets(); list.Add(entity); }
public mEntity copy() { mEntity copy = CreateInstance <mEntity>(); copy.name = this.name + "*"; copy.entityName = this.entityName + "*"; // copy.components = new List<IComponent>(this.components);//this.components.ToList(); foreach (IComponent c in components) { copy.components.Add(ECUtils.DeepCopyComponent(c)); } return(copy); }
public bool Contains(mEntity e) { bool contains = true; foreach (IComponent c in e.components) { if (!components.Contains(c)) { contains = false; } } return(contains); }
void initWorkPlace(mEntity workProfile, GameObject comGO, mEntity comProfile) { GameObject workGO = Instantiate(ECUtils.GetComponent <Prefab>(workProfile).prefab); workGO.transform.position = ECUtils.GetComponent <Position>(workProfile).position; workGO.GetComponent <SpriteRenderer>().color = ECUtils.GetComponent <ColorComponent>(comProfile).color; ECUtils.GetComponent <SceneObject>(workProfile).gameObject = workGO; ECUtils.GetComponent <CommunityProfile>(workProfile).profile = comProfile; ECUtils.GetComponent <CommunityObject>(workProfile).community = comGO; workGO.transform.parent = comGO.transform; workGO.GetComponent <WorkPlaceScript>().profile = workProfile; }
public static mEntity DeepCopyEntity(mEntity entity) { mEntity e = new mEntity(); foreach (IComponent c in entity.components) { IComponent comp = new IComponent(); comp = DeepCopyComponent(c); e.components.Add(comp); } e.name = ((string)entity.name.Clone()) + "*"; e.entityName = ((string)entity.entityName.Clone()) + "*"; return(e); }
public void setMap(Tilemap resourceMap) { mEntity resourceMapEntity = ScriptableObject.CreateInstance <mEntity>(); resourceMapEntity.entityName = "ResourceMap"; resourceMapEntity.name = "*" + resourceMapEntity.entityName; ResourceTileMap mapComponent = new ResourceTileMap { map = resourceMap }; resourceMapEntity.components.Add(mapComponent); entities.Add(resourceMapEntity); }
void initHarbor(mEntity harborProfile, GameObject comGO, mEntity comProfile) { GameObject harborGO = Instantiate(ECUtils.GetComponent <Prefab>(harborProfile).prefab); harborGO.transform.position = ECUtils.GetComponent <Position>(harborProfile).position; harborGO.GetComponent <SpriteRenderer>().color = ECUtils.GetComponent <ColorComponent>(comProfile).color; ECUtils.GetComponent <SceneObject>(harborProfile).gameObject = harborGO; ECUtils.GetComponent <CommunityProfile>(harborProfile).profile = comProfile; ECUtils.GetComponent <CommunityObject>(harborProfile).community = comGO; harborGO.transform.parent = comGO.transform; //add this profile to the harbor behavior script harborGO.GetComponent <HarborScript>().profile = harborProfile; }
public static bool entitiesMatch(mEntity e1, mEntity e2) { bool match = true; Type type; foreach (IComponent c in e1.components) { type = c.GetType(); if (!(e2.components.Any(item => item.GetType() == c.GetType()))) { match = false; } } return(match); }
static void Main() { sceneManager = new mScene(); entityManager = new mEntity(); systemManager = new mSystem(); inputManager = new mInput(sceneManager); camera = new oCamera(new Vector3(12, -35, 12), new Vector3(12, 1, 12), new Vector3(0, 0, 1), 45, 1920f / 1080f, 0.1f, 100f); MapLoader.loadMap("Maps/Map.txt"); CreateSystems(); using (sceneManager) { sceneManager.LoadScene(new Game(sceneManager)); sceneManager.Run(60.0, 0.0); } }
public static IComponent DeepCopyComponent(IComponent original) { if (original is Inventory) { Inventory inv = new Inventory(); foreach (mEntity e in ((Inventory)original).list) { mEntity ent = DeepCopyEntity(e); inv.list.Add(ent); } return(inv); } byte[] copy = SerializationUtility.SerializeValue <IComponent>(original, DataFormat.Binary, null); var data = SerializationUtility.DeserializeValue <IComponent>(copy, DataFormat.Binary); return((IComponent)data); }
public static T DeepCopyGoal <T>(T goal) where T : MGoal { string type = goal.GetType().ToString(); // Debug.Log("Now deep copying action " + type); T g = Activator.CreateInstance(goal.GetType()) as T; // Debug.Log("Now deep copying action " + typeof(T)); foreach (mEntity e in goal.filter) { mEntity newE = new mEntity(); newE = e.copy(); //Debug.Log(g); g.filter.Add(newE); } return(g as T); }
public override bool ValidateItem(mEntity item) { bool hasCost = false; bool hasCatch = false; foreach (IComponent c in item.components) { if (c is Cost) { hasCost = true; } if (c is Catch) { hasCatch = true; } } return(hasCost && hasCatch); }
IEnumerator GetFish() { if (tile is null) { tile = cachedInFilter.getEntity <Destination>().getComponent <Destination>().destination; } tile.isHere(owner.gameObject); //fish(mostTile.tileIndex()); tile.fishingHere(owner.gameObject); yield return(null); currentCatch = tile.getFish(owner.gameObject); yield return(null); tile.leftHere(owner.gameObject); }
public static T DeepCopyAction <T>(T action) where T : MAction { var act = new Object() as T; foreach (mEntity e in action.inFilter) { mEntity newE = new mEntity(); newE = e.copy(); act.inFilter.Add(newE); } foreach (mEntity e in action.outFilter) { mEntity newE = new mEntity(); newE = e.copy(); act.outFilter.Add(newE); } return(act as T); }