protected bool Save()
        {
            EntityTemplate entityTemplate;
            if (_entityTemplate == null)
            {

                entityTemplate = new EntityTemplate();
            }
            else
            {
                entityTemplate = _entityTemplate;
            }

            for (int ix = flowLayoutPanel1.Controls.Count - 1; ix >= 0; ix--)
            {
                Control c = flowLayoutPanel1.Controls[ix];
                if (c is BehavioralTestTemplateSessionControl)
                {
                    BehavioralTestTemplateSessionControl bc = (BehavioralTestTemplateSessionControl)c;
                    bc.Save();
                }
            }

            _BehavioralTestTemplate.Name = txtName.Text;
            _BehavioralTestTemplate.BehavioralTestType = (BehavioralTestType)(cmbBehavioralTestType.SelectedItem);
            entityTemplate.SaveBehavioralTest(_BehavioralTestTemplate);
            if (CallerForm is ListForm<EntityTemplate>)
            {
                (CallerForm as ListForm<EntityTemplate>).OrderRefresh(entityTemplate);
            }

            return true;
        }
        public BehavioralTestTemplateForm(EntityTemplate entityTemplate = null)
        {
            InitializeComponent();
            flowLayoutPanel1.HorizontalScroll.Visible = false;

            List<BehavioralTestType> cbBehavioralTestTypes = new List<BehavioralTestType>();

            BehavioralTestType emptyBehavioralTestType = new BehavioralTestType();
            emptyBehavioralTestType.Id = -1;
            emptyBehavioralTestType.Name = "[Please Select]";

            cbBehavioralTestTypes.Add(emptyBehavioralTestType);

            foreach (BehavioralTestType type in BehavioralTestType.All())
            {
                cbBehavioralTestTypes.Add(type);
            }
            cmbBehavioralTestType.DataSource = cbBehavioralTestTypes;

            cmbBehavioralTestType.SelectedIndex = 0;

            _BehavioralTestTemplate = new BehavioralTest();

            if (entityTemplate != null)
            {
                _entityTemplate = entityTemplate;
                txtName.Text = _entityTemplate.Name;

                // deserialize template and read duration txtDuration.Text = entityTemplate.
                BehavioralTest behavioralTest = EntityTemplate.GetAsBehavioralTest(_entityTemplate);
                _BehavioralTestTemplate = behavioralTest;
                cmbBehavioralTestType.SelectedItem = behavioralTest.BehavioralTestType;

                for (int index = 0; index < behavioralTest.Sessions.Count; index++)
                {
                    Session session = behavioralTest.Sessions[index];
                    AddSessionControl(session, index);
                }
            }

            cmbSessionCount.SelectedItem = _BehavioralTestTemplate.Sessions.Count.ToString();
        }
Exemplo n.º 3
0
        public static EntityTemplate CreateCubeEntityTemplate()
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "Cube"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new CubeColor.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new CubeTargetVelocity.Snapshot {
                TargetVelocity = new Vector3f(-2.0f, 0, 0)
            },
                                  WorkerUtils.UnityGameLogic);
            template.AddComponent(new Launchable.Snapshot(), WorkerUtils.UnityGameLogic);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.iOSClient, WorkerUtils.AndroidClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
Exemplo n.º 4
0
        public static EntityTemplate CreateBaseUnitEntityTemplate(UnitSide side, UnitType type, Coordinates coords, CompressedQuaternion?rotation = null, FixedPointVector3?scale = null, OrderType?order = null, uint?rank = null)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot(metaDic[type]), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PostureRoot.Snapshot()
            {
                RootTrans = PostureUtils.ConvertTransform(coords, rotation, scale)
            }, WorkerUtils.UnityGameLogic);

            template.AddComponent(new BaseUnitSight.Snapshot(), WorkerUtils.UnityGameLogic);
            //template.AddComponent(new BaseUnitAction.Snapshot { EnemyPositions = new List<FixedPointVector3>() }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitStatus.Snapshot(side, type, UnitState.Alive, order == null ? orderDic[type] : order.Value, GetRank(rank, type)), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitTarget.Snapshot().DefaultSnapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Launchable.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitHealth.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new GunComponent.Snapshot {
                GunsDic = new Dictionary <int, GunInfo>()
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new FuelComponent.Snapshot(), WorkerUtils.UnityGameLogic);

            if (type.BaseType() == UnitBaseType.Moving)
            {
                template.AddComponent(new BaseUnitMovement.Snapshot(), WorkerUtils.UnityGameLogic);
                template.AddComponent(new BaseUnitReviveTimer.Snapshot {
                    IsStart = false, RestTime = 0.0f
                }, WorkerUtils.UnityGameLogic);
            }

            SwitchType(template, type, WorkerUtils.UnityGameLogic);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(GetReadAttributes(type));
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
Exemplo n.º 5
0
        private static void AddPlayerSpawner(Snapshot snapshot, Coordinates playerSpawnerLocation)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(playerSpawnerLocation), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot {
                EntityType = "PlayerCreator"
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new PlayerCreator.Snapshot(), WorkerUtils.UnityGameLogic);

            var query    = InterestQuery.Query(Constraint.RelativeCylinder(500));
            var interest = InterestTemplate.Create()
                           .AddQueries <Position.Component>(query);

            template.AddComponent(interest.ToSnapshot(), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            snapshot.AddEntity(template);
        }
