示例#1
0
 public ForkEventArgs(SplineBase spline, int splinePointIndex)
 {
     SelectedConnectionIndex = -1;
     m_junction         = spline.GetJunction(splinePointIndex);
     m_spline           = spline;
     m_splinePointIndex = splinePointIndex;
 }
示例#2
0
        public virtual void CreateSplineWalker(
            SplineBase spline,
            SplineWalkerMode mode,
            int duration,
            bool canTriggerEvents = true,
            SplineWalkerTriggerDirection triggerDirection = SplineWalkerTriggerDirection.Forward,
            bool autoStart = true)
        {
            _Spline          = spline;
            _AutoStart       = autoStart;
            CanTriggerEvents = canTriggerEvents;
            TriggerDirection = triggerDirection;
            Duration         = duration;
            WalkerMode       = mode;

            SetPosition(0);
            GetProgress = 0;
            ResetTriggerIndex(false);

            _Spline.EventTriggered += EventTriggered;

            _oldKeyboardState = Keyboard.GetState();
            _oldGamePadState  = GamePad.GetState(PlayerIndex.One);

            Initialized = true;
        }
示例#3
0
        private void UpdateDraggingPositionOnSpline()
        {
            Vector3    positionOnSpline = _target.PositionWithoutOffsetFromSpline(_target.PathPosition);
            Quaternion rotationOnSpline = _target.RotationWithoutOffsetFromSpline(_target.PathPosition);

            EditorGUI.BeginChangeCheck();
            Vector3 newPosition = Handles.PositionHandle(Tools.pivotMode != PivotMode.Center ? positionOnSpline : _target.transform.position, Tools.pivotRotation == PivotRotation.Global ? Quaternion.identity : rotationOnSpline);

            //newPosition = _target.SplineBase.AttemptToApplyGrid(newPosition, 0.1f);
            if (EditorGUI.EndChangeCheck())
            {
                SerializedProperty offset         = this.GetPropertie("_offsetFromTarget");
                SerializedProperty splineProperty = this.GetPropertie("_spline");
                SplineBase         spline         = splineProperty.GetValue <SplineBase>();


                float closestPositionOnSpline = spline.FindClosestPoint(newPosition, 0, -1, 10);
                float currentUnits            = spline.FromPathNativeUnits(closestPositionOnSpline, _target.PositionUnits);
                currentUnits = _target.SplineBase.AttemptToApplyGrid(currentUnits, 0.01f);

                offset.floatValue = currentUnits - _target.PathPositionTarget;
                UpdatePositionFromEditor(offset);
                this.ApplyModification();
            }
        }
示例#4
0
        public static void DrawPathGizmo(SplineBase path, Color pathColor)
        {
            // Draw the path
            Color colorOld = Gizmos.color;

            Gizmos.color = pathColor;
            float   step    = 1f / path.Resolution;
            Vector3 lastPos = path.EvaluatePosition(path.MinPos);
            Vector3 lastW   = (path.EvaluateOrientation(path.MinPos)
                               * Vector3.right) * path.Appearances.Width / 2;

            for (float t = path.MinPos + step; t <= path.MaxPos + step / 2; t += step)
            {
                Vector3    p  = path.EvaluatePosition(t);
                Quaternion q  = path.EvaluateOrientation(t);
                Vector3    w  = (q * Vector3.right) * path.Appearances.Width / 2;
                Vector3    w2 = w * 1.2f;
                Vector3    p0 = p - w2;
                Vector3    p1 = p + w2;
                Gizmos.DrawLine(p0, p1);
                Gizmos.DrawLine(lastPos - lastW, p - w);
                Gizmos.DrawLine(lastPos + lastW, p + w);
#if false
                // Show the normals, for debugging
                Gizmos.color = Color.red;
                Vector3 y = (q * Vector3.up) * path.m_Appearance.width / 2;
                Gizmos.DrawLine(p, p + y);
                Gizmos.color = pathColor;
#endif
                lastPos = p;
                lastW   = w;
            }
            Gizmos.color = colorOld;
        }
