Exemplo n.º 1
0
    public void CreatePlaneWithModifier()
    {
        GameObject primitive = GameObject.CreatePrimitive((PrimitiveType)4);

        this.surface  = (NavMeshSurface)primitive.AddComponent <NavMeshSurface>();
        this.modifier = (NavMeshModifier)primitive.AddComponent <NavMeshModifier>();
    }
    public void CreatePlaneWithModifier()
    {
        var plane = GameObject.CreatePrimitive(PrimitiveType.Plane);

        surface  = plane.AddComponent <NavMeshSurface>();
        modifier = plane.AddComponent <NavMeshModifier>();
    }
Exemplo n.º 3
0
    //
    public void GenerateBlockingMesh()
    {
        for (int i = 0; i < CompositeCollider.pathCount; i++)
        {
            Vector2[] pathPoints = new Vector2[CompositeCollider.GetPathPointCount(i)];
            CompositeCollider.GetPath(i, pathPoints);

            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad);
            go.transform.parent = transform;
            Mesh      mesh  = new Mesh();
            Vector3[] verts = new Vector3[pathPoints.Length];
            for (int j = 0; j < verts.Length; j++)
            {
                verts[j] = pathPoints[j];
            }
            mesh.vertices  = verts;
            mesh.triangles = new int[6] {
                0, 1, 2, 0, 2, 3
            };
            go.GetComponent <MeshFilter>().mesh = mesh;

            NavMeshModifier mod = go.AddComponent <NavMeshModifier>();
            mod.area         = 1;
            mod.overrideArea = true;
        }

        //MeshFilter.gameObject.transform.position = MeshFilter.gameObject.transform.position + Walls.gameObject.transform.position;
        transform.position = transform.position + Walls.gameObject.transform.position;

        GetComponent <NavMeshSurface>().BuildNavMesh();
    }
Exemplo n.º 4
0
        static void _AddNavMeshModifier(GameObject _object, int _state)
        {
            NavMeshModifier _mod = _object.AddComponent <NavMeshModifier>() as NavMeshModifier;

            _mod.overrideArea = true;
            _mod.area         = _state;
        }
Exemplo n.º 5
0
 // Start is called before the first frame update
 void Start()
 {
     mat        = GetComponent <Renderer>().material;
     navMeshMod = GetComponent <NavMeshModifier>();
     if (!isDefaultVisible)
     {
         OnStateChange(PanelVisibleState.Invisible);
     }
 }
Exemplo n.º 6
0
    static bool IsIgnorableByNavMesh(GameObject obj)
    {
        NavMeshModifier navMeshModifier = obj.GetComponent <NavMeshModifier>();

        if (navMeshModifier == null)
        {
            return(false);
        }
        return(navMeshModifier.ignoreFromBuild);
    }
Exemplo n.º 7
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            // Raycast from mouse to background layer
            mouseRay = mainCamera.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(mouseRay, out rayHit, Mathf.Infinity, layerMask))
            {
                GameObject      ground = rayHit.collider.gameObject;
                NavMeshModifier mod    = ground.GetComponent <NavMeshModifier>();

                int currColor = Mathf.Clamp(mod.area - offset, 0, 7);
                int newColor  = currColor ^ (int)Player.Instance.CurrentColor;
                mod.area = newColor + offset;
                surf.BuildNavMesh();

                Renderer groundRenderer = ground.GetComponent <Renderer>();

                switch ((Color)newColor)
                {
                case Color.None:
                    groundRenderer.material.color = UnityEngine.Color.white;
                    break;

                case Color.Red:
                    groundRenderer.material.color = new UnityEngine.Color(0.6981132f, 0.02305092f, 0.02305092f);
                    break;

                case Color.Yellow:
                    groundRenderer.material.color = UnityEngine.Color.yellow;
                    break;

                case Color.Orange:
                    groundRenderer.material.color = new UnityEngine.Color(1f, 0.5568628f, 0);
                    break;

                case Color.Blue:
                    groundRenderer.material.color = UnityEngine.Color.blue;
                    break;

                case Color.Purple:
                    groundRenderer.material.color = new UnityEngine.Color(0.6074608f, 0, 0.8867924f);
                    break;

                case Color.Green:
                    groundRenderer.material.color = UnityEngine.Color.green;
                    break;

                case Color.Black:
                    groundRenderer.material.color = UnityEngine.Color.black;
                    break;
                }
            }
        }
    }
