Ejemplo n.º 1
0
        public void Initialize()
        {
            MeshManager.get.RegisterMesh(this);

            name = name.Replace("(Clone)", "").Trim();

            _meshFilter  = GetComponent <MeshFilter>();
            Mesh         = _meshFilter.mesh;
            MeshRenderer = GetComponent <MeshRenderer>();
            Mesh.MarkDynamic();
            ResetTransformToSpawn();

            // First copy the Mesh arrays into a RowMajor UMeshData instance
            DataRowMajor = new UMeshData(Mesh);
            // Then create the LibiglBehaviour instance which will create a ColMajor instance of the data in the State
            Behaviour = new LibiglBehaviour(this);

            DataRowMajor.LinkBehaviourState(Behaviour);

            BoundingBox = Instantiate(MeshManager.get.boundingBoxPrefab, Vector3.zero, Quaternion.identity, transform)
                          .transform;
            _boundingBoxRenderer = BoundingBox.GetComponent <MeshRenderer>();
            UpdateBoundingBoxSize();
            RepaintBounds();

            MeshManager.OnActiveMeshChanged += OnActiveMeshChanged;

#if UNITY_EDITOR
            DisposeBeforeUnload += Dispose;
#endif
        }
Ejemplo n.º 2
0
        private void Dispose()
        {
            // Dispose all Native data (NativeArrays and anything created with 'new' in C++)
            // Note: may be called twice in the editor
            if (_workerThread != null)
            {
                try
                {
                    _workerThread.Abort();
                    _workerThread.Join();
                }
                catch (Exception e)
                {
                    Debug.LogError(e.ToString());
                }

                _workerThread = null;
            }

            DataRowMajor?.Dispose();
            DataRowMajor = null;
            Behaviour?.Dispose();
            Behaviour = null;

            MeshManager.get.UnregisterMesh(this);

#if UNITY_EDITOR
            DisposeBeforeUnload -= Dispose;
#endif
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initialize the UMeshData with shared data with the <paramref name="behaviour"/>.
        /// </summary>
        public unsafe void LinkBehaviourState(LibiglBehaviour behaviour)
        {
            S = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <uint>(behaviour.State->SPtr, VSize,
                                                                                 Allocator.None);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref S, AtomicSafetyHandle.Create());
#endif
        }