Exemplo n.º 6
0
    private void InitSimulation()
    {
        simulation.AddParameter(VoxelWorld.PARAMETER_WORLD_SIZE, new IntVector3(sizeX, sizeY, sizeZ));
        simulation.AddParameter(Simulation.PARAMETER_STEPS_PER_SECOND, 20);
        simulation.AddParameter(Simulation.PARAMETER_SIMULATION_LISTENER, this);

        simulation.Init();

        voxelView.Init(simulation.GetComponentManager <VoxelWorld>());

        EntityTemplate template1 = new EntityTemplate();

        template1.AddComponent <VoxelComponent>()
        .AddParameter(VoxelComponent.PARAMETER_SHAPE, VoxelShape.Sphere)
        .AddParameter(VoxelComponent.PARAMETER_RADIUS, fint.quarter)
        .AddParameter(VoxelComponent.PARAMETER_COLOR, new FVector3(fint.one, fint.zero, fint.zero))
        .AddParameter(VoxelComponent.PARAMETER_POSITION, FVector3.one + FVector3.up * fint.half + FVector3.forward);

        template1.AddComponent <VoxelPathWalker>();
        template1.AddComponent <Avatar>();

        EntityTemplate template2 = new EntityTemplate();

        template2.AddComponent <VoxelComponent>()
        .AddParameter(VoxelComponent.PARAMETER_SHAPE, VoxelShape.Cylinder)
        .AddParameter(VoxelComponent.PARAMETER_RADIUS, fint.quarter)
        .AddParameter(VoxelComponent.PARAMETER_HEIGHT, fint.one)
        .AddParameter(VoxelComponent.PARAMETER_COLOR, new FVector3(fint.zero, fint.one, fint.zero))
        .AddParameter(VoxelComponent.PARAMETER_POSITION, FVector3.one + FVector3.up * fint.half);

        template2.AddComponent <AvatarMoveRandom>();

        for (int i = 0; i < 100; i++)
        {
            simulation.AddEntity(template1);

            simulation.AddEntity(template2);
        }
    }
Exemplo n.º 7
0
        public void Setup()
        {
            world             = new World("TestWorld");
            connectionHandler = new MockConnectionHandler();
            world.CreateManager <WorkerSystem>(connectionHandler, null,
                                               new LoggingDispatcher(), "TestWorkerType", Vector3.zero);
            receiveSystem = world.CreateManager <SpatialOSReceiveSystem>();
            world.GetOrCreateManager <ComponentUpdateSystem>();
            world.GetOrCreateManager <ComponentConstraintsCallbackSystem>();
            world.CreateManager <SubscriptionSystem>();
            world.CreateManager <CommandCallbackSystem>();
            world.CreateManager <ComponentCallbackSystem>();
            requireLifecycleSystem = world.CreateManager <RequireLifecycleSystem>();

            linker = new EntityGameObjectLinker(world);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), "worker");
            connectionHandler.CreateEntity(EntityId, template);
            receiveSystem.Update();
        }
Exemplo n.º 8
0
        public void Setup()
        {
            var connectionBuilder = new MockConnectionHandlerBuilder();

            connectionHandler = connectionBuilder.ConnectionHandler;

            workerInWorld = WorkerInWorld
                            .CreateWorkerInWorldAsync(connectionBuilder, "TestWorkerType", new LoggingDispatcher(), Vector3.zero)
                            .Result;

            var world = workerInWorld.World;

            receiveSystem          = world.GetExistingSystem <SpatialOSReceiveSystem>();
            requireLifecycleSystem = world.GetExistingSystem <RequireLifecycleSystem>();
            linker = new EntityGameObjectLinker(world);

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), "worker");
            connectionHandler.CreateEntity(EntityId, template);
            receiveSystem.Update();
        }
Exemplo n.º 9
0
        public static EntityTemplate GetTemplate(string id)
        {
            if (_templates.TryGetValue(id, out EntityTemplate ret))
            {
                return(ret);
            }
            else
            {
                TextAsset ta = bundleTemplates.LoadAsset <TextAsset>(id);

                if (ta == null)
                {
                    return(null);
                }

                EntityTemplate template =
                    JsonConvert.DeserializeObject <EntityTemplate>(
                        ta.text, _genericSettings);
                _templates.Add(template.ID, template);
                return(template);
            }
        }
