324 lines
6.4 KiB
C#
324 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class ObjectPool : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public struct stFishCopy
|
|
{
|
|
public int objectGroupID;
|
|
|
|
public Vector3 position;
|
|
|
|
public Quaternion rotation;
|
|
|
|
public Vector3 scale;
|
|
|
|
public float weight;
|
|
|
|
public float length;
|
|
|
|
public float strength;
|
|
|
|
public bool isYoung;
|
|
|
|
public int baitSize;
|
|
|
|
public Fish.WatchStyle watchStyle;
|
|
|
|
public float startStrength;
|
|
|
|
public Vector2 durabilityStartRange;
|
|
|
|
public float durabilityStart;
|
|
|
|
public Vector3 fishSpeed;
|
|
|
|
public float hungerLevel;
|
|
|
|
public float jumpTimer;
|
|
|
|
public float jumpGravity;
|
|
|
|
public Vector2 jumpRotateSpeed;
|
|
|
|
public bool notPulling;
|
|
|
|
public float notPullingTimer;
|
|
|
|
public float durabilityFightSpeed;
|
|
|
|
public float durabilityJerkFactor;
|
|
|
|
public float durabilityJerkSpeed;
|
|
|
|
public float durabilityHandsRotationFactor;
|
|
|
|
public float changeDirectionDelay;
|
|
|
|
public Vector3 targetDirection;
|
|
|
|
public float nextBaitEvaluation;
|
|
|
|
public FishSpawner fishSpawner;
|
|
|
|
internal Transform parent;
|
|
|
|
internal float aggressivenessFight;
|
|
|
|
internal float depthAggressivenessFight;
|
|
|
|
internal float fromPlayerAggressiveness;
|
|
|
|
internal Fish.DepthStyle normalDepthStyle;
|
|
|
|
internal float normalDepthLevel;
|
|
|
|
internal Fish.DepthStyle fightDepthStyle;
|
|
|
|
internal float fightDepthLevel;
|
|
|
|
internal float aggressiveness;
|
|
|
|
internal float depthAggressiveness;
|
|
|
|
internal bool useJumps;
|
|
|
|
internal bool useFightJumps;
|
|
|
|
internal float durabilityCurrent;
|
|
|
|
internal float lastTargetTime;
|
|
|
|
internal float waterInteractive_Multiplier;
|
|
|
|
internal float depthSensorCheckTimer;
|
|
|
|
internal bool isFighting;
|
|
|
|
internal float waterDepth;
|
|
|
|
internal Vector3 terrainLevel;
|
|
|
|
internal Transform terrainTransform;
|
|
|
|
internal float nextTerrainCheck;
|
|
|
|
internal bool isWatchingFish;
|
|
|
|
internal float distanceToBait;
|
|
|
|
internal bool disableLogic;
|
|
|
|
internal bool isInSearchDistance;
|
|
|
|
internal bool isBoatUpdate;
|
|
|
|
public void Init(Fish fish, int objectGroupID_ = -1)
|
|
{
|
|
objectGroupID = objectGroupID_;
|
|
}
|
|
|
|
public bool IsBehaviorDistance(FishingPlayer fishingPlayer)
|
|
{
|
|
if (isFighting)
|
|
{
|
|
return true;
|
|
}
|
|
float num = Vector3.Distance((!fishingPlayer.underwaterCamera.isTurnedOn) ? fishingPlayer.ufpsCamera.transform.position : fishingPlayer.underwaterCamera.transform.position, position);
|
|
distanceToBait = -1f;
|
|
if ((bool)fishingPlayer.currentHands && !fishingPlayer.fish && fishingPlayer.currentHands.bait.isOnWater)
|
|
{
|
|
distanceToBait = Vector3.Distance(fishingPlayer.currentHands.bait.transform.position, position);
|
|
}
|
|
isInSearchDistance = num < fishingPlayer.currentFishDistanceBehavior || (distanceToBait > -1f && distanceToBait < 70f);
|
|
bool result = false;
|
|
if (fishingPlayer.isHunterVisionOn)
|
|
{
|
|
result = isInSearchDistance && num < 110f;
|
|
}
|
|
else if (!fishSpawner.hideOtherDuringFight || !fishingPlayer.fish)
|
|
{
|
|
result = isInSearchDistance;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public struct stObject
|
|
{
|
|
public Fish fishPrefab;
|
|
|
|
public int startSize;
|
|
|
|
public Transform parent;
|
|
|
|
public List<Fish> fishes;
|
|
|
|
public stObject(Fish fishPrefab_, int startSize_, Transform parent_)
|
|
{
|
|
fishPrefab = fishPrefab_;
|
|
startSize = startSize_;
|
|
parent = parent_;
|
|
fishes = new List<Fish>();
|
|
SpawnAllFish();
|
|
}
|
|
|
|
public void SpawnAllFish()
|
|
{
|
|
for (int i = 0; i < startSize; i++)
|
|
{
|
|
fishes.Add(CreateNewFish());
|
|
}
|
|
}
|
|
|
|
private Fish CreateNewFish()
|
|
{
|
|
Fish fish = UnityEngine.Object.Instantiate(fishPrefab, parent);
|
|
Debug.Log("JKM Create new fish " + fishPrefab.name);
|
|
fish.name = fishPrefab.name;
|
|
if (GameController.Instance.useFishesPool)
|
|
{
|
|
jkmStatistic.AddSpawnedFish();
|
|
}
|
|
return fish;
|
|
}
|
|
|
|
public Fish GetFish()
|
|
{
|
|
if (fishes.Count > 0)
|
|
{
|
|
Fish fish = fishes[0];
|
|
fishes.Remove(fish);
|
|
return fish;
|
|
}
|
|
return CreateNewFish();
|
|
}
|
|
|
|
internal void Add(Fish fish)
|
|
{
|
|
fishes.Add(fish);
|
|
fish.transform.parent = parent;
|
|
}
|
|
}
|
|
|
|
public List<stObject> objects;
|
|
|
|
private static ObjectPool instance;
|
|
|
|
public static ObjectPool Instance
|
|
{
|
|
get
|
|
{
|
|
if (!instance)
|
|
{
|
|
instance = UnityEngine.Object.FindObjectOfType<ObjectPool>();
|
|
if (GameController.Instance.useFishesPool)
|
|
{
|
|
foreach (stObject @object in instance.objects)
|
|
{
|
|
@object.SpawnAllFish();
|
|
}
|
|
}
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
public Fish GetFish(Fish fishPrefab)
|
|
{
|
|
for (int i = 0; i < objects.Count; i++)
|
|
{
|
|
if (fishPrefab == objects[i].fishPrefab)
|
|
{
|
|
return objects[i].GetFish();
|
|
}
|
|
}
|
|
stObject item = new stObject(fishPrefab, 1, base.transform);
|
|
objects.Add(item);
|
|
Fish fish = item.GetFish();
|
|
fish.gameObject.SetActive(true);
|
|
return fish;
|
|
}
|
|
|
|
public Fish GetFish(stFishCopy fishCopy)
|
|
{
|
|
Fish fish = objects[fishCopy.objectGroupID].GetFish();
|
|
if (!fish.isInitialized)
|
|
{
|
|
fish.fishSpawner = fishCopy.fishSpawner;
|
|
fish.Initialize();
|
|
}
|
|
fish.SetParamFromCopy(fishCopy);
|
|
fish.gameObject.SetActive(true);
|
|
return fish;
|
|
}
|
|
|
|
public stFishCopy ReturnFish(Fish fish, bool returnCopy = true)
|
|
{
|
|
fish.gameObject.SetActive(false);
|
|
for (int i = 0; i < objects.Count; i++)
|
|
{
|
|
if (fish.name == objects[i].fishPrefab.name)
|
|
{
|
|
stFishCopy fishCopy = new stFishCopy
|
|
{
|
|
objectGroupID = -1
|
|
};
|
|
if (returnCopy)
|
|
{
|
|
fishCopy.objectGroupID = i;
|
|
fish.FillFishCopy(ref fishCopy);
|
|
}
|
|
objects[i].Add(fish);
|
|
return fishCopy;
|
|
}
|
|
}
|
|
stObject item = new stObject(fish, 0, base.transform);
|
|
objects.Add(item);
|
|
stFishCopy fishCopy2 = new stFishCopy
|
|
{
|
|
objectGroupID = -1
|
|
};
|
|
if (returnCopy)
|
|
{
|
|
fishCopy2.objectGroupID = objects.Count - 1;
|
|
fish.FillFishCopy(ref fishCopy2);
|
|
}
|
|
item.Add(fish);
|
|
return fishCopy2;
|
|
}
|
|
|
|
public void SetFishActive(ref List<Fish> fishList, ref List<stFishCopy> fishCopies, int fishIndex, bool show)
|
|
{
|
|
if (show)
|
|
{
|
|
if (fishCopies[fishIndex].objectGroupID != -1)
|
|
{
|
|
fishList[fishIndex] = GetFish(fishCopies[fishIndex]);
|
|
fishCopies[fishIndex] = default(stFishCopy);
|
|
}
|
|
}
|
|
else if ((bool)fishList[fishIndex])
|
|
{
|
|
SetSameSizeInCopyList(ref fishCopies, fishList.Count);
|
|
fishCopies[fishIndex] = ReturnFish(fishList[fishIndex]);
|
|
fishList[fishIndex] = null;
|
|
}
|
|
}
|
|
|
|
private void SetSameSizeInCopyList(ref List<stFishCopy> fishCopies, int size)
|
|
{
|
|
while (fishCopies.Count < size)
|
|
{
|
|
stFishCopy item = new stFishCopy
|
|
{
|
|
objectGroupID = -1
|
|
};
|
|
fishCopies.Add(item);
|
|
}
|
|
}
|
|
}
|