浏览代码

Fix Callable Selection Dropdown (Callable Property Drawer) (#43)

* Fixed Callable Selection Dropdon (Callable Property Drawer) that was somehow broken.

* Fix Multiple Inspectors
/main
GitHub 3 年前
当前提交
5425f8e9
共有 3 个文件被更改,包括 36 次插入14 次删除
  1. 2
      CHANGELOG.md
  2. 8
      Editor/IngredientsExplorer/IngredientsExplorerWindow.cs
  3. 40
      Editor/PropertyDrawers/CallablePropertyDrawer.cs

2
CHANGELOG.md


#### Fixed
* CheckWindow: Better search for referenced objects in scene
* Fixed Callable Dropdown that was somehow broken.
## 2020.2.3

8
Editor/IngredientsExplorer/IngredientsExplorerWindow.cs


internal static void OpenWindow(MonoBehaviour selected)
{
OpenWindow();
s_Instance.Repaint();
s_Instance.SelectItem(selected);
instance.Repaint();
instance.SelectItem(selected);
}
const int PANEL_WIDTH = 400;

public static void Refresh()
{
s_Instance.ReloadCallHierarchy();
s_Instance.Repaint();
instance.ReloadCallHierarchy();
instance.Repaint();
}
private void OnGUI()

40
Editor/PropertyDrawers/CallablePropertyDrawer.cs


using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace GameplayIngredients.Editor
{

private Callable setNextObjectValue = null;
private static Dictionary<string, Callable> setNextObjectValue = new Dictionary<string, Callable>();
if(setNextObjectValue != null)
string path = Binding.propertyToPath(property);
if (setNextObjectValue.ContainsKey(path))
property.objectReferenceValue = setNextObjectValue;
setNextObjectValue = null;
property.objectReferenceValue = setNextObjectValue[path];
property.serializedObject.ApplyModifiedProperties();
GUI.changed = true;
setNextObjectValue.Remove(path);
if(IngredientsExplorerWindow.visible)
{
IngredientsExplorerWindow.Refresh();

var objRect = new Rect(position);
objRect.xMax -= 188;
var obj = EditorGUI.ObjectField(objRect, property.objectReferenceValue, typeof(Callable), true);

var components = (property.objectReferenceValue as Callable).gameObject.GetComponents<Callable>();
foreach(var component in components)
{
menu.AddItem(new GUIContent(component.GetType().Name + " - " + component.Name), component == property.objectReferenceValue, SetMenu, component);
menu.AddItem(new GUIContent(component.GetType().Name + " - " + component.Name), component == property.objectReferenceValue, SetMenu, new Binding(property, component));
}
menu.ShowAsContext();

{
Callable component = o as Callable;
setNextObjectValue = component;
Binding binding = o as Binding;
if (setNextObjectValue.ContainsKey(binding.propertyPath))
setNextObjectValue[binding.propertyPath] = binding.callable;
else
setNextObjectValue.Add(binding.propertyPath, binding.callable);
}
class Binding
{
public string propertyPath;
public Callable callable;
public Binding(SerializedProperty serializedProperty, Callable value)
{
propertyPath = propertyToPath(serializedProperty);
callable = value;
}
public static string propertyToPath(SerializedProperty serializedProperty)
{
return $"{serializedProperty.serializedObject.targetObject.GetInstanceID()}:{serializedProperty.propertyPath}";
}
}
}

正在加载...
取消
保存