コード例 #1
0
        private void SetData(TShapeData shapeData)
        {
            TShapeData previousPointData = m_GetShapeDataFunc();

            if (shapeData == previousPointData)
            {
                return;
            }

            if (!CanDependOnShapeBlueprint.CanCreateDependence(m_Dependent, shapeData))
            {
                Debug.LogError("Can't chose data because it will create a cycle in dependences");
                return;
            }

            if (previousPointData != null)
            {
                m_Dependent.RemoveDependenceOn(previousPointData);
            }
            m_SetShapeDataFunc.Invoke(shapeData);
            if (shapeData != null)
            {
                m_Dependent.CreateDependenceOn(shapeData);
            }
            UpdateName();
            m_UpdateValidatorAction?.Invoke();
        }
コード例 #2
0
        public ChoseShapeDataField(ShapeDataFactory shapeDataFactory, CanDependOnShapeBlueprint dependent,
                                   string fieldName, Func <TShapeData> getShapeDataFunc, Action <TShapeData> setShapeDataFunc)
        {
            m_DataFactory      = shapeDataFactory;
            m_Dependent        = dependent;
            m_FieldName        = fieldName;
            m_GetShapeDataFunc = getShapeDataFunc;
            m_SetShapeDataFunc = setShapeDataFunc;

            VisualElement firstRow = new VisualElement {
                style = { flexDirection = FlexDirection.Row }
            };

            firstRow.Add(m_Label = new Label());

            m_ToolbarMenu = new ToolbarMenu {
                text = "Change", style = { flexDirection = FlexDirection.Row }
            };
            m_ToolbarMenu.RemoveFromClassList("unity-toolbar-menu");
            m_ToolbarMenu.AddToClassList("unity-button");

            firstRow.Add(m_ToolbarMenu);

            Add(firstRow);

            IValidator pointNotEmptyValidator =
                new DataNotEmptyValidator <TShapeData>(getShapeDataFunc, action => m_UpdateValidatorAction = action);
            VisualElement validatorField = new ValidatorField(pointNotEmptyValidator);

            Add(validatorField);

            m_DataFactory.BecameDirty.Subscribe(BecameDirty);
            m_AutoSaveScheduler = schedule.Execute(Update);
            m_AutoSaveScheduler.Every(200);

            UpdateList();
            UpdateName();
            m_UpdateValidatorAction?.Invoke();
        }