Exemplo n.º 8
0
    //helper function to create the game object.
    private void CreateGameObject(Mesh mesh)
    {
        //destroy old container if exist
        if (transform.Find(containerName))
        {
            DestroyImmediate(transform.Find(containerName).gameObject);
        }

        meshContainer = new GameObject();
        meshContainer.transform.position = transform.position;
        meshContainer.transform.parent   = transform;
        meshContainer.name = containerName;
        MeshFilter mF = meshContainer.AddComponent <MeshFilter>();

        mF.mesh = mesh;
        MeshRenderer mR = meshContainer.AddComponent <MeshRenderer>();

        //add nav Mesh Modifier if exists navMeshModifier = true
        if (navMeshModifier)
        {
            NavMeshModifier nMM = meshContainer.AddComponent <NavMeshModifier>();
            //override the area with navigationArea area type.
            nMM.overrideArea = true;
            nMM.area         = navigationArea;
        }

        //apply the material, if set.
        if (material != null)
        {
            mR.material = material;
        }

        meshContainer.layer = layerIndex;

        //add nav Mesh Modifier if exists navMeshModifier = true
        if (meshCollider)
        {
            MeshCollider mC = meshContainer.AddComponent <MeshCollider>();
            mC.sharedMesh = mesh;
            //on a flat mesh, unity gives a convex mesh a width of .05f .. which allows us to hit it with a raycast.
            //nvm .. this causes other issues.
            //mC.convex = true;
            if (physicsMaterial != null)
            {
                mC.material = physicsMaterial;
            }
        }
    }
    void OnValidate()
    {
        if (this.gameObject == null)
        {
            return;
        }

        if (navmeshMod == null)
        {
            navmeshMod = GetComponent <NavMeshModifier> ();
        }

        navmeshMod.ignoreFromBuild = true;
        navmeshMod.overrideArea    = false;
        navmeshMod.area            = 0; //walkable, the list is 0 indexed
    }
Exemplo n.º 10
0
    /// <summary>
    /// Analyze all childern of the sceneRoot, and classifies them as walkable or not walkable based on
    /// </summary>
    void UpdateNavMeshSettingsForObjsUnderRoot()
    {
        // Iterate all the Scene Objects
        foreach (Transform sceneObjContainer in sceneRoot.transform)
        {
            foreach (Transform sceneObj in sceneObjContainer.transform)
            {
                NavMeshModifier nvm = sceneObj.gameObject.AddComponent <NavMeshModifier>();

                // Walkable = 0, Not Walkable = 1
                // This area types are unity predefined, in the unity inspector in the navigation tab go to areas
                // to see them
                nvm.overrideArea = true;
                nvm.area         = sceneObj.parent.name == "Floor" ? (int)AreaType.Walkable : (int)AreaType.NotWalkable;
            }
        }
    }
Exemplo n.º 11
0
        private void Start()
        {
            _navMeshSurfaces = surfaceContainerObject.GetComponents <NavMeshSurface>();
            _navMeshModifier = GetComponent <NavMeshModifier>();

            if (_buildCoroutineWasLaunched)
            {
                return;
            }

            foreach (var navMeshSurface in _navMeshSurfaces)
            {
                navMeshSurface.UpdateNavMesh(navMeshSurface.navMeshData);
            }

            _buildCoroutineWasLaunched = true;
        }