示例#5
0
        private static float GetT(this SplineBase spline, float tStart, float tEnd, Vector3 testPoint, ref int iter, float eps = 0.01f)
        {
            iter++;
            float   sqrEps = eps * eps;
            Vector3 start  = spline.GetPoint(tStart);
            Vector3 end    = spline.GetPoint(tEnd);

            Vector3 toStart = start - testPoint;
            Vector3 toEnd   = end - testPoint;

            if (toStart.sqrMagnitude < toEnd.sqrMagnitude)
            {
                if ((end - start).sqrMagnitude <= sqrEps)
                {
                    return(tStart);
                }
                return(spline.GetT(tStart, (tStart + tEnd) / 2.0f, testPoint, ref iter, eps));
            }

            if ((end - start).sqrMagnitude <= sqrEps)
            {
                return(tEnd);
            }
            return(spline.GetT((tStart + tEnd) / 2.0f, tEnd, testPoint, ref iter, eps));
        }
        public void OnClosed()
        {
            if (RuntimeSelection.gameObjects == null)
            {
                return;
            }

            GameObject[] gameObjects = RuntimeSelection.gameObjects.OfType <GameObject>().ToArray();
            for (int i = 0; i < gameObjects.Length; ++i)
            {
                GameObject go = gameObjects[i];
                if (go == null)
                {
                    continue;
                }

                SplineBase spline = go.GetComponentInParent <SplineBase>();
                if (spline == null)
                {
                    continue;
                }

                spline.Unselect();
            }
        }
示例#7
0
 private void Restart()
 {
     m_spline      = Spline;
     m_t           = Offset % 1;
     m_isCompleted = false;
     IsRunning     = true;
 }
        public bool ChangeSplineAndPosition(SplineBase splineBase, float newPosition)
        {
            if (_splineController.SplineBase == splineBase)
            {
                ChangePosition(newPosition);
                return(false);
            }
            SerializedProperty spline       = this.GetPropertie("_spline");
            SerializedProperty pathPosition = this.GetPropertie("_pathPosition");

            spline.objectReferenceValue = splineBase;
            pathPosition.floatValue     = newPosition;
            this.ApplyModification();

            ResetEventsOfControllersEvents(_splineController.transform);

            ControllerStickOffset[] allOffset = FindObjectsOfType <ControllerStickOffset>();
            for (int i = 0; i < allOffset.Length; i++)
            {
                if (allOffset[i] == _splineController)
                {
                    continue;
                }
                ControllerStickOffsetEditor offsetEditor = (ControllerStickOffsetEditor)UnityEditor.Editor.CreateEditor((ControllerStickOffset)allOffset[i], typeof(ControllerStickOffsetEditor));
                offsetEditor.ChangeSplineOfController(splineBase);
                DestroyImmediate(offsetEditor);

                ResetEventsOfControllersEvents(allOffset[i].transform);
            }

            this.ApplyModification();
            return(true);
        }
