Inheritance: UnityEngine.Behaviour
 static public int get_velocity(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshObstacle self = (UnityEngine.AI.NavMeshObstacle)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.velocity);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int get_shape(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshObstacle self = (UnityEngine.AI.NavMeshObstacle)checkSelf(l);
         pushValue(l, true);
         pushEnum(l, (int)self.shape);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int get_carvingMoveThreshold(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshObstacle self = (UnityEngine.AI.NavMeshObstacle)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.carvingMoveThreshold);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 4
0
 void Start()
 {
     if (!pivot)
     {
         this.enabled = false;
     }
     navMeshObstacle = GetComponentInChildren <UnityEngine.AI.NavMeshObstacle>();
     if (navMeshObstacle)
     {
         navMeshObstacle.enabled = false;
         navMeshObstacle.carving = true;
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshObstacle o;
         o = new UnityEngine.AI.NavMeshObstacle();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_shape(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshObstacle      self = (UnityEngine.AI.NavMeshObstacle)checkSelf(l);
         UnityEngine.AI.NavMeshObstacleShape v;
         checkEnum(l, 2, out v);
         self.shape = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_carveOnlyStationary(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshObstacle self = (UnityEngine.AI.NavMeshObstacle)checkSelf(l);
         bool v;
         checkType(l, 2, out v);
         self.carveOnlyStationary = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_velocity(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshObstacle self = (UnityEngine.AI.NavMeshObstacle)checkSelf(l);
         UnityEngine.Vector3            v;
         checkType(l, 2, out v);
         self.velocity = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_radius(IntPtr l)
 {
     try {
         UnityEngine.AI.NavMeshObstacle self = (UnityEngine.AI.NavMeshObstacle)checkSelf(l);
         float v;
         checkType(l, 2, out v);
         self.radius = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 10
0
    public void InitTowerAI()
    {
        emission       = GetComponentInChildren <EffectEmission>();
        circleMaterial = AttackCircle.GetComponentInChildren <MeshRenderer>().material;
        cs             = GetComponent <CharacterState>();
        cc             = GetComponent <CharacterController>();
        navOb          = GetComponent <UnityEngine.AI.NavMeshObstacle>();

        cs.OnDead += ShowDeathEffect;
        AttackCircle.transform.localScale = 2f * Vector3.one * GetAtkRange() / AttackCircle.transform.lossyScale.x;
        AttackCircle.gameObject.SetActive(false);
        inited    = true;
        changeRed = false;
        pss       = AttackEffect.GetComponentsInChildren <ParticleSystem>();
    }
Esempio n. 11
0
 public virtual void SetupNavMeshObstacle()
 {
     UnityEngine.AI.NavMeshObstacle navMeshObstacle = ai_prefab.GetComponent <UnityEngine.AI.NavMeshObstacle>();
     if (navMeshObstacle == null)
     {
         navMeshObstacle = ai_prefab.AddComponent <UnityEngine.AI.NavMeshObstacle>();
     }
     CoverShooter.Tools.NavMeshObstacle nav_MeshObstacle = ai_scriptable.navMeshObstacle;
     navMeshObstacle.shape   = nav_MeshObstacle.shape;
     navMeshObstacle.center  = nav_MeshObstacle.center;
     navMeshObstacle.radius  = nav_MeshObstacle.radius;
     navMeshObstacle.carving = nav_MeshObstacle.carve;
     navMeshObstacle.carvingMoveThreshold    = nav_MeshObstacle.move_threshold;
     navMeshObstacle.carvingTimeToStationary = nav_MeshObstacle.time_to_stationary;
     navMeshObstacle.carveOnlyStationary     = nav_MeshObstacle.carve_only_station;
 }
Esempio n. 12
0
 void Start()
 {
     open        = true;
     squeekSound = GetComponent <AudioSource>();
     if (this.transform.name == "SingleDoor")
     {
         Door = transform.Find("Door");
     }
     else if (this.transform.name == "DoubleDoor")
     {
         LeftDoor  = transform.Find("LeftDoor");
         RightDoor = transform.Find("RightDoor");
     }
     obstacle = GetComponent <UnityEngine.AI.NavMeshObstacle>();
     locked   = false;
 }
Esempio n. 13
0
    // Update is called once per frame
    void Update()
    {
        float forwardAmount = Input.GetAxis("Vertical") * forwardRate;
        float turnForce     = Input.GetAxis("Horizontal") * turnRate;

        transform.Rotate(0, turnForce, 0);
        transform.position += transform.forward * forwardAmount * Time.deltaTime;

        if (Input.GetButtonDown("Fire2"))
        {
            GameObject newPoison = Instantiate(poison, transform.position, transform.rotation);
            obstacle = newPoison.GetComponent <UnityEngine.AI.NavMeshObstacle> ();
            newPoison.transform.parent = poisonGroup;
            bool walkable = GetRandomValue();
            obstacle.enabled = walkable;
            StartCoroutine(destroyPoison(newPoison));
        }
    }
Esempio n. 14
0
    void OnDrawGizmos()
    {
        UnityEngine.AI.NavMeshObstacle obstacle = fence.GetComponent <UnityEngine.AI.NavMeshObstacle>();

        Gizmos.color = Color.black;
        //left
        Gizmos.DrawWireCube(new Vector3(0.0f, 0.0f, stageDepth / 2),
                            new Vector3(obstacle.size.z, obstacle.size.y, obstacle.size.x * (stageDepth / 2)));
        //up
        Gizmos.DrawWireCube(new Vector3(stageWidth / 2, 0.0f, stageDepth),
                            new Vector3(obstacle.size.x * (stageDepth / 2) + obstacle.size.x * 0.5f, obstacle.size.y, obstacle.size.z));
        //right
        Gizmos.DrawWireCube(new Vector3(stageWidth, 0.0f, stageDepth / 2),
                            new Vector3(obstacle.size.z, obstacle.size.y, obstacle.size.x * (stageDepth / 2)));
        //down
        Gizmos.DrawWireCube(new Vector3(stageWidth / 2, 0.0f, 0.0f),
                            new Vector3(obstacle.size.x * (stageDepth / 2) + obstacle.size.x * 0.5f, obstacle.size.y, obstacle.size.z));
    }
Esempio n. 15
0
    private void GenerateObstacle()
    {
        navOb         = pos.gameObject.AddMissingComponent <UnityEngine.AI.NavMeshObstacle>();
        navOb.shape   = UnityEngine.AI.NavMeshObstacleShape.Box;
        navOb.carving = true;
        float x, y, z;
        float mSizeRate = mCurSkillNode.angle / 360f;

        x = y = mCurSkillNode.aoe_wide * mSizeRate;
        z = mCurSkillNode.aoe_long * mSizeRate;
        Vector3 mTargetPos = transform.position + transform.forward * (z + mExtendSize);
        float   mTempDis   = z;

        if (!attackerCs.pm.nav.enabled)
        {
            attackerCs.pm.nav.enabled = true;
        }
        if (attackerCs.pm.nav.Raycast(mTargetPos, out navMeshHit))
        {
            mTempDis = Vector3.Distance(navMeshHit.position, pos.position);
        }
        if (Physics.Linecast(transform.position, mTargetPos, 1 << (int)GameLayer.Obstacle))
        {
            mTempDis = z;
        }
        z            = mTempDis;
        navOb.size   = new Vector3(x, y, z);
        navOb.center = new Vector3(0, 0, z / 2);
        Rigidbody rd = pos.gameObject.AddMissingComponent <Rigidbody>();

        rd.useGravity  = false;
        rd.isKinematic = true;
        BoxCollider bc = pos.gameObject.AddMissingComponent <BoxCollider>();

        bc.isTrigger         = false;
        bc.size              = new Vector3(x, y, z);
        bc.center            = new Vector3(0, 0, z / 2);
        pos.gameObject.layer = (int)GameLayer.Obstacle;
    }
Esempio n. 16
0
    void Awake()
    {
        myTransform = transform;

        animLeftCanon  = GetComponent <Animator>();
        animRightCanon = GetComponent <Animator>();

        obstacle = GetComponentInChildren <UnityEngine.AI.NavMeshObstacle>();

        switch (typeOfCore)
        {
        case "hero":
            heroTurret  = true;
            enemyTurret = false;
            break;

        case "Hero":
            heroTurret  = true;
            enemyTurret = false;
            break;

        case "enemy":
            heroTurret  = false;
            enemyTurret = true;
            break;

        case "Enemy":
            heroTurret  = false;
            enemyTurret = true;
            break;

        case "tower":
            break;

        default:
            break;
        }
    }
Esempio n. 17
0
    // Use this for initialization
    void Start()
    {
        GameObject tempObj = Instantiate(carObjs[Random.Range(0, carObjs.Length)], transform.position, Quaternion.identity) as GameObject;

        tempObj.name             = "CarModel";
        tempObj.transform.parent = transform;
        carMover = tempObj.GetComponent <carMovementS>();

        maxSpeed = randomMaxSpeed + Random.Range(-randomMaxSpeedRange, randomMaxSpeedRange);

        int RandomPath = Random.Range(0, numberOfPaths);

        path        = iTweenPath.GetPath("Path" + RandomPath.ToString());
        totolLenght = iTween.PathLength(path);

        speed   = maxSpeed;
        lastPos = transform.position;

        iTween.PutOnPath(gameObject, path, 0.0f);
        iTween.LookTo(gameObject, iTween.PointOnPath(path, 0.001f), 0.0f);

        obstacle = GetComponentInChildren <UnityEngine.AI.NavMeshObstacle>();
    }
Esempio n. 18
0
        List <NavMeshBuildSource> CollectSources()
        {
            var sources = new List <NavMeshBuildSource>();
            var markups = new List <NavMeshBuildMarkup>();

            List <NavMeshModifier> modifiers;

            if (m_CollectObjects == CollectObjects.Children)
            {
                modifiers = new List <NavMeshModifier>(GetComponentsInChildren <NavMeshModifier>());
                modifiers.RemoveAll(x => !x.isActiveAndEnabled);
            }
            else
            {
                modifiers = NavMeshModifier.activeModifiers;
            }

            foreach (var m in modifiers)
            {
                if ((m_LayerMask & (1 << m.gameObject.layer)) == 0)
                {
                    continue;
                }
                if (!m.AffectsAgentType(m_AgentTypeID))
                {
                    continue;
                }
                var markup = new NavMeshBuildMarkup();
                markup.root            = m.transform;
                markup.overrideArea    = m.overrideArea;
                markup.area            = m.area;
                markup.ignoreFromBuild = m.ignoreFromBuild;
                markups.Add(markup);
            }

#if UNITY_EDITOR
            if (!EditorApplication.isPlaying)
            {
                if (m_CollectObjects == CollectObjects.All)
                {
                    UnityEditor.AI.NavMeshBuilder.CollectSourcesInStage(
                        null, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, gameObject.scene, sources);
                }
                else if (m_CollectObjects == CollectObjects.Children)
                {
                    UnityEditor.AI.NavMeshBuilder.CollectSourcesInStage(
                        transform, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, gameObject.scene, sources);
                }
                else if (m_CollectObjects == CollectObjects.Volume)
                {
                    Matrix4x4 localToWorld = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
                    var       worldBounds  = GetWorldBounds(localToWorld, new Bounds(m_Center, m_Size));

                    UnityEditor.AI.NavMeshBuilder.CollectSourcesInStage(
                        worldBounds, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, gameObject.scene, sources);
                }
            }
            else
#endif
            {
                if (m_CollectObjects == CollectObjects.All)
                {
                    NavMeshBuilder.CollectSources(null, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources);
                }
                else if (m_CollectObjects == CollectObjects.Children)
                {
                    NavMeshBuilder.CollectSources(transform, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources);
                }
                else if (m_CollectObjects == CollectObjects.Volume)
                {
                    Matrix4x4 localToWorld = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
                    var       worldBounds  = GetWorldBounds(localToWorld, new Bounds(m_Center, m_Size));
                    NavMeshBuilder.CollectSources(worldBounds, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources);
                }
            }

            // --- --- --- Terrain trees --- --- ---

            Terrain[] terrains = GameObject.FindObjectsOfType <Terrain>();

            if (terrains.Length > 0)
            {
                foreach (Terrain item in terrains)
                {
                    Terrain     terrain     = item.GetComponent <Terrain>();
                    TerrainData terrainData = terrain.terrainData;
                    Vector3     size        = Terrain.activeTerrain.terrainData.size;
                    Vector3     terrainPos  = terrain.GetPosition();
                    if (m_Debug)
                    {
                        Debug.Log("terrainPos = " + terrainPos);
                    }
                    int treesArea = NavMesh.GetAreaFromName("Not Walkable");
                    if (treesArea < 0)
                    {
                        Debug.LogError("Unrecognized area name! The default area will be used instead.");
                        treesArea = 0;
                    }

                    TreePrototype[] treePrototypes = terrainData.treePrototypes;
                    TreeInstance[]  treeInstances  = terrainData.treeInstances;
                    if (m_Debug)
                    {
                        Debug.Log("trees found = " + treeInstances.Length);
                    }
                    for (int i = 0; i < treeInstances.Length; i++)
                    {
                        //treeInstances[i] is the current ACTUAL tree we're going over.
                        //the tree prototype is the "template" used by this tree.
                        TreePrototype prototype = treePrototypes[treeInstances[i].prototypeIndex];
                        GameObject    prefab    = prototype.prefab;

                        NavMeshObstacle obstacle     = prefab.GetComponent <NavMeshObstacle>();
                        Collider        collider     = prefab.GetComponentInChildren <Collider>();
                        bool            obstacleBool = obstacle != null && (m_SelectionType == SelectionType.All || m_SelectionType == SelectionType.Obstacles);
                        bool            colliderBool = collider != null && (m_SelectionType == SelectionType.All || m_SelectionType == SelectionType.Colliders);
                        if (obstacleBool || colliderBool)
                        {
                            Vector3 center = Vector3.zero;
                            if (obstacle != null)
                            {
                                center = obstacle.center;
                            }
                            else if (collider != null)
                            {
                                center = collider.bounds.center;
                            }

                            if (m_Debug)
                            {
                                Debug.Log("treeInstances[" + i + "] info:\n" + treeInstances[i].position + " " + treeInstances[i].rotation + " " + treeInstances[i].widthScale + " " + treeInstances[i].heightScale);
                            }
                            Vector3 worldTreePos = terrainPos + Vector3.Scale(treeInstances[i].position, size) + center;

                            Quaternion worldTreeRot   = Quaternion.Euler(0, treeInstances[i].rotation * Mathf.Rad2Deg, 0);
                            Vector3    worldTreeScale = new Vector3(treeInstances[i].widthScale, treeInstances[i].heightScale, treeInstances[i].widthScale);
                            if (m_Debug)
                            {
                                Debug.Log("CREATED MATRIX FOR TRS:\nworldTreePos = " + worldTreePos + "\nworldTreeRot = " + worldTreeRot + "\nworldTreeScale = " + worldTreeScale);
                            }

                            NavMeshBuildSource src = new NavMeshBuildSource();
                            src.transform = Matrix4x4.TRS(worldTreePos, worldTreeRot, worldTreeScale);

                            if (obstacleBool)
                            {
                                switch (obstacle.shape)
                                {
                                case NavMeshObstacleShape.Capsule:
                                    src.shape = NavMeshBuildSourceShape.Capsule;

                                    //Unity 2019.2.0f1: BUG!! navMeshObstacle.height returns exactly HALF of the actual height of the obstacle.
                                    //Use the size property instead.
                                    src.size = obstacle.size;
                                    break;

                                case NavMeshObstacleShape.Box:
                                    src.shape = NavMeshBuildSourceShape.Box;
                                    src.size  = obstacle.size;
                                    break;

                                default:
                                    Debug.LogError("Unsupported type of " + typeof(NavMeshObstacleShape).Name
                                                   + " for the building of the " + typeof(NavMeshSurface).Name + "! (" + obstacle.shape + ")");
                                    break;
                                }
                            }
                            else if (colliderBool)
                            {
                                if (collider is CapsuleCollider)
                                {
                                    src.shape = NavMeshBuildSourceShape.Capsule;

                                    //Unity 2019.2.0f1: BUG!! navMeshObstacle.height returns exactly HALF of the actual height of the obstacle.
                                    //Use the size property instead.
                                    src.size = ((CapsuleCollider)collider).radius * Vector3.one * m_ColliderTolerance;
                                }
                                else if (collider is BoxCollider)
                                {
                                    src.shape = NavMeshBuildSourceShape.Box;
                                    src.size  = collider.bounds.size * m_ColliderTolerance;
                                }
                                else
                                {
                                    Debug.LogError("Unsupported type of " + typeof(NavMeshObstacleShape).Name
                                                   + " for the building of the " + typeof(NavMeshSurface).Name + "! (" + obstacle.shape + ")");
                                }
                            }

                            // Scale size
                            src.size = Vector3.Scale(src.size, prefab.transform.localScale);
                            if (m_Debug)
                            {
                                Debug.Log("src.size = " + src.size);
                            }
                            src.area = treesArea;
                            sources.Add(src);
                        }
                    }
                }
            }

            // --- --- --- End of Terrain trees --- --- ---

            if (m_IgnoreNavMeshAgent)
            {
                sources.RemoveAll((x) => (x.component != null && x.component.gameObject.GetComponent <NavMeshAgent>() != null));
            }

            if (m_IgnoreNavMeshObstacle)
            {
                sources.RemoveAll((x) => (x.component != null && x.component.gameObject.GetComponent <NavMeshObstacle>() != null));
            }

            AppendModifierVolumes(ref sources);

            return(sources);
        }
Esempio n. 19
0
        void AddObstacles(List <NavMeshBuildSource> sources)
        {
            // ---------Terrain trees-- - ------

            Terrain     terrain     = Terrain.activeTerrain;
            TerrainData terrainData = terrain.terrainData;
            Vector3     size        = Terrain.activeTerrain.terrainData.size;
            Vector3     terrainPos  = terrain.GetPosition();
            //Debug.Log("terrainPos = " + terrainPos);
            int treesArea = NavMesh.GetAreaFromName("Not Walkable");

            if (treesArea < 0)
            {
                Debug.LogError("Unrecognized area name! The default area will be used instead.");
                treesArea = 0;
            }

            TreePrototype[] treePrototypes = terrainData.treePrototypes;
            TreeInstance[]  treeInstances  = terrainData.treeInstances;
            for (int i = 0; i < treeInstances.Length; i++)
            {
                //treeInstances[i] is the current ACTUAL tree we're going over.
                //the tree prototype is the "template" used by this tree.
                TreePrototype   prototype = treePrototypes[treeInstances[i].prototypeIndex];
                GameObject      prefab    = prototype.prefab;
                NavMeshObstacle obstacle  = prefab.GetComponent <NavMeshObstacle>();
                if (obstacle == null)
                {
                    continue;
                }

                //Debug.Log("treeInstances[" + i + "] info:\n" + treeInstances[i].position + " " + treeInstances[i].rotation + " " + treeInstances[i].widthScale + " " + treeInstances[i].heightScale);
                Vector3 worldTreePos = terrainPos + Vector3.Scale(treeInstances[i].position, size)
                                       + obstacle.center;
                Quaternion worldTreeRot   = Quaternion.Euler(0, treeInstances[i].rotation * Mathf.Rad2Deg, 0);
                Vector3    worldTreeScale = new Vector3(treeInstances[i].widthScale, treeInstances[i].heightScale, treeInstances[i].widthScale);
                //Debug.Log("CREATED MATRIX FOR TRS:\nworldTreePos = " + worldTreePos + "\nworldTreeRot = " + worldTreeRot + "\nworldTreeScale = " + worldTreeScale);

                NavMeshBuildSource src = new NavMeshBuildSource();
                src.transform = Matrix4x4.TRS(worldTreePos, worldTreeRot, worldTreeScale);

                switch (obstacle.shape)
                {
                case NavMeshObstacleShape.Capsule:
                    src.shape = NavMeshBuildSourceShape.Capsule;

                    //Unity 2019.2.0f1: BUG!! navMeshObstacle.height returns exactly HALF of the actual height of the obstacle.
                    //Use the size property instead.
                    src.size = obstacle.size;
                    break;

                case NavMeshObstacleShape.Box:
                    src.shape = NavMeshBuildSourceShape.Box;
                    src.size  = obstacle.size;
                    break;

                default:
                    Debug.LogError("Unsupported type of " + typeof(NavMeshObstacleShape).Name
                                   + " for the building of the " + typeof(NavMeshSurface).Name + "! (" + obstacle.shape + ")");
                    break;
                }
                src.size = Vector3.Scale(src.size, prefab.transform.localScale);
                //Debug.Log("src.size = " + src.size);
                src.area = treesArea;
                sources.Add(src);
            }

            // --- --- --- End of Terrain trees --- --- ---
        }
Esempio n. 20
0
 void Awake()
 {
     obstacle = GetComponent <UnityEngine.AI.NavMeshObstacle>();
     locked   = false;
 }
Esempio n. 21
0
 // Start is called before the first frame update
 void Start()
 {
     enterText.enabled = false;
     exitText.enabled  = false;
     obstacle          = GetComponent <UnityEngine.AI.NavMeshObstacle>();
 }
Esempio n. 22
0
    //passes in the main FBX's gameobject as well as the current gameobject that needs to be edited
    private void ApplyLayersToSubObjects(GameObject fbxGameObject, GameObject currentObject)
    {
        //save the imported FBX's obj transform into a var for use later
        Transform objTransform = currentObject.transform;

        //loop through all of the children in the transform we we're passed
        for (int i = 0; i < objTransform.childCount; i++)
        {
            //get the current child
            Transform child = objTransform.GetChild(i);
            if (child == null)
            {
                continue;
            }

            string lowerCaseName = child.name.ToLower();

            if (lowerCaseName.Contains("highpoly") || lowerCaseName.Contains("lod_mesh"))
            {
                continue;
            }

            //if this object has any children then we need to tag and layer those properly too
            if (child.childCount > 0)
            {
                ApplyLayersToSubObjects(fbxGameObject, child.gameObject);
            }

            //if the object contains the tag obstacle that means we need to tag and layer it oppropriatly
            if (lowerCaseName.Contains("obstacle"))
            {
                child.tag = "MapGeometry";
                child.gameObject.layer = LayerMask.NameToLayer("MapGeometry");
            }

            if (lowerCaseName.Contains("portal"))
            {
                Portal     portal = child.gameObject.AddComponent <Portal>();
                GameObject obj    = new GameObject();
                obj.transform.parent = portal.transform;
                obj.AddComponent <Camera>();
            }

            if (lowerCaseName.Contains("spawnpoint"))
            {
                //check if it's a player spawn point
                if (lowerCaseName.Contains("player"))
                {
                    child.gameObject.AddComponent <PlayerSpawnPoint>();
                }
                //check if it's an enemy spawn point
                else if (lowerCaseName.Contains("enemy"))
                {
                    m_NumberOfSpawnPoints++;
                    EnemySpawnPoint spawnPoint = child.gameObject.AddComponent <EnemySpawnPoint>();

                    IslandRoom r = fbxGameObject.GetComponent <IslandRoom>();
                    if (r.RoomSpawnPoints == null)
                    {
                        r.RoomSpawnPoints = new System.Collections.Generic.List <EnemySpawnPoint>();
                    }
                    r.RoomSpawnPoints.Add(spawnPoint);
                }
                //check if it's an item spawn point
                else if (lowerCaseName.Contains("item"))
                {
                    child.gameObject.AddComponent <ItemSpawnPoint>();
                }
            }

            //next we check for "dimentions" via the name. If it's a box throw on a box collider
            if (lowerCaseName.Contains("box"))
            {
                child.gameObject.AddComponent <BoxCollider>();
            }
            //if it's a circle or a sphere then we need to add a sphere collider to it
            else if (lowerCaseName.Contains("sphere") || lowerCaseName.Contains("circle"))
            {
                child.gameObject.AddComponent <SphereCollider>();
            }
            //if it's a capsule then add a capsule collider
            else if (lowerCaseName.Contains("capsule"))
            {
                child.gameObject.AddComponent <CapsuleCollider>();
            }
            //if it's a mesh collider then we begrudingly add a mesh collider to it
            else if (lowerCaseName.Contains("mesh") && !lowerCaseName.Contains("highpoly"))
            {
                m_MeshColliderCount++;
                child.gameObject.AddComponent <MeshCollider>();
                Transform findHighPoly = fbxGameObject.transform;

                for (int j = 0; j < findHighPoly.childCount; j++)
                {
                    if (findHighPoly.GetChild(j).name.Contains("highpoly") &&
                        findHighPoly.GetChild(j).name.Contains(lowerCaseName))
                    {
                        child.GetComponent <MeshFilter>().mesh = findHighPoly.GetComponent <MeshFilter>().mesh;
                        Editor.DestroyImmediate(findHighPoly.gameObject);
                        break;
                    }
                }
            }
            else if (lowerCaseName.Contains("castpoint"))
            {
                child.gameObject.AddComponent <CastPoints>();
            }

            if ((lowerCaseName.Contains("traverse") || lowerCaseName.Contains("traversable")) == false)
            {
                UnityEngine.AI.NavMeshObstacle obstacle = child.gameObject.AddComponent <UnityEngine.AI.NavMeshObstacle>();
                obstacle.carving = true;
                if (child.GetComponent <Collider>() != null)
                {
                    child.GetComponent <Collider>().material = Resources.Load <PhysicMaterial>("PhysicsMaterials/WallMaterial");
                }
            }

            if (lowerCaseName.Contains("invisablewall"))
            {
                child.gameObject.GetComponent <MeshFilter>().mesh = null;
            }
        }
    }
Esempio n. 23
0
 void OnEnable()
 {
     obstacle = GetComponent <UnityEngine.AI.NavMeshObstacle>();
     wasSeen  = false;
 }