Exemplo n.º 12
0
    void Start()
    {
        GameObject[] pathways     = GameObject.FindGameObjectsWithTag("pathway");
        int          walkableArea = NavMesh.GetAreaFromName(WALKABLE_AREA);

        foreach (GameObject pathway in pathways)
        {
            pathway.GetComponents <MeshRenderer>();
            NavMeshModifier navMeshModifier = pathway.AddComponent <NavMeshModifier>();
            navMeshModifier.ignoreFromBuild = false;
            navMeshModifier.overrideArea    = true;
            navMeshModifier.area            = walkableArea;
        }
        GameObject[] roadways = GameObject.FindGameObjectsWithTag("roadway");
        int          roadArea = NavMesh.GetAreaFromName(ROAD_AREA);

        foreach (GameObject roadway in roadways)
        {
            roadway.GetComponents <MeshRenderer>();
            NavMeshModifier navMeshModifier = roadway.AddComponent <NavMeshModifier>();
            navMeshModifier.ignoreFromBuild = false;
            navMeshModifier.overrideArea    = true;
            navMeshModifier.area            = roadArea;
        }
        PedestrianCrossing[] pedestrianCrossings = GameObject.FindObjectsOfType <PedestrianCrossing>();
        int pedestrianCrossingArea = NavMesh.GetAreaFromName(PEDESTRIAN_CROSSING_AREA);

        foreach (PedestrianCrossing crossing in pedestrianCrossings)
        {
            crossing.gameObject.GetComponents <MeshRenderer>();
            NavMeshModifier navMeshModifier = crossing.gameObject.AddComponent <NavMeshModifier>();
            navMeshModifier.ignoreFromBuild = false;
            navMeshModifier.overrideArea    = true;
            navMeshModifier.area            = pedestrianCrossingArea;
        }
        navMeshSurface = GameObject.FindObjectOfType <NavMeshSurface>();
        navMeshSurface.BuildNavMesh();
        this.pedestrianCrossings = pedestrianCrossings.ToList();
    }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a new gameobject to use it as NavMeshObject.
        /// </summary>
        public void CreateNewNavMesh(bool walkable = true)
        {
            //create gameobject
            GameObject navGO = new GameObject(walkable ? "New Walkable NavMesh" : "New Not Walkable NavMesh");

            navGO.transform.parent = script.transform;
            navGO.isStatic         = true;
            navGO.AddComponent <NavMeshObject>();
            NavMeshModifier modifier = navGO.AddComponent <NavMeshModifier>();

            if (!walkable)
            {
                modifier.overrideArea = true;
                modifier.area         = 1;
            }

            //modify renderer to ignore shadows
            MeshRenderer mRenderer = navGO.GetComponent <MeshRenderer>();

            #if UNITY_4_6 || UNITY_4_7
            mRenderer.castShadows = false;
            #else
            mRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            #endif
            mRenderer.receiveShadows = false;
            if (script.meshMaterial)
            {
                mRenderer.sharedMaterial = script.meshMaterial;
            }
            else
            {
                mRenderer.enabled = false;
            }

            Undo.RegisterCreatedObjectUndo(navGO, "Created NavMesh");
            Selection.activeGameObject = navGO;
        }
        public void SetIgnoreFromNavMesh(bool value)
        {
            NavMeshModifier nmm = GetComponent <NavMeshModifier>();

            nmm.ignoreFromBuild = value;
        }
Exemplo n.º 15
0
 void Awake()
 {
     rend         = GetComponent <Renderer>();
     navModifier  = GetComponent <NavMeshModifier>();
     highlighting = false;
 }
Exemplo n.º 16
0
 // Use this for initialization
 void Start()
 {
     areaSize        = this.gameObject.GetComponent <Renderer>().bounds.size.x *this.gameObject.GetComponent <Renderer>().bounds.size.z;
     navMeshModifier = this.gameObject.GetComponent <NavMeshModifier>();
 }
