Пример #1
0
        public override void OnInspectorGUI()
        {
            PathFinderScene myTarget = (PathFinderScene)target;

            myTarget.sceneNavmeshData = (SceneNavmeshData)EditorGUILayout.ObjectField(new GUIContent("Navmesh Data",
                                                                                                     "Scriptable object with serialized NavMesh data. You can save all current data to it in pathfinder menu. Later it will be loaded from here"),
                                                                                      myTarget.sceneNavmeshData, typeof(SceneNavmeshData), false);

            if (GUILayout.Button("Load"))
            {
                PathFinder.LoadCurrentSceneData();
            }
        }
        public static void CallThisWhenSceneObjectWasGone()
        {
            if (_sceneInstance == null)//if it's already null then do nothing
            {
                return;
            }

            Debug.Log("PathFinder: scene object was destroyed. clearing data and debug");
            _sceneInstance = null;

            ClearAll();
#if UNITY_EDITOR
            Debuger_K.ClearGeneric();
            Debuger_K.ClearChunksDebug();
#endif
        }
        //return if scene object was loaded
        public static bool Init()
        {
            if (!_areInit)
            {
                _areInit = true;
                //asume init was in main thread
                _mainThreadID = Thread.CurrentThread.ManagedThreadId;
            }

            if (Thread.CurrentThread.ManagedThreadId != _mainThreadID)
            {
                return(false);
            }


            if (_settings == null)
            {
                _settings = PathFinderSettings.LoadSettings();
                foreach (var item in _settings.areaLibrary)
                {
                    _hashData.AddAreaHash(item);
                }
#if UNITY_EDITOR
                if (Debuger_K.doDebug)
                {
                    Debug.LogFormat("settings init");
                }
#endif
            }

            if (_sceneInstance == null || _sceneInstance.gameObject == null)
            {
                try {
                    GameObject go = GameObject.Find(_settings.helperName);

                    if (go == null)
                    {
                        go = new GameObject(_settings.helperName);
                    }

                    _sceneInstance = go.GetComponent <PathFinderScene>();

                    if (_sceneInstance == null)
                    {
                        _sceneInstance = go.AddComponent <PathFinderScene>();
                    }

                    _sceneInstance.AddCoroutine((int)NavMeshTaskType.navMesh, TemplatePopulationLoop());
                    _sceneInstance.AddCoroutine((int)NavMeshTaskType.graphFinish, ChunkConnection());
                    _sceneInstance.AddCoroutine((int)NavMeshTaskType.disconnect, ChunkDisconnection());

                    _sceneInstance.InitComputeShaderRasterization3D(_settings.ComputeShaderRasterization3D);
                    _sceneInstance.InitComputeShaderRasterization2D(_settings.ComputeShaderRasterization2D);

                    _sceneInstance.Init();
                }
                catch (Exception e) {
                    Debug.LogError(e);
                    throw;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }