コード例 #1
0
        public void ArrangeClones(bool checkForDirtiness)
        {
            if (checkForDirtiness && clones.Count != IdealCloneCount)
            {
                ComputeClones();
                return;
            }

            gameObject.hideFlags = hideClonerInHierarchy ? HideFlags.HideInHierarchy : HideFlags.None;

            int clonerIndex = transform.GetSiblingIndex();

            foreach (var clone in clones)
            {
                if (checkForDirtiness)
                {
                    if (clone == null || clone.source != GetSource(clone.index))
                    {
                        ComputeClones();
                        return;
                    }
                }

                var m = transform.localToWorldMatrix * matrices[clone.index];
                clone.gameObject.hideFlags = hideClonesInHierarchy ? HideFlags.HideInHierarchy : HideFlags.None;
                clone.transform.SetParent(transform.parent, false);
                clone.transform.SetSiblingIndex(clonerIndex + 1 + clone.index);
                clone.transform.position = GeomUtils.ExtractPosition(m);
                clone.transform.rotation = m.rotation;
            }
        }
コード例 #2
0
        void OnDrawGizmos()
        {
            if (!enabled)
            {
                return;
            }

            PainfulCallOfOnDrawGizmosOnClonesComponents();

            bool showPoints = gizmoShowPoints || (clones.Count == 0 && matrices.Length > 0);

            if (!showPoints && !gizmoShowAxis && !gizmoShowIndexes)
            {
                return;
            }

            Gizmos.matrix  = transform.localToWorldMatrix;
            Handles.matrix = transform.localToWorldMatrix;

            var cameraPosition = SceneView.currentDrawingSceneView.camera.transform.position;
            var ms             = gizmoSortByDistance
                ? GetSortedByDistanceMatrices(cameraPosition).Select(b => (b.matrix, b.index))
                : matrices.Select((m, i) => (m, i));

            GUIStyle style = new GUIStyle();

            foreach (var(m, index) in ms)
            {
                var p = GeomUtils.ExtractPosition(m);

                if (showPoints || gizmoShowIndexes)
                {
                    float x = matrices.Length > 1 ? (float)index / (matrices.Length - 1) : 0f;
                    Gizmos.color = Color.Lerp(gizmoColorA, gizmoColorB, x);
                }

                if (showPoints)
                {
                    Gizmos.DrawSphere(p, 0.1f);
                }

                if (gizmoShowIndexes)
                {
                    style.normal.textColor = Gizmos.color;
                    Handles.Label(p, string.Format("{0}", index), style);
                }

                if (gizmoShowAxis)
                {
                    Gizmos.color = Color.red;
                    Gizmos.DrawLine(p, p + GeomUtils.ExtractRight(m) * 0.5f);
                    Gizmos.color = Color.green;
                    Gizmos.DrawLine(p, p + GeomUtils.ExtractUp(m) * 0.5f);
                    Gizmos.color = Color.blue;
                    Gizmos.DrawLine(p, p + GeomUtils.ExtractForward(m) * 0.5f);
                }
            }
        }