public override void OnPreviewGUI(Rect r, GUIStyle background) { base.OnPreviewGUI(r, background); float size = 0.95f * Mathf.Min(r.width, r.height); Rect canvasRect = new Rect(r.center.x - 0.5f * size, r.center.y - 0.5f * size, size, size); CustomGestureTemplate template = target as CustomGestureTemplate; Vector2 center = canvasRect.center; float scale = 0.95f * size; Handles.color = Color.white; for (int i = 1; i < template.PointCount; ++i) { Vector2 p1 = template.GetPosition(i - 1); Vector2 p2 = template.GetPosition(i); p1.y = -p1.y; p2.y = -p2.y; p1 = center + scale * p1; p2 = center + scale * p2; if (canvasRect.width > 100) { float handleSize = canvasRect.width / 200.0f; Handles.CircleCap(0, p1, Quaternion.identity, handleSize); } Handles.DrawLine(p1, p2); } }
public override void OnPreviewSettings() { base.OnPreviewSettings(); CustomGestureTemplate template = target as CustomGestureTemplate; GUILayout.Label(template.PointCount + " points, " + template.StrokeCount + " stroke(s)"); }
public static CustomGestureEditor Open(CustomGestureTemplate template) { CustomGestureEditor window = EditorWindow.GetWindow <CustomGestureEditor>(true, "Gesture Editor: " + template.name); window.maxSize = new Vector2(GestureAreaSize, GestureAreaSize + ToolbarHeight + 22); window.minSize = window.maxSize; window.Init(template); window.Focus(); return(window); }
public bool AddTemplate(CustomGestureTemplate template) { if (FindNormalizedTemplate(template) != null) { Debug.Log("AddTemplate Exist"); return(false); } List <Point> points = new List <Point>(); for (int i = 0; i < template.PointCount; ++i) { points.Add(new Point(template.GetStrokeId(i), template.GetPosition(i))); } NormalizedTemplate nt = new NormalizedTemplate(); nt.Source = template; nt.Points = Normalize(points); normalizedTemplates.Add(nt); if (template.isRotate) { const float PI = 3.141592f; const float Angle = 1.0f / 180.0f * PI; float ox = template.GetPosition(template.PointCount / 2).x; float oy = template.GetPosition(template.PointCount / 2).y; List <Point> newPoints = new List <Point>(); for (int i = (int)template.RotateStep; i < template.RotateAngle; i += (int)template.RotateStep) { for (int j = 0; j < template.PointCount; ++j) { float curAngle = i * Angle; float px = template.GetPosition(j).x; float py = template.GetPosition(j).y; float x = ox - (px - ox) * UnityEngine.Mathf.Cos(curAngle) - (py - oy) * UnityEngine.Mathf.Sin(curAngle); float y = oy - (px - ox) * UnityEngine.Mathf.Sin(curAngle) + (py - oy) * UnityEngine.Mathf.Cos(curAngle); newPoints.Add(new Point(0, new UnityEngine.Vector2(x, y))); } NormalizedTemplate newNT = new NormalizedTemplate(); newNT.Source = template; newNT.Points = Normalize(newPoints); normalizedTemplates.Add(newNT); newPoints.Clear(); } } return(true); }
public override void OnInspectorGUI() { CustomGestureTemplate template = target as CustomGestureTemplate; if (GUILayout.Button("Edit", GUILayout.Height(50))) { CustomGestureEditor.Open(template); } template.tolerance = EditorGUILayout.IntField(LABEL_Tolerance, template.tolerance); template.isCaclTowards = EditorGUILayout.Toggle(LABEL_CaclTowards, template.isCaclTowards); template.isRotate = EditorGUILayout.Toggle(LABEL_IsRotate, template.isRotate); template.RotateAngle = EditorGUILayout.FloatField(LABEL_RotateAngle, template.RotateAngle); template.RotateStep = EditorGUILayout.FloatField(LABEL_RotateStep, template.RotateStep); /* * if( GUILayout.Button( "Triangle" ) ) * { * template.BeginPoints(); * template.AddPoint( 0, 1, 1 ); * template.AddPoint( 0, 2, 2 ); * template.AddPoint( 0, 3, 1 ); * template.AddPoint( 0, 1, 1 ); * template.EndPoints(); * } * * if( GUILayout.Button( "Square" ) ) * { * template.BeginPoints(); * template.AddPoint( 0, 2, 1 ); * template.AddPoint( 0, 2, 3 ); * template.AddPoint( 0, 4, 3 ); * template.AddPoint( 0, 4, 1 ); * template.AddPoint( 0, 2, 1 ); * template.EndPoints(); * }*/ }
NormalizedTemplate FindNormalizedTemplate(CustomGestureTemplate template) { return(normalizedTemplates.Find(t => (t.Source == template))); }
public static void CreateCustomGesture() { CustomGestureTemplate template = FingerGesturesEditorUtils.CreateAsset <CustomGestureTemplate>(); FingerGesturesEditorUtils.SelectAssetInProjectView(template); }
void Init(CustomGestureTemplate template) { this.template = template; points = new List <Vector2>(); }