示例#9
0
        protected override SplineEditorEvent GetEvent(out SplineEditorEventArgs args)
        {
            SplineEditorEvent evnt = SplineEditorEvent.None;

            args = null;

            SplineBase[]     splines         = Splines;
            SplineRenderer[] splineRenderers = SplineRenderers;
            if (splines == null || splineRenderers == null)
            {
                return(SplineEditorEvent.None);
            }

            SplineRenderer dragSplineRenderer = null;

            for (int i = 0; i < splines.Length; ++i)
            {
                SplineRenderer splineRenderer = splineRenderers[i];
                SplineBase     spline         = splines[i];

                for (int j = 0; j < spline.PointsCount; ++j)
                {
                    if ((IsJunctionDrag || IsSplinePointCreator) && DragSpline == spline && j == DragPointIndex)
                    {
                        dragSplineRenderer = splineRenderer;
                        continue;
                    }

                    DrawSplinePoint(ref args, ref evnt, splineRenderer, spline, j);
                }
            }

            if (IsSplinePointCreator || IsJunctionDrag)
            {
                DrawSplinePoint(ref args, ref evnt, dragSplineRenderer, DragSpline, DragPointIndex);
            }

            if (evnt == SplineEditorEvent.SplinePointDrag || evnt == SplineEditorEvent.SplinePointCreatorDrag)
            {
                m_pointerOver = false;
            }

            if (evnt == SplineEditorEvent.SplinePointDrop || evnt == SplineEditorEvent.SplinePointCreatorDrop)
            {
                if (m_pointerOverSpline != null && m_pointerOverSplinePointIndex != -1)
                {
                    if (!m_pointerOver)
                    {
                        m_pointerOverSpline           = null;
                        m_pointerOverSplinePointIndex = -1;
                    }

                    args = new SplineEditorEventArgs(m_pointerOverSpline, m_pointerOverSplinePointIndex);
                    m_pointerOverSpline           = null;
                    m_pointerOverSplinePointIndex = -1;
                }
            }

            return(evnt);
        }
        public override void OnInspectorGUI()
        {
            SerializedObject sObj = GetSerializedObject();

            sObj.Update();
            m_firstTarget = targets[0];
            if (m_splineBase == null)
            {
                m_splineBase = GetTarget();
            }

            if (m_splineBase == null)
            {
                return;
            }

            DrawSelectedPointInspectorsOverride();
            OnInspectorGUIOverride();


            if (target != null)
            {
                sObj.ApplyModifiedProperties();
            }
        }
示例#11
0
        private void EndDrag()
        {
            if (m_junctionDrag)
            {
                if (m_dragJunction.ConnectionsCount < 2)
                {
                    DestroyObject(m_dragJunction.gameObject);
                }
            }

            m_beforeSplinePointCreatorDrag = false;
            m_splinePointCreatorDrag       = false;

            m_splinePointDrag = false;

            m_beforeJunctionDrag = false;
            m_junctionDrag       = false;

            m_splineCtrlPointDrag = false;

            m_newJunction        = null;
            m_dragSpline         = null;
            m_dragPointIndex     = -1;
            m_dragCtrlPointIndex = -1;
            m_dragJunction       = null;
        }
示例#12
0
        public void Find(IEnumerable <JunctionBase> junctions, IEnumerable <SplineBase> splines)
        {
            m_queue.Clear();

            m_visitedSplines   = new HashSet <SplineBase>(splines.Distinct());
            m_visitedJunctions = new HashSet <JunctionBase>(junctions.Distinct());
            foreach (JunctionBase junction in m_visitedJunctions)
            {
                m_queue.Enqueue(junction);
            }

            foreach (SplineBase spline in m_visitedSplines)
            {
                ExtractJunctions(spline);
            }

            while (m_queue.Count != 0)
            {
                JunctionBase junction = m_queue.Dequeue();
                for (int i = 0; i < junction.ConnectionsCount; ++i)
                {
                    SplineBase spline = junction.GetSpline(i);
                    if (spline != null)
                    {
                        if (!m_visitedSplines.Contains(spline))
                        {
                            ExtractJunctions(spline);
                            m_visitedSplines.Add(spline);
                        }
                    }
                }
            }
        }
示例#13
0
        public override void OnInspectorGUI()
        {
            SplineBase spline = (target as SplineBase);

            if (GUILayout.Button("Copy material parameters to layer"))
            {
                Layer      layer           = spline.Layer;
                Material[] sharedMaterials = spline.GetComponent <Renderer>().sharedMaterials;
                for (int i = 0; i < sharedMaterials.Length; ++i)
                {
                    if (!sharedMaterials[i].HasProperty("CMain"))
                    {
                        continue;
                    }
                    layer.mainColor         = sharedMaterials[i].GetColor("CMain");
                    layer.specularColor     = sharedMaterials[i].GetColor("CSpecular");
                    layer.fresnelIntensity  = sharedMaterials[i].GetFloat("CFresnelIntensity");
                    layer.diffuse.tile      = sharedMaterials[i].GetFloat("CDiffuseTile");
                    layer.detail.tile       = sharedMaterials[i].GetFloat("CDetailTile");
                    layer.normal.tile       = sharedMaterials[i].GetFloat("CNormalTile");
                    layer.detailNormal.tile = sharedMaterials[i].GetFloat("CDetailNormalTile");
                    layer.normal.bump       = sharedMaterials[i].GetFloat("CNormalBump");
                    layer.detailNormal.bump = sharedMaterials[i].GetFloat("CDetailNormalBump");
                }
            }
        }
