public static void CallHarvestActionEffectEvent(Vector3 effectPosition, HarvestActionEffect harvestActionEffect) { if (HarvestActionEffectEvent != null) { HarvestActionEffectEvent(effectPosition, harvestActionEffect); } }
// Event that get's published when the player harvests something (rock, wood, reapable scenary) - subscribers will use this to emitt particle effects for the given harvest effect // i.e. chopping, leaves falling, breaking, reaping public static void CallHarvestActionEffectEvent(Vector3 effectPosition, HarvestActionEffect harvestActionEffect) { // Check if there are any subscribers - or else do nothing! if (HarvestActionEffectEvent != null) { HarvestActionEffectEvent(effectPosition, harvestActionEffect); } }
private void displayHarvestActionEffect(Vector3 effectPosition, HarvestActionEffect harvestActionEffect) { switch (harvestActionEffect) { case HarvestActionEffect.deciduousLeavesFalling: GameObject deciduousLeaveFalling = PoolManager.Instance.ReuseObject(deciduousLeavesFallingPrefab, effectPosition, Quaternion.identity); deciduousLeaveFalling.SetActive(true); StartCoroutine(DisableHarvestActionEffect(deciduousLeaveFalling, twoSeconds)); break; case HarvestActionEffect.pineConesFalling: GameObject pineConesFalling = PoolManager.Instance.ReuseObject(pineConesFallingPrefab, effectPosition, Quaternion.identity); pineConesFalling.SetActive(true); StartCoroutine(DisableHarvestActionEffect(pineConesFalling, twoSeconds)); break; case HarvestActionEffect.choppingTreeTrunk: GameObject choppingTreeTrunk = PoolManager.Instance.ReuseObject(choppingTreeTrunkPrefab, effectPosition, Quaternion.identity); choppingTreeTrunk.SetActive(true); StartCoroutine(DisableHarvestActionEffect(choppingTreeTrunk, twoSeconds)); break; case HarvestActionEffect.breakingStone: GameObject breakingStone = PoolManager.Instance.ReuseObject(breakingStonePrefab, effectPosition, Quaternion.identity); breakingStone.SetActive(true); StartCoroutine(DisableHarvestActionEffect(breakingStone, twoSeconds)); break; case HarvestActionEffect.reaping: GameObject reaping = PoolManager.Instance.ReuseObject(reapingPrefab, effectPosition, Quaternion.identity); reaping.SetActive(true); StartCoroutine(DisableHarvestActionEffect(reaping, twoSeconds)); break; case HarvestActionEffect.none: break; default: break; } }
// This method checkes what the harvest action was (chopping, reaping, breaking, etc), and then initiates the proper coroutine to display the corresponding particle effect private void displayHarvestActionEffect(Vector3 effectPosition, HarvestActionEffect harvestActionEffect) { // Check what the harvestActionEffect was! switch (harvestActionEffect) { // Deciduous leaves falling from the tree as you chop it case HarvestActionEffect.deciduousLeavesFalling: // If it was a deciduousLeavesFalling harvest (ie chopping the tree), Grab the deciduousLeavesFalling GameObject from the PoolManager // deciduousLeavesFalling queue, set it to active (This starts the particle effect in the prefab), and then initiate the // coroutine to disable the gameObject after two seconds GameObject deciduousLeavesFalling = PoolManager.Instance.ReuseObject(deciduousLeavesFallingPrefab, effectPosition, Quaternion.identity); deciduousLeavesFalling.SetActive(true); StartCoroutine(DisableHarvestActionEffect(deciduousLeavesFalling, twoSeconds)); break; // Pine cones falling from the tree as you chop it case HarvestActionEffect.pineConesFalling: // If it was a pineConesFalling harvest (ie chopping the spruce tree), Grab the pineConesFalling GameObject from the PoolManager // pineConesFalling queue, set it to active (This starts the particle effect in the prefab), and then initiate the // coroutine to disable the gameObject after two seconds GameObject pineConesFalling = PoolManager.Instance.ReuseObject(pineConesFallingPrefab, effectPosition, Quaternion.identity); pineConesFalling.SetActive(true); StartCoroutine(DisableHarvestActionEffect(pineConesFalling, twoSeconds)); break; // Wood splinters bursting as you chop a trunk case HarvestActionEffect.choppingTreeTrunk: // If it was a choppingTreeTrunk harvest (ie chopping the trunk), Grab the choppingTreeTrunk GameObject from the PoolManager // choppingTreeTrunk queue, set it to active (This starts the particle effect in the prefab), and then initiate the // coroutine to disable the gameObject after two seconds GameObject choppingTreeTrunk = PoolManager.Instance.ReuseObject(choppingTreeTrunkPrefab, effectPosition, Quaternion.identity); choppingTreeTrunk.SetActive(true); StartCoroutine(DisableHarvestActionEffect(choppingTreeTrunk, twoSeconds)); break; // rock chunks spray as you break a stone case HarvestActionEffect.breakingStone: // If it was a breakingStone harvest (ie breaking rocks), Grab the breakingStone GameObject from the PoolManager // breakingStone queue, set it to active (This starts the particle effect in the prefab), and then initiate the // coroutine to disable the gameObject after two seconds GameObject breakingStone = PoolManager.Instance.ReuseObject(breakingStonePrefab, effectPosition, Quaternion.identity); breakingStone.SetActive(true); StartCoroutine(DisableHarvestActionEffect(breakingStone, twoSeconds)); break; // Grass particles flying as you reap grass case HarvestActionEffect.reaping: // If it was a reaping harvest, Grab the reaping GameObject from the PoolManager reaping queue, set it to active (This starts the // particle effect), and then initiate the coroutine to disable the gameObject after two seconds GameObject reaping = PoolManager.Instance.ReuseObject(reapingPrefab, effectPosition, Quaternion.identity); reaping.SetActive(true); StartCoroutine(DisableHarvestActionEffect(reaping, twoSeconds)); break; // If anything else, just do nothing case HarvestActionEffect.none: break; default: break; } }