Пример #1
0
    void OnTriggerEnter(Collider other)
    {
//		Debug.Log("WARP");

        WarpObject WO = other.gameObject.GetComponent <WarpObject>();

        if (WO.justWarped)
        {
            return;
        }

        other.gameObject.transform.position = otherGate.transform.position;
    }
Пример #2
0
    void OnTriggerExit(Collider other)
    {
//		Debug.Log("WARP");

        WarpObject WO = other.gameObject.GetComponent <WarpObject>();

        if (WO.justWarped)
        {
            WO.justWarped = false;
        }
        else
        {
            WO.justWarped = true;
        }
//			other.gameObject.transform.position = otherGate.transform.position;
    }
Пример #3
0
    private void CustomObject(GameObject obj, int objectId, int customId, Vector3Int pos, List <MapObject> mapObjects)
    {
        switch (objectId)
        {
        case (int)Utility.ObjectId.House:
            MapObject mapObject = new MapObject(obj, objectId, pos);
            mapObjects.Add(mapObject);
            AngleCustom(obj, customId);
            break;

        case (int)Utility.ObjectId.Warp:
            WarpObject warpObject = new WarpObject(obj, objectId, pos, customId);
            mapObjects.Add(warpObject);

            obj.GetComponent <Warp>().number = customId;
            break;
        }
    }
