Esempio n. 1
0
        private void ExecuteCreateEntity(Type type, string entityName = "", DAction <float> loadingAction = null, DAction <Entity> loadDoneAction = null)
        {
            EntityInfoAttribute att = (EntityInfoAttribute)type.GetCustomAttributes(false) [0];

            if (att == null)
            {
                this.e("damon", "资源信息未添加");
                return;
            }

            //取回一个实体对象并且进行初始化
            Entity     entity = (Entity)Main.referencePoolManager.OnSpawn(type);
            GameObject go     = null;

            entity.Reset();
            string typeName = type.GetType().FullName;

            if (mEntities.ContainsKey(type))
            {
                if (att.isUseObject)
                {
                    if (mObjectPool.Count > 0)
                    {
                        go = mObjectPool[type].Dequeue();
                    }
                    else
                    {
                    }
                }
                else
                {
                    if (mDefineEntity.ContainsKey(typeName) && (mDefineEntity.ContainsKey(typeName) != null))
                    {
                        GameObject prefab = mDefineEntity[typeName];
                        go = Instantiate(prefab);
                        go.SetParent(mEntityGroup[type]);
                        entity.gameObject = go;
                    }
                    else
                    {
                        //需要将游戏对象加载到容器中
                    }
                }
                go.SetParent(mEntityGroup[type]);
                entity.gameObject = go;
                mEntities[type].Add(entity);
                entity.name = (entityName == "" ? type.Name : entityName);
                entity.OnAwake();
                entity.active = true;
                entity.OnStart();
            }
            else //这里字典中包含该类型
            {
                this.e("damon", "不是指定的类型");
            }
        }
Esempio n. 2
0
 public Entity()
 {
     System.Object[] attributes = this.GetType().GetCustomAttributes(true);
     for (int i = 0; i < attributes.Length; i++)
     {
         EntityInfoAttribute a = attributes[i] as EntityInfoAttribute;
         assetBundleName = a.assetBundleName;
         assetPath       = a.assetPath;
         resPath         = a.resourcePath;
     }
 }
Esempio n. 3
0
        public override void OnInitialization()
        {
            base.OnInitialization();
            mEntityRoot = GameObject.Find("EntityRoot").transform;

            for (int i = 0; i < defineEntityNames.Count; i++)
            {
                if (!mDefineEntity.ContainsKey(defineEntityNames[i]))
                {
                    mDefineEntity.Add(defineEntityNames[i], defineEntityGos[i]);
                }
            }

            //初始化相关的数据 并且将指定的类型均已添加到实体字典中
            List <Type> types = GlobalTool.GetRuntimeTypes();

            foreach (Type t in types)
            {
                if (!t.IsSubclassOf(typeof(Entity)))
                {
                    continue;
                }
                System.Object[]     objs = t.GetCustomAttributes(true);
                EntityInfoAttribute att  = objs[0] as EntityInfoAttribute;
                if (att != null)
                {
                    mEntities.Add(t, new List <Entity> ());

                    //对放实体对象的容器
                    GameObject group = GameObjectTool.NewGameObject(t.Name + "_[Group]", mEntityRoot.gameObject);
                    mEntityGroup[t] = group;

                    //按照实体的类型将队列初始化
                    mObjectPool[t] = new Queue <GameObject> ();
                    this.d("+++++", "添加实体类型" + t.GetType(), false);
                }
                else
                {
                    this.e("damon", "未定义实体资源属性");
                }
            }
            //实体的生命周期
            foreach (List <Entity> list in mEntities.Values)
            {
                foreach (Entity e in list)
                {
                    e.OnAwake();
                }
            }
        }
        public void CreateOneToManyRelationship <TOne, TMany>(Expression <Func <TMany, EntityReference <TOne> > > lookupExpr, EntityAttributes.Metadata.AttributeRequiredLevel lookupRequiredLevel, string relationshipPrefix = "new")
            where TOne : CrmPlusPlusEntity, new()
            where TMany : CrmPlusPlusEntity, new()
        {
            Guard.This(relationshipPrefix).AgainstNullOrEmpty();

            var oneEntityName      = EntityNameAttribute.GetFromType <TOne>();
            var manyEntityName     = EntityNameAttribute.GetFromType <TMany>();
            var oneDisplayName     = EntityInfoAttribute.GetFromType <TOne>().DisplayName;
            var lookupPropertyName = PropertyNameAttribute.GetFromType(lookupExpr);

            var oneToManyRequest = new CreateOneToManyRequest
            {
                OneToManyRelationship = new OneToManyRelationshipMetadata
                {
                    ReferencedEntity            = oneEntityName,
                    ReferencingEntity           = manyEntityName,
                    SchemaName                  = relationshipPrefix.EndsWith("_") ? relationshipPrefix : relationshipPrefix + "_" + oneEntityName + "_" + manyEntityName,
                    AssociatedMenuConfiguration = new AssociatedMenuConfiguration
                    {
                        Behavior = AssociatedMenuBehavior.UseLabel,
                        Group    = AssociatedMenuGroup.Details,
                        Label    = oneDisplayName.ToLabel(),
                        Order    = 10000
                    },
                    CascadeConfiguration = new CascadeConfiguration
                    {
                        Assign   = CascadeType.NoCascade,
                        Delete   = CascadeType.RemoveLink,
                        Merge    = CascadeType.NoCascade,
                        Reparent = CascadeType.NoCascade,
                        Share    = CascadeType.NoCascade,
                        Unshare  = CascadeType.NoCascade
                    }
                },
                Lookup = new LookupAttributeMetadata
                {
                    SchemaName    = lookupPropertyName,
                    DisplayName   = (oneDisplayName + " Lookup").ToLabel(),
                    RequiredLevel = new AttributeRequiredLevelManagedProperty(lookupRequiredLevel.ToSimilarEnum <AttributeRequiredLevel>()),
                    Description   = (oneDisplayName + " Lookup").ToLabel()
                }
            };

            service.Execute(oneToManyRequest);
        }
        public void CreateEntity <T>() where T : CrmPlusPlusEntity, new()
        {
            var entityName = EntityNameAttribute.GetFromType <T>();
            var entityInfo = EntityInfoAttribute.GetFromType <T>();

            var createEntityRequest = new CreateEntityRequest
            {
                Entity = new EntityMetadata
                {
                    SchemaName            = entityName,
                    DisplayName           = entityInfo.DisplayName.ToLabel(),
                    DisplayCollectionName = entityInfo.PluralDisplayName.ToLabel(),
                    Description           = entityInfo.Description.ToLabel(),
                    OwnershipType         = entityInfo.OwnershipType,
                    IsActivity            = false
                },
                PrimaryAttribute = new StringAttributeMetadata
                {
                    SchemaName    = entityName + "primary",
                    RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
                    MaxLength     = 100,
                    FormatName    = Microsoft.Xrm.Sdk.Metadata.StringFormatName.Text,
                    DisplayName   = "Primary attribute".ToLabel(),
                    Description   = string.Format("The primary attribute for the {0} entity", entityInfo.DisplayName).ToLabel()
                }
            };

            var response = (CreateEntityResponse)service.Execute(createEntityRequest);

            var addReq = new AddSolutionComponentRequest()
            {
                ComponentType      = (int)SolutionComponentTypes.Entity,
                ComponentId        = response.EntityId,
                SolutionUniqueName = Solution.Name
            };

            service.Execute(addReq);
        }
Esempio n. 6
0
 public PrefabInfo(EntityInfoAttribute att) : base(att.assetBundleName, att.assetPath, att.resourcePath)
 {
 }