Example #1
0
        void BuildPlayerEntity(List <IImplementor> implementors, out EntityInitializer playerInitializer)
        {
            //Build the Svelto ECS entity for the player. Svelto.ECS has the unique feature to let the user decide
            //the ID of the entity (which must be anyway unique). The user may think that using, for example,
            //the GameObject.GetInstanceID() value as entity ID is a good idea, as it would be simple to fetch the
            //entity from the outcome of unity callbacks (like collisions). While you can do so, you must not think
            //it's the only way to go. For this reason I decide instead to use 0 for this example and show how
            //to handle the situation.
            //ECSGroups.PlayersGroup is the group where the entity player will be built. I usually expect a
            //group for entity descriptor. It is the safest way to go, but advanced users may decide to use different
            //groups layout if needed.
            //if the Svelto entity is linked to an external OOP resource, like the GameObject in this case, the
            //relative implementor must be passed to the BuildEntity method.
            //Pure ECS (no OOP) entities do not need implementors passed.
            playerInitializer = _entityFactory.BuildEntity <PlayerEntityDescriptor>(0, ECSGroups.PlayersGroup, implementors);

            //BuildEntity returns an initializer that can be used to initialise all the entity components generated
            //by the entity descriptor. In this case I am initializing just the Health.
            //being lazy here, it should be read from json file
            playerInitializer.Init(new HealthComponent
            {
                currentHealth = 100
            });
            playerInitializer.Init(new SpeedComponent(6));
        }
Example #2
0
        public static void Main(string[] args)
        {
            TestClass test = new TestClass()
            {
                BoolProperty = true,
                DateTimeProperty = DateTime.Now,
                DecimalProperty = 10m,
                DoubleProperty = 10,
                FloatProperty = 10f,
                IntProperty = 10,
                LongProperty = 10,
                StringProperty = "10"
            };

            TestClass test1 = new TestClass()
            {
                BoolProperty = false,
                DateTimeProperty = DateTime.Now,
                DecimalProperty = 20m,
                DoubleProperty = 20,
                FloatProperty = 20f,
                IntProperty = 20,
                LongProperty = 20,
                StringProperty = "20"
            };

            List<TestClass> testList = new List<TestClass>();
            testList.Add(test);
            testList.Add(test1);

            EntityInitializer init = new EntityInitializer();
            string str = init.GetInitializerForSingleEntity(test);
            string strList = init.GetInitializerFor(testList);
        }
Example #3
0
        /// <summary>
        /// This demo has just one camera, but it would be simple to create a camera for each player for a split
        /// screen scenario.
        /// <param name="playerID"></param>
        /// <param name="gameObject"></param>
        void BuildCameraEntity(EntityInitializer playerID, GameObject camera)
        {
            //implementors can be attatched at run time, while not? Check the player spawner engine to
            //read more about implementors
            var implementor = camera.AddComponent <CameraImplementor>();

            implementor.offset = camera.transform.position - playerID.Get <CameraTargetEntityViewComponent>().targetComponent.position;

            _entityFactory.BuildEntity <CameraEntityDescriptor>((uint)playerID.EGID.entityID, ECSGroups.Camera
                                                                , new[] { implementor });
        }
        /// <summary>
        /// Callback function from the EntityLoader
        /// </summary>
        /// <param name="args"></param>
        private void OnStartupEntitiesLoaded(RealmEventArgs args)
        {
            var zoneList = args.Data["zones"].CastAs <List <int> >();

            if (zoneList == null)
            {
                throw new InvalidDataException(Resources.ERR_NO_STARTUP_ZONES);
            }

            Log.DebugFormat("{0} Zones to be loaded at startup.", zoneList.Count);

            _startupSet = new BooleanSet("StartupSet", OnStartupLoadingComplete);
            EntityInitializer.LoadStartupEntities(_startupSet, zoneList);
        }
        protected virtual void InitializeMockEntities()
        {
            string testsAssemblyPath = Assembly.Load("SoftwareMonkeys.SiteStarter.Tests").Location;
            string entitiesTestsAssemblyPath = Assembly.Load("SoftwareMonkeys.SiteStarter.Entities.Tests").Location;

            string[] assemblyPaths = new String[] {testsAssemblyPath,
                entitiesTestsAssemblyPath};

            EntityInitializer initializer = new EntityInitializer();

            // Set the specific assemblies used during testing as it can't do it automatically in the mock environment
            initializer.Scanner.AssemblyPaths = assemblyPaths;

            initializer.Initialize(true);
        }
        protected virtual void InitializeMockEntities()
        {
            string testsAssemblyPath         = Assembly.Load("SoftwareMonkeys.SiteStarter.Tests").Location;
            string entitiesTestsAssemblyPath = Assembly.Load("SoftwareMonkeys.SiteStarter.Entities.Tests").Location;

            string[] assemblyPaths = new String[] { testsAssemblyPath,
                                                    entitiesTestsAssemblyPath };

            EntityInitializer initializer = new EntityInitializer();

            // Set the specific assemblies used during testing as it can't do it automatically in the mock environment
            initializer.Scanner.AssemblyPaths = assemblyPaths;

            initializer.Initialize(true);
        }
Example #7
0
        void BuildGunEntity(EntityInitializer playerInitializer, List <IImplementor> implementors)
        {
            //Gun and player are two different entities, but they are linked by the EGID
            //in this case we assume that we know at all the time the ID of the gun and the group where the gun is
            //but this is not often the case when groups must be swapped.
            var init = _entityFactory.BuildEntity <PlayerGunEntityDescriptor>(playerInitializer.EGID.entityID
                                                                              , ECSGroups.PlayersGunsGroup, implementors);

            //being lazy here, it should be read from json file
            init.Init(new GunAttributesComponent()
            {
                timeBetweenBullets = 0.15f
                , range            = 100f
                , damagePerShot    = 20
                ,
            });
        }
Example #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //Do this before mapper section to add class in current assembly
            EntityInitializer.Init();

            #region FoMapper

            //add custom profile to mapperconfiguration
            var mapperConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new FoMappingProfile(Configuration));
                //if you want to use custom profiles use this class
                //mc.AddProfile(new CustomMapperProfile());
            });

            //create mapper and add it to assembly in singleton mode
            services.AddSingleton(mapperConfig.CreateMapper());

            #endregion FoMapper

            services.AddControllers();
        }
Example #9
0
 public static void SetEntityInitializer <T>(EntityInitializer entityInitializer) where T : DbContext
 {
     InitializerFactory.SetEntityInitializer <T>(entityInitializer);
 }