Пример #4
0
    void LateUpdate()
    {
        // If the space scene camera is not set for some reason (maybe recreated?)...
        if (_spaceCamera == null)
        {
            // Find the space scene camera and return
            _spaceCamera = FindObjectOfType <SU_SpaceSceneCamera>();
            return;
        }

        // Calculate the delta position of the object that's warping
        Vector3 _deltaPosition = transform.position - _previousPosition;

        _previousPosition = transform.position;

        if (WarpSpeedMultiplier > maxSpeed + _ultraSpeedAddon)
        {
            WarpSpeedMultiplier = maxSpeed + _ultraSpeedAddon;
        }

        // WARP BEGIN
        // If Warp is set to enabled from external script and WarpState is set to NONE - start initiating the warp
        if (Warp && warpState == WarpState.NONE)
        {
            // Clear the dictionary containing all objects that are affected by the warp
            _warpObjects.Clear();

            // Build a dictionary of objects that are affected by the warp (those objects will need to be moved to simulate warping away from them)
            foreach (GameObject _g in FindObjectsOfType <GameObject>())
            {
                // Exclude objects from being offset by the warp
                bool _exclude = false;

                // Exclude cameras if set in the inspector (excluded by default)
                if (excludeCameras && _g.GetComponent <Camera>() != null)
                {
                    _exclude = true;
                }

                // Exclude lights if set in the inspector (excluded by default)
                if (excludeLights && _g.GetComponent <Light>() != null)
                {
                    _exclude = true;
                }

                // Exclude objects in the deep space layer (we don't want simulate moving away from large objects like stars and planets) (excluded by default)
                if (!_exclude && excludeDeepSpaceLayer && _g.layer == 20)
                {
                    _exclude = true;
                }

                // Exclude space particles (excluded by default)
                if (!_exclude && _g.GetComponent <SU_SpaceParticles>() != null)
                {
                    _exclude = true;
                }

                // Exclude specific layers as configured in the array of layers in the inspector
                if (!_exclude && excludedLayers.Length > 0)
                {
                    foreach (int _i in excludedLayers)
                    {
                        if (_g.layer == _i)
                        {
                            _exclude = true;
                        }
                    }
                }

                // Exclude specific tags as configured in the array of tags in the inspector
                if (!_exclude && excludedTags.Length > 0)
                {
                    foreach (string _s in excludedTags)
                    {
                        if (_g.tag == _s)
                        {
                            _exclude = true;
                        }
                    }
                }

                // Exclude specific gameobjects as configured in the array of objects in the inspector
                if (!_exclude && excludedGameObjects.Length > 0)
                {
                    foreach (GameObject _xg in excludedGameObjects)
                    {
                        if (_g == _xg)
                        {
                            _exclude = true;
                        }
                    }
                }

                // Exclude self (this object) and any children of this gameobject
                if (!_exclude && excludeSelf)
                {
                    foreach (Transform _t in transform.GetComponentsInChildren <Transform>())
                    {
                        if (_g == _t.gameObject)
                        {
                            _exclude = true;
                        }
                    }
                }

                // If the game object has not been excluded, add it to the dictionary so it can be moved during the warp phase to simulate warping away from it
                // Unity only supports float values for vector3 so we can't make a huge universe in a scene. This is why we need to identify gameobjects that we want
                // to appear to be rapidly moving away from them and move them manually.
                if (!_exclude && _g.transform != null)
                {
                    // Create a new warp object
                    WarpObject _wo = new WarpObject();
                    // Remember the gameobject and transform for increased perofmance when translating the objects
                    _wo.gameObject = _g;
                    _wo.transform  = _g.transform;
                    // Remember the original position of the gameobject
                    _wo.position = _g.transform.position;
                    // If the object has a collider...
                    if (_g.GetComponent <Collider>() != null)
                    {
                        // Inspect whether the collider is enabled or not (so we can return it to the same state later)
                        _wo.colliderEnabled = _g.GetComponent <Collider>().enabled;
                        // Disable the collider, we don't want to bump into this object during warp - it'll abruptly halt the warp. Better to just warp through it.
                        _g.GetComponent <Collider>().enabled = false;
                    }
                    // Add the warp object to a the dictionary
                    _warpObjects.Add(_g, _wo);
                }
            }

            // Find all instances of SU_SpaceParticles component (both particles and fog uses this)
            _spaceParticles = FindObjectsOfType <SU_SpaceParticles>();

            // Set the previous position for delta movement detection to current position
            _previousPosition = transform.position;

            // Enable the warp renderer
            EnableRenderer();

            // Set state to ACCELERATE
            warpState = WarpState.ACCELERATE;
        }

        // ACCELERATE
        if (warpState == WarpState.ACCELERATE)
        {
            // While we have not achieved max speed with the warp speed multiplier...
            if (WarpSpeedMultiplier < maxSpeed + _ultraSpeedAddon)
            {
                // Increase the warp speed multiplier by acceleration
                WarpSpeedMultiplier += acceleration * Time.deltaTime;
            }
            else
            {
                warpState = WarpState.WARP;
            }

            // If no longer warping (Warp is set to false from external script) switch to DECELERATE state
            if (!Warp)
            {
                warpState = WarpState.DECELERATE;
            }
        }

        // WARPING
        if (warpState == WarpState.WARP)
        {
            // Loop through warp objects and hide any object that is beyond warp hide distance
            foreach (KeyValuePair <GameObject, WarpObject> _g in _warpObjects)
            {
                if (_g.Key != null)
                {
                    if (_g.Key.activeSelf)
                    {
                        if (Vector3.Distance(_g.Key.transform.position, transform.position) > warpSpeedHideDistance)
                        {
                            _g.Key.SetActive(false);
                        }
                    }
                }
            }

            // If no longer warping (Warp is set to false from external script) switch to DECELERATE state
            if (!Warp)
            {
                warpState = WarpState.DECELERATE;
            }

            if (WarpSpeedMultiplier < maxSpeed + _ultraSpeedAddon)
            {
                warpState = WarpState.ACCELERATE;
            }
        }

        // DECELERATION
        if (warpState == WarpState.DECELERATE)
        {
            // If warping...
            if (WarpSpeedMultiplier > 0.0001f)
            {
                // Decreas the speed
                WarpSpeedMultiplier -= acceleration * Time.deltaTime;
                // Set all objects that were disabled (that you warped away from) to active again
                foreach (KeyValuePair <GameObject, WarpObject> _g in _warpObjects)
                {
                    if (_g.Key != null)
                    {
                        if (!_g.Key.activeSelf)
                        {
                            _g.Key.SetActive(true);
                        }
                    }
                }
            }
            else
            {
                // If not warping, make sure speed is 0
                WarpSpeedMultiplier = 0f;
                // Disable the warp renderer
                DisableRenderer();
                // Iterate though all warp objects that were translated/moved away from you during warp
                foreach (KeyValuePair <GameObject, WarpObject> _g in _warpObjects)
                {
                    // If gameobject still exists...
                    if (_g.Key != null)
                    {
                        // And it has a collider
                        if (_g.Key.GetComponent <Collider>() != null)
                        {
                            // Re-enable the collider
                            _g.Value.colliderEnabled = _g.Key.GetComponent <Collider>().enabled;
                            _g.Key.GetComponent <Collider>().enabled = true;
                        }
                    }
                }
                // Set warpstate to none
                warpState = WarpState.NONE;
            }
        }

        // If warp state is not none...
        if (warpState != WarpState.NONE)
        {
            if (audioSourceWarp != null)
            {
                // Set the volume of the warp sound effect relative to the warp speed
                audioSourceWarp.volume = Mathf.Clamp01(WarpSpeedMultiplier / maxSpeed);
                // Set the pitch of the warp sound effect relative to the warp speed
                audioSourceWarp.pitch = 0.5f + (WarpSpeedMultiplier / maxSpeed);
            }
            // If you are warping moving...
            if (_deltaPosition.magnitude > 0.1f)
            {
                // Iterate though all warp objects and move them relatively away from you(!) you are not actually flying fast in the scene, we are simulating it by moving other objects away from you
                foreach (KeyValuePair <GameObject, WarpObject> _g in _warpObjects)
                {
                    if (_g.Key != null)
                    {
                        _g.Key.transform.Translate(-_deltaPosition.normalized * WarpSpeedMultiplier * Time.deltaTime * surroundingObjectMultiplier, Space.World);
                    }
                }
                // Offset all space particles so they respawn appropriately when you stop warping as they are then out of distance
                foreach (SU_SpaceParticles _s in _spaceParticles)
                {
                    _s.WarpParticles = -_deltaPosition * WarpSpeedMultiplier * Time.deltaTime * surroundingObjectMultiplier;
                }
                // Set the strength of the warp shader effect
                SetStrength(Mathf.Clamp01((((WarpSpeedMultiplier / maxSpeed) * WarpSpeedMultiplier * visualWarpEffectMagnitude))));
                // Move relatively within the space scene - this is what actually moves the SU_SpaceCamera camera component to achieve movement within the space scene
                _spaceCamera.Move(_deltaPosition.normalized * WarpSpeedMultiplier * 0.01f);
            }
            else
            {
                // Not warping, make sure warp shader effect strength is 0
                SetStrength(0f);
            }

            // If the gameobject has a rigidbody...
            if (_rigidbody != null)
            {
                // Calculate the *local* angular velocity of the object
                Vector3 localangularvelocity = transform.InverseTransformDirection(_rigidbody.angularVelocity).normalized *_rigidbody.angularVelocity.magnitude;
                // Send the angular vector to the shader so the warp distortion tube mesh can be bent by the vertex shader
                _material.SetVector(_shaderIDWarpBend, localangularvelocity);
            }
            // Expand/shrink the tube in the vertex shader based distance between the main camera and the object that's warping (so the camera doesn't move out of the tube)
            _material.SetFloat(_shaderIDWarpRadiusMultiplier, (Vector3.Distance(Camera.main.transform.position, transform.position) / 500f) * 2.1f);
        }
        else
        {
            // If we are not warping... set the speed of the warp particles to 0
            if (_spaceParticles != null)
            {
                foreach (SU_SpaceParticles _s in _spaceParticles)
                {
                    _s.WarpParticles = Vector3.zero;
                }
            }
        }
    }