示例#14
0
        private Quaternion GetDragPointRotation(SplineBase spline, int index, int nextIndex, int ctrlPointIndex)
        {
            Vector3 nextCtrlPointPosition =
                spline.InterpolationMode == 0 ?
                spline.GetCtrlPointPosition(nextIndex, ctrlPointIndex) :
                spline.GetPointPosition(nextIndex);

            Vector3 toNextSplinePoint = index < nextIndex ?
                                        nextCtrlPointPosition - spline.GetPointPosition(index) :
                                        spline.GetPointPosition(index) - nextCtrlPointPosition;

            GameObject ctrlPoint = index < nextIndex?spline.GetCtrlPoint(index, 1) : spline.GetCtrlPoint(index, 0);

            Vector3 v = index < nextIndex ? Vector3.forward : Vector3.back;

            if (toNextSplinePoint.magnitude > MinMag)
            {
                Quaternion rotation;
                if (ctrlPoint != null)
                {
                    Quaternion rot = Quaternion.FromToRotation(ctrlPoint.transform.localPosition.normalized, v);
                    rotation = Quaternion.LookRotation(toNextSplinePoint) * rot;
                }
                else
                {
                    rotation = Quaternion.LookRotation(toNextSplinePoint);
                }

                return(rotation);
            }
            return(spline.GetPointRotation(index));
        }
示例#15
0
        static void AddPoint(SplineBase spline)
        {
            Vector3[] points     = spline.Points;
            string[]  colorNames = spline.Info.colorNames;
            int       i          = spline.ActivePoint;

            if (spline.IsHazard)
            {
                ArrayUtility.Insert(ref colorNames, i, colorNames[i]);
            }
            if (i != 0)
            {
                ArrayUtility.Insert(ref points, i, Vector3.Lerp(points[i], points[i - 1], 0.5f));
                points[i].y     = CourseBase.TerrainHeight(points[i].x, points[i].z);
                points[i - 1].y = CourseBase.TerrainHeight(points[i - 1].x, points[i - 1].z);
            }
            else
            {
                ArrayUtility.Insert(ref points, i, Vector3.Lerp(points[i], points[points.Length - 1], 0.5f));
                points[i].y = CourseBase.TerrainHeight(points[i].x, points[i].z);
                points[points.Length - 1].y = CourseBase.TerrainHeight(points[points.Length - 1].x, points[points.Length - 1].z);
            }

            spline.Points          = points;
            spline.Info.colorNames = colorNames;
            spline.UpdateLine();
            spline.LineChanged();
        }