Exemplo n.º 10
0
        private static EntityTemplate CreatePlayerEntityTemplate(EntityId entityId, string workerId, byte[] serializedArguments)
        {
            var clientAttribute = EntityTemplate.GetWorkerAccessAttribute(workerId);

            var initInfo = SerializeUtils.DeserializeArguments <PlayerInitInfo>(serializedArguments);

            return(BaseUnitTemplate.CreateAdvancedUnitEntityTemplate(workerId, initInfo.pos.ToCoordinates(), initInfo.side));
            //var template = new EntityTemplate();
            //template.AddComponent(new Position.Snapshot { Coords = initInfo.pos.ToCoordinates() }, clientAttribute);
            //template.AddComponent(new Metadata.Snapshot("Player"), serverAttribute);
            //template.AddComponent(new BulletComponent.Snapshot(), clientAttribute);
            //template.AddComponent(new PlayerInput.Snapshot(), clientAttribute);
            //template.AddComponent(new BaseUnitStatus.Snapshot { Side = initInfo.side }, serverAttribute);

            //TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, clientAttribute);
            //PlayerLifecycleHelper.AddPlayerLifecycleComponents(template, workerId, serverAttribute);

            //template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute);
            //template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            //return template;
        }
Exemplo n.º 11
0
        void Test()
        {
            var playerQuery = InterestQuery.Query(
                Constraint.All(
                    Constraint.Component <PlayerInfo.Component>(),
                    Constraint.RelativeSphere(20))
                ).FilterResults(Position.ComponentId, PlayerInfo.ComponentId);

            var minimapQuery = InterestQuery.Query(
                Constraint.All(
                    Constraint.Component <MinimapRepresentaion.Component>(),
                    Constraint.RelativeBox(50, double.PositiveInfinity, 50))
                ).FilterResults(Position.ComponentId, MinimapRepresentaion.ComponentId);

            var interestTemplate = InterestTemplate.Create()
                                   .AddQueries <PlayerControls.Component>(playerQuery, minimapQuery)
                                   .AddQueries <PlayerInput.Component>(playerQuery);

            var playerTemplate = new EntityTemplate();

            playerTemplate.AddComponent(interestTemplate.ToSnapshot(), WorkerUtils.UnityGameLogic);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Handles the <see cref="ButtonBase.Click"/> event for the "Change Terrain" <see
        /// cref="Button"/> on the <see cref="TerrainTab"/> page.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="RoutedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnBackgroundChange</b> shows the <see cref="Dialog.ChangeTemplate"/> dialog with the
        /// selected item in the "Terrain Class" combo box, if any, and calls <see
        /// cref="OnTerrainTabChanged"/> if the user made any changes.</remarks>

        private void OnBackgroundChange(object sender, RoutedEventArgs args)
        {
            args.Handled = true;
            if (!this._initialized)
            {
                return;
            }

            // retrieve background terrain, if any
            EntityTemplate template = (EntityTemplate)BackgroundCombo.Tag;

            if (template == null)
            {
                return;
            }

            // attempt to find underlying entity class
            EntityClass entityClass;

            if (!ChangeTemplate.CanEdit(this, template, out entityClass))
            {
                return;
            }

            // show Change Template dialog
            var dialog = new ChangeTemplate(template, entityClass)
            {
                Owner = this
            };

            dialog.ShowDialog();

            // broadcast data changes
            if (dialog.DataChanged)
            {
                OnTerrainTabChanged();
            }
        }
Exemplo n.º 13
0
        private void NewButtonClicked(EntitySpawnSelectButton sender, EntityTemplate template, string templateName)
        {
            if (sender.selected)
            {
                sender.selected = false;
                _placementManager.Clear();
                return;
            }

            foreach (
                GuiComponent curr in
                _entityList.components.Where(curr => curr.GetType() == typeof(EntitySpawnSelectButton)))
            {
                ((EntitySpawnSelectButton)curr).selected = false;
            }

            string overrideMode = "";

            if (_lstOverride.CurrentlySelected != null)
            {
                if (_lstOverride.CurrentlySelected.Text.Text != "None")
                {
                    overrideMode = _lstOverride.CurrentlySelected.Text.Text;
                }
            }

            var newObjInfo = new PlacementInformation
            {
                PlacementOption = overrideMode.Length > 0 ? overrideMode : template.PlacementMode,
                EntityType      = templateName,
                Range           = -1,
                IsTile          = false
            };

            _placementManager.BeginPlacing(newObjInfo);

            sender.selected = true; //This needs to be last.
        }
        public static EntityTemplate DeploymentState()
        {
            const uint sessionTimeSeconds = 300;

            var position = new Position.Snapshot();
            var metadata = new Metadata.Snapshot {
                EntityType = "DeploymentState"
            };

            var template = new EntityTemplate();

            template.AddComponent(position, WorkerUtils.UnityGameLogic);
            template.AddComponent(metadata, WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Session.Snapshot(Status.LOBBY), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Deployment.Snapshot(), WorkerUtils.DeploymentManager);
            template.AddComponent(new Timer.Snapshot(0, sessionTimeSeconds), WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.DeploymentManager, WorkerUtils.UnityClient, WorkerUtils.MobileClient);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
        private void PreparePlacement(string templateName)
        {
            EntityTemplate template =
                IoCManager.Resolve <IEntityManagerContainer>().EntityManager.EntityTemplateDatabase.GetTemplate(
                    templateName);

            if (template == null)
            {
                return;
            }

            ComponentParameter spriteParam = template.GetBaseSpriteParamaters().FirstOrDefault();
            //Will break if states not ordered correctly.
            //if (spriteParam == null) return;

            var          spriteName = spriteParam == null?"":spriteParam.GetValue <string>();
            CluwneSprite sprite     = ResourceManager.GetSprite(spriteName);

            CurrentBaseSprite = sprite;
            CurrentTemplate   = template;

            IsActive = true;
        }
Exemplo n.º 16
0
        static public EntityTemplate CreateNPCEntity()
        {
            var         entityTemplate = new EntityTemplate();
            Coordinates coord          = new Coordinates((double)(Random.Range(16.0f, 60.0f)), (double)3.0f, (double)(Random.Range(3.0f, 46.0f)));

            entityTemplate.AddComponent(new Position.Snapshot {
                Coords = coord
            }, WorkerUtils.UnityGameLogic);
            entityTemplate.AddComponent(new Metadata.Snapshot {
                EntityType = "NPC"
            }, WorkerUtils.UnityGameLogic);
            entityTemplate.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            entityTemplate.AddComponent(new State.Snapshot(), WorkerUtils.AIWorker);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(entityTemplate, WorkerUtils.UnityGameLogic);

            entityTemplate.SetReadAccess(WorkerUtils.UnityGameLogic, WorkerUtils.UnityClient, WorkerUtils.AIWorker);
            entityTemplate.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.AIWorker);

            // send create entity command request without reserving an entity id
            // The SpatialOS Runtime will automatically assign a SpatialOS entity id to the newly created entity
            //commandSender.SendCreateEntityCommand(new WorldCommands.CreateEntity.Request(entityTemplate), OnCreateEntityResponse);
            return(entityTemplate);
        }
Exemplo n.º 17
0
        public static EntityTemplate CreateSphereTemplate(Quaternion rotation, Vector3 position = default)
        {
            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(Coordinates.FromUnityVector(position)), serverAttribute);
            template.AddComponent(new Metadata.Snapshot("Sphere"), serverAttribute);
            template.AddComponent(new Persistence.Snapshot(), serverAttribute);

            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, serverAttribute, rotation, position);

            const int serverRadius = 500;

            var query    = InterestQuery.Query(Constraint.RelativeCylinder(serverRadius));
            var interest = InterestTemplate.Create().AddQueries <Position.Component>(query);

            template.AddComponent(interest.ToSnapshot());

            template.SetReadAccess(UnityClientConnector.WorkerType, MobileClientWorkerConnector.WorkerType, serverAttribute);

            return(template);
        }
