/*** Metodes per defecte de Unity ***/ protected override void Awake() { base.Awake (); objectName = "Yamato Army Building"; spawnableUnits = new RTSObjectType[] { RTSObjectType.UnitArcher, RTSObjectType.UnitCavalry, RTSObjectType.UnitWarrior}; getModels("Prefabs/Yamato_ArmyBuilding", "Prefabs/Yamato_ArmyBuilding_onConstruction", "Prefabs/Yamato_ArmyBuilding_Semidemolished"); }
/*** Metodes per defecte de Unity ***/ protected override void Awake() { base.Awake(); objectName = "Persian Town Center"; baseDefense = 5; spawnableUnits = new RTSObjectType[] { RTSObjectType.UnitCivil, RTSObjectType.UnitCivilAxe, RTSObjectType.UnitCivilPick, RTSObjectType.UnitCivilRack }; getModels("Prefabs/Persian_TownCenter", "Prefabs/Persian_TownCenter_onConstruction", "Prefabs/Persian_TownCenter_Semidemolished"); }
/*** Metodes per defecte de Unity ***/ protected override void Awake() { base.Awake(); objectName = "Sumerian Academy"; cost = 400; hitPoints = maxHitPoints = 800; baseDefense = 5; spawnableUnits = new RTSObjectType[] { RTSObjectType.UnitArcherAdvanced, RTSObjectType.UnitCavalryAdvanced, RTSObjectType.UnitWarriorAdvanced }; getModels("Prefabs/Sumerian_Academy", "Prefabs/Sumerian_Academy_onConstruction", "Prefabs/Sumerian_Academy_Semidemolished"); }
/*** Metodes per defecte de Unity ***/ protected override void Awake() { base.Awake(); objectName = "Hittite Civil"; cost = 100; baseAttackStrength = 10; baseDefense = 3; baseAttackSpeed = 1.0f; anim.runtimeAnimatorController = Resources.Load ("AnimatorControllers/Hittite_civil_AC") as RuntimeAnimatorController; chargeSounds ("Hittite_civil"); buildableBuildings = new RTSObjectType[] { RTSObjectType.BuildingTownCenter, RTSObjectType.BuildingArmyBuilding, RTSObjectType.BuildingWallTower, RTSObjectType.BuildingWallEntrance, RTSObjectType.BuildingWall, RTSObjectType.BuildingCivilHouse, RTSObjectType.BuildingAcademy }; }
private void CreateBuilding(RTSObjectType objectType) { GameObject buildingPrefabTemplate = RTSObjectFactory.GetObjectTemplate (objectType, owner.civilization); if (buildingPrefabTemplate == null) return; StartBuildingLocationSelection (buildingPrefabTemplate); }
/// <summary> /// Memoize, if required, the information for the specified object and civilization which is initialized on the start script. /// </summary> /// <param name="type">The type of the object.</param> /// <param name="civilization">The civilization of the object.</param> private static ObjectInfo GetObjectInfo(RTSObjectType type, PlayerCivilization civilization) { // We have a pretty big problem here, which is that the costs of the object // are actually defined in the object initialization scripts and not in the prefab // For this reason, to get the cost, we need to actually initialize the object, // get the cost, and destroy it again. Since this is pretty costly, once we get it, // memoize the value to avoid recaculating it in future calls if (!memoizedObjectInfo.ContainsKey(new KeyValuePair<RTSObjectType, PlayerCivilization>(type, civilization))) { // Get object template. If not existing return empty ObjectInfo. var objectTemplate = GetObjectTemplate(type, civilization); if (objectTemplate == null) { memoizedObjectInfo[new KeyValuePair<RTSObjectType, PlayerCivilization>(type, civilization)] = new ObjectInfo(); return memoizedObjectInfo[new KeyValuePair<RTSObjectType, PlayerCivilization>(type, civilization)]; } // Initialize object instance and script. Otherwise return empty ObjectInfo. var objectInstance = GameObject.Instantiate(objectTemplate); try { var objectScript = objectInstance.GetComponent<RTSObject>(); if (objectScript == null) { memoizedObjectInfo[new KeyValuePair<RTSObjectType, PlayerCivilization>(type, civilization)] = new ObjectInfo(); return memoizedObjectInfo[new KeyValuePair<RTSObjectType, PlayerCivilization>(type, civilization)]; } // Get properties from initialized script memoizedObjectInfo[new KeyValuePair<RTSObjectType, PlayerCivilization>(type, civilization)] = new ObjectInfo { Cost = objectScript.cost, ObjectIconSprite = objectScript.objectIconSprite }; } finally { // Make sure we destroy the temporary GameObject we created GameObject.Destroy(objectInstance); } } return memoizedObjectInfo[new KeyValuePair<RTSObjectType, PlayerCivilization>(type, civilization)]; }
/// <summary> /// Get the default object resource prefab for the specified civilization. /// </summary> /// <param name="type">The type of object to load.</param> /// <param name="civilization">The civilization of the player.</param> /// <param name="useFallback">If resource is not available for given civilization, return an equivalent for another civilization.</param> /// <returns>A reference to the object resource prefab, or null if not available.</returns> public static GameObject GetObjectTemplate(RTSObjectType type, PlayerCivilization civilization, bool useFallback = false) { // Validate input arguments correctness if (!Enum.IsDefined(typeof(RTSObjectType), type)) throw new ArgumentOutOfRangeException("type"); if (!Enum.IsDefined(typeof(PlayerCivilization), civilization)) throw new ArgumentOutOfRangeException("civilization"); // Load list of prefabs for the given object if (!resourceNames.ContainsKey(type)) throw new NotSupportedException("The object type '" + type + "' doesn't have its prefabs defined. " + "Define them in " + typeof(RTSObjectFactory) + "."); var prefabsForObject = resourceNames[type]; // Try to load the resource for the exact civilization passed as an argument if (prefabsForObject.ContainsKey(civilization)) { var loadedResource = LoadAndCheckPrefab(prefabsForObject[civilization], true); if (loadedResource != null) return loadedResource; } if (useFallback) { // If the resource couldn't be loaded and useFallback was given, try to load the object // Iterate over the civilizations in order in order to get a consistent behaviour // (dictionary enumeration order is undefined) foreach (var fallbackCivilization in prefabsForObject.Keys.Where(k => k != civilization).OrderBy(k => k)) { var loadedResource = LoadAndCheckPrefab(prefabsForObject[fallbackCivilization], false); if (loadedResource != null) { Debug.LogWarning("Using model for civilization " + fallbackCivilization + " for object of type " + type + " because no model is available for civilization " + civilization + "."); HUDInfo.insertMessage("Object " + type + " not available for civilization " + civilization + "; Using fallback."); return loadedResource; } } throw new NotSupportedException("No prefab available for object type '" + type + " for any civilization. " + "Check the prefab definition in " + typeof(RTSObjectFactory) + "."); } return null; }
/// <summary> /// Get the preview icon sprite the specified object for the specified civilization. /// </summary> /// <param name="type">The type of the object.</param> /// <param name="civilization">The civilization of the object.</param> /// <returns>The preview icon sprite for the required object.</returns> public static Sprite GetObjectIconSprite(RTSObjectType type, PlayerCivilization civilization) { return GetObjectInfo(type, civilization).ObjectIconSprite; }
/// <summary> /// Get the cost of creating the specified object for the specified civilization. /// </summary> /// <param name="type">The type of the object to create.</param> /// <param name="civilization">The civilization of the object to create.</param> /// <returns>The cost in resources required to create the object</returns> public static int GetObjectCost(RTSObjectType type, PlayerCivilization civilization) { return GetObjectInfo(type, civilization).Cost; }
private void CreateUnit(RTSObjectType objectType) { GameObject creationUnit = RTSObjectFactory.GetObjectTemplate (objectType, owner.civilization); if (creationUnit == null) return; AddUnitToCreationQueue (creationUnit); }
/// <summary> /// Get a human-readable name for the given RTS object type. /// </summary> /// <param name="objectType">The type of the object.</param> /// <returns>A human-readable name corresponding to the object type.</returns> public static string GetObjectName(RTSObjectType objectType) { return objectNames[objectType]; }