示例#1
0
        public void Setup(ThingConfig config)
        {
            Config    = config;
            Hitpoints = config.Hitpoints;

            RefreshSprite();

            if (!string.IsNullOrEmpty(Config.PathTag))
            {
                Game.UpdateAstarPath(transform.position.ToVector2IntFloor(), Config.PathTag);
            }

            // todo: must be a better way...
            if (config.TileRuleConfig != null)
            {
                var type     = Type.GetType(config.TileRuleConfig.Type);
                var instance = (ITileRule)Activator.CreateInstance(type, new object[] { config.TileRuleConfig.Sprites });
                TileRule = instance;
            }

            if (Config.LightBlocking)
            {
                gameObject.AddComponent <BoxCollider2D>();
                gameObject.layer = LayerMask.NameToLayer("Blocks Light");
            }

            if (Config.Inventory)
            {
                Inventory = gameObject.AddComponent <Inventory>();
            }

            if (Config.FactoryConfig != null)
            {
                Factory = gameObject.AddComponent <Factory>();
                Factory.Setup(Config.FactoryConfig);
            }

            if (Config.Fire)
            {
                Fire = gameObject.AddComponent <Fire>();
            }

            if (Config.Storage)
            {
                Storage = gameObject.AddComponent <Storage>();
            }

            if (Config.CropConfig != null)
            {
                Crop = gameObject.AddComponent <Crop>();
                Crop.Setup(Config.CropConfig);
            }

            switch (Config.Agent)
            {
            case AgentConfig.Villager:
                Agent = gameObject.AddComponent <Villager>();
                break;

            case AgentConfig.Animal:
                //Agent = gameObject.AddComponent<Animal>();
                break;
            }
        }