浏览代码

Fix core changes to UIElements Toggle with compatibility layer

/main
Peter Bay Bastian 6 年前
当前提交
31db4b9f
共有 6 个文件被更改,包括 35 次插入24 次删除
  1. 18
      com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardFieldPropertyView.cs
  2. 8
      com.unity.shadergraph/Editor/Drawing/Controls/ToggleControl.cs
  3. 8
      com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs
  4. 8
      com.unity.shadergraph/Editor/Drawing/Views/Slots/BooleanSlotControlView.cs
  5. 8
      com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs
  6. 9
      com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs

18
com.unity.shadergraph/Editor/Drawing/Blackboard/BlackboardFieldPropertyView.cs


m_Graph = graph;
m_Property = property;
m_ExposedToogle = new Toggle(() =>
{
property.generatePropertyBlock = m_ExposedToogle.value;
DirtyNodes(ModificationScope.Graph);
});
m_ExposedToogle = new Toggle();
m_ExposedToogle.OnToggleChanged(evt =>
{
property.generatePropertyBlock = evt.newValue;
DirtyNodes(ModificationScope.Graph);
});
m_ExposedToogle.value = property.generatePropertyBlock;
AddRow("Exposed", m_ExposedToogle);

else if (property is BooleanShaderProperty)
{
var booleanProperty = (BooleanShaderProperty)property;
Action onBooleanChanged = () =>
EventCallback<ChangeEvent<bool>> onBooleanChanged = evt =>
booleanProperty.value = !booleanProperty.value;
booleanProperty.value = evt.newValue;
var field = new Toggle(onBooleanChanged);
var field = new Toggle();
field.OnToggleChanged(onBooleanChanged);
field.value = booleanProperty.value;
AddRow("Default", field);
}

8
com.unity.shadergraph/Editor/Drawing/Controls/ToggleControl.cs


var panel = new VisualElement { name = "togglePanel" };
if (!string.IsNullOrEmpty(label))
panel.Add(new Label(label));
Action changedToggle = () => { OnChangeToggle(); };
m_Toggle = new UnityEngine.Experimental.UIElements.Toggle(changedToggle);
m_Toggle = new Toggle();
m_Toggle.OnToggleChanged(OnChangeToggle);
m_Toggle.SetEnabled(value.isEnabled);
m_Toggle.value = value.isOn;
panel.Add(m_Toggle);

}
}
void OnChangeToggle()
void OnChangeToggle(ChangeEvent<bool> evt)
value.isOn = !value.isOn;
value.isOn = evt.newValue;
m_PropertyInfo.SetValue(m_Node, value, null);
this.MarkDirtyRepaint();
}

8
com.unity.shadergraph/Editor/Drawing/Views/PBRSettingsView.cs


ps.Add(new PropertyRow(new Label("Two Sided")), (row) =>
{
row.Add(new Toggle(null), (toggle) =>
row.Add(new Toggle(), (toggle) =>
toggle.OnToggle(ChangeTwoSided);
toggle.OnToggleChanged(ChangeTwoSided);
});
});

m_Node.alphaMode = (AlphaMode)evt.newValue;
}
void ChangeTwoSided()
void ChangeTwoSided(ChangeEvent<bool> evt)
td.isOn ^= true;
td.isOn = evt.newValue;
m_Node.twoSided = td;
}
}

8
com.unity.shadergraph/Editor/Drawing/Views/Slots/BooleanSlotControlView.cs


{
AddStyleSheetPath("Styles/Controls/BooleanSlotControlView");
m_Slot = slot;
Action changedToggle = () => { OnChangeToggle(); };
var toggleField = new UnityEngine.Experimental.UIElements.Toggle(changedToggle);
var toggleField = new Toggle();
toggleField.OnToggleChanged(OnChangeToggle);
void OnChangeToggle()
void OnChangeToggle(ChangeEvent<bool> evt)
value = !value;
value = evt.newValue;
m_Slot.value = value;
m_Slot.owner.Dirty(ModificationScope.Node);
}

8
com.unity.shadergraph/Editor/Drawing/Views/UnlitSettingsView.cs


ps.Add(new PropertyRow(new Label("Two Sided")), (row) =>
{
row.Add(new Toggle(null), (toggle) =>
row.Add(new Toggle(), (toggle) =>
toggle.OnToggle(ChangeTwoSided);
toggle.OnToggleChanged(ChangeTwoSided);
});
});

m_Node.alphaMode = (AlphaMode)evt.newValue;
}
void ChangeTwoSided()
void ChangeTwoSided(ChangeEvent<bool> evt)
td.isOn ^= true;
td.isOn = evt.newValue;
m_Node.twoSided = td;
}
}

9
com.unity.shadergraph/Editor/Util/CompatibilityExtensions.cs


element.ReleaseMouseCapture();
}
#endif
public static void OnToggleChanged(this Toggle toggle, EventCallback<ChangeEvent<bool>> callback)
{
#if UNITY_2018_3_OR_NEWER
toggle.OnValueChanged(callback);
#else
toggle.OnToggle(() => callback(ChangeEvent<bool>.GetPooled(!toggle.value, toggle.value)));
#endif
}
}
static class TrickleDownEnum

正在加载...
取消
保存