void UpdateObstacle() { if (CustomObstacle != null && Obstacle != null) { #if UNITY_EDITOR Undo.RecordObject(Obstacle, ""); #endif CustomNavMeshObstacle.TransferObstacleValues(CustomObstacle, Obstacle); Obstacle.center = Vector3.zero; // keep mesh centered } }
/// <summary> /// Transfers the parameters of a CustomNavMeshObstacle to a NavMeshObstacle. /// </summary> /// <param name="sourceObs">The CustomNavMeshObstacle to copy</param> /// <param name="destObs">The destination NavMeshObstacle</param> public static void TransferObstacleValues(CustomNavMeshObstacle sourceObs, NavMeshObstacle destObs) { // only assigning the properties that are different would yield no performance benefits destObs.carveOnlyStationary = sourceObs.m_CarveOnlyStationary; destObs.carving = sourceObs.m_Carve; destObs.carvingMoveThreshold = sourceObs.m_MoveThreshold; destObs.carvingTimeToStationary = sourceObs.m_TimeToStationary; destObs.center = sourceObs.m_Center; destObs.shape = sourceObs.m_Shape; destObs.size = sourceObs.m_Size; }
private void OnEnable() { obstacle = target as CustomNavMeshObstacle; navMeshObstacle = obstacle.GetComponent <NavMeshObstacle>(); if (navMeshObstacle != null) { // prevent the user from changing the obstacle through the NavMeshObstacle's inspector navMeshObstacle.hideFlags = HideFlags.HideInInspector; } m_Shape = serializedObject.FindProperty("m_Shape"); m_Center = serializedObject.FindProperty("m_Center"); m_Size = serializedObject.FindProperty("m_Size"); m_Carve = serializedObject.FindProperty("m_Carve"); m_MoveThreshold = serializedObject.FindProperty("m_MoveThreshold"); m_TimeToStationary = serializedObject.FindProperty("m_TimeToStationary"); m_CarveOnlyStationary = serializedObject.FindProperty("m_CarveOnlyStationary"); }