Exemple #1
0
    protected void SetOffspringData(UrbAgent Offspring)
    {
        if (Offspring == null || !Offspring.IsBreeder)
        {
            return;
        }

        UrbObjectData[] ChildOffspringData = new UrbObjectData[OffspringData.Length];

        OffspringData.CopyTo(ChildOffspringData, 0);

        Offspring.Breeder.OffspringData = ChildOffspringData;
    }
Exemple #2
0
    public static UrbAgent LoadAgentFromID(int ID, UrbTile Tile, UrbObjectData Data)
    {
        if (ID < 0 || !HasInstance || ID >= Instance.AgentTypes.Count)
        {
            return(null);
        }

        if (!UrbAgentSpawner.SpawnAgent(Instance.AgentTypes[ID], Tile, out var AgentObject, Data))
        {
            return(null);
        }

        UrbAgent LoadedAgent = AgentObject.GetComponent <UrbAgent>();

        return(LoadedAgent);
    }
Exemple #3
0
    public static UrbObjectData Read(GameObject Target)
    {
        UrbObjectData ObjectData = new UrbObjectData();

        ObjectData.Name = Target.name;
        UrbBase[] cs = Target.GetComponents <UrbBase>();

        ObjectData.Components = new UrbComponentData[cs.Length];

        for (int c = 0; c < cs.Length; c++)
        {
            UrbComponentData ComponentData = cs[c].GetComponentData();
            ObjectData.Components[c] = ComponentData;
        }

        return(ObjectData);
    }
Exemple #4
0
    public static GameObject Write(UrbObjectData Data, GameObject Target)
    {
        Target.name = Data.Name;

        for (int c = 0; c < Data.Components.Length; c++)
        {
            System.Type ComponentType = System.Type.GetType(Data.Components[c].Type);
            UrbBase     Component     = (UrbBase)Target.GetComponent(ComponentType);

            if (Component == null)
            {
                Component = (UrbBase)Target.AddComponent(ComponentType);
            }

            Component.SetComponentData(Data.Components[c]);
        }

        return(Target);
    }
Exemple #5
0
    public static UrbObjectData[] GetObjectDataArray(string Name, UrbComponentData Data)
    {
        for (int i = 0; i < Data.StringArrays.Length; i++)
        {
            if (Data.StringArrays[i].Name.CompareTo(Name) == 0)
            {
                UrbObjectData[] Output = new UrbObjectData[Data.StringArrays[i].Value.Length];

                for (int o = 0; o < Data.StringArrays[i].Value.Length; o++)
                {
                    Output[o] = JsonUtility.FromJson <UrbObjectData>(Data.StringArrays[i].Value[o]);
                }

                return(Output);
            }
        }

        return(new UrbObjectData[0]);
    }
    public static bool SpawnAgent(UrbAgent TestAgent, UrbTile Tile, out GameObject spawned, UrbObjectData Data = null)
    {
        Assert.IsTrue(Tile != null, "Tile != null");
        Assert.IsTrue(Tile.Occupants != null, "Tile.Occupants != null");

        s_SpawnAgent_prof.Begin();

        if (Tile.Occupants.Count >= UrbTile.MaximumOccupants)
        {
            spawned = null;
            //Debug.Log("Failed to spawn agent because Tile hit max occupancy!", TestAgent);
            s_SpawnAgent_prof.End();
            return(false);
        }

        if (TestAgent.WasDestroyed)
        {
            spawned = null;
            //Debug.Log("Failed to spawn agent because TestAgent was null!", TestAgent);
            s_SpawnAgent_prof.End();
            return(false);
        }

        UrbTileprint TestPrint = new UrbTileprint(TestAgent.TileprintString);

        if (TestPrint.TilePrintCollisionCheck(Tile))
        {
            spawned = null;
            //Debug.Log("Failed to spawn agent because of TestPrint check on Tile!");
            s_SpawnAgent_prof.End();
            return(false);
        }

        Vector3 SpawnLocation = Tile.Location;

        spawned = Object.Instantiate(TestAgent.gameObject, SpawnLocation, Quaternion.identity);

        if (Data != null)
        {
            UrbEncoder.Write(Data, spawned);
        }

        // Tweaked the Critter prefabs so they *should* spawn as inactive
        // if (spawned.activeSelf == false)
        // {
        //     Debug.Log("the spawned object was inactive!");
        // }

        UrbAgent Agent = spawned.GetComponent <UrbAgent>();

        //Doing this should mean not required to manually activate children
        spawned.SetActive(true);

        if (!Agent.HasAwakeBeenCalled)
        {
            Agent.gameObject.SetActive(true);
        }

        //This loop is kept around mostly out of concern that Agent SetActive
        //may fail to trigger children. Decent chance this is no longer required.
        //light testing shows removing may be acceptable.
        foreach (var urb in Agent.GetComponents <UrbBase>())
        {
            if (!urb.isActiveAndEnabled)
            {
                urb.gameObject.SetActive(true);
            }
        }

        Tile.OnAgentArrive(Agent);
        UrbAgent.TotalAgents++;

        s_SpawnAgent_prof.End();
        return(true);
    }