Ejemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        //FORCEFIELDS
        if (other.CompareTag("Deactivator"))
        {
            AudioSource.PlayClipAtPoint(gotItem, transform.position);
            Deactivator deact = other.GetComponent<Deactivator>();
            Forcefield field = deact.GetForcefield();
            field.Deactivate();
            deact.Remove();
        }

        //FINAL DOOR
        //Pick up final keycard
        if (other.CompareTag("Keycard"))
        {
            if(keycard == null)
            {
                keycard = other.gameObject;
                AudioSource.PlayClipAtPoint(gotKeycard, transform.position);

                keycard.transform.SetParent(transform);
                keycard.transform.position = transform.position + Vector3.right * 0.5f + Vector3.up * 1.5f;
            }
        }
    }
Ejemplo n.º 2
0
    void OnMouse()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (BallPrefab != null)
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                GameObject prefab = (GameObject)GameObject.Instantiate(BallPrefab, transform.position + transform.forward, Quaternion.identity);
                prefab.GetComponent <Rigidbody>().AddForce(ray.direction * 55f, ForceMode.VelocityChange);
                prefab.GetComponent <Rigidbody>().AddTorque(new Vector3(Random.Range(-20f, 20f), Random.Range(-20f, 20f), Random.Range(-20f, 20f)));
            }
        }

        if (Input.GetMouseButton(1) && curTime >= FireRate)
        {
            curTime = 0.0f;

            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, 500.0f))
            {
                Forcefield ffHit = hit.transform.gameObject.GetComponent <Forcefield>();
                if (ffHit != null)
                {
                    ffHit.OnHit(hit.point, hitPower);

                    if (ParticlePrefab != null)
                    {
                        GameObject.Instantiate(ParticlePrefab, hit.point, Quaternion.identity);
                    }

                    if (ShieldHitSFX.Length > 0)
                    {
                        int index = Random.Range(0, ShieldHitSFX.Length);

                        for (int i = 0; i < 10; i++)
                        {
                            if (!ShieldHitSFX[index].isPlaying)
                            {
                                break;
                            }
                            else
                            {
                                index = Random.Range(0, ShieldHitSFX.Length);
                            }
                        }

                        ShieldHitSFX[index].transform.position = hit.point;
                        ShieldHitSFX[index].Play();
                    }
                }
            }
        }
    }
