public void CreateRandomItem(ItemCreatePointComponent comp) { //创建一个可以捡的道具 CollisionComponent colc = new CollisionComponent(); colc.area.direction = new Vector3(1, 0, 0); colc.area.position = comp.pos.ToVector(); colc.area.areaType = AreaType.Circle; colc.area.radius = 0.5f; //colc.isStatic = true; ItemComponent ic = new ItemComponent(); AssetComponent assert = new AssetComponent(); TransfromComponent tc = new TransfromComponent(); tc.pos = comp.pos; int r = m_world.GetRandom() % comp.randomList.Count; //Debug.Log("r " + r + " comp.randomList.Count " + comp.randomList.Count); string itemID = comp.randomList[r]; ic.ItemData = DataGenerateManager <ItemsDataGenerate> .GetData(itemID); assert.m_assetName = ic.ItemData.m_modelid; ic.ItemID = int.Parse(itemID); string identify = comp.Entity.ID + "Item" + comp.pos.ToVector(); //通过标识符保证唯一ID m_world.CreateEntity(identify, colc, ic, assert, tc); }
public override void FixedUpdate(int deltaTime) { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { ItemCreatePointComponent icpc = list[i].GetComp <ItemCreatePointComponent>(); CollisionComponent cc = list[i].GetComp <CollisionComponent>(); icpc.CreateTimer -= deltaTime; //Debug.Log("CreateTimer " + icpc.CreateTimer + " frame " + m_world.FrameCount); if (CanCreate(cc)) { if (icpc.CreateTimer <= 0) { CreateRandomItem(icpc); } } else { icpc.CreateTimer = 10 * 1000; } } }
public override MomentComponentBase DeepCopy() { ItemCreatePointComponent mc = new ItemCreatePointComponent(); mc.pos = pos.DeepCopy(); mc.randomList = randomList; mc.CreateTimer = CreateTimer; mc.CreateItemID = CreateItemID; return(mc); }
void InitElementCreatePoint() { string content = ResourceManager.ReadTextFile("elementCreatePointData"); string[] contentArray = content.Split('\n'); for (int i = 0; i < contentArray.Length; i++) { if (contentArray[i] != "") { ItemCreatePointComponent tmp = deserializer.Deserialize <ItemCreatePointComponent>(contentArray[i]); m_world.CreateEntity("ElementCreatePoint" + i, tmp); } } }
void InitElementCreatePoint() { string content = FileTool.ReadStringByFile(Environment.CurrentDirectory + "/Map/elementCreatePointData.txt"); string[] contentArray = content.Split('\n'); for (int i = 0; i < contentArray.Length; i++) { if (contentArray[i] != "") { SyncComponent sc = new SyncComponent(); ItemCreatePointComponent tmp = deserializer.Deserialize <ItemCreatePointComponent>(contentArray[i]); CollisionComponent cc = new CollisionComponent(); cc.area.position = tmp.pos.ToVector(); cc.area.areaType = AreaType.Circle; cc.area.radius = 1; m_world.CreateEntityImmediately("ElementCreatePoint" + i, tmp, sc, cc); } } }
public override void NoRecalcBeforeFixedUpdate(int deltaTime) { List <EntityBase> list = GetEntityList(); for (int i = 0; i < list.Count; i++) { ItemCreatePointComponent icpc = list[i].GetComp <ItemCreatePointComponent>(); CollisionComponent cc = list[i].GetComp <CollisionComponent>(); icpc.CreateTimer -= deltaTime; if (icpc.CreateTimer <= 0) { if (CanCreate(cc)) { CreateRandomItem(icpc); } icpc.CreateTimer = 10 * 1000; } } }
public void CreateRandomItem(ItemCreatePointComponent comp) { //创建一个可以捡的道具 CollisionComponent colc = new CollisionComponent(); colc.area.position = comp.pos.ToVector(); colc.area.areaType = AreaType.Circle; colc.area.radius = 0.5f; ItemComponent ic = new ItemComponent(); AssetComponent assert = new AssetComponent(); TransfromComponent tc = new TransfromComponent(); tc.pos = comp.pos; Random random = new Random(); int r = random.Next() % comp.randomList.Count; assert.m_assetName = comp.randomList[r]; string identify = comp.Entity.ID + "Item" + comp.pos.ToVector(); //通过标识符保证唯一ID m_world.CreateEntity(identify, colc, ic, assert, tc); }