コード例 #1
0
        /// Yield a set of locations and orientations for each target
        public IEnumerable <LayoutObject> Layout(IAnimationTarget target)
        {
            var count      = target.GameObjects().Count();
            var n          = (int)Mathf.Floor(Mathf.Sqrt(count));
            var origin_x   = -Width / 2f * Left;
            var origin_y   = -Height / 2f * Up;
            var interval_x = Width / (n - 1) * Left; // Number of gaps, not objects
            var interval_y = Height / (n - 1) * Up;
            var offset     = 0;

            foreach (var gp in target.GameObjects())
            {
                var x     = offset / n;
                var y     = offset % n;
                var pos_x = origin_x + x * interval_x;
                var pos_y = origin_y + y * interval_y;
                offset += 1;
                var pos = this.Origin + pos_x + pos_y;
                yield return(new LayoutObject
                {
                    GameObject = gp,
                    Rotation = this.Rotation,
                    Position = pos
                });
            }
        }
コード例 #2
0
        /// Yield a set of locations and orientations for each target
        public IEnumerable <LayoutObject> Layout(IAnimationTarget target)
        {
            var count = target.GameObjects().Count();
            var half  = (count - 1) / 2f;

            // Since the parent controls the layout, the left is always the same
            var left = Vector3.left;

            // Find the origin for layout
            var origin = -left * half * _gap;

            // Layout towards the given target~
            var offset = 0;

            foreach (var gp in target.GameObjects())
            {
                var pos = origin + offset * _gap * left + this._offset;
                yield return(new LayoutObject
                {
                    GameObject = gp,
                    Rotation = Quaternion.LookRotation(Vector3.forward, Vector3.up),
                    Position = pos
                });

                offset += 1;
            }
        }
コード例 #3
0
        /// Yield a set of locations and orientations for each target
        public IEnumerable<LayoutObject> Layout(IAnimationTarget target)
        {
            var count = target.GameObjects().Count();
            var half = (count - 1) / 2f;

            /// Since the parent controls the layout, the left is always the same
            var left = Vector3.left;

            /// Find the origin for layout
            var origin = -left * half * gap;

            /// Layout towards the given target~
            var offset = 0;
            foreach (var gp in target.GameObjects())
            {
                var pos = origin + offset * gap * left + this.offset;
                yield return new LayoutObject
                {
                    gameObject = gp,
                    rotation = Quaternion.LookRotation(Vector3.forward, Vector3.up),
                    position = pos
                };
                offset += 1;
            }
        }
コード例 #4
0
 /// Yield a set of locations and orientations for each target
 public IEnumerable<LayoutObject> Layout(IAnimationTarget target)
 {
     var count = target.GameObjects().Count();
     var n = (int)Mathf.Floor(Mathf.Sqrt(count));
     var origin_x = -width / 2f * left;
     var origin_y = -height / 2f * up;
     var interval_x = width / (n - 1) * left;  // Number of gaps, not objects
     var interval_y = height / (n - 1) * up;
     var offset = 0;
     foreach (var gp in target.GameObjects())
     {
         var x = offset / n;
         var y = offset % n;
         var pos_x = origin_x + x * interval_x;
         var pos_y = origin_y + y * interval_y;
         offset += 1;
         var pos = this.origin + pos_x + pos_y;
         yield return new LayoutObject
         {
             gameObject = gp,
             rotation = this.rotation,
             position = pos
         };
     }
 }
コード例 #5
0
 /// Add an animation to a specific stream
 public void Add(TStream stream, IAnimation animation, IAnimationCurve curve, IAnimationTarget target)
 {
     Validate();
     animation.AnimationCurve  = curve;
     animation.AnimationTarget = target;
     Streams.Add(stream, animation);
 }
コード例 #6
0
 /// Yield a set of locations and orientations for each target
 public IEnumerable<LayoutObject> Layout(IAnimationTarget target)
 {
     var count = target.GameObjects().Count();
     var origin_x = -width / 2f * left;
     var interval_x = width / (count - 1) * left;  // Number of gaps, not objects
     var offset = 0;
     foreach (var gp in target.GameObjects())
     {
         var pos_x = origin_x + offset * interval_x;
         var pos = this.origin + pos_x;
         offset += 1;
         yield return new LayoutObject
         {
             gameObject = gp,
             rotation = this.rotation,
             position = pos
         };
     }
 }
