예제 #1
0
    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);
    }
예제 #2
0
    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;
    }
예제 #3
0
    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);
    }
예제 #4
0
 public override void AddItem(mEntity Item)
 {
     if (ValidateItem(Item))
     {
         items.Add(Item);
     }
 }
예제 #5
0
    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);
    }
예제 #6
0
    public override void initCached(BaseAgentBehavior owner)
    {
        base.initCached(owner);

        destination = cachedOutFilter.getEntity <Destination>();
        map         = (cachedInFilter.getEntity <ResourceTileMap>()).getComponent <ResourceTileMap>().map;
    }
예제 #7
0
    public override void initCached(BaseAgentBehavior owner)
    {
        base.initCached(owner);

        tile = owner.entities.getEntity <Destination>().getComponent <Destination>().destination;

        currentCatch = owner.entities.getEntity <Catch>();
    }
예제 #8
0
 public virtual void init()
 {
     foreach (mEntity e in filter)
     {
         mEntity ent = ECUtils.getMatchingEntity(e, owner.entities);
         cachedFilter.Add(ent);
     }
 }
예제 #9
0
    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));
        }
    }
예제 #10
0
    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;
    }
예제 #11
0
 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);
 }
예제 #12
0
    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();
    }
예제 #13
0
    // 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);
    }
예제 #14
0
    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);
    }
예제 #15
0
    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);
    }
예제 #16
0
    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);
    }
예제 #17
0
    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);
    }
예제 #18
0
    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);
    }
예제 #19
0
    public bool Contains(mEntity e)
    {
        bool contains = true;

        foreach (IComponent c in e.components)
        {
            if (!components.Contains(c))
            {
                contains = false;
            }
        }

        return(contains);
    }
예제 #20
0
    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;
    }
예제 #21
0
    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);
    }
예제 #22
0
    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);
    }
예제 #23
0
    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;
    }
예제 #24
0
    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);
    }
예제 #25
0
파일: Main.cs 프로젝트: Deanb1996/CitySim
        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);
            }
        }
예제 #26
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);
    }
예제 #27
0
    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);
    }
예제 #28
0
    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);
    }
예제 #29
0
    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);
    }
예제 #30
0
    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);
    }