Ejemplo n.º 1
0
        public static LeafBud Create(Branch parent, Vector3 pos, float angle, Sprite sprite)
        {
            GameObject o = new GameObject("leaf");

            o.transform.SetParent(parent.transform, false);
            o.transform.position = pos;
            //SpriteRenderer r = o.AddComponent<SpriteRenderer>();
            //r.sprite = sprite;
            //r.sortingOrder = 10;

            LeafBud l = o.AddComponent <LeafBud>();

            l.parent = parent;

            l.angle = angle;

            Vector3 n = Vector3.Cross(parent.transform.forward, parent.parent.transform.forward);

            o.transform.Rotate(n, angle);

            parent.leaf.Add(l);

            //o.transform.LookAt (parent.transform.up + parent.transform.position);


            return(l);
        }
Ejemplo n.º 2
0
 private void Leafing(Branch b, int leafcount = 3)
 {
     for (int i = 0; i < leafcount; i++)
     {
         LeafBud l = LeafBud.Create(b,
                                    b.transform.position + b.transform.rotation * b.smoothsteps [(int)(b.smoothsteps.Length * (float)(i + 1) / (leafcount + 1))],
                                    30.0f * ((i % 2 == 0? 1 : (-1))), this.leaf);
     }
 }
Ejemplo n.º 3
0
        protected Vector3 WorldDir(LeafBud l, int childcount)
        {
            Vector3 result = Vector3.zero;

            Vector3 normal = Vector3.Cross(l.parent.dir, l.parent.parent.dir);
            Vector3 target = l.parent.dir;

            result = Quaternion.AngleAxis((Random.Range(1, 10) % 2 == 0? 1 : -1) * l.angle, normal * -1) * target;

            return(result.normalized);
        }