private static void ProjectCPs(ComponentGroupArray <PlanarBezierFilter> bcs)
        {
            Plane   plane = new Plane();
            Vector3 projPoint;

            foreach (var entity in bcs)
            {
                // set plane position and normal
                Transform PT = entity.comp.planeTransform;
                plane.SetNormalAndPosition(PT.up, PT.position);
                // now loop through transforms of each control point
                // and project them onto plane
                foreach (BezierCPComponent CP in entity.comp.controlPoints)
                {
                    projPoint             = plane.ClosestPointOnPlane(CP.transform.position);
                    CP.transform.position = projPoint;
                    CP.Lp = CP.transform.localPosition;
                    CP.transform.rotation = PT.rotation;
                }

                // for debuging
                //if (entity.comp.debugSphere)
                //{
                //    entity.comp.debugSphere.position = plane.ClosestPointOnPlane(entity.comp.debugSphere.position);
                //    entity.comp.debugSphere.rotation = entity.comp.planeTransform.rotation;
                //    Debug.DrawLine(PT.position, entity.comp.debugSphere.position, Color.red);
                //}
            }
        }
Example #2
0
    protected override void OnUpdate()
    {
        ComponentGroupArray <RequiredComponents> matchingEntities = GetEntities <RequiredComponents>();

        foreach (var componentGroupArray in matchingEntities)
        {
            ObstacleSpawnerComponent obstacleSpawnerComponent = componentGroupArray.obstacleSpawnerComponent;
            float             spawnDelay       = componentGroupArray.obstacleSpawnerComponent.spawnDelay;
            float             lastSpawnTime    = componentGroupArray.obstacleSpawnerComponent.lastSpawnTime;
            List <GameObject> spawnedObstacles = componentGroupArray.obstacleSpawnerComponent.spawnedObstacles;


            var currentTime = Time.time;
            if (currentTime - lastSpawnTime > spawnDelay)
            {
                SpawnObstacles(obstacleSpawnerComponent.obstacleLayer, obstacleSpawnerComponent.spawnedObstacles, obstacleSpawnerComponent.obstacleGO, ref obstacleSpawnerComponent.spawnDelay, ref obstacleSpawnerComponent.lastSpawnTime);
            }
            for (int i = spawnedObstacles.Count - 1; i >= 0; i--)
            {
                GameObject obstacle = spawnedObstacles[i];
                if (obstacle == null)
                {
                    spawnedObstacles.RemoveAt(i);
                    continue;
                }
                obstacle.transform.position += new Vector3(Settings.moveSpeed, 0, 0);
            }
        }
    }
Example #3
0
        unsafe public void ComponentEnumerator()
        {
            var go     = new GameObject("test", typeof(Rigidbody), typeof(Light));
            var entity = GameObjectEntity.AddToEntityManager(m_Manager, go);

            m_Manager.AddComponentData(entity, new EcsTestData(5));
            m_Manager.AddComponentData(entity, new EcsTestData2(6));

            var cache = new ComponentGroupArrayStaticCache(typeof(MyEntity), m_Manager);

            var array      = new ComponentGroupArray <MyEntity>(cache);
            int iterations = 0;

            foreach (var e in array)
            {
                Assert.AreEqual(5, e.testData->value);
                Assert.AreEqual(6, e.testData2->value0);
                Assert.AreEqual(go.GetComponent <Light>(), e.light);
                Assert.AreEqual(go.GetComponent <Rigidbody>(), e.rigidbody);
                iterations++;
            }
            Assert.AreEqual(1, iterations);

            cache.Dispose();
            Object.DestroyImmediate(go);
        }
        // project points onto plane
        protected override void OnUpdate()
        {
            base.OnUpdate();
            ComponentGroupArray <PlanarBezierFilter> bezierEntities = GetEntities <PlanarBezierFilter>();

            if (bezierEntities.Length > 0)
            {
                ProjectCPs(bezierEntities);
            }
        }
        // for projected points on start
        protected override void OnStartRunning()
        {
            base.OnStartRunning();
            ComponentGroupArray <PlanarBezierFilter> bezierEntities = GetEntities <PlanarBezierFilter>();

            // Project Transforms...
            if (bezierEntities.Length > 0)
            {
                ProjectCPs(bezierEntities);
            }
        }
