コード例 #1
0
    void CreateRegionObjectsAndMeshes()
    {
        foreach (int[,] region in regionsList)
        {
            //create a building gameobject that contains a MeshGenerator, buildingMemory, ColorTimer, and ChangeColor
            GameObject building = new GameObject();
            building.name = "BuildingObj";
            MeshGenerator buildingMeshGen      = building.AddComponent <MeshGenerator> () as MeshGenerator;
            MeshFilter    buildingMeshFilter   = building.AddComponent <MeshFilter> () as MeshFilter;
            MeshRenderer  buildingMeshRenderer = building.AddComponent <MeshRenderer> () as MeshRenderer;
            buildingMeshRenderer.material = buildingMat;
            MeshCollider   buildingMeshCollider      = building.AddComponent <MeshCollider> () as MeshCollider;
            buildingMemory buildingMemoryScript      = building.AddComponent <buildingMemory> () as buildingMemory;
            colorTimer     buildingColorTimerScript  = building.AddComponent <colorTimer> () as colorTimer;
            changeColor    buildingChangeColorScript = building.AddComponent <changeColor> () as changeColor;

            GameObject buildingWalls = new GameObject();
            buildingWalls.name = "WallMesh";
            MeshFilter   wallsMeshFilter   = buildingWalls.AddComponent <MeshFilter> () as MeshFilter;
            MeshRenderer wallsMeshRenderer = buildingWalls.AddComponent <MeshRenderer> () as MeshRenderer;
            wallsMeshRenderer.material = wallMat;

            buildingMeshGen.walls = wallsMeshFilter;
            buildingWalls.transform.SetParent(building.transform);

            buildingMeshGen.GenerateMesh(region, 1f);
        }
    }
コード例 #2
0
ファイル: fieldOfView.cs プロジェクト: AMichal8/Asyndetown
    void FindBuildings()
    {
        RaycastHit hit;


        Vector3 pos = transform.position;
        Vector3 mid = transform.forward * viewRadius;



        if (Physics.Raycast(pos, mid, out hit, viewRadius))
        {
            //Debug.Log ("Raycasted!");

            if (hit.collider.CompareTag("building"))
            {
                if (currentBuildingMid == null)
                {
                    currentBuildingMid = hit.collider.gameObject.GetComponent <buildingMemory> ();
                    currentBuildingMid.contacted();
                }
                else if (hit.collider.gameObject.GetComponent <buildingMemory> () == currentBuildingMid)
                {
                    currentBuildingMid.contacted();
                }
                else
                {
                    currentBuildingMid.uncontacted();
                    currentBuildingMid = null;
                }
            }
        }

        Vector3 left = DirectionFromAngle(-viewAngle / 2, false) * viewRadius;

        if (Physics.Raycast(pos, left, out hit, viewRadius))
        {
            //Debug.Log ("Raycasted!");

            if (hit.collider.CompareTag("building"))
            {
                if (currentBuildingLeft == null)
                {
                    currentBuildingLeft = hit.collider.gameObject.GetComponent <buildingMemory> ();
                    currentBuildingLeft.contacted();
                }
                else if (hit.collider.gameObject.GetComponent <buildingMemory> () == currentBuildingLeft)
                {
                    currentBuildingLeft.contacted();
                }
                else
                {
                    currentBuildingLeft.uncontacted();
                    currentBuildingLeft = null;
                }
            }
        }



        Vector3 right = DirectionFromAngle(viewAngle / 2, false) * viewRadius;

        if (Physics.Raycast(pos, right, out hit, viewRadius))
        {
            //Debug.Log ("Raycasted!");

            if (hit.collider.CompareTag("building"))
            {
                if (currentBuildingRight == null)
                {
                    currentBuildingRight = hit.collider.gameObject.GetComponent <buildingMemory> ();
                    currentBuildingRight.contacted();
                }
                else if (hit.collider.gameObject.GetComponent <buildingMemory> () == currentBuildingRight)
                {
                    currentBuildingRight.contacted();
                }
                else
                {
                    currentBuildingRight.uncontacted();
                    currentBuildingRight = null;
                }
            }
        }

        Vector3 leftMid = left + mid * viewRadius;

        if (Physics.Raycast(pos, leftMid, out hit, viewRadius))
        {
            //Debug.Log ("Raycasted!");

            if (hit.collider.CompareTag("building"))
            {
                if (currentBuildingLeftMid == null)
                {
                    currentBuildingLeftMid = hit.collider.gameObject.GetComponent <buildingMemory> ();
                    currentBuildingLeftMid.contacted();
                }
                else if (hit.collider.gameObject.GetComponent <buildingMemory> () == currentBuildingLeftMid)
                {
                    currentBuildingLeftMid.contacted();
                }
                else
                {
                    currentBuildingLeftMid.uncontacted();
                    currentBuildingLeftMid = null;
                }
            }
        }



        Vector3 rightMid = right + mid * viewRadius;

        if (Physics.Raycast(pos, rightMid, out hit, viewRadius))
        {
            //Debug.Log ("Raycasted!");

            if (hit.collider.CompareTag("building"))
            {
                if (currentBuildingRightMid == null)
                {
                    currentBuildingRightMid = hit.collider.gameObject.GetComponent <buildingMemory> ();
                    currentBuildingRightMid.contacted();
                }
                else if (hit.collider.gameObject.GetComponent <buildingMemory> () == currentBuildingRightMid)
                {
                    currentBuildingRightMid.contacted();
                }
                else
                {
                    currentBuildingRightMid.uncontacted();
                    currentBuildingRightMid = null;
                }
            }
        }
    }