示例#16
0
        protected override void Initialize()
        {
            base.Initialize();

            Setup.Initialize(Editor.graphics);
            Setup.ShowCurves           = false;
            Setup.ShowDirectionVectors = false;
            Setup.ShowLines            = false;
            Setup.ShowPoints           = false;
            UseWorldUnits = true;

            MySpline = Editor.Content.Load <SplineBase>("RaceTrack");
            MySpline.PolygonStripeTexture = Editor.Content.Load <Texture2D>("roadTexture");
            MySpline.Loop = true;
            GetSpline     = MySpline;

            CenterSpline();

            SetMultiSampleCount(8);

            Editor.SetDisplayStyle    = Forms.Services.GFXService.DisplayStyle.TopRight;
            Editor.ShowCursorPosition = false;
            Editor.ShowFPS            = false;

            OnMouseWheelUpwards   += PolygonSplineControl_OnMouseWheelUpwards;
            OnMouseWheelDownwards += PolygonSplineControl_OnMouseWheelDownwards;
        }
        private void Start()
        {
            SplineRuntimeEditor.Created   += OnRuntimeEditorCreated;
            SplineRuntimeEditor.Destroyed += OnRuntimeEditorDestroyed;

            CreateRuntimeComponents();
            if (m_spline == null)
            {
                m_spline = GetComponentInParent <SplineBase>();
                if (m_spline == null)
                {
                    Debug.LogError("Is not a child of gameobject with Spline or MeshDeformer component");
                    return;
                }
                m_spline.ControlPointModeChanged     -= OnControlPointModeChanged;
                m_spline.ControlPointModeChanged     += OnControlPointModeChanged;
                m_spline.ControlPointPositionChanged -= OnControlPointPositionChanged;
                m_spline.ControlPointPositionChanged += OnControlPointPositionChanged;
            }

            m_localPosition         = m_spline.GetControlPointLocal(m_index);
            transform.localPosition = m_localPosition;

            UpdateMaterial();
        }
        public static GameObject CreatePointsLister(string nameGameObject = "Points Lister")
        {
            GameObject whereToPut;

            if (Selection.activeGameObject != null)
            {
                SplineBase spline = Selection.activeGameObject.GetComponent <SplineBase>();
                if (spline != null)
                {
                    whereToPut = new GameObject(nameGameObject);
                    whereToPut.transform.SetParent(spline.transform);
                    whereToPut.transform.localPosition = Vector3.zero;
                    Undo.RegisterCreatedObjectUndo(whereToPut, "Create " + nameGameObject);
                }
                else
                {
                    whereToPut = Selection.activeGameObject;
                }
            }
            else
            {
                whereToPut = new GameObject(nameGameObject);
                whereToPut.transform.localPosition = Vector3.zero;
                Undo.RegisterCreatedObjectUndo(whereToPut, "Create " + nameGameObject);
            }
            return(whereToPut);
        }
示例#19
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Loading a spline with the MonoGame.SplineFlower.Content.Pipeline
            // MySpline = Content.Load<SplineBase>(@"BezierTest");
            // MySpline = Content.Load<SplineBase>(@"CatMulRomTest");
            MySpline = Content.Load <SplineBase>(@"HermiteTest");

            // Place a SplineWalker on the spline
            MySplineWalker = new Car();
            MySplineWalker.CreateSplineWalker(MySpline, SplineWalker.SplineWalkerMode.Loop, 7);
            MySplineWalker.LoadContent(Content, Content.Load <SpriteFont>(@"GameFont"));

            // Uncomment to directly set the position of the spline (SplineCenter)
            // MySpline.Position(new Vector2(200, 150));

            // Uncomment to translate all control points of the spline from where the it spawned
            // MySpline.Translate(new Vector2(200, 150));

            // Uncomment to rotate the spline
            // MySpline.Rotate(-90f);

            // Uncomment to scale the spline
            // MySpline.Scale(-50f);

            // Uncomment to scale-rotate the spline and scale it again afterwards
            // MySpline.ScaleRotate(-180f);
            // MySpline.Scale(-50f);
        }
示例#20
0
        private void Awake()
        {
            enabled = false;

            m_splinePoint = GetComponentInParent <SplinePointBase>();
            m_spline      = GetComponentInParent <SplineBase>();
        }
示例#21
0
 static void HazardChangeClear()
 {
     startSpline          = null;
     startSplineIndex     = -1;
     startSplineDirection = 1;
     startSplineLayer     = null;
     endSplineIndex       = -1;
 }
