daily pastebin goal
39%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. for (int i = 0; i < path.NumPoints; i++)
  2.     {
  3.         Vector2 newPos = Handles.FreeMoveHandle(path[i], Quaternion.identity, .1f, Vector2.zero, Handles.CylinderHandleCap);
  4.         if (path[i] != newPos)
  5.         {
  6.             Undo.RecordObject(creator, "Move point");
  7.             path.MovePoint(i, newPos);
  8.         }
  9.     }
  10.    
  11. [CustomEditor(typeof(PathCreator))]
  12. public class PathEditor : Editor {
  13.  
  14. PathCreator creator;
  15. Path path;
  16.  
  17. public override void OnInspectorGUI()
  18. {
  19.     base.OnInspectorGUI();
  20.     EditorGUI.BeginChangeCheck();
  21.  
  22.     bool continuousControlPoints = GUILayout.Toggle(path.isContinuous, "Set Continuous Control Points");
  23.     if (continuousControlPoints != path.isContinuous)
  24.     {
  25.         Undo.RecordObject(creator, "Toggle set continuous controls");
  26.         path.isContinuous = continuousControlPoints;
  27.     }
  28.  
  29.     if (EditorGUI.EndChangeCheck())
  30.     {
  31.         SceneView.RepaintAll();
  32.     }
  33. }
  34.  
  35. void OnSceneGUI()
  36. {
  37.     Input();
  38.     Draw();
  39. }
  40.  
  41. void Input()
  42.  {
  43.     Event guiEvent = Event.current;
  44.     Vector2 mousePos = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition).origin;
  45.  
  46.     if (guiEvent.type == EventType.MouseDown && guiEvent.button == 0 && guiEvent.shift)
  47.     {
  48.         Undo.RecordObject(creator, "Add segment");
  49.         path.AddSegment(mousePos);
  50.     }
  51. }
  52.  
  53. void Draw()
  54. {
  55.  
  56.      Transform handleTransform = creator.transform;
  57.     Quaternion handleRotation = Tools.pivotRotation == PivotRotation.Local ?
  58.         handleTransform.rotation : Quaternion.identity;
  59.  
  60.     for (int i = 0; i < path.NumSegments; i++)
  61.     {
  62.         Vector2[] points = path.GetPointsInSegment(i);
  63.         Handles.color = Color.black;
  64.  
  65.         Vector2 p0 = handleTransform.TransformPoint(points[0]);
  66.         Vector2 p1 = handleTransform.TransformPoint(points[1]);
  67.         Vector2 p2 = handleTransform.TransformPoint(points[2]);
  68.         Vector2 p3 = handleTransform.TransformPoint(points[3]);
  69.  
  70.         Handles.DrawLine(p1, p0);
  71.         Handles.DrawLine(p2, p3);
  72.         Handles.DrawBezier(p0, p3, p1, p2, Color.green, null, 2);
  73.  
  74.     }
  75.  
  76.  
  77.     Handles.color = Color.red;
  78.     for (int i = 0; i < path.NumPoints; i++)
  79.     {
  80.         Vector2 newPos = Handles.FreeMoveHandle(path[i], Quaternion.identity, .1f, Vector2.zero, Handles.CylinderHandleCap);
  81.         if (path[i] != newPos)
  82.         {
  83.             Undo.RecordObject(creator, "Move point");
  84.             path.MovePoint(i, newPos);
  85.         }
  86.     }
  87. }
  88.  
  89. void OnEnable()
  90. {
  91.     creator = (PathCreator)target;
  92.     if (creator.path == null)
  93.     {
  94.         creator.CreatePath();
  95.     }
  96.     path = creator.path;
  97. }
  98. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top