Пример #1
0
        public AMEventParameter CreateClone()
        {
            AMEventParameter a = new AMEventParameter();

            a.valueType  = valueType;
            a.val_int    = val_int;
            a.val_vect4  = val_vect4;
            a.val_string = val_string;
            a.val_obj    = val_obj;
            foreach (AMEventParameter e in lsArray)
            {
                a.lsArray.Add(e.CreateClone());
            }
            return(a);
        }
Пример #2
0
        //set target to a valid ref. for meta
        public bool setMethodInfo(GameObject target, Component component, bool setComponent, MethodInfo methodInfo, ParameterInfo[] cachedParameterInfos, bool restoreValues, System.Action <AMEventKey> onPreChange)
        {
            MethodInfo _methodInfo = getMethodInfo(target);

            // if different component or methodinfo
            string _componentName = component.GetType().Name;

            if ((_methodInfo != methodInfo) || (this.componentName != _componentName) || !isMatch(cachedParameterInfos))
            {
                if (onPreChange != null)
                {
                    onPreChange(this);
                }

                this.component     = setComponent ? component : null;
                this.componentName = _componentName;
                methodName         = methodInfo.Name;
                cachedMethodInfo   = methodInfo;
                //this.parameters = new object[numParameters];

                Dictionary <string, ParamKeep> oldParams = null;
                if (restoreValues && parameters != null && parameters.Count > 0)
                {
                    Debug.Log("Parameters have been changed, from code? Attempting to restore data.");
                    oldParams = new Dictionary <string, ParamKeep>(parameters.Count);
                    for (int i = 0; i < parameters.Count; i++)
                    {
                        if (!string.IsNullOrEmpty(parameters[i].paramName) && (parameters[i].valueType != (int)AMEventParameter.ValueType.Array || parameters[i].checkArrayIntegrity()))
                        {
                            try {
                                object valObj = parameters[i].toObject();

                                oldParams.Add(parameters[i].paramName, new ParamKeep()
                                {
                                    type = parameters[i].getParamType(), val = valObj
                                });
                            }
                            catch {
                                continue;
                            }
                        }
                    }
                }

                this.parameters = new List <AMEventParameter>();

                // add parameters
                for (int i = 0; i < cachedParameterInfos.Length; i++)
                {
                    AMEventParameter a = new AMEventParameter();
                    a.paramName = cachedParameterInfos[i].Name;
                    a.setValueType(cachedParameterInfos[i].ParameterType);

                    //see if we can restore value from previous
                    if (oldParams != null && oldParams.ContainsKey(a.paramName))
                    {
                        ParamKeep keep = oldParams[a.paramName];
                        if (keep.type == cachedParameterInfos[i].ParameterType)
                        {
                            a.fromObject(keep.val);
                        }
                    }

                    this.parameters.Add(a);
                }

                return(true);
            }
            return(false);
        }