void OnSceneGUI() { PolygonalImage2D polygon2D = target as PolygonalImage2D; if (null == polygon2D.points_) { return; } Track track = new Track(); for (int i = 0; i < polygon2D.points_.Length; ++i) { Vector3 pos = polygon2D.points_[i]; pos = polygon2D.transform.TransformPoint(pos); track.selected_ = false; Vector3 nextPos = Handles.FreeMoveHandle(pos, Quaternion.identity, 1.5f, SnapeSize, track.DrawCapHook); if (pos != nextPos || track.selected_) { selected_ = i; polygon2D.points_[i] = polygon2D.transform.InverseTransformPoint(nextPos); polygon2D.SetVerticesDirty(); EditorUtility.SetDirty(target); } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); SerializedProperty propPoints = serializedObject.FindProperty("points_"); //EditorGUILayout.PropertyField(propPoints, true); ShowList(propPoints, selected_); if (!serializedObject.isEditingMultipleObjects) { int numPoints = propPoints.arraySize; if (numPoints < 3) { EditorGUILayout.HelpBox("At least three points are required.", MessageType.Warning); } else { EditorGUILayout.HelpBox(numPoints + " points in total.", MessageType.Info); } } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Reset", EditorStyles.miniButtonLeft)) { for (int i = 0; i < targets.Length; ++i) { if (PrefabUtility.GetPrefabType(targets[i]) != PrefabType.Prefab) { PolygonalImage2D polygonalImage2D = targets[i] as PolygonalImage2D; polygonalImage2D.resetPoints(); polygonalImage2D.SetVerticesDirty(); EditorUtility.SetDirty(targets[i]); } } } if (GUILayout.Button("Reset Smaller", EditorStyles.miniButtonRight)) { for (int i = 0; i < targets.Length; ++i) { if (PrefabUtility.GetPrefabType(targets[i]) != PrefabType.Prefab) { PolygonalImage2D polygonalImage2D = targets[i] as PolygonalImage2D; polygonalImage2D.resetPointsSmaller(); polygonalImage2D.SetVerticesDirty(); EditorUtility.SetDirty(targets[i]); } } } EditorGUILayout.EndHorizontal(); if (serializedObject.ApplyModifiedProperties() || (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")) { for (int i = 0; i < targets.Length; ++i) { if (PrefabUtility.GetPrefabType(targets[i]) != PrefabType.Prefab) { EditorUtility.SetDirty(targets[i]); } } } }