예제 #1
0
        private PropertyReorder <Transform> GetTransDrawer(SerializedProperty p)
        {
            var t = tPool.Get(p.propertyPath);

            if (t == null)
            {
                var trans = p.FindPropertyRelative("trans");
                t           = new PropertyReorder <Transform>(trans);
                t.onAdd     = i => OnAddTrans(p, i);
                t.onRemove  = i => OnRemoveTrans(p, i);
                t.onReorder = (i1, i2) => OnReorderTrans(p, i1, i2);
                t.canAdd    = () =>
                {
                    if (Selection.activeGameObject == null)
                    {
                        return(false);
                    }
                    var sel = Selection.activeGameObject.transform;
                    // check duplicate
                    for (int i = 0; i < trans.arraySize; ++i)
                    {
                        if (trans.GetArrayElementAtIndex(i).objectReferenceValue == sel)
                        {
                            return(false);
                        }
                    }
                    // check if in visibility array
                    var objs = p.serializedObject.FindProperty("objs");
                    return(IsDuplicate(objs, Selection.activeObject));
                };
                tPool[p.propertyPath] = t;
            }
            return(t);
        }
예제 #2
0
        private PropertyReorder <bool> GetVisibilityDrawer(SerializedProperty p)
        {
            var v = vPool.Get(p.propertyPath);

            if (v == null)
            {
                var visibility = p.FindPropertyRelative("visibility");
                v          = new PropertyReorder <bool>(visibility);
                v.drawItem = OnDrawVisibility;

                v.onAdd     = i => OnAddObject(visibility, i);
                v.onRemove  = i => OnRemoveObject(visibility, i);
                v.onReorder = (i1, i2) => OnReorderObject(visibility, i1, i2);
                v.canAdd    = () =>
                {
                    var objs = p.serializedObject.FindProperty("objs");
                    return(!IsDuplicate(objs, Selection.activeObject));
                };
                vPool[p.propertyPath] = v;
            }
            return(v);

            void OnDrawVisibility(SerializedProperty item, Rect rect, int index, bool isActive, bool isFocused)
            {
                var union = SwitcherInspector.GetVisibilityUnion(item.serializedObject.targetObject as Switcher);

                using (new ContentColorScope(Color.gray, !union[index]))
                {
                    var bounds = rect.SplitByWidths(25, 25);
                    // draw index
                    EditorGUI.PrefixLabel(bounds[0], new GUIContent(index.ToString()));
                    // draw bool
                    EditorGUI.PropertyField(bounds[1], item, new GUIContent(""));
                    var objs   = item.serializedObject.FindProperty("objs");
                    var obj    = objs.GetArrayElementAtIndex(index);
                    var oldObj = obj.objectReferenceValue;
                    EditorGUI.PropertyField(bounds[2], obj, new GUIContent(""));
                    if (obj.objectReferenceValue == null || IsDuplicate(objs, obj.objectReferenceValue))
                    {
                        obj.objectReferenceValue = oldObj;
                    }
                }
            }
        }