예제 #1
0
        /// <summary>
        /// Spawns an object at the specified position and determines the next spawn position
        /// </summary>
        /// <param name="spawnPosition">Spawn position.</param>
        protected virtual void LinkedSpawn(Vector3 spawnPosition)
        {
            GameObject spawnedObject = Spawn(spawnPosition);

            if (spawnedObject == null)
            {
                if (_lastSpawnedTransform == null)
                {
                    _lastSpawnedTransform = this.transform;
                }
                _nextSpawnDistance = 0f;
            }
            else
            {
                LinkedSpawnedObject spawnedLinkedSpawnedObject = spawnedObject.GetComponent <LinkedSpawnedObject>();
                if (_lastLinkedSpawnedObject != null)
                {
                    // we reposition the linked spawned object to have its In match the previously spawned object's Out.
                    //Vector3 newPosition = spawnedObject.In;
                    spawnedObject.transform.position = _lastSpawnedTransform.position + _lastLinkedSpawnedObject.Out - spawnedLinkedSpawnedObject.In;
                }

                _lastSpawnedTransform    = spawnedObject.transform;
                _lastLinkedSpawnedObject = spawnedLinkedSpawnedObject;
                // we define the next spawn position based on the size of the current object and the specified gaps
                _nextSpawnDistance = 0f;
            }
        }
예제 #2
0
    public virtual void OnEnable()
    {
        _linkedSpawnedObject = (LinkedSpawnedObject)target;
        _renderer            = _linkedSpawnedObject.GetComponent <Renderer>();
        _style = new GUIStyle();
        _style.normal.textColor = Color.green;

        if (_linkedSpawnedObject.In == Vector3.zero && _linkedSpawnedObject.Out == Vector3.zero)
        {
            ResetInOutPosition();
        }
    }
예제 #3
0
    public override void OnInspectorGUI()
    {
        _linkedSpawnedObject = (LinkedSpawnedObject)target;

        EditorGUILayout.LabelField("In/Out Set up", _linkedSpawnedObject.InOutSetup.ToString());

        DrawDefaultInspector();

        if (GUILayout.Button("In/Out Reset"))
        {
            ResetInOutPosition();
        }
    }
예제 #4
0
        /// <summary>
        /// Triggered every frame
        /// </summary>
        protected virtual void FixedUpdate()
        {
            if (OnlySpawnWhileGameInProgress)
            {
                if (GameManager.Instance.Status != GameManager.GameStatus.GameInProgress)
                {
                    _lastSpawnedTransform    = null;
                    _lastLinkedSpawnedObject = null;
                    return;
                }
            }


            if ((_lastSpawnedTransform == null) || (!_lastSpawnedTransform.gameObject.activeInHierarchy))
            {
                FirstSpawn();
            }

            if (_lastSpawnedTransform != null)
            {
                /// if we've reached the next spawn position, we spawn a new object
                if (transform.position.x - _lastSpawnedTransform.position.x >= _nextSpawnDistance)
                {
                    /// we reposition the object
                    Vector3 spawnPosition;
                    if (_lastSpawnedTransform != this.transform)
                    {
                        spawnPosition = _lastSpawnedTransform.transform.position + _lastSpawnedTransform.GetComponent <LinkedSpawnedObject>().Out;
                    }
                    else
                    {
                        spawnPosition = _lastSpawnedTransform.transform.position;
                    }

                    LinkedSpawn(spawnPosition);
                }
            }
        }