Exemple #1
0
    public EZParallaxObjectElement AddNewParallaxingElement(Transform targetElement, float privateSpeedScalarX, float privateSpeedScalarY)
    {
        for(int i = 0; i < m_parallaxElements.Length; i++)
        {
            if(m_parallaxElements[i].parallaxObject == targetElement)
            {
                Debug.Log("WARNING -- AddNewParallaxingElement attempted to add an element that was arleady in the parallax list. Aborting.");
                return null;
            }
        }
        List<EZParallaxObjectElement> tempElementArray = new List<EZParallaxObjectElement>(m_parallaxElements);
        EZParallaxObjectElement newParallaxElement = new EZParallaxObjectElement(targetElement);
        newParallaxElement.privateParallaxSpeedScalarX = privateSpeedScalarX;
        newParallaxElement.privateParallaxSpeedScalarY = privateSpeedScalarY;
        tempElementArray.Add(newParallaxElement);
        m_parallaxElements = tempElementArray.ToArray();

        if( (targetElement.position.z - m_playerObj.transform.position.z) > m_maxDist)
        {
            m_maxDist = targetElement.position.z - m_playerObj.transform.position.z;
            m_maxDistDiv = 1 / m_maxDist;
        }

        if(m_initialized)
        {
            newParallaxElement.Initialize();
            SetElementScreenSpaceExtents(newParallaxElement);
        }

        return newParallaxElement;
    }
Exemple #2
0
    void UpdateDupeObjects(EZParallaxObjectElement targetPE, bool direction)
    {
        EZParallaxObjectElement edgeElement = FindEdgeSpawningElement(targetPE, direction);
        EZParallaxObjectElement prevEdgeElement = FindEdgeSpawningElement(targetPE, !direction);
        Camera actualCamera = m_mainCamera.GetComponent<Camera>();
        float screenWidth = actualCamera.pixelWidth;
        float newSpawnOffset = 0;
        float newSpawnOffsetScreenSpace = 0;
        float objectPosX = 0;
        if(edgeElement.parallaxObject != null)
        {
            objectPosX = actualCamera.WorldToScreenPoint(edgeElement.parallaxObject.position).x;
        }
        else
        {
            Debug.Log("WARNING -- UpdateDupeObjects is trying to access a parallax object, for the EZP object element " + edgeElement.name + ", that doesn't exist! objectPosX is remaining 0.");
        }

        float edgeCheckBuffer = screenWidth;
        if(direction) //Element is moving to the left side of the screen. Camera most likely is moving to the right.
        {
            while( (objectPosX + targetPE.elementScreenSpaceExtentX + edgeCheckBuffer) < 0.0f )
            {
                if(targetPE.randomSpawnX)
                {
                    int spawnGroupIdx = targetPE.spawnGroupIndex;

                    if(m_rndDistArrayIndex[spawnGroupIdx] == m_randomOffsetHistorySize)
                    {
                        m_rndDistArrayIndex[spawnGroupIdx] = 0;
                    }
                    else
                    {
                        m_rndDistArrayIndex[spawnGroupIdx]++;
                    }

                    if(!m_rndDistArray[spawnGroupIdx, m_rndDistArrayIndex[spawnGroupIdx]].HasValue)
                    {
                        //Random offset not stored for this index. Make a new one and store it at this index.
                        newSpawnOffset = Random.Range(targetPE.spawnDistanceMinX, targetPE.spawnDistanceMaxX);
                        m_rndDistArray[spawnGroupIdx, m_rndDistArrayIndex[spawnGroupIdx]] = newSpawnOffset;
                    }
                    else
                    {
                        newSpawnOffset = (float)m_rndDistArray[spawnGroupIdx, m_rndDistArrayIndex[spawnGroupIdx]];
                    }

                    Vector3 objectOffsetVector = new Vector3(newSpawnOffset, 0, 0);
                    newSpawnOffsetScreenSpace = actualCamera.WorldToScreenPoint(targetPE.parallaxObject.position).x - actualCamera.WorldToScreenPoint(targetPE.parallaxObject.position - objectOffsetVector).x;
                }
                else
                {
                    newSpawnOffset = targetPE.spawnDistanceX;
                    newSpawnOffsetScreenSpace = targetPE.spawnDistanceScreenX;
                }

                edgeElement.parallaxObject.position = prevEdgeElement.parallaxObject.position + new Vector3(edgeElement.meshWidth + newSpawnOffset, 0, 0);
                edgeElement.initialSpawnDistanceX = newSpawnOffset;
                edgeElement.initialLeftSpawnDistanceScreenSpaceX = newSpawnOffsetScreenSpace;

                if(edgeElement.dupeElementRight != null)
                {
                    edgeElement.dupeElementRight.dupeElementLeft = null;
                }
                edgeElement.dupeElementRight = null;
                if(prevEdgeElement.dupeElementLeft == edgeElement)
                {
                    prevEdgeElement.dupeElementLeft = null;
                }
                prevEdgeElement.dupeElementRight = edgeElement;

                edgeElement.dupeElementLeft = prevEdgeElement;

                edgeElement = FindEdgeSpawningElement(targetPE, direction);
                prevEdgeElement = FindEdgeSpawningElement(targetPE, !direction);

                objectPosX = actualCamera.WorldToScreenPoint(edgeElement.parallaxObject.position).x;
            }
        }
        else //Element is moving to the right side of the screen. Camera most likely is moving to the left.
        {
            while( (objectPosX - ( targetPE.elementScreenSpaceExtentX + edgeCheckBuffer )) > screenWidth )
            {
                if(targetPE.randomSpawnX)
                {
                    int spawnGroupIdx = targetPE.spawnGroupIndex;

                    int indexLeftShift = m_rndDistArrayIndex[spawnGroupIdx] - m_rndElementGroupSize[spawnGroupIdx];
                    if(indexLeftShift < 0)
                    {
                        indexLeftShift = m_randomOffsetHistorySize - Mathf.Abs(indexLeftShift);
                    }

                    if(!m_rndDistArray[spawnGroupIdx, indexLeftShift].HasValue)
                    {
                        newSpawnOffset = Random.Range(targetPE.spawnDistanceMinX, targetPE.spawnDistanceMaxX);
                        m_rndDistArray[spawnGroupIdx, indexLeftShift] = newSpawnOffset;
                    }
                    else
                    {
                        newSpawnOffset = (float)m_rndDistArray[spawnGroupIdx, indexLeftShift];
                    }

                    Vector3 objectOffsetVector = new Vector3(newSpawnOffset, 0, 0);
                    newSpawnOffsetScreenSpace = actualCamera.WorldToScreenPoint(targetPE.parallaxObject.position).x - actualCamera.WorldToScreenPoint(targetPE.parallaxObject.position - objectOffsetVector).x;

                    if(m_rndDistArrayIndex[spawnGroupIdx] == 0)
                    {
                        m_rndDistArrayIndex[spawnGroupIdx] = m_randomOffsetHistorySize;
                    }
                    else
                    {
                        m_rndDistArrayIndex[spawnGroupIdx]--;
                    }

                }
                else
                {
                    newSpawnOffset = targetPE.spawnDistanceX;
                    newSpawnOffsetScreenSpace = targetPE.spawnDistanceScreenX;
                }

                edgeElement.parallaxObject.position = prevEdgeElement.parallaxObject.position - new Vector3(edgeElement.meshWidth + newSpawnOffset, 0, 0);
                edgeElement.initialRightSpawnDistanceX = newSpawnOffset;
                edgeElement.initialRightSpawnDistanceScreenSpaceX = newSpawnOffsetScreenSpace;
                if(edgeElement.dupeElementLeft != null)
                {
                    edgeElement.dupeElementLeft.dupeElementRight = null;
                }
                edgeElement.dupeElementLeft = null;
                if(prevEdgeElement.dupeElementRight == edgeElement)
                {
                    prevEdgeElement.dupeElementRight = null;
                }
                prevEdgeElement.dupeElementLeft = edgeElement;

                edgeElement.dupeElementRight = prevEdgeElement;

                edgeElement = FindEdgeSpawningElement(targetPE, direction);
                prevEdgeElement = FindEdgeSpawningElement(targetPE, !direction);

                objectPosX = actualCamera.WorldToScreenPoint(edgeElement.parallaxObject.position).x;
            }
        }
    }
