예제 #1
0
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(SpawnerComponent) });

            group.OnAdd().Subscribe(entity =>
            {
                var spawner  = entity.GetComponent <SpawnerComponent>();
                var delay    = TimeSpan.FromSeconds(0f);
                var interval = TimeSpan.FromSeconds(spawner.SpawnTime);
                Observable.Timer(delay, interval).Subscribe(_ =>
                {
//			        if(playerHealth.currentHealth <= 0f)
//			        {
//			            return;
//			        }

//					Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);

                    var instance = PrefabFactory.Instantiate(spawner.Prefab, spawner.transform);
                    // instance.transform.SetParent(spawner.transform, false);
                    instance.transform.position = spawner.transform.position;
                    instance.transform.rotation = spawner.transform.rotation;
                }).AddTo(spawner);
            }).AddTo(this);
        }
예제 #2
0
        public Group CreateGroup(Type[] types)
        {
            var group = GroupFactory.Create(types);

            groups.Add(group);
            return(group);
        }
예제 #3
0
        public IObservableGroup GetObservableGroup(IGroup group, string collectionName = null)
        {
            var requiredComponents   = ComponentTypeLookup.GetComponentTypes(group.RequiredComponents);
            var excludedComponents   = ComponentTypeLookup.GetComponentTypes(group.ExcludedComponents);
            var lookupGroup          = new LookupGroup(requiredComponents, excludedComponents);
            var observableGroupToken = new ObservableGroupToken(lookupGroup, collectionName);

            if (observableGroups.ContainsKey(observableGroupToken))
            {
                return(observableGroups[observableGroupToken]);
            }

            var entityMatches = GetEntitiesFor(lookupGroup, collectionName);
            var configuration = new ObservableGroupConfiguration
            {
                ObservableGroupToken = observableGroupToken,
                InitialEntities      = entityMatches
            };

            if (collectionName != null)
            {
                configuration.NotifyingCollection = collections[collectionName];
            }
            else
            {
                configuration.NotifyingCollection = this;
            }

            var observableGroup = GroupFactory.Create(configuration);

            observableGroups.Add(observableGroupToken, observableGroup);

            return(observableGroups[observableGroupToken]);
        }
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            EventSystem.OnEvent <DamageEvent> ().Where(_ => _.Target.HasComponent <InputComponent>() == false).Subscribe(_ =>
            {
                if (_.Target.GetComponent <HealthComponent>().CurrentHealth.Value <= 0)
                {
                    return;
                }

                var viewComponent = _.Target.GetComponent <ViewComponent>();
                var soundFX       = viewComponent.Transforms[0].GetComponentsInChildren <AudioSource>();
                var hurtFX        = soundFX.Where(_2 => _2.clip.name.Contains("Hurt")).FirstOrDefault();
                hurtFX.Play();

                var particles = viewComponent.Transforms[0].GetComponentInChildren <ParticleSystem> ();
                particles.transform.position = _.HitPoint;
                particles.Play();
            }).AddTo(this);

            var group = GroupFactory.Create(new Type[] { typeof(ViewComponent), typeof(HealthComponent), typeof(NavMeshAgent), typeof(CapsuleCollider), typeof(Animator), typeof(Rigidbody) });

            group.OnAdd().Subscribe(entity =>
            {
                var viewComponent   = entity.GetComponent <ViewComponent> ();
                var targetTransform = viewComponent.Transforms[0];
                var healthComponent = entity.GetComponent <HealthComponent> ();
                var capsuleCollider = entity.GetComponent <CapsuleCollider>();
                var animator        = entity.GetComponent <Animator>();
                var rb = entity.GetComponent <Rigidbody>();

                healthComponent.CurrentHealth.DistinctUntilChanged().Where(value => value <= 0).Subscribe(_ =>
                {
                    capsuleCollider.isTrigger = true;
                    animator.SetTrigger("Die");
                    var soundFX = targetTransform.GetComponentsInChildren <AudioSource> ();
                    var deathFX = soundFX.Where(_2 => _2.clip.name.Contains("Death")).FirstOrDefault();
                    deathFX.Play();

                    rb.isKinematic = true;
//					ScoreManager.score += scoreValue;

                    Observable.Timer(TimeSpan.FromSeconds(1)).Subscribe(_2 =>
                    {
                        var sink = Observable.EveryUpdate().Subscribe(_3 =>
                        {
                            targetTransform.Translate(-Vector3.up * DeathSinkSpeed * Time.deltaTime);
                        }).AddTo(viewComponent.Disposer);

                        Observable.Timer(TimeSpan.FromSeconds(2)).Subscribe(_3 =>
                        {
                            sink.Dispose();
                        });
                    });
                }).AddTo(viewComponent.Disposer);
            }).AddTo(this);
        }
