コード例 #1
0
ファイル: GLCurvyRenderer.cs プロジェクト: Klanly/UnityClient
 void OnPostRender()
 {
     if (Splines.Length == 0)
     {
         return;
     }
     for (int s = 0; s < Splines.Length; s++)
     {
         CurvySplineBase   spline    = Splines[s];
         UnityEngine.Color lineColor = (s < Colors.Length) ? Colors[s] : UnityEngine.Color.green;
         if (spline && spline.IsInitialized)
         {
             Points = spline.GetApproximation();
             CreateLineMaterial();
             lineMaterial.SetPass(0);
             GL.Begin(GL.LINES);
             GL.Color(lineColor);
             for (int i = 1; i < Points.Length; i++)
             {
                 GL.Vertex(Points[i - 1]);
                 GL.Vertex(Points[i]);
             }
             GL.End();
         }
     }
 }
コード例 #2
0
 void Awake()
 {
     mRenderer = GetComponent<LineRenderer>();
     m_Spline = GetComponent<CurvySpline>();
     if (!m_Spline)
         m_Spline = GetComponent<CurvySplineGroup>();
 }
 void OnSplineRefresh(CurvySplineBase spline)
 {
     Planar = CurvyUtility.isPlanar(Spline, out IgnoreAxis);
     if (Planar)
         Triangulate();
     Repaint();
 }
コード例 #4
0
        /*! \cond PRIVATE */

        void getInterpolatedSourcePosition(CurvySplineBase spline, float tf, out Vector3 position, out Vector3 tangent, out Vector3 up)
        {
            if (spline.Length == 0)
            {
                position = spline.transform.localPosition;
                tangent  = Vector3.forward;
                up       = Vector3.up;
            }
            else
            {
                if (UseCache)
                {
                    position = spline.InterpolateFast(tf);
                    tangent  = spline.GetTangentFast(tf);
                }
                else
                {
                    position = spline.Interpolate(tf);
                    tangent  = spline.GetTangent(tf, position);
                }
                up = spline.GetOrientationUpFast(tf);
            }
            if (Space == Space.World)
            {
                position = spline.transform.TransformPoint(position);
                tangent  = spline.transform.TransformDirection(tangent);
                up       = spline.transform.TransformDirection(up);
            }
        }
コード例 #5
0
ファイル: CurvySplineBase.cs プロジェクト: Kaiymu/OOS_Tools
 protected void OnRefreshEvent(CurvySplineBase sender)
 {
     if (OnRefresh != null)
     {
         OnRefresh(sender);
     }
 }
 void hookSplineEvents(CurvySplineBase spline)
 {
     if (SplineOnRefresh.IsSetup)
     {
         spline.OnRefresh.AddListener(onSplineRefresh);
         setupEventTarget(SplineOnRefresh, ref splineOnRefreshEventTarget);
     }
 }
コード例 #7
0
 void UnhookSpline(CurvySplineBase spline)
 {
     if (!spline)
     {
         return;
     }
     spline.OnRefresh -= OnSourceRefresh;
 }
コード例 #8
0
 SplinePolyLine(CurvySplineBase spline, VertexCalculation vertexMode, float angle, float distance, Space space = Space.World)
 {
     Spline     = spline;
     VertexMode = vertexMode;
     Angle      = angle;
     Distance   = distance;
     Space      = space;
 }
コード例 #9
0
 void OnSplineRefresh(CurvySplineBase sender)
 {
     if (Time.realtimeSinceStartup - mLastRefresh > AutoRefreshSpeed)
     {
         mLastRefresh = Time.realtimeSinceStartup;
         Refresh();
     }
 }
コード例 #10
0
 void OnSplineRefresh(CurvySplineBase spline)
 {
     Planar = CurvyUtility.isPlanar(Spline, out IgnoreAxis);
     if (Planar)
     {
         Triangulate();
     }
     Repaint();
 }
コード例 #11
0
 void Awake()
 {
     mRenderer = GetComponent <LineRenderer>();
     m_Spline  = GetComponent <CurvySpline>();
     if (!m_Spline)
     {
         m_Spline = GetComponent <CurvySplineGroup>();
     }
 }
コード例 #12
0
        public override void OnEnter()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(GameObject);

            if (go)
            {
                _spl = go.GetComponent <CurvySplineBase>();
            }
        }
コード例 #13
0
 void OnSplineRefresh(CurvySplineBase spl)
 {
     if (!Splines.Contains((CurvySpline)spl))
     {
         spl.OnRefresh -= OnSplineRefresh;
         return;
     }
     doRefreshLength();
 }
コード例 #14
0
 void UnhookSpline(CurvySplineBase spline)
 {
     if (!spline)
     {
         return;
     }
     spline.OnRefresh.RemoveListener(OnSourceRefresh);
     splineTransforms.Remove(spline);
 }
コード例 #15
0
 public void Add(CurvySplineBase spline)
 {
     if (spline != null)
     {
         Splines.Add(new GLSlotData()
         {
             Spline = spline
         });
     }
 }
コード例 #16
0
 public void Remove(CurvySplineBase spline)
 {
     for (int i = Splines.Count - 1; i >= 0; i--)
     {
         if (Splines[i].Spline == spline)
         {
             Splines.RemoveAt(i);
         }
     }
 }
コード例 #17
0
 void HookSpline(CurvySplineBase spline)
 {
     if (!spline)
     {
         return;
     }
     spline.OnRefresh.AddListenerOnce(OnSourceRefresh);
     if (!splineTransforms.ContainsKey(spline))
     {
         splineTransforms.Add(spline, new TTransform(spline.transform));
     }
 }
コード例 #18
0
    // Look for another lane to the left or right
    bool TrySwitchLane(Vector3 dir)
    {
        CurvySplineBase followUpSpline;
        float           newTF;

        if (RaycastForFollowUpSpline(dir, out followUpSpline, out newTF))
        {
            Spline = followUpSpline;
            TF     = newTF;
            return(true);
        }
        return(false);
    }
コード例 #19
0
ファイル: CurvyUtility.cs プロジェクト: shaunvxc/Infamy
        public CurvyMeshSegmentInfo(SplinePathMeshBuilder mb, float tf, float distance, Vector3 scale)
        {
            Target = mb.Spline;
            TF = tf;
            mDistance = distance;

            Vector3 p = (mb.FastInterpolation) ? Target.InterpolateFast(TF) : Target.Interpolate(TF);

            if (mb.UseWorldPosition)
                Matrix = Matrix4x4.TRS(mb.Transform.InverseTransformPoint(p), Target.GetOrientationFast(TF), scale);
            else
                Matrix = Matrix4x4.TRS(Target.Transform.InverseTransformPoint(p), Target.GetOrientationFast(TF), scale);
        }
コード例 #20
0
        void CurveGUI(SplinePolyLine curve)
        {
            GUILayout.BeginHorizontal();
            CurvySplineBase o = curve.Spline;

            curve.Spline = (CurvySplineBase)EditorGUILayout.ObjectField(curve.Spline, typeof(CurvySplineBase), true, GUILayout.Width(140));

            if (o != curve.Spline)
            {
                UnhookSpline(o);
            }
            HookSpline(curve.Spline);

            curve.VertexMode = (SplinePolyLine.VertexCalculation)EditorGUILayout.EnumPopup(curve.VertexMode, GUILayout.Width(140));
            GUILayout.Space(20);
            curve.Orientation = (ContourOrientation)EditorGUILayout.EnumPopup(curve.Orientation);
            if (GUILayout.Button(new GUIContent(CurvyStyles.DeleteSmallTexture, "Remove"), GUILayout.ExpandWidth(false)))
            {
                if (curve.Spline)
                {
                    UnhookSpline(curve.Spline);
                }
                Curves.Remove(curve);
                refreshNow = true;
                GUIUtility.ExitGUI();
            }
            switch (curve.VertexMode)
            {
            case SplinePolyLine.VertexCalculation.ByAngle:
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.Space(150);
                float lw = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 40;
                curve.Angle = Mathf.Max(0, EditorGUILayout.FloatField("Angle", curve.Angle, GUILayout.Width(140)));
                EditorGUIUtility.labelWidth = 60;
                GUILayout.Space(20);
                curve.Distance = EditorGUILayout.FloatField("Min. Dist.", curve.Distance, GUILayout.Width(150));
                EditorGUIUtility.labelWidth = lw;
                if (curve.Angle == 0)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(140);
                    EditorGUILayout.HelpBox("Angle must be >0", MessageType.Error);
                }
                break;
            }
            GUILayout.EndHorizontal();
        }