Exemple #3
0
    void SpawnSingleElementDupes(EZParallaxObjectElement targetElement, Camera actualCamera, float screenWidth)
    {
        DupeChainHandle dupeChainParent;

        if(targetElement.dupeChainObject == null)
        {
            dupeChainParent = new DupeChainHandle();
            dupeChainParent.targetGameObject = new GameObject();
            dupeChainParent.targetGameObject.name = "EZP " + targetElement.name + " Dupe Handle";
            Transform origParent = targetElement.parallaxObject.parent;
            targetElement.parallaxObject.parent = dupeChainParent.targetGameObject.transform;
            dupeChainParent.targetGameObject.transform.parent = origParent;
            targetElement.dupeChainObject = dupeChainParent;

            if(m_dupeChainHandles != null)
            {
                DupeChainHandle[] tempDCArray = new DupeChainHandle[m_dupeChainHandles.Length + 1];
                for(int i = 0; i < m_dupeChainHandles.Length; i++)
                {
                    tempDCArray[i] = m_dupeChainHandles[i];
                }

                tempDCArray[m_dupeChainHandles.Length] = dupeChainParent;
                m_dupeChainHandles = tempDCArray;
            }
            else
            {
                m_dupeChainHandles = new DupeChainHandle[1];
                m_dupeChainHandles[0] = dupeChainParent;
            }
        }
        else
        {
            dupeChainParent = targetElement.dupeChainObject;
        }

        float targetElementScreenWidth = targetElement.elementScreenSpaceExtentX * 2;
        Vector2 targetCenterPosScreenPt = actualCamera.WorldToScreenPoint(targetElement.parallaxObject.position);
        //Create an array of randomized offsets and use that array to figure out how wide the initial positioning needs to be, then draw from that array when spawning the individual elements.
        List<float> randomOffsetsList = new List<float>();
        int maxDupes = 0;
        if (targetElement.randomSpawnX)
        {
            //Goof check
            if(targetElement.initialSpawnDistanceMinX > targetElement.initialSpawnDistanceMaxX)
            {
                Debug.Log ("WARNING -- For your " + targetElement.name + " element, your minimum random spawn distance is greater than your maximum random spawn distance. Swapping your minimum for your maximum.");
                float swapVar = targetElement.initialSpawnDistanceMinX;
                targetElement.initialSpawnDistanceMinX = targetElement.initialSpawnDistanceMaxX;
                targetElement.initialSpawnDistanceMaxX = swapVar;
            }

            float minScreenSpcOffset = targetCenterPosScreenPt.x - actualCamera.WorldToScreenPoint(targetElement.parallaxObject.position - new Vector3( targetElement.spawnDistanceMinX, 0, targetElement.parallaxObject.position.z)).x;
            int greatestMaxDupesX = Mathf.CeilToInt( ( screenWidth * 3 )/ (targetElementScreenWidth + minScreenSpcOffset)) + 2; // * 3 screenwidth and +2 for buffer objects

            for(int k = 0; k < greatestMaxDupesX; k++)
            {
                float randomOffset = Random.Range(targetElement.spawnDistanceMinX, targetElement.spawnDistanceMaxX);
                randomOffsetsList.Add(randomOffset);
                m_rndDistArray[m_randomSpawnCtr, m_rndDistStartIndex + k] = randomOffset;
            }

            maxDupes = greatestMaxDupesX;
            m_rndElementGroupSize[m_randomSpawnCtr] = maxDupes; //Does not include the original object that was spawned from
            m_rndDistArrayIndex[m_randomSpawnCtr] = m_rndDistStartIndex + maxDupes - 1; //Subtract 1 to make room for the initial index shift when the character starts moving, pos or neg
            targetElement.spawnGroupIndex = m_randomSpawnCtr;
            m_randomSpawnCtr++;

            if(m_rndElementGroupSize[m_randomSpawnCtr - 1] >= m_randomOffsetHistorySize)
            {
                Debug.Log ("An EZParallax element object named " + targetElement.name + " needs to spawn more objects than there are slots in the random offset history! Raise your history size to greater than " + maxDupes + " to resolve this problem. Aborting the creation of duplicate objects for " + targetElement.name + ".");
                return;
            }
        }
        else
        {
            targetElement.initialSpawnDistanceScreenX = targetElement.spawnDistanceScreenX;
            targetElement.initialLeftSpawnDistanceScreenSpaceX = targetElement.spawnDistanceScreenX;
            targetElement.initialRightSpawnDistanceScreenSpaceX = targetElement.spawnDistanceScreenX;
            maxDupes = Mathf.CeilToInt( ( screenWidth * 3 ) / ( targetElementScreenWidth + targetElement.spawnDistanceScreenX ) ) + 2; // +2 buffer objects
            targetElement.spawnGroupIndex = 0;
        }

        int numRightDupes = Mathf.Min( Mathf.CeilToInt( ( (screenWidth * 1.5f) - targetCenterPosScreenPt.x) / targetElementScreenWidth), maxDupes);
        if(numRightDupes < 0)
        {
            numRightDupes = 0;
        }
        int numLeftDupes = maxDupes - numRightDupes;
        if(numLeftDupes < 0)
        {
            numLeftDupes = 0;
        }

        //Spawn all objects on the left side
        EZParallaxObjectElement dupeTargetElement = targetElement;
        EZParallaxObjectElement previousElement = targetElement;

        for ( int j = 0; j < numLeftDupes; ++j )
        {
            if(dupeTargetElement.dupeElementLeft != null)
            {
                dupeTargetElement = dupeTargetElement.dupeElementLeft;
                continue;
            }

            Vector3 objectOffsetVector;
            if(dupeTargetElement.randomSpawnX)
            {
                int offsetIndex = numLeftDupes - 1 - j;
                objectOffsetVector = new Vector3(randomOffsetsList[offsetIndex] + dupeTargetElement.meshWidth, 0, 0);
                dupeTargetElement.initialLeftSpawnDistanceX = randomOffsetsList[offsetIndex];
                dupeTargetElement.initialLeftSpawnDistanceScreenSpaceX = targetCenterPosScreenPt.x - actualCamera.WorldToScreenPoint(dupeTargetElement.parallaxObject.position - (new Vector3(randomOffsetsList[offsetIndex], 0, dupeTargetElement.parallaxObject.position.z))).x;
            }
            else
            {
                objectOffsetVector = new Vector3(targetElement.spawnDistanceX + dupeTargetElement.meshWidth, 0, 0);
                dupeTargetElement.initialLeftSpawnDistanceX = dupeTargetElement.initialSpawnDistanceX;
                dupeTargetElement.initialLeftSpawnDistanceScreenSpaceX = dupeTargetElement.initialSpawnDistanceScreenX;
            }
            Transform leftDupeObject = (Transform)(Instantiate(dupeTargetElement.parallaxObject, dupeTargetElement.parallaxObject.position - objectOffsetVector, dupeTargetElement.parallaxObject.rotation) );
            leftDupeObject.transform.parent =  dupeTargetElement.parallaxObject.parent;
            dupeTargetElement.dupeElementLeft = AddNewParallaxingElement(leftDupeObject);
            dupeTargetElement.dupeElementLeft.Initialize();
            dupeTargetElement.dupeElementLeft.initialRightSpawnDistanceX = dupeTargetElement.leftSpawnDistanceX;
            dupeTargetElement.dupeElementLeft.initialRightSpawnDistanceScreenSpaceX = dupeTargetElement.leftSpawnDistanceScreenSpaceX;
            dupeTargetElement = dupeTargetElement.dupeElementLeft;
            dupeTargetElement.isMotorized = targetElement.isMotorized;
            dupeTargetElement.initialMotorSpeed = targetElement.initialMotorSpeed;
            dupeTargetElement.randomSpawnX = targetElement.randomSpawnX;
            dupeTargetElement.spawnGroupIndex = targetElement.spawnGroupIndex;
            dupeTargetElement.privateParallaxSpeedScalarX = targetElement.privateParallaxSpeedScalarX;
            dupeTargetElement.privateParallaxSpeedScalarY = targetElement.privateParallaxSpeedScalarY;
            dupeTargetElement.isDupe = true;
            dupeTargetElement.dupeChainObject = dupeChainParent;
            dupeTargetElement.dupeElementRight = previousElement;
            previousElement = dupeTargetElement;
        }

        if(randomOffsetsList.Count > 0)
        {
            randomOffsetsList.RemoveRange(0, numLeftDupes);
        }

        //Spawn all objects on the right side
        dupeTargetElement = targetElement;
        previousElement = targetElement;
        for ( int k = 0; k < numRightDupes; ++k )
        {
            if(dupeTargetElement.dupeElementRight != null)
            {
                dupeTargetElement = dupeTargetElement.dupeElementRight;
                continue;
            }

            Vector3 objectOffsetVector;
            if(dupeTargetElement.randomSpawnX)
            {
                objectOffsetVector = new Vector3(randomOffsetsList[k] + dupeTargetElement.meshWidth, 0, 0);
                dupeTargetElement.initialRightSpawnDistanceX = randomOffsetsList[k];
                dupeTargetElement.initialRightSpawnDistanceScreenSpaceX = targetCenterPosScreenPt.x - actualCamera.GetComponent<Camera>().WorldToScreenPoint(dupeTargetElement.parallaxObject.position - (new Vector3(randomOffsetsList[k], 0, dupeTargetElement.parallaxObject.position.z))).x;
            }
            else
            {
                objectOffsetVector = new Vector3(targetElement.spawnDistanceX + dupeTargetElement.meshWidth, 0, 0);
                dupeTargetElement.initialRightSpawnDistanceX = dupeTargetElement.spawnDistanceX;
                dupeTargetElement.initialRightSpawnDistanceScreenSpaceX = dupeTargetElement.spawnDistanceScreenX;
            }

            Transform rightDupeObject = (Transform)(Instantiate(dupeTargetElement.parallaxObject, dupeTargetElement.parallaxObject.position + objectOffsetVector, dupeTargetElement.parallaxObject.rotation) );
            rightDupeObject.transform.parent =  dupeTargetElement.parallaxObject.parent;
            dupeTargetElement.dupeElementRight = AddNewParallaxingElement(rightDupeObject);
            dupeTargetElement.dupeElementRight.Initialize();
            dupeTargetElement.dupeElementRight.initialLeftSpawnDistanceX = dupeTargetElement.rightSpawnDistanceX;
            dupeTargetElement.dupeElementRight.initialLeftSpawnDistanceScreenSpaceX = dupeTargetElement.rightSpawnDistanceScreenSpaceX;
            dupeTargetElement = dupeTargetElement.dupeElementRight;
            dupeTargetElement.isMotorized = targetElement.isMotorized;
            dupeTargetElement.initialMotorSpeed = targetElement.initialMotorSpeed;
            dupeTargetElement.randomSpawnX = targetElement.randomSpawnX;
            dupeTargetElement.spawnGroupIndex = targetElement.spawnGroupIndex;
            dupeTargetElement.privateParallaxSpeedScalarX = targetElement.privateParallaxSpeedScalarX;
            dupeTargetElement.privateParallaxSpeedScalarY = targetElement.privateParallaxSpeedScalarY;
            dupeTargetElement.dupeChainObject = dupeChainParent;
            dupeTargetElement.isDupe = true;
            dupeTargetElement.dupeElementLeft = previousElement;
            previousElement = dupeTargetElement;
        }
    }
