Esempio n. 1
0
 void Start()
 {
     tutorialFlag = true;
     energyLevel = 0;
     soundManager = GameObject.Find("SoundManager").GetComponent<EmitterSoundManager>();
     crowdManager = GameObject.Find ("CrowdManager").GetComponent<CrowdManager>();
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="mesh">The navigation mesh used by the query.</param>
 /// <param name="query">A navigation mesh query.</param>
 /// <param name="crowd">A crowd.</param>
 /// <param name="filter">The filter to use with the query.</param>
 /// <param name="extents">The extents to use with the query.</param>
 /// <param name="cloneFilter">
 /// If true, the filter will be cloned rather than referenced.
 /// </param>
 public NavGroup(Navmesh mesh, NavmeshQuery query, CrowdManager crowd
     , NavmeshQueryFilter filter, Vector3 extents
     , bool cloneFilter)
 {
     this.mesh = mesh;
     this.query = query;
     this.crowd = crowd;
     this.filter = (cloneFilter ? filter.Clone() : filter);
     this.extents = extents;
 }
Esempio n. 3
0
	void Start ()
	{
		state = CivilState.Waiting;
		home = transform.position;

		nav = GetComponent <NavMeshAgent> ();
		weapon = GetComponent <RaygunScript_00> ();
		player = GameObject.FindGameObjectWithTag ("Player").transform;
		crowdManager = GameObject.FindGameObjectWithTag ("CrowdManager").GetComponent<CrowdManager>();
		moraleManager = GameObject.FindGameObjectWithTag ("MoraleManager").GetComponent<MoraleManager_00>();
		healthScript = GetComponent<HealthScript_00> ();
		//weapon.setFiring (false);


		nav.speed = Random.Range (MIN_SPEED, MAX_SPEED);
		nav.angularSpeed = Random.Range (MIN_ANGULAR_SPEED, MAX_ANGULAR_SPEED);
		nav.acceleration = Random.Range (MIN_ACCELERATION, MAX_ACCELERATION);
	}
        void CreateScene()
        {
            var cache = GetSubsystem<ResourceCache>();

            scene = new Scene();

            // Create octree, use default volume (-1000, -1000, -1000) to (1000, 1000, 1000)
            // Also create a DebugRenderer component so that we can draw debug geometry
            scene.CreateComponent<Octree>();
            scene.CreateComponent<DebugRenderer>();

            // Create scene node & StaticModel component for showing a static plane
            Node planeNode = scene.CreateChild("Plane");
            planeNode.Scale = new Vector3(100.0f, 1.0f, 100.0f);
            StaticModel planeObject = planeNode.CreateComponent<StaticModel>();
            planeObject.Model = (cache.Get<Model>("Models/Plane.mdl"));
            planeObject.SetMaterial(cache.Get<Material>("Materials/StoneTiled.xml"));

            // Create a Zone component for ambient lighting & fog control
            Node zoneNode = scene.CreateChild("Zone");
            Zone zone = zoneNode.CreateComponent<Zone>();
            zone.SetBoundingBox(new BoundingBox(-1000.0f, 1000.0f));
            zone.AmbientColor = new Color(0.15f, 0.15f, 0.15f);
            zone.FogColor = new Color(0.5f, 0.5f, 0.7f);
            zone.FogStart = 100.0f;
            zone.FogEnd = 300.0f;

            // Create a directional light to the world. Enable cascaded shadows on it
            Node lightNode = scene.CreateChild("DirectionalLight");
            lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f));
            Light light = lightNode.CreateComponent<Light>();
            light.LightType = LightType.LIGHT_DIRECTIONAL;
            light.CastShadows = true;
            light.ShadowBias = new BiasParameters(0.00025f, 0.5f);
            // Set cascade splits at 10, 50 and 200 world units, fade shadows out at 80% of maximum shadow distance
            light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f);

            // Create randomly sized boxes. If boxes are big enough, make them occluders
            const uint numBoxes = 20;
            Node boxGroup = scene.CreateChild("Boxes");
            for (uint i = 0; i < numBoxes; ++i)
            {
                Node boxNode = boxGroup.CreateChild("Box");
                float size = 1.0f + NextRandom(10.0f);
                boxNode.Position = (new Vector3(NextRandom(80.0f) - 40.0f, size * 0.5f, NextRandom(80.0f) - 40.0f));
                boxNode.SetScale(size);
                StaticModel boxObject = boxNode.CreateComponent<StaticModel>();
                boxObject.Model = (cache.Get<Model>("Models/Box.mdl"));
                boxObject.SetMaterial(cache.Get<Material>("Materials/Stone.xml"));
                boxObject.CastShadows = true;
                if (size >= 3.0f)
                    boxObject.Occluder = true;
            }

            // Create a DynamicNavigationMesh component to the scene root
            DynamicNavigationMesh navMesh = scene.CreateComponent<DynamicNavigationMesh>();
            // Set the agent height large enough to exclude the layers under boxes
            navMesh.AgentHeight = 10.0f;
            navMesh.CellHeight = 0.05f;
            navMesh.DrawObstacles = true;
            navMesh.DrawOffMeshConnections = true;
            // Create a Navigable component to the scene root. This tags all of the geometry in the scene as being part of the
            // navigation mesh. By default this is recursive, but the recursion could be turned off from Navigable
            scene.CreateComponent<Navigable>();
            // Add padding to the navigation mesh in Y-direction so that we can add objects on top of the tallest boxes
            // in the scene and still update the mesh correctly
            navMesh.Padding = new Vector3(0.0f, 10.0f, 0.0f);
            // Now build the navigation geometry. This will take some time. Note that the navigation mesh will prefer to use
            // physics geometry from the scene nodes, as it often is simpler, but if it can not find any (like in this example)
            // it will use renderable geometry instead
            navMesh.Build();

            // Create an off-mesh connection to each box to make them climbable (tiny boxes are skipped). A connection is built from 2 nodes.
            // Note that OffMeshConnections must be added before building the navMesh, but as we are adding Obstacles next, tiles will be automatically rebuilt.
            // Creating connections post-build here allows us to use FindNearestPoint() to procedurally set accurate positions for the connection
            CreateBoxOffMeshConnections(navMesh, boxGroup);

            // Create some mushrooms
            const uint numMushrooms = 100;
            for (uint i = 0; i < numMushrooms; ++i)
                CreateMushroom(new Vector3(NextRandom(90.0f) - 45.0f, 0.0f, NextRandom(90.0f) - 45.0f));

            // Create a CrowdManager component to the scene root
            crowdManager = scene.CreateComponent<CrowdManager>();
            var parameters = crowdManager.GetObstacleAvoidanceParams(0);
            // Set the params to "High (66)" setting
            parameters.VelBias = 0.5f;
            parameters.AdaptiveDivs = 7;
            parameters.AdaptiveRings = 3;
            parameters.AdaptiveDepth = 3;
            crowdManager.SetObstacleAvoidanceParams(0, parameters);

            // Create some movable barrels. We create them as crowd agents, as for moving entities it is less expensive and more convenient than using obstacles
            CreateMovingBarrels(navMesh);

            // Create Jack node that will follow the path
            SpawnJack(new Vector3(-5.0f, 0.0f, 20.0f), scene.CreateChild("Jacks"));

            // Create the camera. Limit far clip distance to match the fog
            CameraNode = new Node();
            Camera camera = CameraNode.CreateComponent<Camera>();
            camera.FarClip = 300.0f;

            // Set an initial position for the camera scene node above the plane
            CameraNode.Position = new Vector3(0.0f, 50.0f, 0.0f);
            Pitch = 80.0f;
            CameraNode.Rotation = new Quaternion(Pitch, Yaw, 0.0f);
        }
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="copy">The group to copy.</param>
 /// <param name="cloneFilter">
 /// If true, the filter will be cloned. Otherwise it will be referenced.
 /// </param>
 public NavGroup(NavGroup copy, bool cloneFilter)
 {
     this.mesh = copy.mesh;
     this.query = copy.query;
     this.crowd = copy.crowd;
     this.filter = (cloneFilter ? copy.filter.Clone() : copy.filter);
     this.extents = copy.extents;
 }
Esempio n. 6
0
	// Use this for initialization
	void Start () 
	{
		healthScript = GetComponent<HealthScript_00> ();
		moraleManager = GameObject.FindGameObjectWithTag ("MoraleManager").GetComponent<MoraleManager_00>();
		crowdManager = GameObject.FindGameObjectWithTag ("CrowdManager").GetComponent<CrowdManager>();
	}