Exemplo n.º 18
0
    /// <summary>
    /// only make new Entity. not add components
    /// </summary>
    private IEntity MakeEntityByContext(EntityTemplate EntityTemplate, Contexts contexts)
    {
        System.Diagnostics.Debug.WriteLine($"entityInfo.ContextType : {EntityTemplate.Context}");
        IEntity newEntity = null;

        switch (EntityTemplate.Context)
        {
        case "Game":
            newEntity = contexts.game.CreateEntity();
            break;

        /*case "Input":
         *  newEntity = contexts.input.CreateEntity();
         *  break;
         * case "Ui":
         *  newEntity = contexts.ui.CreateEntity();
         * break;*/
        default:
            throw new Exception($" {EntityTemplate.Context} is not support type. if you have atribute, add it EntitySaveLoaderMakeEntityByContext() ");
        }

        return(newEntity);
    }
Exemplo n.º 19
0
        public static EntityTemplate CreateTreeTemplate(Vector3f position, uint initialRotation)
        {
            var serverAttribute = UnityGameLogicConnector.WorkerType;

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(new Coordinates(position.X, position.Y, position.Z)), serverAttribute);
            template.AddComponent(new Metadata.Snapshot(SimulationSettings.TreePrefabName), serverAttribute);
            template.AddComponent(new Persistence.Snapshot(), serverAttribute);
            template.AddComponent(new TransformComponent.Snapshot(initialRotation), serverAttribute);

            template.AddComponent(new Harvestable.Snapshot(), serverAttribute);
            template.AddComponent(new Health.Snapshot(SimulationSettings.TreeMaxHealth, SimulationSettings.TreeMaxHealth, true), serverAttribute);
            template.AddComponent(new Flammable.Snapshot(false, true, FireEffectType.BIG), serverAttribute);
            var treeStateComponent = new Dinopark.Plants.TreeState.Snapshot((TreeType)Random.Range(0, 2), TreeFSMState.HEALTHY);

            template.AddComponent(treeStateComponent, serverAttribute);

            template.SetReadAccess(UnityClientConnector.WorkerType, UnityGameLogicConnector.WorkerType, MobileClientWorkerConnector.WorkerType);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            return(template);
        }