コード例 #21
0
 GLSlotData getSlot(CurvySplineBase spline)
 {
     if (spline)
     {
         foreach (var slot in Splines)
         {
             if (slot.Spline == spline)
             {
                 return(slot);
             }
         }
     }
     return(null);
 }
コード例 #22
0
    static public void CreateCloneBuilder()
    {
        var path = SplinePathCloneBuilder.Create();

        if (Selection.activeGameObject)
        {
            CurvySplineBase spl = Selection.activeGameObject.GetComponent <CurvySplineBase>();

            if (spl)
            {
                path.Spline = spl;
            }
        }
        Selection.activeGameObject = path.gameObject;
    }
コード例 #23
0
        // Code that runs on entering the state.
        public override void OnEnter()
        {
            if (!Spline.IsNone)
            {
                mSpline = Spline.Value.GetComponent <CurvySplineBase>();
            }

            if (mSpline && !everyFrame)
            {
                DoInterpolate();
            }
            if (!everyFrame)
            {
                Finish();
            }
        }
コード例 #24
0
ファイル: Obsolete.cs プロジェクト: scumbly/Organ-Grinder
    public CurvyMeshSegmentInfo(SplinePathMeshBuilder mb, float tf, float distance, Vector3 scale)
    {
        Target    = mb.Spline;
        TF        = tf;
        mDistance = distance;

        Vector3 p = (mb.FastInterpolation) ? Target.InterpolateFast(TF) : Target.Interpolate(TF);

        if (mb.UseWorldPosition)
        {
            Matrix = Matrix4x4.TRS(mb.Transform.InverseTransformPoint(p), Target.GetOrientationFast(TF), scale);
        }
        else
        {
            Matrix = Matrix4x4.TRS(Target.transform.InverseTransformPoint(p), Target.GetOrientationFast(TF), scale);
        }
    }
コード例 #25
0
 // Raycast a direction for another spline and get the nearest position on it
 bool RaycastForFollowUpSpline(Vector3 dir, out CurvySplineBase newSpline, out float newTF)
 {
     newSpline = null;
     newTF = 0;
     Ray R = new Ray(mTransform.position, dir);
     RaycastHit hitInfo;
     if (Physics.Raycast(R, out hitInfo, LAYER_LANE))
     {
         newSpline = hitInfo.collider.transform.parent.GetComponent<CurvySplineBase>();
         if (newSpline)
         {
             newTF = newSpline.GetNearestPointTF(hitInfo.point);
             return true;
         }
     }
     return false;
 }
コード例 #26
0
ファイル: GLCurvyRenderer.cs プロジェクト: shaunvxc/Infamy
 void RenderSpline(CurvySplineBase spl, Color lineColor)
 {
     if (spl && spl.IsInitialized)
     {
         Points = spl.GetApproximation();
         CreateLineMaterial();
         lineMaterial.SetPass(0);
         GL.Begin(GL.LINES);
         GL.Color(lineColor);
         for (int i = 1; i < Points.Length; i++)
         {
             GL.Vertex(Points[i - 1]);
             GL.Vertex(Points[i]);
         }
         GL.End();
     }
 }
コード例 #27
0
        // Code that runs on entering the state.
        public override void OnEnter()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(GameObject);

            if (go)
            {
                mSpline = go.GetComponent <CurvySplineBase>();
                if (mSpline && !everyFrame && !lateUpdate)
                {
                    DoInterpolate();
                }
            }
            if (!everyFrame)
            {
                Finish();
            }
        }
コード例 #28
0
 void RenderSpline(CurvySplineBase spl, Color lineColor)
 {
     if (spl && spl.IsInitialized)
     {
         Points = spl.GetApproximation();
         CreateLineMaterial();
         lineMaterial.SetPass(0);
         GL.Begin(GL.LINES);
         GL.Color(lineColor);
         for (int i = 1; i < Points.Length; i++)
         {
             GL.Vertex(Points[i - 1]);
             GL.Vertex(Points[i]);
         }
         GL.End();
     }
 }