Example #6
0
        public void ComponentGroupArraySubtractive()
        {
            var entityArrayCache = new ComponentGroupArrayStaticCache(typeof(TestEntitySub2), m_Manager);

            m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));
            m_Manager.CreateEntity(typeof(EcsTestData));

            var entities = new ComponentGroupArray <TestEntitySub2>(entityArrayCache);

            Assert.AreEqual(1, entities.Length);
        }
Example #7
0
    protected override void OnStartRunning()
    {
        base.OnStartRunning();
        _cameraOrientation = GetEntities <CameraOrientation>();

        for (int i = 0; i < _cameraOrientation.Length; ++i)
        {
            _xRot = _cameraOrientation[i].transform.localEulerAngles.x;
            _yRot = _cameraOrientation[i].transform.localEulerAngles.y;
        }
    }
Example #8
0
    protected override void OnUpdate()
    {
        float deltaTime = Time.deltaTime;

        ComponentGroupArray <blockComponent> blockComponentArray = GetEntities <blockComponent>();

        foreach (blockComponent bc in blockComponentArray)
        {
            bc.transform.rotation = bc.transform.rotation * Quaternion.AngleAxis(180 * bc.blockController.rotateSpeed * deltaTime, bc.blockController.rotationDirection);
        }
    }
        protected override void OnUpdate()
        {
            ComponentGroupArray <RotationContraintFilter> bezierEntities = GetEntities <RotationContraintFilter>();

            if (bezierEntities.Length > 0)
            {
                foreach (RotationContraintFilter entity in bezierEntities)
                {
                    ContrainRotation(entity.comp);
                }
            }
        }
Example #10
0
    protected override void OnUpdate()
    {
        ComponentGroupArray <Comp> list = GetEntities <Comp>();

        int boidPerFrame = list.Length < (amountToRefresh * list.Length) / 100 ? 1 : (amountToRefresh * list.Length) / 100;
        //Debug.Log("BoidPerFrame " + boidPerFrame);

        int startingOffset = (frameIndex * boidPerFrame) % list.Length;

        //Debug.Log(startingOffset + " = (" + frameIndex + " * " + boidPerFrame + " )% " + list.Length);

        for (int iBoidA = startingOffset; iBoidA < list.Length && iBoidA < startingOffset + boidPerFrame; iBoidA++)
        {
            for (int iBoidB = 0; iBoidB < list.Length; iBoidB++)
            {
                if (iBoidB != iBoidA)
                {
                    Comp boidA = list[iBoidA];
                    Comp boidB = list[iBoidB];

                    if (Vector3.Distance(boidA.t.position, boidB.t.position) < boidA.data.detectionRange)
                    {
                        if (Vector3.Distance(boidA.t.position, boidB.t.position) < boidA.data.detectionRange)
                        {
                            if (isDetected(boidA, boidB))
                            {
                                addToDictionnary(perceptions, boidA, boidB);
                            }
                        }
                    }
                }
            }
        }

        frameIndex++;


        foreach (Comp e in list)
        {
            if (perceptions.ContainsKey(e))
            {
                foreach (Comp otherBoid in perceptions[e])
                {
                    applyForces(e, otherBoid);
                }
            }

            applyForces(e);

            e.t.position += e.t.forward * e.data.speed;
        }
    }
    protected override void OnUpdate()
    {
        var        time           = Time.deltaTime;
        GameObject playerInstance = GameManager.GetPlayerInstance();

        ComponentGroupArray <Component> components = GetEntities <Component>();

        foreach (var e in components)
        {
            e.rigidbody.maxAngularVelocity = e.chase.maxSpeed / 2;
            Move(playerInstance, e);
        }
    }
 protected override void OnUpdate()
 {
     if (Input.GetButtonUp("Jump"))
     {
         ComponentGroupArray <RequiredComponents> matchingEntities = GetEntities <RequiredComponents>();
         foreach (var componentGroupArray in matchingEntities)
         {
             float   magnitude = componentGroupArray.jumpComponent.jumpMagnitude;
             Vector2 force     = Vector2.up * magnitude;
             componentGroupArray.rigidBody2DComponent.AddForce(force);
         }
     }
 }
