Ejemplo n.º 1
0
        public Mesh GetMesh(Sprite sprite)
        {
            Mesh mesh;

            if (map.ContainsKey(sprite))
            {
                mesh = map[sprite];
            }
            else
            {
                mesh = new Mesh();
                NavMeshBuilderNBLD.sprite2mesh(sprite, mesh);
                map.Add(sprite, mesh);
            }
            return(mesh);
        }
Ejemplo n.º 2
0
        List <NavMeshBuildSource> CollectSources()
        {
            var sources = new List <NavMeshBuildSource>();
            var markups = new List <NavMeshBuildMarkup>();

            List <NavMeshModifier> modifiers;

            if (m_CollectObjects == CollectObjectsNBLD.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 == CollectObjectsNBLD.All)
                {
                    UnityEditor.AI.NavMeshBuilder.CollectSourcesInStage(
                        null, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, gameObject.scene, sources);
                }
                else if (m_CollectObjects == CollectObjectsNBLD.Children)
                {
                    UnityEditor.AI.NavMeshBuilder.CollectSourcesInStage(
                        transform, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, gameObject.scene, sources);
                }
                else if (m_CollectObjects == CollectObjectsNBLD.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);
                }
                var builder = new NavMeshBuilderNBLDWrapper();
                builder.defaultArea     = defaultArea;
                builder.layerMask       = layerMask;
                builder.agentID         = agentTypeID;
                builder.useMeshPrefab   = useMeshPrefab;
                builder.overrideByGrid  = overrideByGrid;
                builder.compressBounds  = compressBounds;
                builder.overrideVector  = overrideVector;
                builder.CollectGeometry = useGeometry;
                builder.CollectBoth     = m_CollectBoth;
                builder.CollectObjects  = collectObjects;
                builder.parent          = gameObject;
                NavMeshBuilderNBLD.CollectSources(sources, builder);
            }
            else
#endif
            {
                if (m_CollectObjects == CollectObjectsNBLD.All)
                {
                    NavMeshBuilder.CollectSources(null, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources);
                }
                else if (m_CollectObjects == CollectObjectsNBLD.Children)
                {
                    NavMeshBuilder.CollectSources(transform, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources);
                }
                else if (m_CollectObjects == CollectObjectsNBLD.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);
                }
                var builder = new NavMeshBuilderNBLDWrapper();
                builder.defaultArea     = defaultArea;
                builder.layerMask       = layerMask;
                builder.agentID         = agentTypeID;
                builder.useMeshPrefab   = useMeshPrefab;
                builder.overrideByGrid  = overrideByGrid;
                builder.compressBounds  = compressBounds;
                builder.overrideVector  = overrideVector;
                builder.CollectGeometry = useGeometry;
                builder.CollectBoth     = m_CollectBoth;
                builder.CollectObjects  = collectObjects;
                builder.parent          = gameObject;
                NavMeshBuilderNBLD.CollectSources(sources, builder);
            }
            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);
        }