Exemplo n.º 1
0
 protected override sealed void Init()
 {
     if (linker == null)
     {
         linker = new ReceiverLinker();
     }
     receivers = linker.Build(this);
     receivers.SetRegistered(true);
     base.Init();
 }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.serializedObject.isEditingMultipleObjects)
            {
                return;
            }

            EditorGUI.BeginProperty(position, label, property);

            var linker  = new ReceiverLinker();
            var members = property.FindPropertyRelative(nameof(linker.Members));

            var accessorList = new List <ReceiverLinkerItem>();

            {
                for (int i = 0; i < members.arraySize; i++)
                {
                    accessorList.Add(LoadObject(members.GetArrayElementAtIndex(i)));
                }
            }

            members.ClearArray();

            var targetObject     = property.serializedObject.targetObject as MonoBehaviour;
            var targetObjectType = targetObject.GetType();

            foreach (var method in ReceiverMethod.GetAll(targetObject))
            {
                var option = DrawProviderOptions(position, accessorList.Find(item => item.Receiver == method.Name), method, targetObject);
                position.y += EditorGUIUtility.singleLineHeight;

                var linkerItem = new ReceiverLinkerItem();
                linkerItem.Receiver     = method.Name;
                linkerItem.ReceiverType = option.ReceiverTypeName;
                linkerItem.Path         = option.Path;

                if (!string.IsNullOrEmpty(option.ReceiverTypeName))
                {
                    int size = members.arraySize;
                    members.InsertArrayElementAtIndex(size);
                    var obj = members.GetArrayElementAtIndex(size);
                    SaveObject(obj, linkerItem);
                }
                if (linkerItem.ReceiverType != ReceiverLinker.IgnoreReceiver)
                {
                    DrawProviderPreview(position, linkerItem, method, option.ReceiverType, targetObject);
                }
                position.y += EditorGUIUtility.singleLineHeight;
            }

            EditorGUI.EndProperty();
        }
Exemplo n.º 3
0
 protected virtual void OnEnable()
 {
     if (receivers == null)
     {
         if (linker == null)
         {
             linker = new ReceiverLinker();
         }
         receivers = linker.Build(this);
         receivers.SetRegistered(true);
         Create();
     }
     else
     {
         receivers.SetRegistered(true);
     }
     Enable();
 }