/// <summary> Creates a new Food from an existing one (FlyWeight Pattern). </summary> /// <param name="objectType"> The type of the Food to create. </param> /// <param name="position"> The position to create the Food in. </param> /// <returns> The new Food Game Object. </returns> public GameObject CreateFood(ObjectType objectType, Vector2 position) { GameObject flyWeightObject; int calories; switch (objectType) { case ObjectType.StandardApple: flyWeightObject = flyWeightStandardApple; calories = StandardAppleCalories; break; case ObjectType.GoldenApple: flyWeightObject = flyWeightGoldenApple; calories = GoldenAppleCalories; break; case ObjectType.StandardCarrot: flyWeightObject = flyWeightStandardCarrot; calories = StandardCarrotCalories; break; case ObjectType.GoldenCarrot: flyWeightObject = flyWeightGoldenCarrot; calories = GoldenCarrotCalories; break; default: throw new Exception("Operation not supported."); } GameObject foodGameObject = CommonFactory.CreateCommonObject(flyWeightObject, objectType.ToString(), position); foodGameObject.AddComponent <Food>().Calories = calories; return(foodGameObject); }
/// <summary> Creates a new Rock Game Object from an existing one (FlyWeight Pattern). </summary> /// <param name="position"> The position to create the Game Object in. </param> /// <returns> The new created Rock. </returns> public GameObject CreateRock(Vector2 position) { return(CommonFactory.CreateCommonObject(flyWeightRock, "Rock", position)); }
/// <summary> Creates a Cactus Game Object from an existing one (FlyWeight Pattern). </summary> /// <param name="position"> The position to create object in. </param> /// <returns> The new Cactus Game Object. </returns> public GameObject CreateCactus(Vector2 position) { return(CommonFactory.CreateCommonObject(flyWeightCactus, "Cactus", position)); }
/// <summary> Creates a new Life Game Object from an existing one (FlyWeight Pattern). </summary> /// <param name="position"> The position to create the object in. </param> /// <returns> The new Life Game Object. </returns> public GameObject CreateLife(Vector2 position) { return(CommonFactory.CreateCommonObject(flyWeightLife, "Life", position)); }
/// <summary> /// Creates a new Energy Capsule from an existing one, to reuse the common data (FlyWeight Pattern). /// </summary> /// <param name="position"> The position to create the Energy Capsule in. </param> /// <returns> The created Energy Capsule. </returns> public GameObject CrateEnergyCapsule(Vector2 position) { return(CommonFactory.CreateCommonObject(flyWeightEnergyCapsule, "EnergyCapsule", position)); }