Exemple #4
0
    private void SetNullChainItems(EZParallaxObjectElement targetElement)
    {
        if(targetElement.dupeElementLeft != null)
        {
            targetElement.dupeElementLeft.dupeElementRight = null;
            targetElement.dupeElementLeft = null;
        }

        if(targetElement.dupeElementRight != null)
        {
            targetElement.dupeElementRight.dupeElementLeft = null;
            targetElement.dupeElementRight = null;
        }
    }
Exemple #5
0
 private void SetElementScreenSpaceExtents(EZParallaxObjectElement[] elementArray)
 {
     for(int i = 0; i < elementArray.Length; i++)
     {
         SetElementScreenSpaceExtents(elementArray[i]);
     }
 }
Exemple #6
0
    private void SetElementScreenSpaceExtents(EZParallaxObjectElement targetElement)
    {
        Camera actualCamera = m_mainCamera.GetComponent<Camera>();
        if(targetElement.needsNewScreenspaceExtents == true)
        {
            Vector2 elementCenterScreenPt = actualCamera.WorldToScreenPoint(targetElement.parallaxObject.position);
            Vector2 elementXEdgeScreenPt = actualCamera.WorldToScreenPoint(targetElement.parallaxObject.position + new Vector3(targetElement.meshExtentX, 0.0f, 0.0f));
            float newExtentX = Mathf.Abs(elementXEdgeScreenPt.x - elementCenterScreenPt.x);
            targetElement.initialElementScreenSpaceExtentX = newExtentX;
        }

        if(targetElement.spawnsDuplicateOnX && targetElement.spawnDistanceX != 0)
        {
            float offset = actualCamera.WorldToScreenPoint(targetElement.parallaxObject.position).x -  actualCamera.WorldToScreenPoint(targetElement.parallaxObject.position - new Vector3(targetElement.spawnDistanceX, 0, targetElement.parallaxObject.position.z)).x;
            targetElement.initialRightSpawnDistanceScreenSpaceX = offset;
            targetElement.initialLeftSpawnDistanceScreenSpaceX = offset;
        }
    }