예제 #5
0
    public void InitializeGrid()
    {
        groupPattern = Substitute.For <IGroupPattern>();
        rotationMock = new List <Coord[]>()
        {
            new Coord[] {
                new Coord(0, 0),
                new Coord(0, -1),
                new Coord(1, 0),
                new Coord(-1, 0),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(-1, 0),
                new Coord(0, -1),
                new Coord(0, 1),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(0, 1),
                new Coord(-1, 0),
                new Coord(1, 0),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(1, 0),
                new Coord(0, 1),
                new Coord(0, -1),
            },
        };
        groupPattern.Patterns.Returns(rotationMock);

        groupPatternList = new List <IGroupPattern>();
        groupPatternList.Add(groupPattern);

        groupFactory = new GroupFactory(blockFactory, groupPatternList);

        gridFactory = new GridFactory(setting, groupFactory);

        // create grid
        grid = gridFactory.Create();
        grid.NewGame();

        blockPattern  = Substitute.For <IBlockPattern>();
        blockTypeMock = new BlockType[]
        {
            BlockType.One,
            BlockType.Six,
            BlockType.Three,
            BlockType.Five,
        };
        blockPattern.Types.Returns(blockTypeMock);

        group = groupFactory.Create(setting, blockPattern, groupPattern);
    }
예제 #6
0
    public void InitializeGrid()
    {
        groupPattern = Substitute.For<IGroupPattern>();
        rotationMock = new List<Coord[]>() {
            new Coord[] {
                new Coord(0, 0),
                new Coord(0, -1),
                new Coord(1, 0),
                new Coord(-1, 0),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(-1, 0),
                new Coord(0, -1),
                new Coord(0, 1),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(0, 1),
                new Coord(-1, 0),
                new Coord(1, 0),
            },
            new Coord[] {
                new Coord(0, 0),
                new Coord(1, 0),
                new Coord(0, 1),
                new Coord(0, -1),
            },
        };
        groupPattern.Patterns.Returns(rotationMock);

        groupPatternList = new List<IGroupPattern>();
        groupPatternList.Add(groupPattern);

        groupFactory = new GroupFactory(blockFactory, groupPatternList);

        gridFactory = new GridFactory(setting, groupFactory);

        // create grid
        grid = gridFactory.Create();
        grid.NewGame();

        blockPattern = Substitute.For<IBlockPattern>();
        blockTypeMock = new BlockType[]
        {
            BlockType.One,
            BlockType.Six,
            BlockType.Three,
            BlockType.Five,
        };
        blockPattern.Types.Returns(blockTypeMock);

        group = groupFactory.Create(setting, blockPattern, groupPattern);
    }
예제 #7
0
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(ViewComponent), typeof(HealthComponent), typeof(InputComponent), typeof(Animator) });

            group.OnAdd().Subscribe(entity =>
            {
                var viewComponent   = entity.GetComponent <ViewComponent>();
                var targetTransform = viewComponent.Transforms[0];
                var health          = entity.GetComponent <HealthComponent> ();
                var previousValue   = health.CurrentHealth.Value;

                var audioSources = targetTransform.GetComponentsInChildren <AudioSource>();
                var hurtSound    = audioSources.Where(audioSource => audioSource.clip.name.Contains("Hurt")).FirstOrDefault();

                health.CurrentHealth.DistinctUntilChanged().Subscribe(value =>
                {
                    // if you got hurt and are still alive...
                    if (value < previousValue && value >= 0)
                    {
                        if (DamageImage != null)
                        {
                            DamageImage.color = FlashColor;
                            DOTween.To(() => DamageImage.color, x => DamageImage.color = x, Color.clear, FlashSpeed);
                        }

                        hurtSound.Play();
                    }

                    HealthSlider.value = value;
                    previousValue      = value;
                }).AddTo(this.Disposer).AddTo(health.Disposer);
            }).AddTo(this.Disposer);

            DeadEntities.OnAdd().Subscribe(entity =>
            {
                if (entity.HasComponent <InputComponent>() == false)
                {
                    return;
                }

                var viewComponent = entity.GetComponent <ViewComponent>();
                var animator      = entity.GetComponent <Animator>();

                var audioSources = viewComponent.Transforms[0].GetComponentsInChildren <AudioSource>();
                var deathSound   = audioSources.Where(audioSource => audioSource.clip.name.Contains("Death")).FirstOrDefault();
                animator.SetTrigger("Die");
                deathSound.Play();
            }).AddTo(this.Disposer);
        }
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(HealthComponent), typeof(ViewComponent), typeof(UnityEngine.AI.NavMeshAgent) });

            group.OnAdd().Subscribe(entity =>
            {
                var viewComponent = entity.GetComponent <ViewComponent>();
                var navMeshAgent  = entity.GetComponent <NavMeshAgent> ();
                var health        = entity.GetComponent <HealthComponent> ();

                Observable.EveryUpdate().Subscribe(_ =>
                {
                    if (Target == null)
                    {
                        var go = GameObject.FindGameObjectWithTag("Player");
                        if (go == null)
                        {
                            return;
                        }

                        Target = go.transform;
                        if (Target == null)
                        {
                            return;
                        }

                        TargetHealth = Target.GetComponent <EntityBehaviour> ().Entity.GetComponent <HealthComponent> ();
                        if (TargetHealth == null)
                        {
                            return;
                        }
                    }

                    if (health.CurrentHealth.Value > 0 && TargetHealth.CurrentHealth.Value > 0)
                    {
                        navMeshAgent.SetDestination(Target.position);
                    }
                    else
                    {
                        navMeshAgent.enabled = false;
                    }
                }).AddTo(navMeshAgent).AddTo(health);
            }).AddTo(this);
        }
