Beispiel #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);
    }
Beispiel #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);
    }
Beispiel #3
0
    public void SetParent(AGrowable parent)
    {
        Parent = parent;

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

        SetParentBehaviour(parent);
    }
Beispiel #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);
    }
Beispiel #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);
    }
Beispiel #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;
    }
Beispiel #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;
             }
         }
     }
 }
Beispiel #8
0
 void Start()
 {
     _environmentHelper = FindObjectOfType <EnvironmentHelper>();
     _assetManager      = FindObjectOfType <AssetManager>();
     _root = AddNewBranch(null);
 }
Beispiel #9
0
 public bool IsEnlightened(AGrowable growable)
 {
     return(!Physics.Raycast(growable.GameObject.transform.position, _sun.transform.position - growable.GameObject.transform.position, 1000));
 }
Beispiel #10
0
 public virtual void SetParentBehaviour(AGrowable parent)
 {
 }