Exemple #7
0
    private EZParallaxObjectElement FindEdgeSpawningElement( EZParallaxObjectElement targetElement, bool direction)
    {
        if(direction) //If moving to the right
        {
            if(targetElement.dupeElementLeft == null || targetElement.dupeElementLeft == targetElement)
            {
                if(targetElement.dupeElementLeft == targetElement)
                {
                    Debug.Log("WARNING -- You are trying to manipulate an element, " + targetElement.name + ", that was set to spawn duplicates, but in fact has none. You may need to initialize, or may have purged your duplicates without respawning new ones.");
                }
                return targetElement;
            }
            return FindEdgeSpawningElement(targetElement.dupeElementLeft, direction);
        }
        else //Moving to the left
        {
            if(targetElement.dupeElementRight == null || targetElement.dupeElementRight == targetElement)
            {
                return targetElement;
            }

            if(targetElement.dupeElementRight == targetElement)
            {
                Debug.Log("WARNING -- You are trying to manipulate an element, " + targetElement.name + ", that was set to spawn duplicates, but in fact has none. You may need to initialize, or may have purged your duplicates without respawning new ones.");
            }
            return FindEdgeSpawningElement(targetElement.dupeElementRight, direction);
        }
    }
Exemple #8
0
 void UpdateTargetScale(EZParallaxObjectElement targetElement)
 {
     Transform targetElemTransform = targetElement.parallaxObject;
     float currentOrthoSizeRatio = 1;
     if(m_currentOrthoSize != m_prevOrthoSize)
     {
         currentOrthoSizeRatio = 1 + ( (m_mainCamera.GetComponent<Camera>().orthographicSize / m_camStartOrthoSize) - 1) * (Mathf.Abs(targetElemTransform.position.z - m_playerObj.transform.position.z) * m_maxDistDiv);
         if(m_enableDollyZoom)
         {
             targetElement.UpdateScale(currentOrthoSizeRatio, m_mainCamera);
         }
     }
 }
Exemple #9
0
    //Use this function to set the infinite wrap settings on an object that you have dynamically added to the parallax list at runtime.
    public void SetElementWrapSettings(EZParallaxObjectElement targetElement, bool xWrapOn,  float spawnDistanceX)
    {
        targetElement.spawnsDuplicateOnX = xWrapOn;
        targetElement.initialSpawnDistanceX = spawnDistanceX;

        if(m_initialized)
        {
            SetElementScreenSpaceExtents(targetElement);
            SpawnSingleElementDupes(targetElement, m_mainCamera.GetComponent<Camera>(), m_mainCamera.GetComponent<Camera>().pixelWidth);
        }
    }
Exemple #10
0
    void AddTaggedElements()
    {
        GameObject[] taggedElements = GameObject.FindGameObjectsWithTag(m_parallaxingTagName);
        GameObject[] taggedWrapXElements = null;

        int totalElementSum = taggedElements.Length;
        if(m_wrapXParallaxingTagName != "" && m_wrapXParallaxingTagName != null)
        {
            taggedWrapXElements = GameObject.FindGameObjectsWithTag(m_wrapXParallaxingTagName);
            totalElementSum += taggedWrapXElements.Length;
        }

        if(totalElementSum == 0)
        {
            return;
        }

        List<EZParallaxObjectElement> tempElementArray = new List<EZParallaxObjectElement>(m_parallaxElements);

        for(int i = 0; i < taggedElements.Length; i++)
        {
            if(!tempElementArray.Exists( ( EZParallaxObjectElement elem ) => { return elem.parallaxObject == taggedElements[i].transform; } ))
            {
                tempElementArray.Add(new EZParallaxObjectElement(taggedElements[i].transform));
            }
        }

        EZParallaxObjectElement newElement;

        if(taggedWrapXElements != null)
        {
            for(int i = 0; i < taggedWrapXElements.Length; i++)
            {
                if(!tempElementArray.Exists( ( EZParallaxObjectElement elem ) => { return elem.parallaxObject == taggedWrapXElements[i].transform; } ))
                {
                    newElement = new EZParallaxObjectElement(taggedWrapXElements[i].transform);
                    tempElementArray.Add(newElement);
                    SetElementWrapSettings(newElement, true, 0);
                }
            }
        }

        m_parallaxElements = tempElementArray.ToArray();
    }
Exemple #11
0
    //Use this function to set an element to infinitely wrap with random distances between its duplicates. It autmatically turns on x wrapping on the target object, so there is no need to manually set wrapping on the target before hand.
    public void SetElementRandomSpawn(EZParallaxObjectElement targetElement, float minRange, float maxRange)
    {
        targetElement.spawnsDuplicateOnX = true;
        targetElement.randomSpawnX = true;
        targetElement.initialSpawnDistanceMinX = minRange;
        targetElement.initialSpawnDistanceMaxX = maxRange;

        if(m_initialized)
        {
            SetElementScreenSpaceExtents(targetElement);

            float?[,] tempArray = new float?[m_randomSpawnCtr + 1, m_randomOffsetHistorySize];
            System.Array.Copy(m_rndDistArray, tempArray, m_rndDistArray.Length);
            m_rndDistArray = new float?[m_randomSpawnCtr + 1, m_randomOffsetHistorySize];
            m_rndDistArray = tempArray;

            int[] tempGrpArray = new int[m_randomSpawnCtr + 1];
            System.Array.Copy(m_rndElementGroupSize, tempGrpArray, m_rndElementGroupSize.Length);
            m_rndElementGroupSize = new int[m_randomSpawnCtr + 1];
            m_rndElementGroupSize = tempGrpArray;

            int[] tempIdxArray = new int[m_randomSpawnCtr + 1];
            System.Array.Copy(m_rndDistArrayIndex, tempIdxArray, m_rndDistArrayIndex.Length);
            m_rndDistArrayIndex = new int[m_randomSpawnCtr + 1];
            m_rndDistArrayIndex = tempIdxArray;

            SpawnSingleElementDupes(targetElement, m_mainCamera.GetComponent<Camera>(), m_mainCamera.GetComponent<Camera>().pixelWidth);
        }
    }
