Esempio n. 1
0
    void OnTriggerExit(Collider other)
    {
        // Manage the list of sounds this character has heard
        SoundEvent sound = other.GetComponent <SoundEvent>();

        if (sound)
        {
            //sound.HeardBy.Remove(this);
            _objectsHeard.Remove(sound);
        }

        HeartBox heart = other.GetComponent <HeartBox>();

        if (heart)
        {
            _charactersCouldHear.Remove(heart);
        }

        OutlineInteractive barrier = other.GetComponent <OutlineInteractive>();

        if (barrier)
        {
            _barriers.Remove(barrier);
        }
    }
Esempio n. 2
0
    void OnTriggerEnter(Collider other)
    {
        // Manage the list of sounds this character has heard
        SoundEvent          sound    = other.GetComponent <SoundEvent>();
        FootstepAudioPlayer footstep = other.GetComponent <FootstepAudioPlayer>();

        if (sound && footstep != null && footstep.LifetimeLived == 0)
        {
            // NOTE: THE SIMPLICITY OF THIS SPHERECOLLIDER ALLOWS SOUNDS TO BE HEARD THROUGH WALLS
            sound.HeardBy.Add(this);
            // HACK: THIS CHECK ALLOWS BABYBOT TO NOT HEAR THE SIGHT PUZZLE IN THE SEWER TUTORIAL
            if (!IgnoreAbove || other.transform.position.y < 70)
            {
                _objectsHeard.AddFirst(sound);
            }
        }

        HeartBox heart = other.GetComponent <HeartBox>();

        if (heart && !_charactersCouldHear.Contains(heart))
        {
            _charactersCouldHear.Add(heart);
        }

        OutlineInteractive barrier = other.GetComponent <OutlineInteractive>();

        if (barrier && !_barriers.Contains(barrier))
        {
            _barriers.Add(barrier);
        }
    }
    static void SetupObject(Transform transform)
    {
        // Get rid of any collider it may already have
        Collider collider = transform.GetComponent <Collider> ();

        if (collider)
        {
            Object.DestroyImmediate(collider);
        }

        // We use box colliders unless told to use mesh collider
        if (transform.name.ToLower().Contains("mesh"))
        {
            transform.gameObject.AddComponent <MeshCollider> ();
        }
        else
        {
            transform.gameObject.AddComponent <BoxCollider> ();
        }

        // Put it on the ground layer
        transform.gameObject.layer = LayerMask.NameToLayer("Ground");

        // Mark it as waypoint for the AI system, unless told not to
        if (!transform.name.ToLower().Contains("waypointless"))
        {
            transform.tag = "Waypoint";
        }

        // Get rid of any child objects that we may have created in previous runs of this script
        DestroyChildren(transform);

        // Change the shader so that it will be outlined as appropriate
        if (!transform.GetComponent <Renderer>().sharedMaterial.shader.name.Contains("Interactive"))
        {
            transform.GetComponent <Renderer>().sharedMaterial.shader = Shader.Find("Outlined/Interactive");
            transform.GetComponent <Renderer>().sharedMaterial.SetFloat("_FadeDis", 15);
        }
        //transform.renderer.sharedMaterial.shader = Shader.Find ("Diffuse");
        OutlineInteractive outlineFader = transform.GetComponent <OutlineInteractive> ();

        if (outlineFader == null)
        {
            outlineFader = transform.gameObject.AddComponent <OutlineInteractive> ();
        }
        outlineFader.enabled = true;
    }
    static void MeshToGameObjects()
    {
        // Load up the assets we need
        playerPrefab = (GameObject)Resources.Load("Prefabs/Characters/Newman");
        ledgePrefab  = (GameObject)Resources.Load("Prefabs/Platforming/Ledge");
        wallPrefab   = (GameObject)Resources.Load("Prefabs/Platforming/Wall");
        ropePrefab   = (GameObject)Resources.Load("Prefabs/Platforming/Rope");
        ladderPrefab = (GameObject)Resources.Load("Prefabs/Platforming/Ladder");

        // We're primarily focused on the root gameobject, and we know that it comes after all its children
        Transform root = selected [selected.Count - 1];

        // Store all the walls, ropes, and ladders in one location
        GameObject prevWalls = GameObject.Find(root.name + " - Walls, Ropes, and Ladders");

        createdLadderColliders = new List <BoxCollider>();
        wallContainer          = new GameObject(root.name + " - Walls, Ropes, and Ladders");

        // Go through each transform and set up the gameobjects
        selected.ForEach(transform => {
            // We only do something if we have meshes
            MeshFilter meshFilter = transform.GetComponent <MeshFilter> ();
            if (!meshFilter)
            {
                OutlineInteractive outliner = transform.GetComponent <OutlineInteractive>();
                if (outliner)
                {
                    GameObject.DestroyImmediate(outliner);
                }
                transform.gameObject.tag   = "Untagged";
                transform.gameObject.layer = LayerMask.NameToLayer("Default");
                return;
            }

            // And if that mesh is named something we recognize
            string name       = meshFilter.name.ToLower();
            bool containsName = false;
            foreach (string objName in objectNames)
            {
                if (name.Contains(objName.ToLower()))
                {
                    containsName = true;
                }
            }
            if (!containsName)
            {
                transform.gameObject.isStatic = true;
                return;
            }

            // Set up the object
            SetupObject(transform);

            // Create the object
            if (name.Contains("ledge") || name.Contains("obstacle"))
            {
                CreateLedge(transform);
            }
            if (name.Contains("wall"))
            {
                CreateWall(transform);
            }
            if (name.Contains("rope"))
            {
                CreateRope(transform);
            }
            if (name.Contains("ladder"))
            {
                CreateLadder(transform);
            }

            // Make the gameobject static for optimization
            transform.gameObject.isStatic = true;
        });

        // Mark objects as static for optimization
        root.gameObject.isStatic = true;
        wallContainer.isStatic   = true;

        // Cleanup the previous wall group
        if (prevWalls != null)
        {
            GameObject.DestroyImmediate(prevWalls);
        }
    }