Exemplo n.º 1
0
    public void RemoveChild(AGrowable child)
    {
        Assert.IsTrue(Children.ContainsKey(child.Type), "Keys must be initialized in the constructor.");

        child.SetParent(null);
        Children[child.Type].Remove(child);
    }
Exemplo n.º 2
0
    public void AddChild(AGrowable child)
    {
        Assert.IsTrue(Children.ContainsKey(child.Type), "Keys must be initialized in the constructor.");

        child.SetParent(this);
        Children[child.Type].Add(child);
    }
Exemplo n.º 3
0
    public void SetParent(AGrowable parent)
    {
        Parent = parent;

        if (parent != null)
        {
            Depth = parent.Depth + 1;
        }

        SetParentBehaviour(parent);
    }
Exemplo n.º 4
0
    public Leaf AddNewLeaf(AGrowable parent, float relativePercentPosition = 0f)
    {
        GameObject gameObject = _assetManager.CreateLeaf(transform);

        Leaf growable = new Leaf(this, gameObject, relativePercentPosition);

        gameObject.GetComponent <GrowableComponent>().Growable = growable;
        gameObject.transform.localScale = Vector3.zero;

        if (parent != null)
        {
            parent.AddChild(growable);
        }
        return(growable);
    }
Exemplo n.º 5
0
    public override void SetParentBehaviour(AGrowable parent)
    {
        // TODO clean
        MaxSize = parent.MaxSize / 2f;

        // TODO: Add these angles in a param
        Vector3 rotation;

        rotation.x = UnityEngine.Random.Range(-45f, 45f);
        rotation.y = UnityEngine.Random.Range(-45f, 45f);
        rotation.z = UnityEngine.Random.Range(-45f, 45f);

        // We need to rotate only once for now
        GameObject.transform.Rotate(rotation);
    }
Exemplo n.º 6
0
    // Params, they must be configurable

    public AGrowable(Tree owner, GameObject gameObject, GrowableType type, Vector3 scale, float maxSize, float relativePercentPosition, EnergyRegulator.EnergyData energyData)
    {
        Owner      = owner;
        GameObject = gameObject;
        Type       = type;
        Scale      = scale;
        RelativePercentPosition = relativePercentPosition;
        EnergyRegulator         = new EnergyRegulator(energyData);

        // Initialiaze the children container
        Children = new Dictionary <GrowableType, List <AGrowable> >();
        foreach (GrowableType growableType in (GrowableType[])Enum.GetValues(typeof(GrowableType)))
        {
            Children[growableType] = new List <AGrowable>();
        }
        Depth       = 0;
        CurrentSize = 0;
        MaxSize     = maxSize;
        Parent      = null;
    }
Exemplo n.º 7
0
 public override void UpdateBehaviour(EnergyRegulator energyRegulator, float deltaTime)
 {
     if (energyRegulator.IsDepletedUnrecoverable())
     {
         Kill();
     }
     else if (!ShouldDie())
     {
         // Accumulate energy from the sun
         if (EnvironmentHelper.Instance.IsEnlightened(this))
         {
             AGrowable growable = Parent;
             while (growable != null)
             {
                 // Energy is distributed to all parent equally
                 // TODO gain energy only if all parent are not depletedUnrecoverable
                 float energyGain = (_energyGainPerSecond * deltaTime) / Depth;
                 growable.EnergyRegulator.GainEnergy(energyGain);
                 growable = growable.Parent;
             }
         }
     }
 }
Exemplo n.º 8
0
 void Start()
 {
     _environmentHelper = FindObjectOfType <EnvironmentHelper>();
     _assetManager      = FindObjectOfType <AssetManager>();
     _root = AddNewBranch(null);
 }
Exemplo n.º 9
0
 public bool IsEnlightened(AGrowable growable)
 {
     return(!Physics.Raycast(growable.GameObject.transform.position, _sun.transform.position - growable.GameObject.transform.position, 1000));
 }
Exemplo n.º 10
0
 public virtual void SetParentBehaviour(AGrowable parent)
 {
 }