Exemplo n.º 1
0
 public ReceiverCreator(ReceiverMethod receiverMethod, Type type = null, GetterChainCall getters = null)
 {
     this.type       = type ?? receiverMethod.Type;
     this.methodType = receiverMethod.Type;
     this.method     = receiverMethod.Method;
     this.getters    = getters;
     this.Attribute  = receiverMethod.Attribute;
 }
Exemplo n.º 2
0
        private ReceiversCreator BuildCreator(MonoBehaviour target)
        {
            var creators = new ReceiversCreator();

            foreach (var d in ReceiverMethod.GetAll(target))
            {
                var member = GetMember(d.Name);
                if (member == null)
                {
                    // The default behaviour
                    creators.Add(new ReceiverCreator(d));
                }
                else
                {
                    // Set manually
                    if (member.ReceiverType == IgnoreReceiver)
                    {
                        continue;
                    }

                    // Subtype of the receiver method's parameter type
                    var type = d.Type;
                    if (!string.IsNullOrEmpty(member.ReceiverType))
                    {
                        type = Type.GetType(member.ReceiverType, false);
                        if (type == null)
                        {
                            Debug.LogError($"[{target.GetType().Name}] Receiver ({member.Receiver}) type {member.ReceiverType} not found", target);
                            continue;
                        }
                    }

                    if (string.IsNullOrEmpty(member.Path))
                    {
                        creators.Add(new ReceiverCreator(d, type));
                    }
                    else
                    {
                        // Getter calls
                        try
                        {
                            var path = member.Path.Split('/');
                            creators.Add(new ReceiverCreator(d, type, GetterChainCall.Construct(type, path)));
                        }
                        catch (Exception e)
                        {
                            Debug.LogError($"[{target.GetType().Name}] Receiver {member.Receiver} type {type.Name}:{member.Path} creation failed:\n{e.Message}\n{e.StackTrace}", target);
                            continue;
                        }
                    }
                }
            }
            return(creators);
        }