public void SetTextureBySeason(TDCEnum.EGameSeason season) { if (m_Renderer != null) { m_Renderer.material.mainTexture = m_SeasonTextures[(int)season]; } }
public TDCSkillSlot(TDCEnum.EGameType skillType, TDCEntity owner) { m_GameManager = TDCGameManager.GetInstance(); m_SkillData = m_GameManager.GetSkillData(skillType); m_SkillType = skillType; m_Owner = owner; m_TimeDelay = 0f; for (int i = 0; i < m_SkillData.TriggerEnvent.Length; i++) { m_Owner.AddEventListener(m_SkillData.TriggerEnvent[i], ActiveSkill); } }
public override int AddItem(TDCEnum.EGameType gameType, TDCEnum.EItemType itemType, int amount) { var inventory = m_Entity.GetInventory(); var indexItemInInventory = FindItemSlot(gameType); var emptySlot = FindEmptySlot(); if (emptySlot == -1) return -1; switch (itemType) { case TDCEnum.EItemType.Food: case TDCEnum.EItemType.Item: case TDCEnum.EItemType.GObject: { if (indexItemInInventory != -1) { inventory[indexItemInInventory].GetData().Amount++; return indexItemInInventory; } else { inventory[emptySlot] = m_GameManager.CreateItem(gameType, itemType, this, amount); } break; } case TDCEnum.EItemType.Weapon: { inventory[emptySlot] = m_GameManager.CreateItem(gameType, itemType, this, amount); break; } } if (emptySlot != -1) { var item = GetInventory()[emptySlot]; m_Inventory.AddItem(emptySlot, item); } return emptySlot; }
public static bool IsSeason(TDCEnum.EGameSeason season) { return Season == season; }
public virtual int AddItemInventory(TDCEnum.EGameType gameType, TDCEnum.EItemType itemType, int amount) { return 0; }
protected int FindItemSlot(TDCEnum.EGameType gameType) { var inventory = m_Entity.GetInventory(); for (int i = 0; i < inventory.Length; i++) { if (inventory[i] == null) continue; var data = inventory[i].GetData(); if (data != null) { if (data.GameType == gameType) return i; } } return -1; }
public bool AlarmComplete(int h, int d, TDCEnum.EGameSeason s) { bool complete = false; if (alarmFlag == (1 << 0)) { if (this.hour != h) { completed = false; } complete = this.hour == h && completed == false; } else if (alarmFlag == (1 << 1)) { if (this.day != d) { completed = false; } complete = this.day == d && completed == false; } else if (alarmFlag == (1 << 2)) { if (this.season != s) { completed = false; } complete = this.season == s && completed == false; } else if (alarmFlag == (1 << 1 | 1 << 2)) { if (this.day != (d % 30) || this.season != s) { completed = false; } complete = this.day == (d % 30) && this.season == s && completed == false; } else if (alarmFlag == (1 << 0 | 1 << 1 | 1 << 2)) { if (this.hour == h || this.day != d || this.season != s) { completed = false; } complete = this.hour == h && this.day == d && this.season == s && completed == false; } if (complete) { alarmFlag = Repeat == false ? (byte)0 : alarmFlag; completed = true; if (Callback != null) { Callback(); } } return complete; }
public TDCSkillData GetSkillData(TDCEnum.EGameType skill) { return m_DataReader.GetSkillData(skill); }
public TDCEntity CreateCreature(TDCEnum.EGameType type, Vector3 position, Quaternion rotation, GameObject parent = null) { TDCBaseData data = null; TDCBaseController controller = null; TDCEntity entity = null; GameObject gObject = null; var random = m_ListEntities.Count; var typeIndex = (int)type; if (typeIndex == (int)TDCEnum.EGameType.Sun) { data = m_DataReader.GetSunData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[random % data.ModelPath.Length]), position, rotation) as GameObject; controller = gObject.AddComponent<TDCSunController>(); entity = new TDCSun(controller, data); } else if (typeIndex == (int)TDCEnum.EGameType.GrassLandPlane) { data = m_DataReader.GetPlaneData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[random % data.ModelPath.Length]), position, rotation) as GameObject; controller = gObject.AddComponent<TDCPlaneController>(); entity = new TDCPlane(controller, data); } else if (typeIndex == (int)TDCEnum.EGameType.SeasonGrassLand) { data = m_DataReader.GetSeasonData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[random % data.ModelPath.Length]), position, rotation) as GameObject; controller = gObject.AddComponent<TDCSeasonController>(); entity = new TDCSeason(controller, data); } else if (typeIndex >= 5 && typeIndex < 50) // Creature { data = m_DataReader.GetCreatureData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[random % data.ModelPath.Length]), position, rotation) as GameObject; switch ((data as TDCCreatureData).CreatureType) { case TDCEnum.ECreatureType.GroundCreature: controller = gObject.AddComponent<TDCGroundAIController>(); break; case TDCEnum.ECreatureType.FlyCreature: controller = gObject.AddComponent<TDCFlyAIController>(); break; } entity = new TDCCreature(controller, data); } else if (typeIndex > 50 && typeIndex < 100) // Enviroment { data = m_DataReader.GetEnviromentData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[random % data.ModelPath.Length]), position, rotation) as GameObject; controller = gObject.AddComponent<TDCEnviromentController>(); entity = new TDCEnviroment(controller, data); } else if (typeIndex > 100 && typeIndex < 200) // Item { data = m_DataReader.GetItemData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[random % data.ModelPath.Length]), position, rotation) as GameObject; controller = gObject.AddComponent<TDCItemController>(); entity = new TDCItem(controller, data); } else if (typeIndex > 200 && typeIndex < 300) // Group { data = m_DataReader.GetGroupData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[random % data.ModelPath.Length]), position, rotation) as GameObject; switch ((data as TDCGroupData).GroupType) { case TDCEnum.EGroupType.GroupNestCreature: controller = gObject.AddComponent<TDCNestGroupCreatureController>(); break; case TDCEnum.EGroupType.GroupCreature: controller = gObject.AddComponent<TDCGroupCreatureController>(); break; } entity = new TDCGroup(controller, data); } else if (typeIndex > 300 && typeIndex < 400) // Object { data = m_DataReader.GetGObjectData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[0]), position, rotation) as GameObject; controller = gObject.AddComponent <TDCCampfireController>(); entity = new TDCCampfire(controller, data); } else if (typeIndex > 400 && typeIndex < 500) // Weapon { // TODO } else if (typeIndex > 500 && typeIndex < 700) // Skill { data = m_DataReader.GetSkillData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[0]), position, rotation) as GameObject; switch ((data as TDCSkillData).SkillType) { case TDCEnum.ESkillType.Active: controller = gObject.AddComponent<TDCActiveSkillController>(); break; case TDCEnum.ESkillType.Passive: controller = gObject.AddComponent<TDCPasiveSkillController>(); break; } entity = new TDCSkill(controller, data); } else if (typeIndex > 800 && typeIndex < 900) // Egg { data = m_DataReader.GetEggData(type); gObject = GameObject.Instantiate(Resources.Load<GameObject>(data.ModelPath[0]), position, rotation) as GameObject; controller = gObject.AddComponent<TDCEggController>(); entity = new TDCEgg(controller, data); } else { Debug.LogError("[GameManager] Out of index"); } data.ID = m_ListEntities.Count + 1; entity.SetActive(false); controller.SetEntity(entity); controller.Init (); controller.name = string.Format("{0}-{1}", type, m_ListEntities.Count); if (parent != null) { gObject.transform.SetParent (parent.transform); } m_ListEntities.Add(controller.name, entity); return entity; }
public TDCEntity GetObjectPool(TDCEnum.EGameType type) { TDCEntity result = null; if (m_ObjectPool[type].Get(ref result)) { return result; } else { Debug.LogError("[GameManager] Set more pool " + type); } return null; }
public bool GetObjectPool(TDCEnum.EGameType type, ref TDCEntity obj) { if (m_ObjectPool[type].Get(ref obj)) { return true; } else { Debug.LogError("[GameManager] Set more pool " + type); } return false; }
public TDCCraftingData GetCraftingData(TDCEnum.EGameType gameType) { return m_DataReader.GetCraftingData(gameType); }
public TDCEntity CreatePlayer(TDCEnum.EGameType type, Vector3 position, Quaternion rotation, GameObject parent = null) { TDCBaseData data = null; GameObject gObject = null; TDCBaseController controller = null; TDCEntity entity = null; var random = m_ListEntities.Count; data = m_DataReader.GetPlayerData (type); gObject = GameObject.Instantiate (Resources.Load<GameObject> (data.ModelPath[random % data.ModelPath.Length]), position, rotation) as GameObject; gObject.AddComponent<AudioListener>(); switch ((data as TDCPlayerData).CreatureType) { case TDCEnum.ECreatureType.GroundPlayer: controller = gObject.AddComponent<TDCPlayerController> (); break; case TDCEnum.ECreatureType.FlyPlayer: controller = gObject.AddComponent<TDCFlyPlayerController> (); break; } CameraController.Instance.Target = gObject.transform; data.ID = m_ListEntities.Count + 1; entity = new TDCPlayer(controller, data); entity.SetActive(false); controller.SetEntity(entity); controller.Init (); controller.name = string.Format("{0}-{1}", type, m_ListEntities.Count); if (parent != null) { gObject.transform.SetParent (parent.transform); } m_ListEntities.Add(controller.name, entity); return entity; }
public UIItemController CreateItem(TDCEnum.EGameType gameType, TDCEnum.EItemType itemType, TDCBaseController owner, int amount) { UIItemData itemData = null; switch (itemType) { default: case TDCEnum.EItemType.Food: itemData = m_DataReader.GetUIFoodData(gameType); break; case TDCEnum.EItemType.Weapon: itemData = m_DataReader.GetUIWeaponData(gameType); break; case TDCEnum.EItemType.GObject: case TDCEnum.EItemType.Item: itemData = m_DataReader.GetUIItemData(gameType); break; } if (itemData == null) return null; var item = new UIItemController(itemData); item.GetData().Owner = owner; item.GetData().Amount = amount; return item; }
public void SetSeason(TDCEnum.EGameSeason value) { m_CurrentSeason = (int)value; }
public override int AddItemInventory(TDCEnum.EGameType gameType, TDCEnum.EItemType itemType, int amount) { return m_Controller.AddItem(gameType, itemType, amount); }
public void SetSeasonAlarmClock(TDCEnum.EGameSeason s, Action complete, bool repeat = false) { var alarm = new AlarmClockInfo (); alarm.SetAlarmSeason (s); alarm.Callback = complete; alarm.Repeat = repeat; m_AlarmClocks.Add (alarm); }
public override int AddItem(TDCEnum.EGameType gameType, TDCEnum.EItemType itemType, int amount) { return 0; }
public void SetAlarmSeason(TDCEnum.EGameSeason s) { this.season = s; this.completed = false; alarmFlag |= 1 << 2; }
private void PressedCraftingButton(TDCEnum.EGameType gameType) { var craftingData = m_GameManager.GetCraftingData(gameType); var inventory = m_Owner.GetInventory(); var canCrafting = CheckEnoughResources(craftingData, inventory); var payResources = false; if (canCrafting) { payResources = HandleResources (craftingData, inventory); } if (payResources) { for (int i = 0; i < craftingData.Amount; i++) { TDCEntity item = null; if (m_GameManager.GetObjectPool(craftingData.GameType, ref item)) { var randomAroundPosition = UnityEngine.Random.insideUnitCircle * m_Owner.GetColliderRadius(); var ownerPosition = m_Owner.TransformPosition; ownerPosition.x += randomAroundPosition.x; ownerPosition.y = 0f; ownerPosition.z += randomAroundPosition.y; item.SetTransformPosition(ownerPosition); item.SetActive(true); } } } }