コード例 #29
0
    // Raycast a direction for another spline and get the nearest position on it
    bool RaycastForFollowUpSpline(Vector3 dir, out CurvySplineBase newSpline, out float newTF)
    {
        newSpline = null;
        newTF     = 0;
        Ray        R = new Ray(mTransform.position, dir);
        RaycastHit hitInfo;

        if (Physics.Raycast(R, out hitInfo, LAYER_LANE))
        {
            newSpline = hitInfo.collider.transform.parent.GetComponent <CurvySplineBase>();
            if (newSpline)
            {
                newTF = newSpline.GetNearestPointTF(hitInfo.point);
                return(true);
            }
        }
        return(false);
    }
コード例 #30
0
        void CurveGUI(SplinePolyLine curve, bool canRemove)
        {
            GUILayout.BeginVertical(GUI.skin.box);
            GUILayout.BeginHorizontal();
            CurvySplineBase o = curve.Spline;

            curve.Spline = (CurvySplineBase)EditorGUILayout.ObjectField(new GUIContent("Spline", "Note: Curves from a SplineGroup needs to be connected!"), curve.Spline, typeof(CurvySplineBase), true);
            if (o != curve.Spline)
            {
                UnhookSpline(o);
            }
            HookSpline(curve.Spline);
            if (canRemove)
            {
                if (GUILayout.Button(new GUIContent(mTexDelete, "Remove"), GUILayout.ExpandWidth(false)))
                {
                    if (curve.Spline)
                    {
                        UnhookSpline(curve.Spline);
                    }
                    Curves.Remove(curve);
                    refreshNow = true;
                    GUIUtility.ExitGUI();
                }
            }
            GUILayout.EndHorizontal();

            curve.VertexMode = (SplinePolyLine.VertexCalculation)EditorGUILayout.EnumPopup(new GUIContent("Vertex Generation"), curve.VertexMode);

            switch (curve.VertexMode)
            {
            case SplinePolyLine.VertexCalculation.ByAngle:
                curve.Angle = Mathf.Max(0, EditorGUILayout.FloatField(new GUIContent("Angle"), curve.Angle));
                if (curve.Angle == 0)
                {
                    EditorGUILayout.HelpBox("Angle must be >0", MessageType.Error);
                }
                curve.Distance = EditorGUILayout.FloatField(new GUIContent("Minimum Distance"), curve.Distance);
                break;
            }
            GUILayout.EndVertical();
        }
コード例 #31
0
 /// <summary>
 /// Grows/Shrinks a spline or a spline group
 /// </summary>
 /// <param name="spline">the spline or group</param>
 /// <param name="center">the center of the effect</param>
 /// <param name="growByPercent">the percentage to grow/shrink</param>
 internal static void Grow(CurvySplineBase spline, UnityEngine.Vector3 center, float growByPercent)
 {
     if (spline is CurvySplineGroup)
     {
         CurvySplineGroup grp = (CurvySplineGroup)spline;
         foreach (CurvySpline spl in grp.Splines)
         {
             Grow(spl, center, growByPercent);
         }
     }
     else
     {
         CurvySpline spl = (CurvySpline)spline;
         foreach (CurvySplineSegment cp in spl.ControlPoints)
         {
             UnityEngine.Vector3 dir = center - cp.Position;
             float dist = dir.magnitude;
             cp.Position = center + dir.normalized * dist * growByPercent;
         }
     }
 }
コード例 #32
0
        public static void CreateMeshBuilder()
        {
            var path = SplinePathMeshBuilder.Create();
            var prim = GameObject.CreatePrimitive(PrimitiveType.Plane);

#if UNITY_3_5_7
            prim.active = false;
#else
            prim.SetActive(false);
#endif
            path.GetComponent <MeshRenderer>().sharedMaterial = prim.GetComponent <MeshRenderer>().sharedMaterial;
            DestroyImmediate(prim);
            if (Selection.activeGameObject)
            {
                CurvySplineBase spl = Selection.activeGameObject.GetComponent <CurvySplineBase>();
                if (spl)
                {
                    path.Spline = spl;
                }
            }
            Selection.activeGameObject = path.gameObject;
        }
コード例 #33
0
ファイル: CurvySplineGroup.cs プロジェクト: Kaiymu/OOS_Tools
 void OnSplineRefresh(CurvySplineBase spl)
 {
     if (!Splines.Contains((CurvySpline)spl))
     {
         spl.OnRefresh -= OnSplineRefresh;
         return;
     }
     if (!mIsInitialized)
     {
         return;
     }
     doRefreshLength();
     mIsContinuous = true;
     for (int i = 0; i < Count - 1; i++)
     {
         if (!NextSplineConnected(i))
         {
             mIsContinuous = false;
             break;
         }
     }
     mIsClosed = (Count > 1 && NextSplineConnected(Count - 1));
 }
コード例 #34
0
 void Init(CurvySplineBase spline)
 {
     Curves.Add(new SplinePolyLine(spline));
     HookSpline(spline);
 }
コード例 #35
0
ファイル: CurvyUtility.cs プロジェクト: shaunvxc/Infamy
 /// <summary>
 /// Creates a Spline2MeshCurve class using Spline2MeshCurve.VertexMode.ByApproximation
 /// </summary>
 public SplinePolyLine(CurvySplineBase spline)
     : this(spline, VertexCalculation.ByApproximation, 0,0)
 {
 }
コード例 #36
0
ファイル: CurvyUtility.cs プロジェクト: shaunvxc/Infamy
 /// <summary>
 /// Creates a Spline2MeshCurve class using Spline2MeshCurve.VertexMode.ByAngle
 /// </summary>
 public SplinePolyLine(CurvySplineBase spline, float angle, float distance)
     : this(spline,VertexCalculation.ByAngle,angle,distance)
 {
 }
コード例 #37
0
 void UnhookSpline(CurvySplineBase spline)
 {
     if (!spline) return;
     spline.OnRefresh -= OnSourceRefresh;
 }
コード例 #38
0
 protected void OnRefreshEvent(CurvySplineBase sender)
 {
     if (OnRefresh != null) {
         OnRefresh(sender);
     }
 }
コード例 #39
0
 GLSlotData getSlot(CurvySplineBase spline)
 {
     if (spline)
     {
         foreach (var slot in Splines)
             if (slot.Spline == spline)
                 return slot;
     }
     return null;
 }
コード例 #40
0
    void Update()
    {
        if (!Spline || !Spline.IsInitialized)
        {
            return;
        }

        // *** Place Player in editor ***
        if (!Application.isPlaying)
        {
            if (Spline.Interpolate(TF) != mTransform.position)
            {
                mTransform.position = Spline.Interpolate(TF);
            }
            return;
        }

        int dir = 1;

        // advance on lane. We use PingPong clamping to detect when we reach the end of a spline (in that case dir changes!)
        Vector3 newPosOnSpline = Spline.MoveBy(ref TF, ref dir, Speed * Time.deltaTime, CurvyClamping.PingPong);
        Vector3 newTangent     = Spline.GetTangent(TF);

        // Advance by spline curvation delta. We don't use newPosOnSpline directly because we don't want a snap-effect when in air or switching lanes
        mTransform.position += newPosOnSpline - mLastPosOnSpline;

        // *** Switch lanes? ***
        if (Input.GetButtonDown("Horizontal"))
        {
            if (TrySwitchLane(Input.GetAxis("Horizontal") < 0 ? Vector3.left : Vector3.right))
            {
                newPosOnSpline = Spline.Interpolate(TF);
            }
        }
        // *** Jump? ***
        if (!mInAir && !Jumping && Input.GetKey(KeyCode.Space))
        {
            StartCoroutine(Jump());
        }

        // Set orientation
        mTransform.forward = newTangent;

        // Oops! We've reached end of spline. Check if we can fall down onto another spline...
        if (dir != 1)
        {
            CurvySplineBase newSpline;
            float           newTF;
            if (RaycastForFollowUpSpline(Vector3.down, out newSpline, out newTF))
            {
                // we found a new spline underneath us. Let's use it from now on
                Spline         = newSpline;
                TF             = newTF;
                newPosOnSpline = Spline.Interpolate(TF);
                mInAir         = (newPosOnSpline - mTransform.position).sqrMagnitude > 0.001f;
            }
            else
            {
                StartCoroutine(Die()); // No Spline found. Time to die...
            }
        }


        // When in air or switching lanes, our position isn't where it should be. So we drag the player toward the lane position
        if (!Jumping)
        {
            Vector3 offset = mTransform.position - newPosOnSpline;
            if (offset.sqrMagnitude > 0.001f)
            {
                if (mInAir)
                {
                    mTransform.position -= offset.normalized * Gravity * Time.deltaTime;
                }
                else
                {
                    mTransform.position -= offset.normalized * SwitchSpeed * Time.deltaTime;
                }
            }
            else
            {
                mInAir = false;
            }
        }
        else   // Perform a jump
        {
            mTransform.Translate(0, mJumpDelta * Time.deltaTime, 0, Space.Self);
        }



        mLastPosOnSpline = newPosOnSpline;
    }
 // Look for another lane to the left or right
 bool TrySwitchLane(Vector3 dir)
 {
     CurvySplineBase followUpSpline;
     float newTF;
     if (RaycastForFollowUpSpline(dir, out followUpSpline, out newTF)) {
         Spline=followUpSpline;
         TF = newTF;
         return true;
     }
     return false;
 }
