Ejemplo n.º 1
0
        public EntityComView(string comName, FieldInfo[] fieldInfos, BaseCom baseCom)
        {
            ComName = comName;
            ComAttribute comAttribute = LCReflect.GetTypeAttr <ComAttribute>(baseCom.GetType());

            if (comAttribute != null)
            {
                ComName = comAttribute.ViewName;
            }
            for (int i = 0; i < fieldInfos.Length; i++)
            {
                FieldInfo       info     = fieldInfos[i];
                ComKeyValueView keyValue = new ComKeyValueView(info.Name, info, baseCom);

                ComValueAttribute comValueAttribute = LCReflect.GetFieldAttr <ComValueAttribute>(info);
                if (comValueAttribute != null)
                {
                    if (comValueAttribute.ViewEditor)
                    {
                        EditorValueList.Add(keyValue);
                    }
                    else
                    {
                        if (comValueAttribute.ShowView)
                        {
                            ValueList.Add(keyValue);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 //添加实体全局单一组件
 private void AddEntityGlobalSingleCom(EntityJson conf, Entity entity)
 {
     for (int i = 0; i < conf.Coms.Count; i++)
     {
         BaseCom com = entity.GetCom(conf.Coms[i].ComName);
         if (ECSHelp.CheckComIsGlobal(com.GetType()))
         {
             if (globalSingleCom.ContainsKey(com.GetType()))
             {
                 ECSLocate.ECSLog.LogError("有多个全局单个组件>>>>>>", conf.EntityName, com.GetType());
                 entity.Disable();
                 return;
             }
             globalSingleCom.Add(com.GetType(), com);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理实体组件
        /// </summary>
        private static List <EntityComView> HandleEntityComs(Entity entity)
        {
            List <EntityComView> comViews = new List <EntityComView>();
            //组件名
            HashSet <string> entityComs = entity.GetAllComStr();

            foreach (string comName in entityComs)
            {
                BaseCom     com    = entity.GetCom(comName);
                FieldInfo[] fields = LCReflect.GetTypeFieldInfos(com.GetType());

                EntityComView comView = new EntityComView(comName, fields, com);

                comViews.Add(comView);
            }

            return(comViews);
        }
Ejemplo n.º 4
0
        private void DrawCom(BaseCom baseCom)
        {
            if (!ContextDataCache.TryGetContextData <GUIStyle>("BigLabel", out var bigLabel))
            {
                bigLabel.value              = new GUIStyle(GUI.skin.label);
                bigLabel.value.fontSize     = 18;
                bigLabel.value.fontStyle    = FontStyle.Bold;
                bigLabel.value.alignment    = TextAnchor.MiddleLeft;
                bigLabel.value.stretchWidth = true;
            }

            List <FieldInfo> serFields   = new List <FieldInfo>();
            List <FieldInfo> noSerFields = new List <FieldInfo>();

            foreach (var item in ReflectionHelper.GetFieldInfos(baseCom.GetType()))
            {
                bool ignore = false;
                foreach (var ignoreName in IgnoreFieldName)
                {
                    if (item.Name.Contains(ignoreName))
                    {
                        ignore = true;
                        continue;
                    }
                }
                if (ignore)
                {
                    continue;
                }

                if (AttributeHelper.TryGetFieldAttribute(item, out NonSerializedAttribute attr))
                {
                    noSerFields.Add(item);
                }
                else
                {
                    serFields.Add(item);
                }
            }

            _serFoldout = EditorGUILayout.Foldout(_serFoldout, "Serialized:");
            if (_serFoldout)
            {
                foreach (var item in serFields)
                {
                    object newValue = GUILayoutExtension.DrawField(item.FieldType, item.GetValue(baseCom), GraphProcessorEditorUtility.GetDisplayName(item.Name), "");
                    if (newValue == null || !newValue.Equals(item.GetValue(baseCom)))
                    {
                        item.SetValue(baseCom, newValue);
                    }
                }
            }

            _noSerFoldout = EditorGUILayout.Foldout(_noSerFoldout, "NoSerialized:");
            if (_noSerFoldout)
            {
                EditorGUI.BeginDisabledGroup(true);
                foreach (var item in noSerFields)
                {
                    GUILayoutExtension.DrawField(item.FieldType, item.GetValue(baseCom), GraphProcessorEditorUtility.GetDisplayName(item.Name), "");
                }
                EditorGUI.EndDisabledGroup();
            }
        }