Example #1
0
    public override void UpdateBehaviour(EnergyRegulator energyRegulator, float deltaTime)
    {
        if (energyRegulator.IsDepletedUnrecoverable())
        {
            if (IsLastBranch())
            {
                Kill();
            }
            else
            {
                // Don't kill but stop growing and stop all energy transfert
                // the consequence is that the child branch will die which seems good in this case
            }
        }
        else
        {
            // Branch consume additional energy based on their size
            //energyRegulator.ConsumeEnergy(deltaTime * CurrentSize * 0.2f * CountAllChildren(true)/* _sizeConsumptionFactor*/);

            if (CanCreateNewLeaf(energyRegulator))
            {
                Owner.AddNewLeaf(this, _nextLeafSpawn);
                energyRegulator.ConsumeEnergy(_energyNeededToCreateLeaf);
                _nextLeafSpawn = Random.Range(_leafSpawnPercentMin, _leafSpawnPercentMax);
            }

            // TODO make a component to manage Growable creation
            if (CanCreateNewBud(energyRegulator))
            {
                Owner.AddNewBud(this, _nextBudSpawn);
                energyRegulator.ConsumeEnergy(_energyNeededToCreateBud);
                _nextBudSpawn = Random.Range(_budSpawnPercentMin, _budSpawnPercentMax);
            }
        }
    }