Exemple #12
0
 //Use this function to set an object to be motorized after dynamically spawning it. If you wish to make the object wrap, be sure to set it to wrap FIRST, before applying the motorspeed.
 public void SetElementMotorized(EZParallaxObjectElement targetElement, float speed)
 {
     targetElement.isMotorized = true;
     targetElement.initialMotorSpeed = speed;
 }
Exemple #13
0
 //If you remove an object from the parallaxing elements, make sure it's not visible in your camera view or it will break the parallaxing illusion for your player! :)
 //This function will only remove a single object. If you'd like to remove an object and all of its duplicates, use PurgeSingleDupeChain() found below.
 public void RemoveParallaxingElement(Transform targetElement)
 {
     int sourceElementCounter = 0;
     int newElementCounter = 0;
     EZParallaxObjectElement[] tempElementArray = new EZParallaxObjectElement[m_parallaxElements.Length - 1];
     foreach (EZParallaxObjectElement arrayElem in m_parallaxElements)
     {
         if(arrayElem.parallaxObject != targetElement)
         {
             tempElementArray[newElementCounter] = m_parallaxElements[sourceElementCounter];
             newElementCounter++;
         }
         sourceElementCounter++;
     }
     m_parallaxElements = tempElementArray;
 }
Exemple #14
0
    void UpdateElementWorldPosition(EZParallaxObjectElement targetPE, Vector3 camFrameDelta, float elemMovementScalar)
    {
        Transform targetElem = targetPE.parallaxObject;
        if(targetPE.dupeChainObject != null && targetPE.dupeChainObject.hasBeenMoved != true)
        {
            targetElem = targetPE.dupeChainObject.targetGameObject.transform;
            targetPE.dupeChainObject.hasBeenMoved = true;
        }
        else if(targetPE.dupeChainObject != null)
        {
            UpdateTargetScale(targetPE);
            return;
        }

        float modifiedSpeedScalar = elemMovementScalar;
        Vector3 newPosition;
        UpdateTargetScale(targetPE);
        float camXRounded = camFrameDelta.x; //Mathf.Round(camFrameDelta.x * 100000.0f) / 100000.0f;
        float newXPos = (camXRounded - ( camXRounded * modifiedSpeedScalar)) * m_parallaxSpeedScalarX * targetPE.privateParallaxSpeedScalarX;
        newPosition = new Vector3(newXPos, ( camFrameDelta.y - (camFrameDelta.y * modifiedSpeedScalar)) * m_parallaxSpeedScalarY * targetPE.privateParallaxSpeedScalarY, 0);
        targetElem.position += newPosition;
    }
Exemple #15
0
    float GetElementMovementScalar(EZParallaxObjectElement targetPE)
    {
        Transform targetElem = targetPE.parallaxObject;
        float elemToPlayerZ = Mathf.Abs(targetElem.position.z - m_playerObj.transform.position.z);
        float modifiedSpeedScalar;
        if(m_playerObj.transform.position.z > targetElem.position.z)
        {
            //If between the player and the camera
            modifiedSpeedScalar = ( (m_maxDist + elemToPlayerZ) / m_maxDist );
        }
        else
        {
            //if between the player and the farthest bg element, including the furthest bg element
            modifiedSpeedScalar = Mathf.Abs( (m_maxDist - elemToPlayerZ) / m_maxDist);
        }

        return modifiedSpeedScalar;
    }