Exemplo n.º 20
0
        public static EntityTemplate CreateDinoTRexTemplate(Coordinates initialPosition, long ownerId, int age)
        {
            var serverAttribute = UnityGameLogicConnector.WorkerType;
            var template        = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(initialPosition), serverAttribute);
            template.AddComponent(new Metadata.Snapshot(SimulationSettings.Dino_TRex_PrefabName), serverAttribute);
            template.AddComponent(new Persistence.Snapshot(), serverAttribute);
            var spawnRotation = (uint)Mathf.CeilToInt(Random.Range(0, 360));

            //Debug.Log("DinoTRex rotation : "+spawnRotation);
            template.AddComponent(new TransformComponent.Snapshot(spawnRotation), serverAttribute);

            template.AddComponent(new DinoAiData.Snapshot(), serverAttribute);
            template.AddComponent(new DinoAttrs.Snapshot(false, 0f, 0f, 0f, 0f, 0, initialPosition.ToUnityVector().ToVector3f(), ownerId, 0f, 0f, 0f), serverAttribute);

            template.AddComponent(new Health.Snapshot(), serverAttribute);
            template.AddComponent(new Age.Snapshot(age, SimulationSettings.NPCAgeMax, SimulationSettings.NPCAgeGrowUp), serverAttribute);

            template.SetReadAccess(UnityClientConnector.WorkerType, UnityGameLogicConnector.WorkerType, MobileClientWorkerConnector.WorkerType);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            return(template);
        }