コード例 #42
0
ファイル: CurvyUtility.cs プロジェクト: shaunvxc/Infamy
 SplinePolyLine(CurvySplineBase spline, VertexCalculation vertexMode, float angle, float distance)
 {
     Spline = spline;
     VertexMode = vertexMode;
     Angle = angle;
     Distance = distance;
 }
コード例 #43
0
ファイル: CurvyUtility.cs プロジェクト: shaunvxc/Infamy
 /// <summary>
 /// Grows/Shrinks a spline or a spline group
 /// </summary>
 /// <param name="spline">the spline or group</param>
 /// <param name="center">the center of the effect</param>
 /// <param name="growByPercent">the percentage to grow/shrink</param>
 internal static void Grow(CurvySplineBase spline, Vector3 center, float growByPercent)
 {
     if (spline is CurvySplineGroup) {
         CurvySplineGroup grp = (CurvySplineGroup)spline;
         foreach (CurvySpline spl in grp.Splines)
             Grow(spl, center, growByPercent);
     }
     else {
         CurvySpline spl = (CurvySpline)spline;
         foreach (CurvySplineSegment cp in spl.ControlPoints) {
             Vector3 dir = center - cp.Position;
             float dist = dir.magnitude;
             cp.Position = center + dir.normalized * dist * growByPercent;
         }
     }
 }
 void OnSplineRefresh(CurvySplineBase sender)
 {
     if (Time.realtimeSinceStartup - mLastRefresh > AutoRefreshSpeed) {
         mLastRefresh = Time.realtimeSinceStartup;
         Refresh(false);
     }
 }
コード例 #45
0
 void OnSplineRefresh(CurvySplineBase spl)
 {
     if (!Splines.Contains((CurvySpline)spl)) {
         spl.OnRefresh -= OnSplineRefresh;
         return;
     }
     doRefreshLength();
 }