示例#22
0
 private void OnScriptReloaded()
 {
     m_spline = GetComponent <SplineBase>();
     if (GLRenderer.Instance != null)
     {
         GLRenderer.Instance.Add(this);
     }
 }
        private void Start()
        {
            if (m_spline == null)
            {
                m_spline = GetComponent <SplineBase>();
            }

            Initialize();
        }
 public override void ChangeSpline(SplineBase newSpline, float newPosition)
 {
     base.ChangeSpline(newSpline, newPosition);
     ManageSplineChange();
     if (_isOnDifferentSpline)
     {
         _lastPathPosition = newPosition;
     }
 }
        //protected virtual void OnStartDragging(GameObject current)
        //{
        //    if (_splineController == null)
        //    {
        //        return;
        //    }
        //    if (current != _splineController.gameObject)
        //    {
        //        return;
        //    }
        //    this.UpdateEditor();
        //
        //    _anchorOption = this.GetPropertie("_anchorOnSplineMoved").boolValue;
        //    this.GetPropertie("_anchorOnSplineMoved").boolValue = true;
        //
        //
        //    _positionAtStartLerp = _previousDraggingPosition = _splineController.PathPosition;
        //    //SetSticky(false);
        //    this.ApplyModification();
        //}

        //protected virtual void OnEndDragging(GameObject current)
        //{
        //    if (_splineController == null)
        //    {
        //        return;
        //    }
        //    if (current != _splineController.gameObject)
        //    {
        //        return;
        //    }
        //    this.UpdateEditor();
        //
        //    this.GetPropertie("_anchorOnSplineMoved").boolValue = _anchorOption;
        //
        //
        //    //SetSticky(true);
        //    this.ApplyModification();
        //}

        public void ConstructSpline(SplineBase spline)
        {
            this.UpdateEditor();
            if (spline != null)
            {
                ExtSerializedProperties.SetObjectReferenceValueIfEmpty <SplineBase>(this.GetPropertie("_spline"), spline.transform);
            }
            ExtSerializedProperties.SetObjectReferenceValueIfEmpty <Transform>(this.GetPropertie("_toMove"), _splineController.transform);
            this.ApplyModification();
        }
示例#26
0
        public static float GetLengthAS(this SplineBase spline, int curve, float tmax, float error)
        {
            Vector3[] v = spline.Slice(curve, tmax);

            float length = 0.0f;

            AddIfClose(v, ref length, error);

            return(length);
        }
示例#27
0
        protected override SplineBase GetTarget()
        {
            ControlPoint controlPoint = (ControlPoint)target;

            if (controlPoint != null)
            {
                SplineBase spline = controlPoint.GetComponentInParent <SplineBase>();
                return(spline);
            }
            return(null);
        }
示例#28
0
        protected override SplineBase GetTarget()
        {
            Scaffold scaffold = (Scaffold)target;

            if (scaffold != null)
            {
                SplineBase spline = scaffold.GetComponentInParent <SplineBase>();
                return(spline);
            }
            return(null);
        }
        private void Start()
        {
            SplineFollow[] splineFollow = SplineFollow.Where(sf => sf != null).ToArray();
            if (splineFollow.Length == 0)
            {
                return;
            }
            if (Distances.Length == 0)
            {
                Debug.LogError("At least one distance required");
                return;
            }
            int initialDistancesCount = Distances.Length;

            System.Array.Resize(ref Distances, SplineFollow.Length - 1);
            for (int i = initialDistancesCount; i < Distances.Length; ++i)
            {
                Distances[i] = Distances[i % initialDistancesCount];
            }

            float      offset = InitialOffset;
            SplineBase spline = splineFollow[0].Spline;

            for (int i = 0;; ++i)
            {
                SplineFollow sf = splineFollow[i];
                if (sf.Spline != spline)
                {
                    Debug.LogError("SplineFollow.Spline != " + spline);
                    return;
                }
                sf.Offset = offset;
                if (i == splineFollow.Length - 1)
                {
                    break;
                }
                float   distance = Distances[i];
                Vector3 pt0      = spline.GetPoint(offset);
                for (int j = 1; j <= Precision; ++j)
                {
                    float t = offset - ((float)j) / Precision;
                    if (t < 0)
                    {
                        t = (1.0f + t % 1.0f);
                    }
                    Vector3 pt = spline.GetPoint(t);
                    if ((pt - pt0).magnitude >= distance)
                    {
                        offset = t;
                        break;
                    }
                }
            }
        }
        private void OnDisable()
        {
            OnDisableOverride();

            SplineBase spline = GetTarget();

            if (spline)
            {
                spline.Unselect();
            }
        }