protected override void BodyGUI()
        {
            base.BodyGUI();
            EditorGUILayout.LabelField("Tracer", EditorStyles.boldLabel);
            SplineTracer tracer = (SplineTracer)target;

            tracer.direction   = (Spline.Direction)EditorGUILayout.EnumPopup("Direction", tracer.direction);
            tracer.physicsMode = (SplineFollower.PhysicsMode)EditorGUILayout.EnumPopup("Physics mode", tracer.physicsMode);
            if (tracer.physicsMode == SplineFollower.PhysicsMode.Rigidbody)
            {
                Rigidbody rb = tracer.GetComponent <Rigidbody>();
                if (rb == null)
                {
                    EditorGUILayout.HelpBox("Assign a Rigidbody component.", MessageType.Error);
                }
                else if (rb.interpolation == RigidbodyInterpolation.None && tracer.updateMethod != SplineUser.UpdateMethod.FixedUpdate)
                {
                    EditorGUILayout.HelpBox("Switch to FixedUpdate mode to ensure smooth update for non-interpolated rigidbodies", MessageType.Warning);
                }
            }
            else if (tracer.physicsMode == SplineFollower.PhysicsMode.Rigidbody2D)
            {
                Rigidbody2D rb = tracer.GetComponent <Rigidbody2D>();
                if (rb == null)
                {
                    EditorGUILayout.HelpBox("Assign a Rigidbody2D component.", MessageType.Error);
                }
                else if (rb.interpolation == RigidbodyInterpolation2D.None && tracer.updateMethod != SplineUser.UpdateMethod.FixedUpdate)
                {
                    EditorGUILayout.HelpBox("Switch to FixedUpdate mode to ensure smooth update for non-interpolated rigidbodies", MessageType.Warning);
                }
            }

            motionEditor.DrawInspector();
            customOffsetEditor.allowSelection = editIndex == -1;
            customOffsetEditor.DrawInspector();
            customRotationEditor.allowSelection = editIndex == -1;
            customRotationEditor.DrawInspector();
            triggerFoldout = EditorGUILayout.Foldout(triggerFoldout, "Triggers");
            if (triggerFoldout)
            {
                int lastTrigger = trigger;
                SplineEditorGUI.TriggerArray(ref tracer.triggers, ref trigger);
                if (lastTrigger != trigger)
                {
                    Repaint();
                }
            }
            cameraFoldout = EditorGUILayout.Foldout(cameraFoldout, "Camera preview");
            if (cameraFoldout)
            {
                if (cam == null)
                {
                    cam = tracer.GetComponentInChildren <Camera>();
                }
                if (cam != null)
                {
                    if (rt == null || rt.width != GetRTWidth() || rt.height != GetRTHeight())
                    {
                        CreateRT();
                    }
                    GUILayout.Box("", GUILayout.Width(rt.width), GUILayout.Height(rt.height));
                    RenderTexture    prevTarget = cam.targetTexture;
                    RenderTexture    prevActive = RenderTexture.active;
                    CameraClearFlags lastFlags  = cam.clearFlags;
                    Color            lastColor  = cam.backgroundColor;
                    cam.targetTexture   = rt;
                    cam.clearFlags      = CameraClearFlags.Color;
                    cam.backgroundColor = Color.black;
                    cam.Render();
                    RenderTexture.active = rt;
                    renderCanvas.SetPixels(new Color[renderCanvas.width * renderCanvas.height]);
                    renderCanvas.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
                    renderCanvas.Apply();
                    RenderTexture.active = prevActive;
                    cam.targetTexture    = prevTarget;
                    cam.clearFlags       = lastFlags;
                    cam.backgroundColor  = lastColor;
                    GUI.DrawTexture(GUILayoutUtility.GetLastRect(), renderCanvas, ScaleMode.StretchToFill);
                }
                else
                {
                    EditorGUILayout.HelpBox("There is no camera attached to the selected object or its children.", MessageType.Info);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            BaseGUI();
            SplineFollower user = (SplineFollower)target;

            user.followMode = (SplineFollower.FollowMode)EditorGUILayout.EnumPopup("Follow mode", user.followMode);
            user.wrapMode   = (SplineFollower.Wrap)EditorGUILayout.EnumPopup("Wrap mode", user.wrapMode);
            GUI.color       = Color.white;

            user.findStartPoint = EditorGUILayout.Toggle("Find Start Point", user.findStartPoint);
            if (!user.findStartPoint)
            {
                user.startPercent = EditorGUILayout.Slider("Start percent", (float)user.startPercent, (float)user.clipFrom, (float)user.clipTo);
            }

            user.autoFollow = EditorGUILayout.Toggle("Auto follow", user.autoFollow);
            if (user.autoFollow)
            {
                if (user.followMode == SplineFollower.FollowMode.Uniform)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("", GUILayout.Width(20));
                    user.followSpeed = EditorGUILayout.FloatField("Follow speed", user.followSpeed);
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Label("", GUILayout.Width(20));
                    user.followDuration = EditorGUILayout.FloatField("Follow duration", user.followDuration);
                    EditorGUILayout.EndHorizontal();
                }
            }
            user.direction = (Spline.Direction)EditorGUILayout.EnumPopup("Direction", user.direction);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(20));
            user.applyPosition = EditorGUILayout.Toggle("Apply position", user.applyPosition);
            EditorGUILayout.EndHorizontal();
            if (user.applyPosition)
            {
                user.offset = EditorGUILayout.Vector2Field("Offset", user.offset);
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(20));
            user.applyRotation = EditorGUILayout.Toggle("Apply rotation", user.applyRotation);
            EditorGUILayout.EndHorizontal();

            if (user.applyRotation)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(40));
                user.applyDirectionRotation = EditorGUILayout.Toggle("Apply follow direction", user.applyDirectionRotation);
                EditorGUILayout.EndHorizontal();
                user.rotationOffset = EditorGUILayout.Vector3Field("Rotation Offset", user.rotationOffset);
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("", GUILayout.Width(20));
            user.applyScale = EditorGUILayout.Toggle("Apply scale", user.applyScale);
            EditorGUILayout.EndHorizontal();

            if (user.applyScale)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(40));
                user.baseScale = EditorGUILayout.Vector3Field("Base scale", user.baseScale);
                EditorGUILayout.EndHorizontal();
            }

            if (GUI.changed && !Application.isPlaying && user.computer != null)
            {
                if (!user.findStartPoint)
                {
                    SplineResult result = GetFollowResult(user, user.startPercent);
                    if (user.autoFollow)
                    {
                        if (user.applyPosition)
                        {
                            user.transform.position = result.position;
                        }
                        if (user.applyRotation)
                        {
                            float dir = 1;
                            if (user.applyDirectionRotation)
                            {
                                dir = user.followSpeed > 0 ? 1f : -1f;
                            }
                            user.transform.rotation = Quaternion.LookRotation(result.direction * dir, result.normal);
                        }
                        if (user.applyScale)
                        {
                            user.transform.localScale = user.baseScale * result.size;
                        }
                    }
                    else
                    {
                        SceneView.RepaintAll();
                    }
                }
            }



            triggerFoldout = EditorGUILayout.Foldout(triggerFoldout, "Triggers");
            if (triggerFoldout)
            {
                int lastTrigger = trigger;
                SplineEditorGUI.TriggerArray(ref user.triggers, ref trigger);
                if (lastTrigger != trigger)
                {
                    Repaint();
                }
            }
        }
Exemple #3
0
        public override void OnInspectorGUI()
        {
            SplineProjector user = (SplineProjector)target;

            if (user.mode == SplineProjector.Mode.Accurate)
            {
                showResolution = false;
                showAveraging  = false;
            }
            else
            {
                showResolution = true;
                showAveraging  = true;
            }
            BaseGUI();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Projector", EditorStyles.boldLabel);
            user.mode = (SplineProjector.Mode)EditorGUILayout.EnumPopup("Mode", user.mode);
            if (user.mode == SplineProjector.Mode.Accurate)
            {
                user.subdivide = EditorGUILayout.IntSlider("Subdivisions", user.subdivide, 1, 8);
            }
            user.projectTarget = (Transform)EditorGUILayout.ObjectField("Project Target", user.projectTarget, typeof(Transform), true);
            user.target        = (Transform)EditorGUILayout.ObjectField("Apply Target", user.target, typeof(Transform), true);
            GUI.color          = Color.white;

            if (user.target != null)
            {
                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(20));
                user.applyPosition = EditorGUILayout.Toggle("Apply position", user.applyPosition);
                EditorGUILayout.EndHorizontal();
                if (user.applyPosition)
                {
                    user.offset = EditorGUILayout.Vector2Field("Offset", user.offset);
                }

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(20));
                user.applyRotation = EditorGUILayout.Toggle("Apply rotation", user.applyRotation);
                EditorGUILayout.EndHorizontal();
                if (user.applyPosition)
                {
                    user.rotationOffset = EditorGUILayout.Vector3Field("Rotation Offset", user.rotationOffset);
                }

                EditorGUILayout.BeginHorizontal();
                GUILayout.Label("", GUILayout.Width(20));
                user.applyScale = EditorGUILayout.Toggle("Apply scale", user.applyScale);
                EditorGUILayout.EndHorizontal();
            }


            //user.smooth = EditorGUILayout.Toggle("Smooth", user.smooth);
            user.autoProject = EditorGUILayout.Toggle("Auto Project", user.autoProject);

            triggerFoldout = EditorGUILayout.Foldout(triggerFoldout, "Triggers");
            if (triggerFoldout)
            {
                int lastTrigger = trigger;
                serializedObject.Update();
                SplineEditorGUI.TriggerArray(ref user.triggers, ref trigger);
                serializedObject.ApplyModifiedProperties();
                if (lastTrigger != trigger)
                {
                    Repaint();
                }
            }

            if (GUI.changed && !Application.isPlaying && user.computer != null)
            {
                if (user.autoProject)
                {
                    user.CalculateProjection();
                    if (user.target == null)
                    {
                        SceneView.RepaintAll();
                    }
                }
            }
        }