Exemplo n.º 21
0
        public EntityFactory(EntityTemplate type, Dungeon dungeon)
        {
            switch (type)
            {
            case EntityTemplate.Door:
                entityParameters = new List <EntityParameter> {
                    new EntityParameter("Next", EntityParameterType.door),
                    new EntityParameter("Position", EntityParameterType.position)
                };
                break;

            case EntityTemplate.CustomPlayer:
                entityParameters = new List <EntityParameter> {
                    new EntityParameter("Position", EntityParameterType.position)
                };
                break;

            default:
                throw new NotImplementedException();
            }

            this.type    = type;
            this.dungeon = dungeon;
        }
        public IEntityTemplate AddEntityTemplate([Required] string name, string description,
                                                 Bitmap bigImage, Bitmap image, Bitmap smallImage, EntityType entityType)
        {
            var result = new EntityTemplate(this, name)
            {
                Description = description,
                EntityType  = entityType
            };

            switch (entityType)
            {
            case EntityType.ExternalInteractor:
                result.BigImage   = bigImage ?? Resources.external_big;
                result.Image      = image ?? Resources.external;
                result.SmallImage = smallImage ?? Resources.external_small;
                break;

            case EntityType.Process:
                result.BigImage   = bigImage ?? Resources.process_big;
                result.Image      = image ?? Resources.process;
                result.SmallImage = smallImage ?? Resources.process_small;
                break;

            case EntityType.DataStore:
                result.BigImage   = bigImage ?? Resources.storage_big;
                result.Image      = image ?? Resources.storage;
                result.SmallImage = smallImage ?? Resources.storage_small;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(entityType), entityType, null);
            }
            Add(result);

            return(result);
        }
        private static void AddPlayerSpawner(Snapshot snapshot)
        {
            var serverAttribute = WorkerTypes.UnityGameLogic;

            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(), serverAttribute);
            template.AddComponent(new Metadata.Snapshot("PlayerCreator"), serverAttribute);
            template.AddComponent(new Persistence.Snapshot(), serverAttribute);
            template.AddComponent(new PlayerCreator.Snapshot(), serverAttribute);

            var query    = InterestQuery.Query(Constraint.RelativeCylinder(500));
            var interest = InterestTemplate.Create()
                           .AddQueries <Position.Component>(query);

            template.AddComponent(interest.ToSnapshot(), serverAttribute);

            template.SetReadAccess(
                WorkerTypes.UnityClient,
                WorkerTypes.UnityGameLogic);
            template.SetComponentWriteAccess(EntityAcl.ComponentId, serverAttribute);

            snapshot.AddEntity(template);
        }
        public static EntityTemplate CreateBaseUnitEntityTemplate(UnitSide side, Coordinates coords, UnitType type, OrderType?order = null)
        {
            var template = new EntityTemplate();

            template.AddComponent(new Position.Snapshot(coords), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Metadata.Snapshot(metaDic[type]), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Persistence.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitMovement.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitAction.Snapshot {
                EnemyPositions = new List <FixedPointVector3>()
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitStatus.Snapshot(side, type, UnitState.Alive, order == null ? orderDic[type]: order.Value), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitSight.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitTarget.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new Launchable.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new BaseUnitHealth.Snapshot(), WorkerUtils.UnityGameLogic);
            template.AddComponent(new GunComponent.Snapshot {
                GunsDic = new Dictionary <PosturePoint, GunInfo>()
            }, WorkerUtils.UnityGameLogic);
            template.AddComponent(new FuelComponent.Snapshot(), WorkerUtils.UnityGameLogic);

            if (type.BaseType() == UnitBaseType.Moving)
            {
                template.AddComponent(new BaseUnitReviveTimer.Snapshot {
                    IsStart = false, RestTime = 0.0f
                }, WorkerUtils.UnityGameLogic);
            }

            SwitchType(template, type, WorkerUtils.UnityGameLogic);
            TransformSynchronizationHelper.AddTransformSynchronizationComponents(template, WorkerUtils.UnityGameLogic);

            template.SetReadAccess(WorkerUtils.AllWorkerAttributes.ToArray());
            template.SetComponentWriteAccess(EntityAcl.ComponentId, WorkerUtils.UnityGameLogic);

            return(template);
        }
Exemplo n.º 25
0
        /// <summary>
        /// Updates the <see cref="TerrainTab"/> page in response to data changes.</summary>
        /// <remarks>
        /// <b>OnTerrainTabChanged</b> reloads the current terrain stack from the current contents
        /// of the <see cref="TerrainTab"/> page, updates any related controls, and sets the <see
        /// cref="DataChanged"/> flag.</remarks>

        private void OnTerrainTabChanged()
        {
            // reload terrain stack
            this._terrains.Clear();
            BackgroundChanged.Visibility = Visibility.Hidden;

            // add background terrain if available
            EntityTemplate template = (EntityTemplate)BackgroundCombo.Tag;

            if (template != null)
            {
                this._terrains.Add(template);
                if (template.IsModified)
                {
                    BackgroundChanged.Visibility = Visibility.Visible;
                }
            }

            // add foreground terrain list
            foreach (EntityListItem item in TerrainList.Items)
            {
                this._terrains.Add(item.Item2);
            }

            // enable or disable terrain list controls
            bool anyTerrains = (TerrainList.Items.Count > 0);

            ChangeTerrainButton.IsEnabled   = anyTerrains;
            RemoveTerrainButton.IsEnabled   = anyTerrains;
            MoveTerrainDownButton.IsEnabled = anyTerrains;
            MoveTerrainUpButton.IsEnabled   = anyTerrains;

            // update preview and broadcast changes
            UpdatePreview(EntityCategory.Terrain);
            DataChanged = true;
        }
        public void WriteTo_uses_the_GameObject_position_and_rotation()
        {
            var gameObject = new GameObject();

            gameObject.transform.position = new Vector3(100, 100, 100);
            gameObject.transform.rotation = Quaternion.Euler(90, 0, 0);
            var transformFromGameObject = gameObject.AddComponent <TransformFromGameObjectAuthoringComponent>();

            var entityTemplate = new EntityTemplate();

            transformFromGameObject.WriteTo(entityTemplate);

            Assert.IsTrue(entityTemplate.TryGetComponent <TransformInternal.Snapshot>(out var transform));

            var position           = transform.Location.ToUnityVector();
            var positionDifference = Vector3.Distance(gameObject.transform.position, position);

            Assert.AreEqual(0.0, positionDifference, float.Epsilon);

            var rotation           = transform.Rotation.ToUnityQuaternion();
            var rotationDifference = Quaternion.Angle(gameObject.transform.rotation, rotation);

            Assert.AreEqual(0.0, rotationDifference, float.Epsilon);
        }
Exemplo n.º 27
0
        public static void PopulateItems(Level level)
        {
            int points = 100;

            while (points > 0)
            {
                Cell   cell = level.RandomCell(true);
                Entity item;
                if (RandomUtils.OneChanceIn(3)) // Relic
                {
                    item    = Relic.MakeRelic();
                    points -= 9; // Relics take a total of 10 points
                }
                else
                {
                    EntityTemplate basic = Assets.GetTemplate(
                        Tables.basicItems.Random());
                    item = new Entity(basic);
                }

                item.Move(level, cell);
                points--;
            }
        }
        public EntitySpawnSelectButton(EntityTemplate entityTemplate, string templateName,
                                       IResourceManager resourceManager)
        {
            _resourceManager = resourceManager;

            var    spriteNameParam = entityTemplate.GetBaseSpriteParamaters().FirstOrDefault();
            string SpriteName      = "";

            if (spriteNameParam != null)
            {
                SpriteName = spriteNameParam.GetValue <string>();
            }
            string ObjectName = entityTemplate.Name;

            associatedTemplate     = entityTemplate;
            associatedTemplateName = templateName;

            objectSprite = _resourceManager.GetSprite(SpriteName);

            font       = _resourceManager.GetFont("CALIBRI");
            name       = new TextSprite("Label" + SpriteName, "Name", font);
            name.Color = Color.Black;
            name.Text  = ObjectName;
        }
Exemplo n.º 29
0
 private void CreateEntityFile(EntityTemplate entity)
 {
     outPutFile("Common\\Entity", entity.EntityClassName + ".cs", entity.TransformText());
 }
Exemplo n.º 30
0
        private void btCreate_Click(object sender, EventArgs e)
        {
            if (!CheckString())
            {
                return;
            }

            //if (string.IsNullOrEmpty(tbNameSpace.Text))
            //{
            //    MessageBox.Show("名称空间必须输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
            if (clbTables.CheckedItems.Count <= 0)
            {
                MessageBox.Show(Resources.SelectTable, Resources.Alert, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            for (var i = 0; i < clbTables.CheckedItems.Count; i++)
            {
                var tableName         = string.Empty;
                var dtColunms         = Access.GetTableColunms(clbTables.CheckedItems[i].ToString(), _txtConn);
                var originalTableName = clbTables.CheckedItems[i].ToString();
                if (originalTableName.IndexOf('_') > 0)
                {
                    string[] arrayTableName = originalTableName.Split('_');
                    tableName = arrayTableName.Aggregate(tableName, (current, tName) => current + Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(tName.ToLower()));
                    //tableName = OriginalTableName.Substring(0, 1).ToUpper() + OriginalTableName.Substring(1, OriginalTableName.IndexOf("_")).ToLower()
                    //           + OriginalTableName.Substring(OriginalTableName.IndexOf("_") + 1, 1) + OriginalTableName.Substring(OriginalTableName.IndexOf("_") + 2).ToLower();
                }
                else
                {
                    tableName = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(originalTableName.ToLower());
                }
                var schema = new SchemaTemplate
                {
                    NameSpace         = tbNameSpace.Text,
                    DtColunms         = dtColunms,
                    TableName         = tableName,
                    OriginalTableName = originalTableName
                };
                CreateSchemaFile(schema);

                var entity = new EntityTemplate
                {
                    NameSpace = tbNameSpace.Text,
                    DtColunms = dtColunms,
                    TableName = tableName
                };
                CreateEntityFile(entity);

                var dataaccess = new DataAccessTemplate
                {
                    NameSpace = tbNameSpace.Text,
                    DtColunms = dtColunms,
                    TableName = tableName
                };
                CreateDataAccessFile(dataaccess);

                var business = new BusinessTemplate
                {
                    NameSpace = tbNameSpace.Text,
                    DtColunms = dtColunms,
                    TableName = tableName
                };
                CreateBusinessFile(business);

                var model = new ModelTemplate
                {
                    NameSpace = tbNameSpace.Text,
                    DtColunms = dtColunms,
                    TableName = tableName
                };
                CreateModelFile(model);
            }

            MessageBox.Show(Resources.OutPutSuccess);
        }
        public void GetEntity_should_throw_exception_if_no_position_component_is_added()
        {
            var template = new EntityTemplate();

            Assert.IsTrue(DidGetEntityThrow(template));
        }
Exemplo n.º 32
0
        public override void AddedToContainer()
        {
            base.AddedToContainer();

            CloseButtonOn = false;

            columnListBox = new ColumnListBox();
            columnListBox.Initialize(2);
            AddDrawBox(columnListBox);
            columnListBox.SetIntOrStringSort(false, false);
            columnListBox.SetColumnName(0, "Name");
            columnListBox.SetColumnName(1, "Type");
            columnListBox.Width  = 200;
            columnListBox.Height = 200;

            columnListBox.ItemDoubleClicked += delegate(object sender, ColumnListBox.ListBoxRow item, int index)
            {
                EntityTemplate template = null;
                foreach (var t in EditorData.EntityTemplates)
                {
                    if (t.TemplateName == (string)item.Values[0])
                    {
                        template = t;
                    }
                }

                string oldName = template.TemplateName;
                EditEntityTemplateForm.ShowDialogue(Parent, template, delegate(object _sender)
                {
                    foreach (var t in EditorData.EntityTemplates)
                    {
                        if (t.TemplateName == template.TemplateName && t != template)
                        {
                            AlertForm.ShowDialogue(Parent, null, "There is a template with that name already.");
                            template.TemplateName = oldName;
                        }
                    }

                    ReloadListBox();
                });
            };

            ReloadListBox();

            var createTemplateButton = new ResizableButton();

            createTemplateButton.Initialize();
            AddDrawBox(createTemplateButton);
            createTemplateButton.Title = "Create New Template";
            createTemplateButton.FitToText();
            Push.ToTheBottomSideOf(createTemplateButton, columnListBox, 3, Push.VerticalAlign.Left);
            createTemplateButton.Width  = 200;
            createTemplateButton.Click += delegate(object sender)
            {
                CreateEntityTemplateForm.ShowDialogue(Parent, delegate(object _sender)
                {
                    var dialogue = (CreateEntityTemplateForm)_sender;

                    if (dialogue.Result != null)
                    {
                        bool nameExists = false;
                        foreach (var t in EditorData.EntityTemplates)
                        {
                            if (t.TemplateName == dialogue.Result.TemplateName)
                            {
                                AlertForm.ShowDialogue(Parent, null, "A template called: \"" + dialogue.Result.TemplateName + "\" already exists");
                                nameExists = true;
                            }
                        }

                        if (!nameExists)
                        {
                            EditorData.EntityTemplates.Add(dialogue.Result);
                            ReloadListBox();
                        }
                    }
                });
            };

            var deleteTemplateButton = new ResizableButton();

            deleteTemplateButton.Initialize();
            AddDrawBox(deleteTemplateButton);
            deleteTemplateButton.Title = "Delete Template";
            deleteTemplateButton.FitToText();
            Push.ToTheBottomSideOf(deleteTemplateButton, createTemplateButton, 3, Push.VerticalAlign.Left);
            deleteTemplateButton.Width  = 200;
            deleteTemplateButton.Click += delegate(object sender)
            {
                if (columnListBox.SelectedRow != null)
                {
                    var findName = (string)columnListBox.SelectedRow.Values[0];

                    foreach (var t in EditorData.EntityTemplates)
                    {
                        if (t.TemplateName == findName)
                        {
                            EditorData.EntityTemplates.Remove(t);
                            ReloadListBox();
                            break;
                        }
                    }
                }
            };

            var editTemplateButton = new ResizableButton();

            editTemplateButton.Initialize();
            AddDrawBox(editTemplateButton);
            editTemplateButton.Title = "Edit Template";
            editTemplateButton.FitToText();
            Push.ToTheBottomSideOf(editTemplateButton, deleteTemplateButton, 3, Push.VerticalAlign.Left);
            editTemplateButton.Width  = 200;
            editTemplateButton.Click += delegate(object sender)
            {
                if (columnListBox.SelectedRow == null)
                {
                    return;
                }

                EntityTemplate template = null;
                foreach (var t in EditorData.EntityTemplates)
                {
                    if (t.TemplateName == (string)columnListBox.SelectedRow.Values[0])
                    {
                        template = t;
                    }
                }

                string oldName = template.TemplateName;
                EditEntityTemplateForm.ShowDialogue(Parent, template, delegate(object _sender)
                {
                    foreach (var t in EditorData.EntityTemplates)
                    {
                        if (t.TemplateName == template.TemplateName && t != template)
                        {
                            AlertForm.ShowDialogue(Parent, null, "There is a template with that name already.");
                            template.TemplateName = oldName;
                        }
                    }

                    ReloadListBox();
                });
            };

            var okButton = new ResizableButton();

            okButton.Initialize();
            AddDrawBox(okButton);
            okButton.Title = "OK";
            okButton.FitToText();
            Push.ToTheBottomSideOf(okButton, editTemplateButton, 3, Push.VerticalAlign.Left);
            okButton.Width  = 200;
            okButton.Click += delegate(object sender)
            {
                EditorData.Save(Globals.EditorDataSaveDir);
                Close();
            };

            Wrap();

            columnListBox.Alignment        = DrawBoxAlignment.GetFull();
            createTemplateButton.Alignment = DrawBoxAlignment.GetLeftRightBottom();
            deleteTemplateButton.Alignment = DrawBoxAlignment.GetLeftRightBottom();
            editTemplateButton.Alignment   = DrawBoxAlignment.GetLeftRightBottom();
            okButton.Alignment             = DrawBoxAlignment.GetLeftRightBottom();

            X = (Parent.Width / 2) - (Width / 2);
            Y = (Parent.Height / 2) - (Height / 2);

            IsClosing += delegate(object sender)
            {
                EditorData.Save(Globals.EditorDataSaveDir);
            };
        }
Exemplo n.º 33
0
        private void _Reload()
        {
            if (_project != null)
            {
                RemoveBehavioralTestControls();
                for (int index = 0; index < _project.BehavioralTests.Count; index++)
                {
                    BehavioralTest behavioralTest = _project.BehavioralTests[index];
                    AddBehavioralTestControl(behavioralTest, index);
                }
            }
            lBehavioralTests.Text = _project.BehavioralTests.Count > 0 ? "Existing Behavioral Tests" : "No Behavioral Tests";

            int height = 180 + _project.BehavioralTests.Count * 70;
            this.Size = new System.Drawing.Size(400, height);
            this.Text = String.Format("Project: {0}", _project);

            List<EntityTemplate> cbEntityTemplates = new List<EntityTemplate>();

            EntityTemplate emptyEntityTemplate = new EntityTemplate();
            emptyEntityTemplate.Id = -1;
            emptyEntityTemplate.Name = "[Please Select]";

            cbEntityTemplates.Add(emptyEntityTemplate);

            foreach (EntityTemplate entityTemplate in EntityTemplate.All())
            {
                cbEntityTemplates.Add(entityTemplate);
            }
            cbTemplate.DataSource = cbEntityTemplates;

            cbTemplate.SelectedIndex = 0;
            txtNewBehavioralTestName.Text = "";
            pAddNew.Visible = false;
            pAddNew.Enabled = false;
            lnkAddBehavioralTest.Visible = true;
        }