void UpdatePopups(SkinnedMeshRenderer[] skinnedMeshRenderers, int targetBoneIndex = 0, int mergeWeightTargetBoneIndex = 0) { if (targetBonePopup != null) { targetBonePopup.UnregisterValueChangedCallback(OnTargetBoneChanged); popupsPlaceholder.Remove(targetBonePopup); targetBonePopup = null; } if (mergeWeightTargetBonePopup != null) { popupsPlaceholder.Remove(mergeWeightTargetBonePopup); mergeWeightTargetBonePopup = null; } if (skinnedMeshRenderers == null) { return; } var bones = skinnedMeshRenderers.SelectMany(r => r.bones).Distinct().ToList(); targetBonePopup = new PopupField <Transform>("Target bone", bones, Math.Min(bones.Count, targetBoneIndex), t => t.name); targetBonePopup.RegisterValueChangedCallback(OnTargetBoneChanged); popupsPlaceholder.Add(targetBonePopup); mergeWeightTargetBonePopup = new PopupField <Transform>("Merge bone weight into", bones, Math.Min(bones.Count, mergeWeightTargetBoneIndex), t => t.name); popupsPlaceholder.Add(mergeWeightTargetBonePopup); }
public RandomNode(RandomNodeModel model, Store store, GraphView graphView) : base(model, store, graphView) { styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "Random.uss")); AddToClassList(k_UssClassName); void OnTitleChange(ChangeEvent <string> e) { Model.MethodBaseName = e.newValue; Model.DefineNode(); store.Dispatch(new RefreshUIAction(UpdateFlags.RequestCompilation | UpdateFlags.GraphTopology)); } void OnParamChange(ChangeEvent <Enum> e) { Model.Variant = (RandomNodeModel.ParamVariant)e.newValue; Model.DefineNode(); store.Dispatch(new RefreshUIAction(UpdateFlags.RequestCompilation | UpdateFlags.GraphTopology)); } RegisterCallback <AttachToPanelEvent>(evt => { // Title : Random [Float v ] [(min, max) v ] if (m_TitleField == null) { title = "Random"; m_TitleField = new PopupField <string>(RandomNodeModel.BaseMethodNames.ToList(), Model.MethodBaseName); m_TitleField.RegisterValueChangedCallback(OnTitleChange); TitleContainer?.Add(m_TitleField); m_ParamField = new EnumField(Model.Variant); m_ParamField.RegisterValueChangedCallback(OnParamChange); TitleContainer?.Add(m_ParamField); m_ParamField?.SetEnabled(RandomNodeModel.RngMethods.Count(m => m.Name == Model.RngMethod.Name) > 1); } }); RegisterCallback <DetachFromPanelEvent>(evt => { m_TitleField.UnregisterValueChangedCallback(OnTitleChange); m_ParamField.UnregisterValueChangedCallback(OnParamChange); }); }
public void OnDisable() { targetBonePopup?.UnregisterValueChangedCallback(OnTargetBoneChanged); rootObjectField.UnregisterValueChangedCallback(OnSkinnedMeshRendererChanged); }