Exemplo n.º 1
0
        public void Clear()
        {
            InvokeTarget.Clear();

            if (argumentObjects != null)
            {
                foreach (var argumentObject in argumentObjects)
                {
                    argumentObject.TargetObject.Clear();
                }
            }
        }
Exemplo n.º 2
0
        public void Invoke()
        {
            Build();

            if (methodInfo == null || parameters == null)
            {
                return;
            }

            var targetGameObject = InvokeTarget.GetValue();

            if (targetGameObject != null)
            {
                var target = targetGameObject.GetComponent(methodInfo.ReflectedType);

                if (target != null)
                {
                    methodInfo.Invoke(target, parameters);
                }
            }
        }
Exemplo n.º 3
0
        private void Build()
        {
            if (build)
            {
                return;
            }

            methodInfo = null;
            parameters = null;

            var target = InvokeTarget.GetValue();

            if (target == null || string.IsNullOrEmpty(methodName))
            {
                return;
            }

            var methods = GetTimeLineEventMethods(target);

            methodInfo = methods.FirstOrDefault(x => GetMethodFullName(x) == methodName);

            if (methodInfo == null)
            {
                Debug.LogErrorFormat("Failed build method timeline event.\nMethod not found : {0}", methodName);
                return;
            }

            var args = new List <object>();

            try
            {
                var methodParameters = methodInfo.GetParameters();

                var valueArgIndex  = 0;
                var objectArgIndex = 0;

                for (var i = 0; i < methodParameters.Length; i++)
                {
                    var param = methodParameters[i];

                    var paramType = param.ParameterType;

                    if (paramType == typeof(GameObject))
                    {
                        GameObject go = null;

                        go = argumentObjects[objectArgIndex].TargetObject.GetValue();

                        args.Add(go);
                        objectArgIndex++;
                    }
                    else
                    {
                        var value = argumentValues[valueArgIndex];

                        if (paramType.IsEnum)
                        {
                            args.Add(value.To <int>());
                        }
                        else if (SupportArgumentTypes.Contains(paramType))
                        {
                            if (paramType == typeof(string))
                            {
                                args.Add(value);
                            }
                            else if (paramType == typeof(int))
                            {
                                args.Add(value.To <int>());
                            }
                            else if (paramType == typeof(float))
                            {
                                args.Add(value.To <float>());
                            }
                            else if (paramType == typeof(bool))
                            {
                                args.Add(value.To <bool>());
                            }
                        }
                        else
                        {
                            throw new NotSupportedException();
                        }

                        valueArgIndex++;
                    }
                }

                parameters = args.ToArray();
            }
            catch (Exception e)
            {
                Debug.LogErrorFormat("Failed build method timeline event.\nMethod arguments error : {0}\n\n{1}", methodName, e);
            }

            build = true;
        }