예제 #9
0
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(InputComponent), typeof(ViewComponent), typeof(Animator) });

            group.OnAdd().Subscribe(entity =>
            {
                var input      = entity.GetComponent <InputComponent> ();
                var horizontal = input.Horizontal.DistinctUntilChanged();
                var vertical   = input.Vertical.DistinctUntilChanged();
                var animator   = entity.GetComponent <Animator>();

                Observable.CombineLatest(horizontal, vertical, (h, v) =>
                {
                    return(h != 0f || v != 0f);
                }).ToReadOnlyReactiveProperty().DistinctUntilChanged().Subscribe(value =>
                {
                    animator.SetBool("IsWalking", value);
                }).AddTo(input.Disposer);
            }).AddTo(Disposer);
        }
예제 #10
0
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            FloorMask = LayerMask.GetMask("Floor");

            var group = GroupFactory.Create(new Type[] { typeof(ViewComponent), typeof(InputComponent), typeof(Rigidbody) });

            Observable.EveryFixedUpdate().Subscribe(_ =>
            {
                foreach (var entity in group.Entities)
                {
                    var input = entity.GetComponent <InputComponent> ();
                    input.Horizontal.Value = Input.GetAxisRaw("Horizontal");
                    input.Vertical.Value   = Input.GetAxisRaw("Vertical");

                    var movement = Vector3.zero;
                    movement.Set(input.Horizontal.Value, 0f, input.Vertical.Value);
                    var speed = 6f;
                    movement  = movement.normalized * speed * Time.deltaTime;
                    var rb    = entity.GetComponent <Rigidbody>();
                    rb.MovePosition(rb.transform.position + movement);

                    // execute turning
                    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit, 1000f, FloorMask))
                    {
                        Vector3 playerToMouse = hit.point - rb.transform.position;
                        playerToMouse.y       = 0f;

                        Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
                        rb.MoveRotation(newRotation);
                    }
                }
            }).AddTo(this);
        }
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(Camera), typeof(FollowerComponent) });

            group.OnAdd().Subscribe(entity =>
            {
                var follower    = entity.GetComponent <FollowerComponent>();
                follower.Offset = follower.transform.position - follower.Target.position;

                Observable.EveryFixedUpdate().Subscribe(_ =>
                {
                    if (follower.Target == null)
                    {
                        return;
                    }

                    Vector3 targetCamPos        = follower.Target.position + follower.Offset;
                    follower.transform.position = Vector3.Lerp(follower.transform.position, targetCamPos, follower.Smoothing * Time.deltaTime);
                }).AddTo(follower);
            }).AddTo(this);
        }
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            ShootableMask = LayerMask.GetMask("Shootable");

            var shooters = GroupFactory.Create(new Type[] { typeof(ViewComponent), typeof(ShooterComponent) });

            shooters.OnAdd().Subscribe(entity =>
            {
                var viewComponent   = entity.GetComponent <ViewComponent> ();
                var targetTransform = viewComponent.Transforms[0];
                var shooter         = entity.GetComponent <ShooterComponent> ();
                shooter.IsShooting  = new BoolReactiveProperty();

                var gunBarrel     = targetTransform.Find("GunBarrelEnd");
                var shotParticles = gunBarrel.GetComponent <ParticleSystem> ();
                var shotLine      = gunBarrel.GetComponent <LineRenderer> ();
                var shotAudio     = gunBarrel.GetComponent <AudioSource> ();
                var shotLight     = gunBarrel.GetComponent <Light> ();

                shooter.IsShooting.DistinctUntilChanged().Subscribe(value =>
                {
                    if (value == true)
                    {
                        // handle shooting
                        var delay     = TimeSpan.FromSeconds(0f);
                        var interval  = TimeSpan.FromSeconds(1f / shooter.ShotsPerSecond);
                        shooter.Shoot = Observable.Timer(delay, interval).Subscribe(_ =>
                        {
                            ShotRay.origin    = gunBarrel.position;
                            ShotRay.direction = gunBarrel.forward;

                            if (Physics.Raycast(ShotRay, out ShotRaycastHit, shooter.Range, ShootableMask))
                            {
                                var targetView = ShotRaycastHit.collider.GetComponent <EntityBehaviour> ();
                                if (targetView != null)
                                {
                                    var targetHealth = targetView.Entity.GetComponent <HealthComponent> ();
                                    if (targetHealth != null)
                                    {
                                        EventSystem.Publish(new DamageEvent(entity, targetView.Entity, shooter.Damage, ShotRaycastHit.point));
                                    }
                                }

                                shotLine.SetPosition(1, ShotRaycastHit.point);
                            }
                            else
                            {
                                shotLine.SetPosition(1, ShotRay.origin + ShotRay.direction * shooter.Range);
                            }

                            // handle fx
                            shotAudio.Play();
                            shotLight.enabled = true;
                            shotParticles.Stop();
                            shotParticles.Play();
                            shotLine.enabled = true;
                            shotLine.SetPosition(0, gunBarrel.position);

                            // disable the shot and/or fx after some arbitrary duration
                            var shotDuration = TimeSpan.FromSeconds((1f / shooter.ShotsPerSecond) / 2f);
                            Observable.Timer(shotDuration).Subscribe(_2 =>
                            {
                                shotLine.enabled  = false;
                                shotLight.enabled = false;
                            }).AddTo(this.Disposer).AddTo(viewComponent.Disposer);
                        }).AddTo(this.Disposer).AddTo(shooter.Disposer);
                    }
                    else
                    {
                        if (shooter.Shoot != null)
                        {
                            shooter.Shoot.Dispose();
                        }
                    }
                }).AddTo(this.Disposer).AddTo(shooter.Disposer);
            }).AddTo(this.Disposer);

            Observable.EveryUpdate().Subscribe(_ =>
            {
                foreach (var entity in shooters.Entities)
                {
                    var shooter = entity.GetComponent <ShooterComponent> ();
                    if (Input.GetButton("Fire1"))
                    {
                        shooter.IsShooting.Value = true;
                    }
                    else
                    {
                        shooter.IsShooting.Value = false;
                    }
                }
            }).AddTo(this.Disposer);
        }