Exemplo n.º 17
0
    public IEnumerator readFile()
    {
        string filename = Directory.GetCurrentDirectory() + "/Assets/ModelAndRules/PCL_Building1.ifc";//EmptyKitchen.ifc";

        string filename1 = "http://162.246.156.210:8080/PCL_Building1.ifc";

        WWW fileText = new WWW(filename1);

        yield return(fileText);

        string      t  = fileText.text;
        DatabaseIfc db = null;

        if (t == "")
        {
            db = new DatabaseIfc(filename);
        }
        else
        {
            UnityEngine.Debug.Log(t);

            TextReader textReader = new StringReader(t);
            db = new DatabaseIfc(textReader);
        }
        GameObject ModelGO = new GameObject(filename);
        List <List <UnityObj> > currentModels     = new List <List <UnityObj> >();
        List <double>           currentModelCosts = new List <double>();

        for (int split = 0; split < SPLIT_NUM; split++)
        {
            List <UnityObj> currentModel = new List <UnityObj>();
            List <Obj>      objectsInDB  = GetObjFromDB(db);
            foreach (Obj o in objectsInDB)
            {
                UnityObj newObj = new UnityObj(o, DefaultMaterialStatic);
                if (o.IfcType > IfcType.IfcAllNonVirtualTypes)
                {
                    if (o.Name.Contains("Single-Flush"))
                    {
                        SetMeshRenderMaterial(newObj.IfcGameObject, DoorMaterial);
                    }
                    else
                    {
                        SetMeshRenderMaterial(newObj.IfcGameObject, DefaultMaterialSpace);
                    }
                }
                if (o.Name.Contains("Single-Flush"))
                {
                    Vector3 scaleChange = new Vector3(0.0f, 0.5f, 0.0f);
                    newObj.IfcGameObject.transform.localScale += scaleChange;

                    NavMeshModifier nmm = newObj.IfcGameObject.AddComponent <NavMeshModifier>() as NavMeshModifier;
                    nmm.overrideArea = true;
                    nmm.area         = 0;
                }

                if (o.Name.Contains("Basic"))
                {
                    NavMeshModifier nmm = newObj.IfcGameObject.AddComponent <NavMeshModifier>() as NavMeshModifier;
                    nmm.overrideArea = true;
                    nmm.area         = 1;
                }
                newObj.IfcGameObject.transform.parent = ModelGO.transform;

                currentModel.Add(newObj);
            }

            currentModels.Add(currentModel);
            currentModelCosts.Add(0.0);
        }
    }
Exemplo n.º 18
0
        /// <summary>
        /// Add a component to a game object based on the component type
        /// </summary>
        /// <param name="componentType"></param>
        /// <param name="targetGameObject"></param>
        private static void AddComponent(ComponentType componentType, GameObject targetGameObject)
        {
            switch (componentType)
            {
            case ComponentType.NavMeshAgent:
                if (targetGameObject.GetComponent <NavMeshAgent>() == null)
                {
                    // Add a navmashagent which allows an object to move around as a AI
                    NavMeshAgent n = targetGameObject.AddComponent <NavMeshAgent>();
                    n.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;
                    n.avoidancePriority     = 0;
                    n.baseOffset            = 0.1f;
                    n.radius = 1.0f;
                }

                break;

            case ComponentType.NotWalkable:
                if (targetGameObject.GetComponent <NavMeshModifier>() == null)
                {
                    // Add a navmash modifier so the navmesh will know that this object is not walkable
                    NavMeshModifier navMeshModifier = targetGameObject.AddComponent <NavMeshModifier>();
                    navMeshModifier.overrideArea = true;
                    navMeshModifier.area         = NavMesh.GetAreaFromName("Not Walkable");
                }

                break;

            case ComponentType.Camera:
                // These camera settings are based on the paid assets pack
                if (targetGameObject.GetComponent <Camera>() == null)
                {
                    GameObject cameraObject = new GameObject();

                    Camera camera = cameraObject.AddComponent <Camera>();
                    camera.clearFlags = CameraClearFlags.Color;
                    // Set default background color
                    camera.backgroundColor = new Color32(88, 85, 74, 255);
                    camera.orthographic    = false;

                    Vector3    defaultPositionForPaidAssetPack    = Vector3.zero;
                    Quaternion defaultRotationForPaidAssetPack    = Quaternion.Euler(0, 0, 0);
                    float      defaultFieldOfViewForPaidAssetPack = 0f;
                    switch (targetGameObject.tag)
                    {
                    case "Plane":
                        cameraObject.tag = "PlaneCamera";

                        defaultPositionForPaidAssetPack    = new Vector3(-0.88f, 25.1f, -4.7f);
                        defaultRotationForPaidAssetPack    = Quaternion.Euler(70, 0, 0);
                        defaultFieldOfViewForPaidAssetPack = 47.1f;
                        break;

                    case "Tank":
                        cameraObject.tag = "TankCamera";

                        defaultPositionForPaidAssetPack    = new Vector3(-1.08f, 1f, 0.23f);
                        defaultFieldOfViewForPaidAssetPack = 60f;
                        break;
                    }

                    cameraObject.transform.position = defaultPositionForPaidAssetPack;
                    cameraObject.transform.rotation = defaultRotationForPaidAssetPack;
                    camera.fieldOfView = defaultFieldOfViewForPaidAssetPack;
                    cameraObject.transform.SetParent(targetGameObject.transform);
                }

                break;
            }
        }