public virtual void BindToLine() { if (track == null) { track = Track3.GetInstance(); } if (null != (track as Track3)) { transform.position = new Vector3( (track as Track3).XCoordOfLine(LineNumber), transform.position.y, transform.position.z); } }
public void PutAllPoolablesToBlocks() { if (blockPrefab != null) { float ZSizeBlock = BlockDecorator.ZSize; float trackSizeZ = 0; Vector3 tarckStart = Vector3.zero; TrackAbstract track = TrackAbstract.GetInstance(); if (null == track) { throw new UnityException("The Track is not found in scene"); } else { trackSizeZ = TrackAbstract.GetInstance().collider.bounds.size.z; tarckStart = new Vector3(TrackAbstract.GetInstance().collider.bounds.center.x, 0f, TrackAbstract.GetInstance().collider.bounds.min.z); } List <IPoolable> Poolables; MonoBehaviour[] behaviours = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[]; if (behaviours != null) { Poolables = behaviours.OfType <IPoolable>().ToList(); } else { Poolables = new List <IPoolable>(0); } for (int i = 0; i *ZSizeBlock < trackSizeZ; i++) { GameObject newGO = Instantiate(blockPrefab, tarckStart + i * Vector3.forward * ZSizeBlock + Vector3.forward * ZSizeBlock * 0.5f, Quaternion.identity) as GameObject; newGO.name = (i < 10)? "block_0" + i : "block_" + i; foreach (IPoolable poolable in Poolables) { Bounds bound = new Bounds(newGO.transform.position, new Vector3(10000, 10000, ZSizeBlock)); if (bound.Contains(poolable.GetGameObject.transform.position)) { poolable.GetGameObject.transform.parent = newGO.transform; } } } } else { Debug.LogWarning("Unable to pack poolables to blocks. Set blockPrefab to TrackChunkManager"); } }
void OnLevelWasLoaded() { if (IsCanUse) { if (Application.loadedLevelName != defaultLevel) { trackChunkManager = TrackChunkManager.GetInstance(); currentLevelConfiguration = LevelConfiguration.Instance; PrefabInitializationManager = FindObjectOfType <PrefabInitializationManager>(); if (PrefabInitializationManager != null) { foreach (PrefabItem prefabItem in PrefabInitializationManager.PrefabItems) { if (prefabItem.prefab.GetComponent <AbstractPoolableObject>() != null) { Pool.InstantiateAndAdd( prefabItem.prefab.GetComponent <AbstractPoolableObject>(), prefabItem.count); } } } if (Controller.GetInstance() != null) { TrackAbstract.GetInstance().CalculateTrackState(currentLevelConfiguration.DefaultPosition); Controller.GetInstance().MoveToPosition(currentLevelConfiguration.DefaultPosition); trackChunkManager.Initialize(currentLevelConfiguration.DefaultPosition); CollectionInitializedEvent(info.bonuses); } } else { Pool = new Pool <AbstractPoolableObject>(); trackChunkManager = null; currentLevelConfiguration = null; PrefabInitializationManager = null; } } }
public void Init(Vector3 startPosition, IEnumerable <IPoolable> Pooalables, float size) { activated = false; this.startCenterPosition = startPosition; this.size = size; enterTriger = gameObject.AddComponent <BoxCollider>(); enterTriger.transform.position = this.startCenterPosition; enterTriger.size = new Vector3(TrackAbstract.GetInstance().LineWidth *10f, 40f, 1f); enterTriger.isTrigger = true; var trigerScript = gameObject.AddComponent <EnterTrackChunkStartTrigger>(); trigerScript.chunk = this; bounds = new Bounds(startPosition + new Vector3(0f, 5f, size / 2f), new Vector3(100f, 20f, size)); foreach (IPoolable poolable in Pooalables) { if (bounds.Contains(poolable.GetGameObject.transform.position)) { try { ISerializator serializator = (ISerializator)gameObject.AddComponent(SerializatorTypes.SerializatorFor(poolable.GetType().Name)); if (serializator == null) { Debug.LogWarning(poolable.GetType().Name + "Serializator not found"); } else { serializator.Serialize(poolable); } } catch (Exception e) { Debug.LogException(e); Debug.LogError(poolable); } } } }
public override void Execute() { if (GameManager.Instance.trackChunkManager != null) { GameManager.Instance.trackChunkManager.DeInitialize(); GameManager.Instance.trackChunkManager.Initialize( GameManager.Instance.currentLevelConfiguration.DefaultPosition); } TrackAbstract.GetInstance().CalculateTrackState(GameManager.Instance.currentLevelConfiguration.DefaultPosition); Controller.GetInstance().MoveToPosition(GameManager.Instance.currentLevelConfiguration.DefaultPosition); Controller.GetInstance().PrepareToReplay(); if (switchableBehaviour != null) { switchableBehaviour.Switch(); } }
public void GenerateChunks() { Debug.Log("GenereateChunks()"); Vector3 trackSrart = Vector3.zero; int chunkCount = 0; TrackAbstract track = TrackAbstract.GetInstance(); if (null == track) { throw new UnityException("The Track is not found in scene"); } else { float fullSize = track.GetComponent <Collider>().bounds.size.z; trackSrart = new Vector3(track.collider.bounds.center.x, track.collider.bounds.max.y, track.collider.bounds.min.z); chunkCount = Mathf.CeilToInt(fullSize / ChunkSize); } Debug.Log("chunkCount:" + chunkCount); trackChuncks = new List <TrackChunk>(chunkCount); List <IPoolable> Poolables; MonoBehaviour[] behaviours = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[]; if (behaviours != null) { Poolables = behaviours.OfType <IPoolable>().ToList(); } else { Poolables = new List <IPoolable>(0); } for (int j = 0; j < chunkCount; j++) { Vector3 startPoint = trackSrart + new Vector3(0, 0, ChunkSize * j); GameObject newObjChunk = new GameObject { name = "chunk" + j }; UnityEditor.GameObjectUtility.SetStaticEditorFlags(newObjChunk, UnityEditor.StaticEditorFlags.BatchingStatic); newObjChunk.transform.parent = gameObject.transform; TrackChunk newChunk = newObjChunk.AddComponent <TrackChunk>(); newChunk.Init(startPoint, Poolables, ChunkSize); newObjChunk.layer = newObjChunk.transform.parent.gameObject.layer; trackChuncks.Add(newChunk); Debug.Log("trackChunks.Count: " + trackChuncks.Count); } try { foreach (IPoolable poolable in Poolables) { if (poolable != null) { if (poolable.GetGameObject != null) { DestroyImmediate(poolable.GetGameObject); } } } } catch (Exception) { Debug.Log("MissingReferenceException: The object of type 'Obstacle' has been destroyed but you are still trying to access it."); } EditorUtility.SetDirty(this); }
protected virtual void OnDisable() { track = null; }
public virtual void OnEnable() { track = TrackAbstract.GetInstance(); }