Exemplo n.º 1
0
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject go in _toRemove)
        {
            WithHealth withHealth = go.GetComponent <WithHealth>();

            if (withHealth && withHealth.deathParticles)
            {
                Object.Instantiate(withHealth.deathParticles, go.GetComponent <Collider>().bounds.center, go.transform.rotation);
            }

            GameObjectManager.unbind(go);
            Object.Destroy(go);
        }
    }
Exemplo n.º 2
0
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject go in _Damagers)
        {
            // Decrease cooldown
            Damager damager = go.GetComponent <Damager>();
            damager.cooldown -= Time.deltaTime;

            // Can the damager attack ?
            if (damager.cooldown > 0)
            {
                continue;
            }

            // It does, so check if it can hit something
            InCollision3D collider = go.GetComponent <InCollision3D>();
            if (collider.Targets.Length == 0)
            {
                continue;
            }

            // Something is in collision, can we damage it ?
            GameObject target   = collider.Targets[0];
            WithHealth targetWH = target.GetComponent <WithHealth>();
            int        i        = 1;

            while (i < collider.Targets.Length && targetWH == null)
            {
                target   = collider.Targets[i];
                targetWH = target.GetComponent <WithHealth>();
                ++i;
            }
            if (i == collider.Targets.Length)
            {
                continue;
            }

            // We can ! Hit and reset cooldown
            targetWH.health -= damager.damagesPerSec;
            if (targetWH.health <= 0)
            {
                GameObjectManager.addComponent <Removed>(target);
            }
            damager.cooldown = 1;
        }
    }
Exemplo n.º 3
0
    public DynamicMaterialSystem()
    {
        foreach (GameObject go in _dynGO)
        {
            DynamicMaterial dynMat = go.GetComponent <DynamicMaterial>();

            if (dynMat.type == EDynMat.HEALTH)
            {
                WithHealth healthComp = go.GetComponent <WithHealth>();
                healthComp.maxHealth = healthComp.health;
                dynMat.percentage    = healthComp.health / healthComp.maxHealth;
            }
            else if (dynMat.type == EDynMat.FREEZE)
            {
                Frozen comp = go.GetComponent <Frozen>();
                dynMat.percentage = 0;
                if (comp)
                {
                    dynMat.percentage = comp.remainingTime / comp.totalTime;
                }
            }
            else if (dynMat.type == EDynMat.B_Cell)
            {
                BCell comp = go.GetComponent <BCell>();
                if (comp)
                {
                    dynMat.percentage = comp.cooldown / comp.delay;
                }
            }

            foreach (Material mat in go.GetComponent <Renderer>().materials)
            {
                if (mat.name.Contains(dynMat.materialName) || go.GetComponent <Renderer>().materials.Length == 1)
                {
                    mat.color = dynMat.startingColor;
                }
            }
        }
    }
Exemplo n.º 4
0
    // Use to process your families.
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject go in _dynGO)
        {
            DynamicMaterial dynMat = go.GetComponent <DynamicMaterial>();

            if (dynMat.type == EDynMat.HEALTH)
            {
                WithHealth healthComp = go.GetComponent <WithHealth>();
                dynMat.percentage = healthComp.health / healthComp.maxHealth;
            }
            else if (dynMat.type == EDynMat.FREEZE)
            {
                Frozen comp = go.GetComponent <Frozen>();
                dynMat.percentage = 0;
                if (comp)
                {
                    dynMat.percentage = comp.remainingTime / comp.totalTime;
                }
            }
            else if (dynMat.type == EDynMat.B_Cell)
            {
                BCell comp = go.GetComponent <BCell>();
                if (comp)
                {
                    dynMat.percentage = comp.cooldown / comp.delay;
                }
            }

            foreach (Material mat in go.GetComponent <Renderer>().materials)
            {
                if (mat.name.Contains(dynMat.materialName) || go.GetComponent <Renderer>().materials.Length == 1)
                {
                    mat.color = Color.Lerp(dynMat.endingColor, dynMat.startingColor, dynMat.percentage);
                }
            }
        }
    }
Exemplo n.º 5
0
    protected override void onProcess(int familiesUpdateCount)
    {
        foreach (GameObject entity in _cells)
        {
            Cell cell = entity.GetComponent <Cell>();

            // If a pathogene entered in the cell, the cell state is changed to INFECTED
            // We also add components that will indicate the cell can be eaten by macrophages
            if (cell.state.Equals(CellState.HEALTHY) && cell.infections.Count > 0)
            {
                cell.state = CellState.INFECTED;
                GameObjectManager.addComponent <Eatable>(entity, new { eatableMask = INFECTED_EATABLE_LAYER });
            }

            // If the cell is infected, we have to replicate all pathogenes, resulting in consuming resources
            // Resources are represented as the cell's health
            WithHealth healthComponent = entity.GetComponent <WithHealth>();
            if (cell.state.Equals(CellState.INFECTED))
            {
                int i = 0;

                while (healthComponent.health > 1 && i < cell.infections.Count)
                {
                    GameObject go         = cell.infections[i].prefab;
                    Infectious infectious = go.GetComponent <Infectious>();

                    // Decrease cooldown
                    infectious.cooldown -= Time.deltaTime;
                    if (infectious.cooldown < 0)
                    {
                        // Replicate once
                        cell.infections[i].nb++;
                        cell.infections[i].originalNb++;

                        healthComponent.health -= infectious.replicationCost;

                        // Reset cooldown
                        infectious.cooldown = infectious.replicationTime;
                    }

                    ++i;
                }

                // If the is no more resources, the cell is about to die
                if (healthComponent.health <= 0)
                {
                    cell.state = CellState.DEAD;
                }
            }

            // The cell is about to die, the factory is created
            if (cell.state.Equals(CellState.DEAD))
            {
                // Create the factory
                GameObject obj = new GameObject();
                obj.transform.position = entity.transform.position;

                // Configure the factory
                Factory factory = obj.AddComponent <Factory>();
                factory.rate              = DEFAULT_RATE;
                factory.entries           = cell.infections;
                factory.useRandomSpawning = true;

                // Bind it to FYFY
                GameObjectManager.bind(obj);

                // Set all prefab as children of the created factory : they will be removed when the factory will desappear too.
                foreach (FactoryEntry entry in cell.infections)
                {
                    entry.prefab.transform.SetParent(obj.transform);
                }

                // Die
                GameObjectManager.addComponent <Removed>(entity);
            }
        }
    }