예제 #13
0
 public NetworkPrefabFactory(GroupFactory groupFactory, PrefabFactory prefabFactory)
 {
     GroupFactory   = groupFactory;
     PrefabFactory  = prefabFactory;
     UserComponents = GroupFactory.Create(typeof(UserComponent), typeof(ViewComponent));
 }
예제 #14
0
        public override void Setup(IEventSystem eventSystem, IPoolManager poolManager, GroupFactory groupFactory)
        {
            base.Setup(eventSystem, poolManager, groupFactory);

            var group = GroupFactory.Create(new Type[] { typeof(ViewComponent), typeof(MeleeComponent) });

            group.OnAdd().Subscribe(entity =>
            {
                var viewComponent      = entity.GetComponent <ViewComponent> ();
                var targetTransform    = viewComponent.Transforms[0];
                var attacker           = entity.GetComponent <MeleeComponent> ();
                attacker.TargetInRange = new BoolReactiveProperty();
                var collider           = targetTransform.GetComponent <Collider> ();

                collider.OnTriggerEnterAsObservable().Subscribe(_ =>
                {
                    var targetView = _.GetComponent <EntityBehaviour> ();
                    if (targetView != null)
                    {
                        if (targetView.Entity.HasComponent <InputComponent>() == false)
                        {
                            return;
                        }

                        if (targetView.Entity.HasComponent <HealthComponent>() == false)
                        {
                            return;
                        }

                        attacker.Target = targetView.Entity;
                        attacker.TargetInRange.Value = true;
                    }
                }).AddTo(collider);

                collider.OnTriggerExitAsObservable().Subscribe(_ =>
                {
                    var targetView = _.GetComponent <EntityBehaviour> ();
                    if (targetView != null)
                    {
                        if (targetView.Entity.HasComponent <InputComponent>() == false)
                        {
                            return;
                        }

                        if (targetView.Entity.HasComponent <HealthComponent>() == false)
                        {
                            return;
                        }

                        attacker.Target = null;
                        attacker.TargetInRange.Value = false;
                    }
                }).AddTo(collider);

                attacker.TargetInRange.DistinctUntilChanged().Subscribe(value =>
                {
                    if (value == true)
                    {
                        // handle shooting
                        var delay       = TimeSpan.FromSeconds(0f);
                        var interval    = TimeSpan.FromSeconds(1f / attacker.AttacksPerSecond);
                        attacker.Attack = Observable.Timer(delay, interval).Subscribe(_ =>
                        {
                            var attackPosition = attacker.Target.GetComponent <ViewComponent>().Transforms[0].position;
                            EventSystem.Publish(new DamageEvent(entity, attacker.Target, attacker.Damage, attackPosition));
                        }).AddTo(attacker.Target.GetComponent <ViewComponent>().Disposer);
                    }
                    else
                    {
                        if (attacker.Attack != null)
                        {
                            attacker.Attack.Dispose();
                        }
                    }
                }).AddTo(viewComponent.Disposer);
            }).AddTo(this);
        }
        public override async Task Update(IPatch patch, string correlationIdentifier)
        {
            if (null == patch)
            {
                throw new ArgumentNullException(FileProvider.ArgumentNamePatch);
            }

            if (null == patch.ResourceIdentifier)
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidPatch);
            }

            if (string.IsNullOrWhiteSpace(patch.ResourceIdentifier.Identifier))
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidPatch);
            }

            if (null == patch.PatchRequest)
            {
                throw new ArgumentException(ProvisioningAgentResources.ExceptionInvalidPatch);
            }

            string informationStarting =
                string.Format(
                    CultureInfo.InvariantCulture,
                    AzureTestProvisioningResources.InformationPatching,
                    patch.ResourceIdentifier.SchemaIdentifier,
                    patch.ResourceIdentifier.Identifier);
            ProvisioningAgentMonitor.Instance.Inform(informationStarting, true, correlationIdentifier);

            PatchRequest2 patchRequest = patch.PatchRequest as PatchRequest2;
            if (null == patchRequest)
            {
                string unsupportedPatchTypeName = patch.GetType().FullName;
                throw new NotSupportedException(unsupportedPatchTypeName);
            }

            IRow row = await this.file.ReadRow(patch.ResourceIdentifier.Identifier);

            string rowSchema = null;
            if
            (
                    !row.Columns.TryGetValue(AttributeNames.Schemas, out rowSchema)
                ||  !string.Equals(rowSchema, patch.ResourceIdentifier.SchemaIdentifier, StringComparison.Ordinal)
            )
            {
                return;
            }

            IReadOnlyDictionary<string, string> columns;
            WindowsAzureActiveDirectoryGroup group = null;
            switch (rowSchema)
            {
                case SchemaIdentifiers.Core2EnterpriseUser:
                    ResourceFactory<Core2EnterpriseUser> userFactory = new UserFactory(row);
                    Core2EnterpriseUser user = userFactory.Create();
                    user.Apply(patchRequest);
                    ColumnsFactory<Core2EnterpriseUser> userColumnsFactory = new UserColumnsFactory(user);
                    columns = userColumnsFactory.CreateColumns();
                    break;

                case SchemaIdentifiers.WindowsAzureActiveDirectoryGroup:
                    ResourceFactory<WindowsAzureActiveDirectoryGroup> groupFactory = new GroupFactory(row);
                    group = groupFactory.Create();
                    group.Apply(patchRequest);
                    ColumnsFactory<WindowsAzureActiveDirectoryGroup> groupColumnsFactory = new GroupColumnsFactory(group);
                    columns = groupColumnsFactory.CreateColumns();
                    break;
                default:
                    throw new NotSupportedException(patch.ResourceIdentifier.SchemaIdentifier);
            }

            IRow rowReplacement = new Row(row.Key, columns);
            await this.file.ReplaceRow(rowReplacement);

            if (group != null)
            {
                await this.UpdateMembers(group, patch);
            }
        }