コード例 #7
0
        /// Yield a set of locations and orientations for each target
        public IEnumerable <LayoutObject> Layout(IAnimationTarget target)
        {
            var count     = target.GameObjects().Count();
            var originX   = -Width / 2f * Left;
            var intervalX = Width / (count - 1) * Left; // Number of gaps, not objects
            var offset    = 0;

            foreach (var gp in target.GameObjects())
            {
                var posX = originX + offset * intervalX;
                var pos  = Origin + posX;
                offset += 1;
                yield return(new LayoutObject
                {
                    GameObject = gp,
                    Rotation = Rotation,
                    Position = pos
                });
            }
        }
コード例 #8
0
 /// Yield a set of locations and orientations for each target
 public IEnumerable<LayoutObject> Layout(IAnimationTarget target)
 {
     var count = target.GameObjects().Count();
     var base_arc = Mathf.Deg2Rad * (180f - (arc * (count - 1))) / 2f;
     var step = arc * Mathf.Deg2Rad;
     var normal = Vector3.Cross(left, up);
     var offset = 0;
     foreach (var gp in target.GameObjects())
     {
         var angle = offset * step;
         var pos_x = Mathf.Cos(base_arc + angle) * length * left;
         var pos_y = Mathf.Sin(base_arc + angle) * length * up;
         var new_normal = (pos_x + pos_y).normalized;
         var pos = this.origin + pos_x + pos_y + normal * verticalIncrement * offset;
         offset += 1;
         yield return new LayoutObject
         {
             gameObject = gp,
             rotation = Quaternion.LookRotation(new_normal, normal),
             position = pos
         };
     }
 }
コード例 #9
0
        /// Yield a set of locations and orientations for each target
        public IEnumerable <LayoutObject> Layout(IAnimationTarget target)
        {
            var count   = target.GameObjects().Count();
            var baseArc = Mathf.Deg2Rad * (180f - (Arc * (count - 1))) / 2f;
            var step    = Arc * Mathf.Deg2Rad;
            var normal  = Vector3.Cross(Left, Up);
            var offset  = 0;

            foreach (var gp in target.GameObjects())
            {
                var angle     = offset * step;
                var posX      = Mathf.Cos(baseArc + angle) * Length * Left;
                var posY      = Mathf.Sin(baseArc + angle) * Length * Up;
                var newNormal = (posX + posY).normalized;
                var pos       = Origin + posX + posY + normal * VerticalIncrement * offset;
                offset += 1;
                yield return(new LayoutObject
                {
                    GameObject = gp,
                    Rotation = Quaternion.LookRotation(newNormal, normal),
                    Position = pos
                });
            }
        }
コード例 #10
0
        /// Yield a set of locations and orientations for each target
        public IEnumerable <LayoutObject> Layout(IAnimationTarget target)
        {
            // Get objects
            var objects = target.GameObjects().ToArray();

            if (objects.Length == 0)
            {
                yield break;
            }

            // Get camera
            if (Camera == null)
            {
                Camera = Camera.main;
            }

            // Angle between instances
            var spread = 2 * Mathf.PI / objects.Length;

            // Cast to origin point; yes, we do this every frame
            var origin = Camera.WorldToScreenPoint(WorldObject.transform.position);

            // Place on the ring
            for (var i = 0; i < objects.Length; ++i)
            {
                var x     = Radius * Mathf.Cos(i * spread);
                var y     = Radius * Mathf.Sin(i * spread);
                var trans = WorldObject.transform;
                yield return(new LayoutObject
                {
                    GameObject = objects[i],
                    Rotation = trans.rotation,
                    Position = origin + x * trans.right + y * trans.up
                });
            }
        }
コード例 #11
0
 public IEnumerable <LayoutObject> Layout(IAnimationTarget target)
 {
     yield break;
 }
コード例 #12
0
 public IEnumerable<LayoutObject> Layout(IAnimationTarget target)
 {
   yield break;
 }
コード例 #13
0
ファイル: LayoutManager.cs プロジェクト: PcloD/unity-n-layout
        /// Apply a layout to a specific target
        public void Add(TStream stream, ILayout layout, LayoutFactoryDelegate factory, IAnimationTarget target)
        {
            var anims = new List <IAnimation>();

            foreach (var lp in layout.Layout(target))
            {
                var animation = factory(lp);
                _manager.Streams.Add(stream, animation);
                anims.Add(animation);
            }
            _pending.Add(new LayoutPending(anims.ToArray(), layout));
        }