Example #13
0
    protected override void OnUpdate()
    {
        float deltaTime = Time.deltaTime;
        ComponentGroupArray <MoveComponents> moveComponents = GetEntities <MoveComponents>();

        foreach (MoveComponents e in moveComponents)
        {
            e.m_transform.position += e.m_direction.m_direction * e.m_speed.m_speed * deltaTime;
            e.m_transform.rotation  = e.m_direction.m_faceToRight
                ? Quaternion.Euler(Vector3.zero)
                : Quaternion.Euler(new Vector3(0f, 180f, 0f));
        }
    }
    protected override void OnUpdate()
    {
        ComponentGroupArray <AttractableFilter> myAttractables = GetEntities <AttractableFilter>();

        float deltaTime = Time.deltaTime;

        foreach (var eAttractable in myAttractables)
        {
            for (int i = 0; i < eAttractable.data.attractorsList.List.Count; i++)
            {
                ApplyGravity(eAttractable.data.attractorsList.List[i], eAttractable.rb, deltaTime);
            }
        }
    }
    protected override void OnUpdate()
    {
        ComponentGroupArray <SpriteComponents> entities = GetEntities <SpriteComponents>();

        foreach (SpriteComponents e in entities)
        {
            if (e.m_sprite.m_switch)
            {
                if (e.m_sprite.m_animator != null)
                {
                    e.m_sprite.m_animator.Play(e.m_sprite.m_animType.ToString());
                }
            }
        }
    }
    public void Restart()
    {
        for (int i = 0; i < Snakes.Length; i++)
        {
            GameObject.Destroy(Snakes[i].SnakeComponent.gameObject);
        }

        if (StartingSnakePrefab == null)
        {
            StartingSnakePrefab = Resources.Load <GameObject>("Prefabs/Snake");
        }

        GameObject Snake = GameObject.Instantiate(StartingSnakePrefab, Vector3.zero, Quaternion.identity);

        Snake.name = Snake.name.Replace("(Clone)", "");

        Snakes = GetEntities <SnakeFilter>();
    }
    protected override void OnUpdate()
    {
        ComponentGroupArray <InputComponents> entities = GetEntities <InputComponents>();
        Vector3   direction = Vector3.zero;
        EAnimType animType  = EAnimType.fish_man_idle;

        foreach (InputComponents e in entities)
        {
            bool faceToRight = e.m_direction.m_faceToRight;
            HandleInput(out direction, ref faceToRight, out animType);
            if (e.m_inputComponent.m_isInputEnable)
            {
                e.m_direction.m_direction   = direction;
                e.m_direction.m_faceToRight = faceToRight;
                e.m_sprite.SetAnimType(animType);
            }
        }
    }
Example #18
0
    protected override void OnUpdate()
    {
        float dt = Time.deltaTime;

        float minDist = 1.0f;

        ComponentGroupArray <PlayerData> playerData = GetEntities <PlayerData>();

        foreach (var entity in GetEntities <PickUpData>())
        {
            float3 diff    = entity.pickUps.Position - playerData[0].player.Position;
            float  diffSqr = math.dot(diff, diff);

            if (diffSqr < minDist)
            {
                entity.pickUps.timeToLive = 0;
            }
        }
    }
