Esempio n. 1
0
        public void OnSceneGUI()
        {
            if (Event.current.type == EventType.Repaint)
            {
                ObiRope rope = cursor.GetComponent <ObiRope>();

                ObiDistanceConstraintBatch distanceBatch = rope.DistanceConstraints.GetFirstBatch();

                Handles.color = Color.yellow;
                int     constraint = rope.GetConstraintIndexAtNormalizedCoordinate(cursor.normalizedCoord);
                Vector3 pos1       = rope.GetParticlePosition(distanceBatch.springIndices[constraint * 2]);
                Vector3 pos2       = rope.GetParticlePosition(distanceBatch.springIndices[constraint * 2 + 1]);

                if (cursor.direction)
                {
                    Handles.DrawWireDisc(pos1, pos2 - pos1, rope.thickness * 2);
                    Vector3 direction = pos2 - pos1;
                    if (direction != Vector3.zero)
                    {
                        Handles.ArrowHandleCap(0, pos1, Quaternion.LookRotation(direction), 0.2f, EventType.Repaint);
                    }
                }
                else
                {
                    Handles.DrawWireDisc(pos2, pos1 - pos2, rope.thickness * 2);
                    Vector3 direction = pos1 - pos2;
                    if (direction != Vector3.zero)
                    {
                        Handles.ArrowHandleCap(0, pos2, Quaternion.LookRotation(direction), 0.2f, EventType.Repaint);
                    }
                }
            }
        }
        private static void DrawGizmos(ObiRopeCursor cursor, GizmoType gizmoType)
        {
            var rope = cursor.GetComponent <ObiRope>();

            if (rope.solver != null)
            {
                Gizmos.color = new Color(1, 0.5f, 0, 0.75f);

                // draw source particle:
                int sourceIndex = cursor.sourceParticleIndex;

                if (sourceIndex >= 0 && rope.IsParticleActive(rope.solver.particleToActor[sourceIndex].indexInActor))
                {
                    Vector3 pos = rope.GetParticlePosition(sourceIndex);
                    Gizmos.DrawWireSphere(pos, HandleUtility.GetHandleSize(pos) * 0.4f);
                }

                // draw cursor:
                var element = cursor.cursorElement;

                if (element != null && element.particle1 != element.particle2)
                {
                    Vector3 pos       = rope.GetParticlePosition(cursor.direction ? element.particle1 : element.particle2);
                    Vector3 pos2      = rope.GetParticlePosition(cursor.direction ? element.particle2 : element.particle1);
                    Vector3 direction = pos2 - pos;

                    float size = HandleUtility.GetHandleSize(pos) * 0.4f;
                    Gizmos.matrix = Matrix4x4.TRS(pos, Quaternion.LookRotation(direction), Vector3.one * size);
                    DrawArrow();
                }
            }
        }