コード例 #1
0
        static void RemoveItem(ReorderableList list, int index)
        {
            list.ListProperty.DeleteArrayElementAtIndex(list.Selected);
            list.ListProperty.serializedObject.ApplyModifiedProperties();

            // The bindings will have changed
            list.RefreshList();
        }
コード例 #2
0
        protected void AddManagedItem(ReorderableList list, Type type, int index)
        {
            var instance = CreateInstance != null?CreateInstance(type) : Activator.CreateInstance(type);;
            var element  = list.ListProperty.InsertArrayElement(index);

            element.managedReferenceValue = instance;
            list.ListProperty.serializedObject.ApplyModifiedProperties();
            list.RefreshList();
        }
        void ShowAddMenu(ReorderableList list, int index, SerializedProperty property)
        {
            var managedList = list as ManagedReferenceReorderableList;

            var            settings = list.ListProperty.serializedObject.targetObject as LocalizationSettings;
            SmartFormatter smartFormatterInstance = null;

            if (settings != null)
            {
                smartFormatterInstance = settings.GetStringDatabase()?.SmartFormatter;
            }
            else
            {
                smartFormatterInstance = property.GetActualObjectForSerializedProperty <SmartFormatter>(fieldInfo);
            }
            Debug.Assert(smartFormatterInstance != null, $"Failed to extract {nameof(SmartFormatter)} instance.");

            var menu = new GenericMenu();

            var foundTypes = TypeCache.GetTypesDerivedFrom(managedList.AddType);

            for (int i = 0; i < foundTypes.Count; ++i)
            {
                var type = foundTypes[i];
                menu.AddItem(new GUIContent(ObjectNames.NicifyVariableName(type.Name)), false, () =>
                {
                    // We only support 2 types of constructor. A default and one that takes a SmartFormatter.
                    var hasDefaultConstructor        = type.GetConstructors().Any(c => c.GetParameters().Length == 0);
                    var hasSmartFormatterConstructor = type.GetConstructors().Any(c => c.GetParameters().Length == 1 && c.GetParameters()[0].ParameterType == typeof(SmartFormatter));

                    if (hasSmartFormatterConstructor || hasDefaultConstructor)
                    {
                        var elementProp = list.ListProperty.InsertArrayElement(index);
                        elementProp.managedReferenceValue = hasDefaultConstructor ? Activator.CreateInstance(type) : Activator.CreateInstance(type, smartFormatterInstance);
                        list.ListProperty.serializedObject.ApplyModifiedProperties();
                        list.RefreshList();
                    }
                    else
                    {
                        Debug.LogWarning($"Can not create an instance of {type}, it does not have a default constructor or a constructor that takes a SmartFormatter parameter.");
                    }
                });
            }
            menu.ShowAsContext();
        }
コード例 #4
0
ファイル: ReorderManipulator.cs プロジェクト: Habi-Thapa/csv
        void OnMouseUp(MouseUpEvent evt)
        {
            if (m_Dragging && CanStopManipulation(evt))
            {
                if (m_ListFrozen)
                {
                    RestoreScrollView();

                    if (m_DragStart != m_CurrentIndex)
                    {
                        m_List.Swap(m_DragStart, m_CurrentIndex);
                    }
                    else
                    {
                        m_List.RefreshList();
                    }
                }

                m_Dragging = false;
                m_CurrentTarget.ReleaseMouse();
                m_CurrentTarget = null;
                evt.StopPropagation();
            }
        }