コード例 #46
0
 void HookSpline(CurvySplineBase spline)
 {
     if (!spline) return;
     spline.OnRefresh.AddListenerOnce(OnSourceRefresh);
     if (!splineTransforms.ContainsKey(spline))
         splineTransforms.Add(spline,new TTransform(spline.transform));
 }
	void Update () 
    {
        if (!Spline || !Spline.IsInitialized)
            return;
        
        // *** Place Player in editor ***
        if (!Application.isPlaying) {
            if (Spline.Interpolate(TF)!=mTransform.position)
                mTransform.position = Spline.Interpolate(TF);
            return;
        }

        int dir=1;
        
        // advance on lane. We use PingPong clamping to detect when we reach the end of a spline (in that case dir changes!)
        Vector3 newPosOnSpline=Spline.MoveBy(ref TF, ref dir, Speed*Time.deltaTime, CurvyClamping.PingPong);
        Vector3 newTangent = Spline.GetTangent(TF);

        // Advance by spline curvation delta. We don't use newPosOnSpline directly because we don't want a snap-effect when in air or switching lanes
        mTransform.position += newPosOnSpline - mLastPosOnSpline;

        // *** Switch lanes? ***
        if (Input.GetButtonDown("Horizontal")) {
            if (TrySwitchLane(Input.GetAxis("Horizontal") < 0 ? Vector3.left : Vector3.right)) {
                newPosOnSpline = Spline.Interpolate(TF);
            }
        }        
        // *** Jump? ***
        if (!mInAir && !Jumping && Input.GetKey(KeyCode.Space)) {
            StartCoroutine(Jump());
        }
       
        // Set orientation
        mTransform.forward = newTangent;

        // Oops! We've reached end of spline. Check if we can fall down onto another spline...
        if (dir != 1) {
            CurvySplineBase newSpline;
            float newTF;
            if (RaycastForFollowUpSpline(Vector3.down, out newSpline, out newTF)) {
                // we found a new spline underneath us. Let's use it from now on
                Spline = newSpline;
                TF = newTF;
                newPosOnSpline = Spline.Interpolate(TF);
                mInAir = (newPosOnSpline - mTransform.position).sqrMagnitude > 0.001f;
            }
            else {
                StartCoroutine(Die()); // No Spline found. Time to die...
            }
        }


        // When in air or switching lanes, our position isn't where it should be. So we drag the player toward the lane position
        if (!Jumping) {
            Vector3 offset = mTransform.position - newPosOnSpline;
            if (offset.sqrMagnitude > 0.001f) {
                if (mInAir)
                    mTransform.position -= offset.normalized * Gravity * Time.deltaTime;
                else
                    mTransform.position -= offset.normalized * SwitchSpeed * Time.deltaTime;
            }
            else
                mInAir = false;
        }
        else { // Perform a jump
            mTransform.Translate(0, mJumpDelta * Time.deltaTime,0, Space.Self);
        }
        
        

        mLastPosOnSpline = newPosOnSpline;
	}
コード例 #48
0
 void UnhookSpline(CurvySplineBase spline)
 {
     if (!spline) return;
     spline.OnRefresh.RemoveListener(OnSourceRefresh);
     splineTransforms.Remove(spline);
 }
コード例 #49
0
 void Init(CurvySplineBase spline)
 {
     Curves.Add(new SplinePolyLine(spline));
     HookSpline(spline);
 }
コード例 #50
0
 public void Remove(CurvySplineBase spline)
 {
     for (int i = Splines.Count - 1; i >= 0; i--)
         if (Splines[i].Spline == spline)
             Splines.RemoveAt(i);
 }
コード例 #51
0
 void OnSourceRefresh(CurvySplineBase spline)
 {
     refreshNow = true;
 }
コード例 #52
0
        /*! \cond PRIVATE */

        void getInterpolatedSourcePosition(CurvySplineBase spline,float tf, out Vector3 position, out Vector3 tangent, out Vector3 up)
        {
            if (UseCache)
            {
                position = spline.InterpolateFast(tf);
                tangent = spline.GetTangentFast(tf);
            }
            else
            {
                position = spline.Interpolate(tf);
                tangent = spline.GetTangent(tf, position);
            }
            up = spline.GetOrientationUpFast(tf);
            if (Space == Space.World)
            {
                position = spline.transform.TransformPoint(position);
                tangent = spline.transform.TransformDirection(tangent);
                up = spline.transform.TransformDirection(up);
            }
        }
コード例 #53
0
 public void Add(CurvySplineBase spline)
 {
     if (spline!=null)
         Splines.Add(new GLSlotData() { Spline = spline });
 }
コード例 #54
0
ファイル: CurvySplineGroup.cs プロジェクト: shaunvxc/Infamy
 void OnSplineRefresh(CurvySplineBase spl)
 {
     if (!Splines.Contains((CurvySpline)spl)) {
         spl.OnRefresh -= OnSplineRefresh;
         return;
     }
     if (!mIsInitialized)
         return;
     doRefreshLength();
     mIsContinuous=true;
     for (int i=0;i<Count-1;i++)
         if (!NextSplineConnected(i)){
             mIsContinuous=false;
             break;
         }
     mIsClosed = (Count>1 && NextSplineConnected(Count - 1));
 }
コード例 #55
0
ファイル: AlignToSpline.cs プロジェクト: shaunvxc/Infamy
 void OnSplineRefresh(CurvySplineBase sender)
 {
     mNeedRefresh=true;
 }