Ejemplo n.º 3
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject == target && !finished)
        {
            Impact();
        }
        Forcefield field = other.GetComponent <Forcefield>();

        if (field != null)
        {
            Debug.Log("Hit field");
            field.OnHit(transform.position, -2, 1);
        }
    }
    void OnStand()
    {
        if (player == null)
        {
            return;
        }

        Vector3 pos = transform.position + Vector3.Normalize(player.transform.position - transform.position) * spawnOffset;

        currentForcefield = Instantiate(forcefieldPrefab, pos, Quaternion.identity);
        currentForcefield.transform.LookAt(new Vector3(player.transform.position.x, currentForcefield.transform.position.y, player.transform.position.z));

        forcefieldDirection = currentForcefield.transform.forward;

        if (genertatorEffect != null)
        {
            genertatorEffect.Play();
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        // Activate on Left mouse button
        if (Input.GetMouseButtonDown(0))
        {
            // Returns a ray going from camera through a screen point
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            // Casts a ray against colliders in the scene
            if (Physics.Raycast(ray, out hit, 500.0f))
            {
                // Get Forcefield script component
                Forcefield ffHit = hit.transform.gameObject.GetComponent <Forcefield>();

                // Generate random hit power value and call Force Field script if successful
                if (ffHit != null)
                {
                    float hitPower = Random.Range(-7.0f, 1.0f);
                    ffHit.OnHit(hit.point, hitPower);
                }
            }
        }
    }
Ejemplo n.º 6
0
    //This is called after a level is loaded.  Create the GameManager if this is the first level loaded.
    //This function should do nothing else.
    public void Awake()
    {
#if !OVERLOAD_LEVEL_EDITOR
        // Defer the Awake until after user level loading is complete
        if (UserLevelLoader.IsLoadingUserLevel)
        {
            UserLevelLoader.ExecuteAfterLoading(() => { Awake(); });
            return;
        }

        Debug.Log("LevelData Awake " + Time.realtimeSinceStartup);

        //If Game Manager doesn't exist (this is the first level to be loaded), create it
        if (Object.Equals(GameManager.m_gm, null))                      //When the game is shutting down in the editor it apparently re-loads the editor level after closing down the GameManager causing this to be called when m_gm is fake-null.   So check for real null.
        {
            GameManager.Required(m_game_manager_prefab != null, "Game manager prefab not specified");
            Instantiate(m_game_manager_prefab, Vector3.zero, Quaternion.identity);
        }

        //Check for geometry data
        GameManager.Required(m_geometry != null, "Geometry data not specified");

        //Save the global for the level initializer object
        GameManager.m_level_data = this;

        // Add local player immediately. Remote clients will only add players once scene is loaded both on server and locally.
        if (NetworkManager.IsServer())
        {
            Client.AddPlayer();
        }
        else
        {
            GameManager.m_player_ship  = PlayerShip.Instantiate();
            GameManager.m_local_player = GameManager.m_player_ship.c_player;
        }

        GameObject legacy_player_start = GameObject.FindGameObjectWithTag("LegacyPlayerStart");
        if (!GameplayManager.IsMultiplayer)
        {
            GameManager.m_player_ship.SetSpawnPosAndRotation(legacy_player_start);
        }
        if (legacy_player_start != null)
        {
            legacy_player_start.SetActive(false);              // start has a camera we want to disable
        }

        //Get the viewer component
        GameManager.m_viewer = Camera.main.GetComponent <Viewer>();
        GameManager.Required(GameManager.m_viewer != null, "Must have Viewer component on camera");

        //Get the mesh containers
        GameManager.m_mesh_container = GameObject.Find("_container_level_meshes");

        //
        // Do some processing on this object's data.  Don't do anything else here.
        //

        //Fix up the door references
        if (m_portal_to_door_references != null)
        {
            foreach (var portal_door_ref in m_portal_to_door_references)
            {
                int portal_index = portal_door_ref.PortalIndex;
                if (portal_index >= 0 && portal_index < m_geometry.Portals.Length)
                {
                    m_geometry.Portals[portal_index].DoorData = portal_door_ref.ReferenceDoor;
                }
                else
                {
                    Debug.LogError(string.Format("Portal Index {0} is out of range for door {1}", portal_index, portal_door_ref.ReferenceDoor.name));
                }
            }
        }

        //Create empty level light and reflection probe arrays if they're not present
        if (m_level_lights == null)
        {
            m_level_lights = new SegmentLightInfo[0];
        }

        if (m_level_reflection_probes == null || m_level_reflection_probes.Length == 0)
        {
            List <SegmentReflectionProbeInfo> srpi_list = new List <SegmentReflectionProbeInfo>();
            // Gather the reflection probes the hard way (slowly)
            GameObject userContainerObject = GameObject.Find("!rprobes");
            if (userContainerObject != null && userContainerObject.transform.parent == null)
            {
                // Gather all the reflection probes under "!probes"
                ReflectionProbe[] rps = userContainerObject.GetComponentsInChildren <ReflectionProbe>();
                int count             = rps.Length;
                for (int i = 0; i < count; i++)
                {
                    SegmentReflectionProbeInfo srpi = new SegmentReflectionProbeInfo();
                    srpi.ProbeObject  = rps[i].gameObject;
                    srpi.SegmentIndex = FindSegmentContainingWorldPosition(rps[i].transform.position);
                    if (srpi.SegmentIndex < 0)
                    {
                        srpi.SegmentIndex = ChunkManager.FindNearestSegment(rps[i].transform.position);
                    }
                    srpi.ProbeType = SegmentReflectionProbeType.UserPlaced;

                    srpi_list.Add(srpi);
                }
            }

            m_level_reflection_probes = srpi_list.ToArray();

            if (m_level_reflection_probes == null)
            {
                m_level_reflection_probes = new SegmentReflectionProbeInfo[0];
            }
        }


        NumSegments = m_geometry.Segments.Length;

        // Associate lights to segments
        {
            Dictionary <int, List <SegmentLightInfo> > mapLightsToSegment = new Dictionary <int, List <SegmentLightInfo> >();

            foreach (var llight in m_level_lights)
            {
                if (llight.SegmentIndex < 0 || llight.SegmentIndex >= NumSegments)
                {
                    Debug.LogErrorFormat("Level light at invalid segment index {0}", llight.SegmentIndex);
                    continue;
                }

                List <SegmentLightInfo> list;
                if (!mapLightsToSegment.TryGetValue(llight.SegmentIndex, out list))
                {
                    list = new List <SegmentLightInfo>();
                    mapLightsToSegment.Add(llight.SegmentIndex, list);
                }

                if (llight.LightObject != null && llight.LightComp != null)
                {
                    list.Add(llight);
                }
            }

            foreach (var kvp in mapLightsToSegment)
            {
                m_geometry.Segments[kvp.Key].Lights = kvp.Value.ToArray();
            }

            // Provide an empty list for the other segments
            SegmentLightInfo[] dummyList = new SegmentLightInfo[0];
            for (int segIndex = 0; segIndex < NumSegments; ++segIndex)
            {
                if (mapLightsToSegment.ContainsKey(segIndex))
                {
                    continue;
                }
                m_geometry.Segments[segIndex].Lights = dummyList;
            }
        }

        // Associate reflection probes to segments
        {
            Dictionary <int, List <SegmentReflectionProbeInfo> > mapProbesToSegment = new Dictionary <int, List <SegmentReflectionProbeInfo> >();

            foreach (var lprobe in m_level_reflection_probes)
            {
                if (lprobe.SegmentIndex < 0 || lprobe.SegmentIndex >= NumSegments)
                {
                    Debug.LogErrorFormat("Level reflection probe at invalid segment index {0}", lprobe.SegmentIndex);
                    continue;
                }

                List <SegmentReflectionProbeInfo> list;
                if (!mapProbesToSegment.TryGetValue(lprobe.SegmentIndex, out list))
                {
                    list = new List <SegmentReflectionProbeInfo>();
                    mapProbesToSegment.Add(lprobe.SegmentIndex, list);
                }

                if (lprobe.ProbeObject != null)
                {
                    list.Add(lprobe);
                }
            }

            foreach (var kvp in mapProbesToSegment)
            {
                m_geometry.Segments[kvp.Key].ReflectionProbes = kvp.Value.ToArray();
            }

            // Provide an empty list for the other segments
            SegmentReflectionProbeInfo[] dummyList = new SegmentReflectionProbeInfo[0];
            for (int segIndex = 0; segIndex < NumSegments; ++segIndex)
            {
                if (mapProbesToSegment.ContainsKey(segIndex))
                {
                    continue;
                }
                m_geometry.Segments[segIndex].ReflectionProbes = dummyList;
            }
        }

        //Find connecting portals for chunk portals
        foreach (ChunkPortal chunk_portal in m_geometry.ChunkPortals)
        {
            if (chunk_portal.ConnectedPortal == -1)
            {
                PortalData seg_portal       = m_geometry.Portals[m_geometry.Segments[chunk_portal.Segnum].Portals[chunk_portal.Sidenum]];
                int        connected_segnum = (seg_portal.MasterSegmentIndex == chunk_portal.Segnum) ? seg_portal.SlaveSegmentIndex : seg_portal.MasterSegmentIndex;
                foreach (int connected_chunk_portal_index in m_geometry.Chunks[chunk_portal.ConnectedChunk].PortalIndices)
                {
                    ChunkPortal connected_chunk_portal = m_geometry.ChunkPortals[connected_chunk_portal_index];
                    if (connected_chunk_portal.Segnum == connected_segnum)
                    {
                        chunk_portal.ConnectedPortal           = connected_chunk_portal.Num;
                        connected_chunk_portal.ConnectedPortal = chunk_portal.Num;
                    }
                }
                Assert.True(chunk_portal.ConnectedPortal != -1);
            }
        }

        //Make list of Chunks
        CreateChunkList();

        //Set up object to access segment visibility
        if (m_geometry.SegmentToSegmentVisibility == null)
        {
            var stopWatch = new System.Diagnostics.Stopwatch();
            stopWatch.Start();
            Segment2SegmentVis.ComputeSegmentVisibility(m_geometry, 55.0f);
            stopWatch.Stop();
            UnityEngine.Debug.LogFormat("ComputeSegmentVisibility took {0} ms", stopWatch.ElapsedMilliseconds);
        }
        if (m_geometry.SegmentToSegmentVisibility != null)
        {
            m_segment_visibility = new IndexAs2D(m_geometry.SegmentToSegmentVisibility, NumSegments);
        }
        else
        {
            m_segment_visibility = null;
        }

        //Make a list of ambient sound sources in the level.  Might make sense to keep that list here, but the gather function is a little audio-specific
        if (GameManager.m_audio != null)                        //Don't do this on game startup
        {
            GameManager.m_audio.GatherAmbientSounds();
        }

        //Find the reactor, if one exists
        Reactor[] reactors = FindObjectsOfType <Reactor>();
        if (reactors.Length == 0)
        {
            //Debug.Log("There is no reactor in this level!");
            Reactor = null;
        }
        else
        {
            if (reactors.Length > 1)
            {
                Debug.Log("There are " + reactors.Length + " reactors in this level!  There should be no more than one!  Will only use the first one found");
            }
            Reactor = reactors[0];
        }

        // Find the alien warper if one exists.
        GameObject alien_warp = GameObject.FindGameObjectWithTag("AlienWarp");
        if (alien_warp != null)
        {
            m_alien_warp_segment = GameManager.m_level_data.FindSegmentContainingWorldPosition(alien_warp.transform.position);
            Debug.Log("Alien warper is in segment " + m_alien_warp_segment);
        }
        else
        {
            m_alien_warp_segment = -1;                          // It's OK if there is no alien warper, most levels don't have one!
        }

        //Reset LevelCustomInfo statics in case the level doesn't have a LevelCustomInfo component
        LevelCustomInfo.Reset();

        //Find segments for spawn points
        SetSpawnPointSegments(m_robot_spawn_points);
        SetSpawnPointSegments(m_item_spawn_points);
        SetSpawnPointSegments(m_player_spawn_points);
        SetSpawnPointSegments(m_mp_camera_points);

        TriggerWindTunnel.UpdateSegmentsForWindTunnels();             // Deal with Wind Tunnels (WindTunnels)
        Forcefield.UpdateSegmentsForForcefields();                    // Deal with Forcefields

        // Deal with teleporters.
        for (int i = 0; i < GameManager.m_level_data.Segments.Length; i++)
        {
            GameManager.m_level_data.Segments[i].WarpDestinationSegs = new int[6];
            for (int j = 0; j < 6; j++)
            {
                GameManager.m_level_data.Segments[i].WarpDestinationSegs[j] = -1;
            }
        }

        //Find & initialize cryotubes
        InitCryotubes();

        // Explode the hierarchy (for optimization reasons)
        if (CrushHierarchy)
        {
            GameManager.m_mesh_container.transform.DetachChildren();

            GameObject container = GameObject.Find("_container_level_lava_meshes");
            container.transform.DetachChildren();

            //container = GameObject.Find("_container_placed_entities");
            //int count = container.transform.childCount;
            //for (int i = count - 1; i >= 0; i--) {
            //	container.transform.GetChild(i).DetachChildren();
            //}
            LevelCustomInfo.TryToCrush();
        }

        Debug.Log("LevelData Awake DONE " + Time.realtimeSinceStartup);
#endif // !OVERLOAD_LEVEL_EDITOR
    }
Ejemplo n.º 7
0
    protected override void OnUpdate()
    {
        while (m_Group.Length != 0)
        {
            var pointObject  = m_Group.PointObject[0];
            var sourceEntity = m_Group.Entity[0];
            var center       = m_Group.Position[0].Value;
            var count        = (pointObject.gridSizeX + 1) * (pointObject.gridSizeY + 1);

            var entities = new NativeArray <Entity>(count, Allocator.Temp);
            //EntityManager.Instantiate(pointObject.prefab, entities);


            var positions = new NativeArray <float3>(count, Allocator.Temp);

            float ox = pointObject.gridSizeX * pointObject.gridGap;
            float oy = pointObject.gridSizeY * pointObject.gridGap;
            //bound of the forcefield
            float4 v = new float4(-ox * 0.5f, -oy * 0.5f, Camera.main.aspect * Camera.main.orthographicSize * 2, Camera.main.orthographicSize * 2);

            float forceMass = pointObject.forceMass;

            //Debug.Log(v);
            //float4 v = new float4(-200, -100, 480, 270);
            //forcefield properties
            Forcefield f = new Forcefield {
                Mass = forceMass, bound = v, frictionCoe = 0.15f
            };

            for (int i = 0, y = 0; y <= pointObject.gridSizeY * pointObject.gridGap; y += pointObject.gridGap)
            {
                for (int x = 0; x <= pointObject.gridSizeX * pointObject.gridGap; x += pointObject.gridGap, i++)
                {
                    //var z = UnityEngine.Random.Range(-0.5f, 0.5f);
                    positions[i]  = new Vector3(x, y);
                    cubeArchetype = EntityManager.CreateArchetype(
                        typeof(Position),
                        typeof(Boid),
                        typeof(Rotation),
                        typeof(Scale),
                        typeof(MeshInstanceRenderer),
                        typeof(Forcefield));
                    Position initialPosition = new Position {
                        Value = positions[i]
                    };
                    Scale scale = new Scale {
                        Value = new Vector3(7, 7, 7)
                    };
                    Boid b = new Boid
                    {
                        position        = initialPosition.Value,
                        initialPosition = initialPosition.Value,
                        radius          = 1f,
                        mass            = pointObject.boidMass,
                        maxLength       = 10,
                        velocity        = Vector3.zero,
                        acceration      = Vector3.zero,
                        timer           = 0,
                        freeTime        = pointObject.freeTime,
                        isDriftPosGot   = 0,
                        driftTime       = pointObject.driftTime,
                        isReturning     = 0,
                        isRunning       = 0,
                        driftPosition   = 0,
                        isInitialStatus = 1,
                        isStop          = 0,
                        driftScale      = 1,
                        id          = i,
                        bounceTimer = 0
                    };

                    entities[i] = EntityManager.CreateEntity(cubeArchetype);
                    EntityManager.SetComponentData(entities[i], initialPosition);
                    EntityManager.SetComponentData(entities[i], scale);
                    EntityManager.SetComponentData(entities[i], f);
                    EntityManager.SetComponentData(entities[i], b);
                    EntityManager.SetSharedComponentData(entities[i], new MeshInstanceRenderer
                    {
                        mesh     = pointObject.myMesh,
                        material = pointObject.myMat
                    });
                }
            }



            entities.Dispose();
            positions.Dispose();

            EntityManager.RemoveComponent <ObjGrid>(sourceEntity);

            // Instantiate & AddComponent & RemoveComponent calls invalidate the injected groups,
            // so before we get to the next spawner we have to reinject them
            UpdateInjectedComponentGroups();
        }
    }