protected override void InitEditor(PropertyEditor editor, PropertyDescriptor descriptor) { base.InitEditor(editor, descriptor); bool canTransform = true; if (Component != null) { ExposeToEditor exposeToEditor = Component.gameObject.GetComponentInParent <ExposeToEditor>(); if (exposeToEditor != null && !exposeToEditor.CanTransform) { canTransform = false; } } if (Editor.Tools.LockAxes == null && canTransform) { return; } if (descriptor.ComponentMemberInfo == Strong.PropertyInfo((Transform x) => x.localPosition, "localPosition")) { Vector3Editor vector3Editor = (Vector3Editor)editor; if (!canTransform) { vector3Editor.IsXInteractable = false; vector3Editor.IsYInteractable = false; vector3Editor.IsZInteractable = false; } else if (Editor.Tools.LockAxes != null) { vector3Editor.IsXInteractable = !Editor.Tools.LockAxes.PositionX; vector3Editor.IsYInteractable = !Editor.Tools.LockAxes.PositionY; vector3Editor.IsZInteractable = !Editor.Tools.LockAxes.PositionZ; } } if (descriptor.ComponentMemberInfo == Strong.PropertyInfo((Transform x) => x.localRotation, "localRotation")) { Vector3Editor vector3Editor = (Vector3Editor)editor; if (!canTransform) { vector3Editor.IsXInteractable = false; vector3Editor.IsYInteractable = false; vector3Editor.IsZInteractable = false; } else if (Editor.Tools.LockAxes != null) { vector3Editor.IsXInteractable = !Editor.Tools.LockAxes.RotationX; vector3Editor.IsYInteractable = !Editor.Tools.LockAxes.RotationY; vector3Editor.IsZInteractable = !Editor.Tools.LockAxes.RotationZ; } } if (descriptor.ComponentMemberInfo == Strong.PropertyInfo((Transform x) => x.localScale, "localScale")) { Vector3Editor vector3Editor = (Vector3Editor)editor; if (!canTransform) { vector3Editor.IsXInteractable = false; vector3Editor.IsYInteractable = false; vector3Editor.IsZInteractable = false; } else if (Editor.Tools.LockAxes != null) { vector3Editor.IsXInteractable = !Editor.Tools.LockAxes.ScaleX; vector3Editor.IsYInteractable = !Editor.Tools.LockAxes.ScaleY; vector3Editor.IsZInteractable = !Editor.Tools.LockAxes.ScaleZ; } } }
private void OnResetClick() { GameObject go = new GameObject(); go.SetActive(false); Component component = go.GetComponent(Component.GetType()); if (component == null) { component = go.AddComponent(Component.GetType()); } bool isMonoBehavior = component is MonoBehaviour; PropertyDescriptor[] descriptors = m_editorsMap.GetPropertyDescriptors(Component.GetType(), this, m_converter); for (int i = 0; i < descriptors.Length; ++i) { PropertyDescriptor descriptor = descriptors[i]; MemberInfo memberInfo = descriptor.ComponentMemberInfo; if (memberInfo is PropertyInfo) { PropertyInfo p = (PropertyInfo)memberInfo; object defaultValue = p.GetValue(component, null); m_editor.Undo.BeginRecordValue(Component, memberInfo); p.SetValue(Component, defaultValue, null); } else { if (isMonoBehavior) { if (memberInfo is FieldInfo) { FieldInfo f = (FieldInfo)memberInfo; object defaultValue = f.GetValue(component); m_editor.Undo.BeginRecordValue(Component, memberInfo); f.SetValue(Component, defaultValue); } } } } for (int i = 0; i < descriptors.Length; ++i) { PropertyDescriptor descriptor = descriptors[i]; MemberInfo memberInfo = descriptor.MemberInfo; PropertyEditor propertyEditor = GetPropertyEditor(memberInfo); if (propertyEditor != null) { propertyEditor.Reload(); } } Destroy(go); m_editor.Undo.BeginRecord(); for (int i = 0; i < descriptors.Length; ++i) { PropertyDescriptor descriptor = descriptors[i]; MemberInfo memberInfo = descriptor.ComponentMemberInfo; if (memberInfo is PropertyInfo) { m_editor.Undo.EndRecordValue(Component, memberInfo); } else { if (isMonoBehavior) { m_editor.Undo.EndRecordValue(Component, memberInfo); } } } m_editor.Undo.EndRecord(); }
protected virtual void InitEditor(PropertyEditor editor, PropertyDescriptor descriptor) { editor.Init(descriptor.Target, descriptor.Target, descriptor.MemberInfo, null, descriptor.Label, null, descriptor.ValueChangedCallback, () => { descriptor.EndEditCallback?.Invoke(); EndEditCallback?.Invoke(); }, true, descriptor.ChildDesciptors); }
public void BuildEditor() { foreach (Transform t in EditorsPanel) { Destroy(t.gameObject); } IMaterialDescriptor selector; if (!m_propertySelectors.TryGetValue(Material.shader.name, out selector)) { selector = new MaterialDescriptor(); } object converter = selector.CreateConverter(this); MaterialPropertyDescriptor[] descriptors = selector.GetProperties(this, converter); if (descriptors == null) { Destroy(gameObject); return; } for (int i = 0; i < descriptors.Length; ++i) { MaterialPropertyDescriptor descriptor = descriptors[i]; PropertyEditor editor = null; PropertyInfo propertyInfo = descriptor.PropertyInfo; RTShaderPropertyType propertyType = descriptor.Type; switch (propertyType) { case RTShaderPropertyType.Range: if (RangeEditor != null) { RangeEditor range = Instantiate(RangeEditor); range.transform.SetParent(EditorsPanel, false); var rangeLimits = descriptor.Limits; range.Min = rangeLimits.Min; range.Max = rangeLimits.Max; editor = range; } break; default: if (m_editorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject editorPrefab = m_editorsMap.GetPropertyEditor(propertyInfo.PropertyType); GameObject instance = Instantiate(editorPrefab); instance.transform.SetParent(EditorsPanel, false); if (instance != null) { editor = instance.GetComponent <PropertyEditor>(); } } break; } if (editor == null) { continue; } editor.Init(descriptor.Target, descriptor.Accessor, propertyInfo, descriptor.EraseTargetCallback, descriptor.Label, null, descriptor.ValueChangedCallback, () => { m_editor.IsDirty = true; UpdatePreview(Material); }); } }
public BoundsAccessor(PropertyEditor <Bounds> editor) { m_editor = editor; }
public void RegisterEditor(PropertyEditor editor) { Array.Resize(ref m_editors, m_editors.Length + 1); m_editors[m_editors.Length - 1] = editor.gameObject; }