Example #19
0
        public void ComponentAccessAfterScheduledJobThrowsEntityArray()
        {
            var entityArrayCache = new ComponentGroupArrayStaticCache(typeof(TestEntity), m_Manager);

            m_Manager.CreateComponentGroup(typeof(EcsTestData));
            m_Manager.CreateEntity(typeof(EcsTestData), typeof(EcsTestData2));

            var job = new TestCopy1To2Job();

            job.entities = new ComponentGroupArray <TestEntity>(entityArrayCache);

            var fence = job.Schedule();

            var entityArray = new ComponentGroupArray <TestEntity>(entityArrayCache);

            Assert.Throws <System.InvalidOperationException>(() => { var temp = entityArray[0]; });

            fence.Complete();
        }
    protected override void OnUpdate()
    {
        var        time           = Time.deltaTime;
        GameObject playerInstance = GameManager.GetPlayerInstance();

        ComponentGroupArray <Component> components = GetEntities <Component>();

        foreach (var e in components)
        {
            if (!e.health.hasUpdatedDamage)
            {
                MeshRenderer renderer = e.health.GetComponent <MeshRenderer>();
                UpdateMaterialColor(renderer, e.health.percentage);
                foreach (MeshRenderer child in e.health.GetComponentsInChildren <MeshRenderer>())
                {
                    UpdateMaterialColor(child, e.health.percentage);
                }

                e.health.hasUpdatedDamage = true;
            }
        }
    }
    protected override void OnUpdate()
    {
        int speed = 100;

        // Only do a getEntities when we need to.
        if (!hasEntities && eList.Length < 1)
        {
            eList       = GetEntities <Components>();
            hasEntities = true;
        }

        float d = Time.deltaTime;

        int count = eList.Length;

        for (int i = 0; i < count; i++)
        {
            Components c = eList[i];

            c.transform.Rotate(0f, c.data.speed * d, 0f);
        }
    }
    protected void _processSingleTurret(GunComponent gun, ComponentGroupArray <TEnemyGroup> enemies)
    {
        Transform gunTransform = gun.CachedTransform;

        BaseGunConfig gunConfigs = gun.mConfigs;

        /// this method can return null if there are no enemies within an attack zone
        EnemyComponent nearestEnemy = _getNearestEnemy(gunTransform, gunConfigs.mRadius, enemies);

        /// skip other logic if there are no enemies near the turret
        if (nearestEnemy == null)
        {
            return;
        }

        Transform enemyTransform = nearestEnemy.CachedTransform;

        /// rotate the turret towards a target
        gunTransform.rotation = QuaternionUtils.LookRotationXZ(enemyTransform.position - gunTransform.position);

        /// shooting logic
        if (gun.mElapsedReloadingTime > gunConfigs.mReloadInterval)
        {
            /// create a deffered request for instantiation of a new bullet
            mInstantiationBuffer.Add(new TInstantiationCommand {
                mGunPosition = gun.mBulletSpawTransform.position, mGunConfigs = gunConfigs, mEnemyTargetPosition = enemyTransform.position
            });

            gun.mElapsedReloadingTime = 0.0f;             // starts to wait for an end of a reloading cycle

            return;
        }

        /// wait for a gun is being reloading
        gun.mElapsedReloadingTime += Time.deltaTime;
    }
Example #23
0
 protected override void OnStartRunning()
 {
     base.OnStartRunning();
     Snakes  = GetEntities <SnakeFilter>();
     Enabled = GameStateSystem.Instance != null && GameStateSystem.Instance.IsPlaying;
 }
    protected EnemyComponent _getNearestEnemy(Transform gunTransform, float gunRadius, ComponentGroupArray <TEnemyGroup> enemies)
    {
        EnemyComponent currEnemy    = null;
        EnemyComponent nearestEnemy = null;

        float minDistance  = float.MaxValue;
        float currDistance = 0.0f;

        Vector3 gunPosition = gunTransform.position;

        Transform enemyTransform = null;

        for (int i = 0; i < enemies.Length; ++i)
        {
            currEnemy = enemies[i].mEnemy;

            enemyTransform = currEnemy.CachedTransform;

            currDistance = Vector3.Distance(gunPosition, enemyTransform.position);

            if (currDistance < minDistance)
            {
                minDistance = currDistance;

                nearestEnemy = currEnemy;
            }
        }

        // if the nearest enemy is located out of attach zone of the gun return null
        if (minDistance > gunRadius)
        {
            return(null);
        }

        return(nearestEnemy);
    }
    protected override void OnStartRunning()
    {
        base.OnStartRunning();

        m_cacheComponents = GetEntities <Components>();
    }
Example #26
0
 public void Restart()
 {
     Snakes = GetEntities <SnakeFilter>();
 }