Exemple #16
0
    public override void OnInspectorGUI()
    {
        EZParallax target = (EZParallax)this.target;

        EditorGUILayout.BeginVertical();

        target.m_parallaxingTagName = EditorGUILayout.TagField(new GUIContent("Auto-Parallax Tag Name", "Choose the tag name you wish to use to automatically assign parallaxing objects to EZP."), target.m_parallaxingTagName);
        target.m_wrapXParallaxingTagName = EditorGUILayout.TagField(new GUIContent("Auto-WrapX-Parallax Tag Name", "Just like the field above, however, THIS tag name will also make the added elements automatically wrap infinitely along the x axis. If you wish to control spawn distance between objects, you'll neeed to actually add the object to the element array below and specify the desired spawn distance."), target.m_wrapXParallaxingTagName);
        target.m_mainCamera = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Camera", "The camera that we will be parallaxing from, most likely your main gameplay camera."), target.m_mainCamera, typeof(GameObject), true);
        target.m_playerObj = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Player", "The player game object."), target.m_playerObj, typeof(GameObject), true);
        target.m_parallaxSpeedScalarX = EditorGUILayout.FloatField(new GUIContent("Parallax Speed Scalar X", "0-1 value used as a multiplier against all x axis movement. Change this value if you want to slow down x movement for all of the parallaxing objects."), target.m_parallaxSpeedScalarX);

        if(target.m_parallaxSpeedScalarX > 1)
        {
            target.m_parallaxSpeedScalarX = 1;
        }

        if(target.m_parallaxSpeedScalarX < 0)
        {
            target.m_parallaxSpeedScalarX = 0;
        }

        target.m_parallaxSpeedScalarY = EditorGUILayout.FloatField(new GUIContent("Parallax Speed Scalar Y", "Same as above, but for the y axis."), target.m_parallaxSpeedScalarY);

        if(target.m_parallaxSpeedScalarY > 1)
        {
            target.m_parallaxSpeedScalarY = 1;
        }

        if(target.m_parallaxSpeedScalarY < 0)
        {
            target.m_parallaxSpeedScalarY = 0;
        }

        target.m_randomOffsetHistorySize = EditorGUILayout.IntField(new GUIContent("Random Offset History Size","The size of the history queue. Make this bigger if you start to notice a recognizable pattern in your randomly spawning objects."), target.m_randomOffsetHistorySize);
        target.m_enableDollyZoom = EditorGUILayout.Toggle(new GUIContent("Enable Dolly Zoom", "Uncheck this box if you do not want to use EZParallax's enhanced zoom effect, which makes changes in orthographic camera sizes create the effect of true camera dollying, instead of just a flat zoom."), target.m_enableDollyZoom);
        target.m_autoInitialize = EditorGUILayout.Toggle(new GUIContent("Auto Initialize", "Uncheck this box if you want to dynamically set values of EZParallax from script before it is actually initialized. If unchecked, be sure to call the initialization function from a script when you're ready to start duplication and parallaxing."), target.m_autoInitialize);

        if(m_parallaxElementViewExpandedByUser == false)
        {
            m_parallaxElementViewExpanded = true;
        }

        m_parallaxElementViewExpanded = EditorGUILayout.Foldout( m_parallaxElementViewExpanded, "ParallaxElements" );

        if(m_parallaxElementViewExpandedByUser == false && m_parallaxElementViewExpanded == false)
        {
            m_parallaxElementViewExpandedByUser = true;
        }

        if ( m_parallaxElementViewExpanded )
        {
            EditorGUI.indentLevel ++;
            int oldNumParallaxElements = (target.m_parallaxElements == null) ? 0 : target.m_parallaxElements.Length;
            int numParallaxElements    = EditorGUILayout.IntField( "Size", oldNumParallaxElements );
            EditorGUI.indentLevel ++;
            if(GUILayout.Button("Add New Parallax Element"))
            {
                numParallaxElements += 1;
            }
            if(GUILayout.Button("Remove Last Parallax Element"))
            {
                numParallaxElements -= 1;
            }
            EditorGUI.indentLevel --;
            if ( numParallaxElements != oldNumParallaxElements )
            {
                EZParallaxObjectElement[] newEZPOElements = new EZParallaxObjectElement[ numParallaxElements ];
                for ( int i = 0; i < oldNumParallaxElements && i < numParallaxElements; ++i )
                {
                    newEZPOElements[i] = target.m_parallaxElements[i];
                }

                for ( int i = oldNumParallaxElements; i < numParallaxElements; ++i )
                {
                    newEZPOElements[i] = new EZParallaxObjectElement(null);
                }

                target.m_parallaxElements = newEZPOElements;
            }

            if ( m_parallaxElementExpanded == null || (target.m_parallaxElements != null && m_parallaxElementExpanded.Length != numParallaxElements ) )
            {
                m_parallaxElementExpanded = new bool[numParallaxElements];
            }

            for ( int i = 0; i < numParallaxElements; ++i )
            {
                EZParallaxObjectElement targetEZParallaxObjectElement = target.m_parallaxElements[i];
                string elementDisplayName = ( targetEZParallaxObjectElement.name != null && targetEZParallaxObjectElement.name.Length != 0) ? targetEZParallaxObjectElement.name : !targetEZParallaxObjectElement.parallaxObject ? "Parallax Element " + i.ToString() : targetEZParallaxObjectElement.parallaxObject.name;
                m_parallaxElementExpanded[i] = EditorGUILayout.Foldout( m_parallaxElementExpanded[i], elementDisplayName);
                if ( m_parallaxElementExpanded[i] )
                {
                    EditorGUI.indentLevel ++;

                    targetEZParallaxObjectElement.name = EditorGUILayout.TextField("Name", targetEZParallaxObjectElement.name);

                    if(targetEZParallaxObjectElement.name != "Parallax Element " + i.ToString())
                    {
                        if(targetEZParallaxObjectElement.parallaxObject)
                        {
                            if(targetEZParallaxObjectElement.name != targetEZParallaxObjectElement.parallaxObject.name && targetEZParallaxObjectElement.name != "")
                            {
                                targetEZParallaxObjectElement.hasCustomName = true;
                            }
                            else
                            {
                                targetEZParallaxObjectElement.hasCustomName = false;
                            }
                        }

                    }
                    targetEZParallaxObjectElement.parallaxObject = (Transform)EditorGUILayout.ObjectField("Parallaxing Object", targetEZParallaxObjectElement.parallaxObject, typeof(Transform), true);
                    if(!targetEZParallaxObjectElement.hasCustomName && targetEZParallaxObjectElement.parallaxObject)
                    {
                        targetEZParallaxObjectElement.name = targetEZParallaxObjectElement.parallaxObject.name;
                    }

                    targetEZParallaxObjectElement.privateParallaxSpeedScalarX = EditorGUILayout.FloatField(new GUIContent("Private Speed Scalar X", "This 0-1 value works as a multiplier to slow down parallax movement for this object only. Use it for fine tuning your parallax speeds along x."), targetEZParallaxObjectElement.privateParallaxSpeedScalarX);

                    if(targetEZParallaxObjectElement.privateParallaxSpeedScalarX > 1)
                    {
                        targetEZParallaxObjectElement.privateParallaxSpeedScalarX = 1;
                    }

                    if(targetEZParallaxObjectElement.privateParallaxSpeedScalarX < 0)
                    {
                        targetEZParallaxObjectElement.privateParallaxSpeedScalarX = 0;
                    }

                    targetEZParallaxObjectElement.privateParallaxSpeedScalarY = EditorGUILayout.FloatField(new GUIContent("Private Speed Scalar Y", "This 0-1 value works as a multiplier to slow down parallax movement for this object only. Use it for fine tuning your parallax speeds along y."), targetEZParallaxObjectElement.privateParallaxSpeedScalarY);

                    if(targetEZParallaxObjectElement.privateParallaxSpeedScalarY > 1)
                    {
                        targetEZParallaxObjectElement.privateParallaxSpeedScalarY = 1;
                    }

                    if(targetEZParallaxObjectElement.privateParallaxSpeedScalarY < 0)
                    {
                        targetEZParallaxObjectElement.privateParallaxSpeedScalarY = 0;
                    }

                    targetEZParallaxObjectElement.isMotorized = EditorGUILayout.Toggle("Is Motorized", targetEZParallaxObjectElement.isMotorized);
                    if(targetEZParallaxObjectElement.isMotorized)
                    {
                        EditorGUI.indentLevel ++;
                        targetEZParallaxObjectElement.initialMotorSpeed = EditorGUILayout.FloatField(new GUIContent("Motor Speed (unit/sec)", "Unity units per second that the object will move at. Negative values will move down negative x, positive values down positive x."), targetEZParallaxObjectElement.motorSpeed);
                        EditorGUI.indentLevel --;
                        GUILayout.Space(5);
                    }

                    targetEZParallaxObjectElement.spawnsDuplicateOnX = EditorGUILayout.Toggle("Spawn Duplicates on X", targetEZParallaxObjectElement.spawnsDuplicateOnX);
                    if(targetEZParallaxObjectElement.spawnsDuplicateOnX)
                    {
                        EditorGUI.indentLevel ++;
                        if(!targetEZParallaxObjectElement.randomSpawnX)
                        {
                            targetEZParallaxObjectElement.initialSpawnDistanceX = EditorGUILayout.FloatField(new GUIContent("Units Between Dupes", "This will be the fixed space between each object. This value will be ignored if randomized distance is enabled."), targetEZParallaxObjectElement.spawnDistanceX);
                        }
                        targetEZParallaxObjectElement.randomSpawnX = EditorGUILayout.Toggle("Randomize Distance", targetEZParallaxObjectElement.randomSpawnX);

                        if(targetEZParallaxObjectElement.randomSpawnX)
                        {
                            EditorGUI.indentLevel ++;
                            targetEZParallaxObjectElement.initialSpawnDistanceMinX = EditorGUILayout.FloatField(new GUIContent("Min Units Between", "The shortest distance between objects spawned from this element."), targetEZParallaxObjectElement.spawnDistanceMinX);
                            targetEZParallaxObjectElement.initialSpawnDistanceMaxX = EditorGUILayout.FloatField(new GUIContent("Max Units Between", "The largest distance between objects spawned from this element."), targetEZParallaxObjectElement.spawnDistanceMaxX);
                            EditorGUI.indentLevel --;
                        }
                        EditorGUI.indentLevel --;
                        GUILayout.Space(5);
                    }

                    EditorGUI.indentLevel --;
                    GUILayout.Space(10);
                }
            }
        }
        EditorGUIUtility.LookLikeControls();
        EditorGUILayout.EndVertical();
    }
    public override void OnInspectorGUI()
    {
        Undo.RecordObject(targetObject, "EZParallaxObject");
        EditorGUILayout.BeginVertical();

        targetObject.m_parallaxingTagName      = EditorGUILayout.TagField(new GUIContent("Auto-Parallax Tag Name", "Choose the tag name you wish to use to automatically assign parallaxing objects to EZP."), targetObject.m_parallaxingTagName);
        targetObject.m_wrapXParallaxingTagName = EditorGUILayout.TagField(new GUIContent("Auto-WrapX-Parallax Tag Name", "Just like the field above, however, THIS tag name will also make the added elements automatically wrap infinitely along the x axis. If you wish to control spawn distance between objects, you'll neeed to actually add the object to the element array below and specify the desired spawn distance."), targetObject.m_wrapXParallaxingTagName);
        targetObject.m_mainCamera           = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Camera", "The camera that we will be parallaxing from, most likely your main gameplay camera."), targetObject.m_mainCamera, typeof(GameObject), true);
        targetObject.m_playerObj            = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Player", "The player game object."), targetObject.m_playerObj, typeof(GameObject), true);
        targetObject.m_parallaxSpeedScalarX = EditorGUILayout.FloatField(new GUIContent("Parallax Speed Scalar X", "0-1 value used as a multiplier against all x axis movement. Change this value if you want to slow down x movement for all of the parallaxing objects."), targetObject.m_parallaxSpeedScalarX);

        if (targetObject.m_parallaxSpeedScalarX > 1)
        {
            targetObject.m_parallaxSpeedScalarX = 1;
        }

        if (targetObject.m_parallaxSpeedScalarX < 0)
        {
            targetObject.m_parallaxSpeedScalarX = 0;
        }

        targetObject.m_parallaxSpeedScalarY = EditorGUILayout.FloatField(new GUIContent("Parallax Speed Scalar Y", "Same as above, but for the y axis."), targetObject.m_parallaxSpeedScalarY);

        if (targetObject.m_parallaxSpeedScalarY > 1)
        {
            targetObject.m_parallaxSpeedScalarY = 1;
        }

        if (targetObject.m_parallaxSpeedScalarY < 0)
        {
            targetObject.m_parallaxSpeedScalarY = 0;
        }

        targetObject.m_randomOffsetHistorySize = EditorGUILayout.IntField(new GUIContent("Random Offset History Size", "The size of the history queue. Make this bigger if you start to notice a recognizable pattern in your randomly spawning objects."), targetObject.m_randomOffsetHistorySize);
        targetObject.m_enableDollyZoom         = EditorGUILayout.Toggle(new GUIContent("Enable Dolly Zoom", "Uncheck this box if you do not want to use EZParallax's enhanced zoom effect, which makes changes in orthographic camera sizes create the effect of true camera dollying, instead of just a flat zoom."), targetObject.m_enableDollyZoom);
        targetObject.m_autoInitialize          = EditorGUILayout.Toggle(new GUIContent("Auto Initialize", "Uncheck this box if you want to dynamically set values of EZParallax from script before it is actually initialized. If unchecked, be sure to call the initialization function from a script when you're ready to start duplication and parallaxing."), targetObject.m_autoInitialize);

        if (m_parallaxElementViewExpandedByUser == false)
        {
            m_parallaxElementViewExpanded = true;
        }

        m_parallaxElementViewExpanded = EditorGUILayout.Foldout(m_parallaxElementViewExpanded, "ParallaxElements");

        if (m_parallaxElementViewExpandedByUser == false && m_parallaxElementViewExpanded == false)
        {
            m_parallaxElementViewExpandedByUser = true;
        }

        if (m_parallaxElementViewExpanded)
        {
            EditorGUI.indentLevel++;
            int oldNumParallaxElements = (targetObject.m_parallaxElements == null) ? 0 : targetObject.m_parallaxElements.Length;
            int numParallaxElements    = EditorGUILayout.IntField("Size", oldNumParallaxElements);
            EditorGUI.indentLevel++;
            if (GUILayout.Button("Add New Parallax Element"))
            {
                numParallaxElements += 1;
            }
            if (GUILayout.Button("Remove Last Parallax Element"))
            {
                numParallaxElements -= 1;
            }
            EditorGUI.indentLevel--;
            if (numParallaxElements != oldNumParallaxElements)
            {
                EZParallaxObjectElement[] newEZPOElements = new EZParallaxObjectElement[numParallaxElements];
                for (int i = 0; i < oldNumParallaxElements && i < numParallaxElements; ++i)
                {
                    newEZPOElements[i] = targetObject.m_parallaxElements[i];
                }

                for (int i = oldNumParallaxElements; i < numParallaxElements; ++i)
                {
                    newEZPOElements[i] = new EZParallaxObjectElement(null);
                }

                targetObject.m_parallaxElements = newEZPOElements;
            }

            if (m_parallaxElementExpanded == null || (targetObject.m_parallaxElements != null && m_parallaxElementExpanded.Length != numParallaxElements))
            {
                m_parallaxElementExpanded = new bool[numParallaxElements];
            }

            for (int i = 0; i < numParallaxElements; ++i)
            {
                EZParallaxObjectElement targetEZParallaxObjectElement = targetObject.m_parallaxElements[i];
                string elementDisplayName = (targetEZParallaxObjectElement.name != null && targetEZParallaxObjectElement.name.Length != 0) ? targetEZParallaxObjectElement.name : !targetEZParallaxObjectElement.parallaxObject ? "Parallax Element " + i.ToString() : targetEZParallaxObjectElement.parallaxObject.name;
                m_parallaxElementExpanded[i] = EditorGUILayout.Foldout(m_parallaxElementExpanded[i], elementDisplayName);
                if (m_parallaxElementExpanded[i])
                {
                    EditorGUI.indentLevel++;

                    targetEZParallaxObjectElement.name = EditorGUILayout.TextField("Name", targetEZParallaxObjectElement.name);

                    if (targetEZParallaxObjectElement.name != "Parallax Element " + i.ToString())
                    {
                        if (targetEZParallaxObjectElement.parallaxObject)
                        {
                            if (targetEZParallaxObjectElement.name != targetEZParallaxObjectElement.parallaxObject.name && targetEZParallaxObjectElement.name != "")
                            {
                                targetEZParallaxObjectElement.hasCustomName = true;
                            }
                            else
                            {
                                targetEZParallaxObjectElement.hasCustomName = false;
                            }
                        }
                    }
                    targetEZParallaxObjectElement.parallaxObject = (Transform)EditorGUILayout.ObjectField("Parallaxing Object", targetEZParallaxObjectElement.parallaxObject, typeof(Transform), true);
                    if (!targetEZParallaxObjectElement.hasCustomName && targetEZParallaxObjectElement.parallaxObject)
                    {
                        targetEZParallaxObjectElement.name = targetEZParallaxObjectElement.parallaxObject.name;
                    }

                    targetEZParallaxObjectElement.privateParallaxSpeedScalarX = EditorGUILayout.FloatField(new GUIContent("Private Speed Scalar X", "This 0-1 value works as a multiplier to slow down parallax movement for this object only. Use it for fine tuning your parallax speeds along x."), targetEZParallaxObjectElement.privateParallaxSpeedScalarX);

                    if (targetEZParallaxObjectElement.privateParallaxSpeedScalarX > 1)
                    {
                        targetEZParallaxObjectElement.privateParallaxSpeedScalarX = 1;
                    }

                    if (targetEZParallaxObjectElement.privateParallaxSpeedScalarX < 0)
                    {
                        targetEZParallaxObjectElement.privateParallaxSpeedScalarX = 0;
                    }

                    targetEZParallaxObjectElement.privateParallaxSpeedScalarY = EditorGUILayout.FloatField(new GUIContent("Private Speed Scalar Y", "This 0-1 value works as a multiplier to slow down parallax movement for this object only. Use it for fine tuning your parallax speeds along y."), targetEZParallaxObjectElement.privateParallaxSpeedScalarY);

                    if (targetEZParallaxObjectElement.privateParallaxSpeedScalarY > 1)
                    {
                        targetEZParallaxObjectElement.privateParallaxSpeedScalarY = 1;
                    }

                    if (targetEZParallaxObjectElement.privateParallaxSpeedScalarY < 0)
                    {
                        targetEZParallaxObjectElement.privateParallaxSpeedScalarY = 0;
                    }

                    targetEZParallaxObjectElement.isMotorized = EditorGUILayout.Toggle("Is Motorized", targetEZParallaxObjectElement.isMotorized);
                    if (targetEZParallaxObjectElement.isMotorized)
                    {
                        EditorGUI.indentLevel++;
                        targetEZParallaxObjectElement.initialMotorSpeed = EditorGUILayout.FloatField(new GUIContent("Motor Speed (unit/sec)", "Unity units per second that the object will move at. Negative values will move down negative x, positive values down positive x."), targetEZParallaxObjectElement.motorSpeed);
                        EditorGUI.indentLevel--;
                        GUILayout.Space(5);
                    }


                    targetEZParallaxObjectElement.spawnsDuplicateOnX = EditorGUILayout.Toggle("Spawn Duplicates on X", targetEZParallaxObjectElement.spawnsDuplicateOnX);
                    if (targetEZParallaxObjectElement.spawnsDuplicateOnX)
                    {
                        EditorGUI.indentLevel++;
                        if (!targetEZParallaxObjectElement.randomSpawnX)
                        {
                            targetEZParallaxObjectElement.initialSpawnDistanceX = EditorGUILayout.FloatField(new GUIContent("Units Between Dupes", "This will be the fixed space between each object. This value will be ignored if randomized distance is enabled."), targetEZParallaxObjectElement.spawnDistanceX);
                        }
                        targetEZParallaxObjectElement.randomSpawnX = EditorGUILayout.Toggle("Randomize Distance", targetEZParallaxObjectElement.randomSpawnX);

                        if (targetEZParallaxObjectElement.randomSpawnX)
                        {
                            EditorGUI.indentLevel++;
                            targetEZParallaxObjectElement.initialSpawnDistanceMinX = EditorGUILayout.FloatField(new GUIContent("Min Units Between", "The shortest distance between objects spawned from this element."), targetEZParallaxObjectElement.spawnDistanceMinX);
                            targetEZParallaxObjectElement.initialSpawnDistanceMaxX = EditorGUILayout.FloatField(new GUIContent("Max Units Between", "The largest distance between objects spawned from this element."), targetEZParallaxObjectElement.spawnDistanceMaxX);
                            GUILayout.Space(3);
                            targetEZParallaxObjectElement.useRandomYSpawnAltOffset = EditorGUILayout.Toggle("Use Randomized Y Offset", targetEZParallaxObjectElement.useRandomYSpawnAltOffset);
                            if (targetEZParallaxObjectElement.useRandomYSpawnAltOffset)
                            {
                                EditorGUI.indentLevel++;
                                targetEZParallaxObjectElement.randomYSpawnLowestAltOffset  = EditorGUILayout.FloatField(new GUIContent("Lowest Offset", "The offset in Unity units that will result in the lowest possible y value for the randomly spawned object. Can be negative."), targetEZParallaxObjectElement.randomYSpawnLowestAltOffset);
                                targetEZParallaxObjectElement.randomYSpawnHighestAltOffset = EditorGUILayout.FloatField(new GUIContent("Highest Offset", "The offset in Unity units that will result in the highest possible y value for the randomly spawned object. Can be negative, if still a higher number than your lowest offset, above."), targetEZParallaxObjectElement.randomYSpawnHighestAltOffset);
                                EditorGUI.indentLevel--;
                            }
                            EditorGUI.indentLevel--;
                        }
                        EditorGUI.indentLevel--;
                        GUILayout.Space(5);
                    }

                    EditorGUI.indentLevel--;
                    GUILayout.Space(10);
                }
            }
        }
        EditorGUIUtility.LookLikeControls();
        EditorGUILayout.EndVertical();

        if (GUI.changed)
        {
            EditorUtility.SetDirty(target);
            EditorApplication.MarkSceneDirty();
        }
    }