Example #1
0
        private static void ApplyPosition(StickFromMouseSceneView stick, SceneView sceneView)
        {
            Ray mouseRay = CalculateMousePosition(sceneView);

            if (SplineLister.Instance != null && SplineLister.Instance.SplineCount > 0)
            {
                List <SplineBase> splines             = SplineLister.Instance.GetSplineBases();
                Vector3[]         closestSpline       = new Vector3[splines.Count];
                float[]           closestPathPosition = new float[splines.Count];

                for (int i = 0; i < splines.Count; i++)
                {
                    float closest = splines[i].FindClosestPointFromRay(mouseRay, 100, 1, stick.PositionUnits);
                    closestSpline[i]       = splines[i].EvaluatePositionAtUnit(closest, stick.PositionUnits);
                    closestPathPosition[i] = closest;
                }

                int closestIndex = GetClosestPointToRay(mouseRay, out float minDist, closestSpline);
                ControllerStickEditor pointsEditor = (ControllerStickEditor)UnityEditor.Editor.CreateEditor((ControllerStick)stick.ControllerStick, typeof(ControllerStickEditor));
                pointsEditor.ChangeSplineAndPosition(splines[closestIndex], closestPathPosition[closestIndex]);
                GameObject.DestroyImmediate(pointsEditor);
            }
            else
            {
                float closest = stick.Spline.FindClosestPointFromRay(mouseRay, 100, 1, stick.PositionUnits);
                ChangePosition(stick.ControllerStick, closest);
            }
        }
Example #2
0
        public static void SetReference(StickFromMouseSceneView stick)
        {
            if (StickReference.Count == 0)
            {
#if UNITY_2019_1_OR_NEWER
                SceneView.duringSceneGui -= DuringSceneGUI;
                SceneView.duringSceneGui += DuringSceneGUI;
#else
                SceneView.onSceneGUIDelegate -= DuringSceneGUI;
                SceneView.onSceneGUIDelegate += DuringSceneGUI;
#endif
            }
            StickReference.AddIfNotContain(stick);
        }