Esempio n. 1
0
 private void SetDefaultValue(NormalComponent dto)
 {
     for (int i = 0; i < dto.PropertyArray.Length; i++)
     {
         TSProperty tSProperty = dto.PropertyArray[i];
         tSProperty.Setter(null, dto, tSProperty.DefaultValue);
     }
 }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="property"></param>
        /// <param name="isDataDriven">是否需要数据驱动</param>
        /// <returns></returns>
        public static TSProperty CreateProperty(object instance, PropertyInfo property, bool isDataDriven = false)
        {
            TSProperty tsProperty = new TSProperty();

            //tsProperty.Name = property.Name;
            //tsProperty.PropertyType = property.PropertyType;
            tsProperty.Setter = CreateSetter(property, isDataDriven);
            tsProperty.Getter = CreateGetter(property);
            return(tsProperty);
        }
Esempio n. 3
0
        private static TSProperty CreateProperty(object instance, FieldInfo fieldInfo, bool isDataDriven)
        {
            TSProperty tsProperty = new TSProperty();

            //tsProperty.Name = fieldInfo.Name;
            //tsProperty.PropertyType = fieldInfo.FieldType;
            tsProperty.Setter = CreateSetter(fieldInfo, isDataDriven);
            tsProperty.Getter = CreateGetter(fieldInfo);
            return(tsProperty);
        }
Esempio n. 4
0
        public static void RegisteComponent(Type instanceType, int index)
        {
            try
            {
                Type varType = instanceType.Assembly.GetType("TSFrame.ECS." + instanceType.Name + "Variable");
                if (varType == null)
                {
                    throw new Exception(instanceType.Name + "没有组件说明类,请先生成组件说明类");
                }
                PropertyInfo countProperty = varType.GetProperty("Count", BindingFlags.Public | BindingFlags.Static);
                if (countProperty == null)
                {
                    throw new Exception(instanceType.Name + "没有组件说明类,请先生成组件说明类");
                }
                int count = (int)countProperty.GetValue(null, null);
                if (count <= 0)
                {
                    return;
                }
                TSProperty[] tempArray = new TSProperty[count];
                //Dictionary<string, TSProperty> tempReturnDic = new Dictionary<string, TSProperty>();
                #region Property

                PropertyInfo[] props = instanceType.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                if (props != null && props.Length > 0)
                {
                    for (int i = 0; i < props.Length; i++)
                    {
                        //bool isDataDriven = false;
                        PropertyInfo property = props[i];
                        if (property.GetSetMethod() == null || property.GetGetMethod() == null)
                        {
                            continue;
                        }
                        FieldInfo varFieldInfo = varType.GetField(property.Name, BindingFlags.Public | BindingFlags.Static);
                        if (varFieldInfo == null)
                        {
                            continue;
                        }
                        ComponentValue componentValue = varFieldInfo.GetValue(null) as ComponentValue;
                        if (componentValue == null)
                        {
                            continue;
                        }
                        TSProperty tsProperty = CreateProperty(null, property, componentValue.NeedReactive);
                        tsProperty.DontCopy = componentValue.DontCopy;
                        object[] objs = property.GetCustomAttributes(_defaultValueType, false);
                        if (objs.Length > 0)
                        {
                            tsProperty.DefaultValue = (objs[0] as DefaultValueAttribute).Value;
                        }
                        else
                        {
                            tsProperty.DefaultValue = property.PropertyType.IsValueType ? Activator.CreateInstance(property.PropertyType) : null;
                        }
                        tempArray[componentValue.PropertyId] = tsProperty;
                        //tempReturnDic.Add(property.Name, tsProperty);
                    }
                }

                #endregion

                #region FieldInfo

                FieldInfo[] fieldInfos = instanceType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                if (fieldInfos != null && fieldInfos.Length > 0)
                {
                    for (int i = 0; i < fieldInfos.Length; i++)
                    {
                        FieldInfo fieldInfo    = fieldInfos[i];
                        FieldInfo varFieldInfo = varType.GetField(fieldInfo.Name, BindingFlags.Public | BindingFlags.Static);
                        if (varFieldInfo == null)
                        {
                            continue;
                        }
                        ComponentValue componentValue = varFieldInfo.GetValue(null) as ComponentValue;
                        if (componentValue == null)
                        {
                            continue;
                        }
                        TSProperty tsProperty = CreateProperty(null, fieldInfo, componentValue.NeedReactive);
                        tsProperty.DontCopy = componentValue.DontCopy;
                        object[] objs = fieldInfo.GetCustomAttributes(_defaultValueType, false);
                        if (objs.Length > 0)
                        {
                            tsProperty.DefaultValue = (objs[0] as DefaultValueAttribute).Value;
                        }
                        else
                        {
                            tsProperty.DefaultValue = fieldInfo.FieldType.IsValueType ? Activator.CreateInstance(fieldInfo.FieldType) : null;
                        }
                        tempArray[componentValue.PropertyId] = tsProperty;
                    }
                }

                #endregion
                //_ilCache.Add(instance.CurrentId, tempArray);
                _ilArrayCache[index] = tempArray;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }