/// <summary> /// If no "Node" instance, this method tries to create one /// given the Collide.Shape component in this game object. /// </summary> /// <returns>True if the node was created - otherwise false.</returns> private bool TryInitialize(Shape shape, DebugRenderManager manager) { if (Node != null) { return(false); } Collide.Mesh mesh = shape as Collide.Mesh; HeightField heightField = shape as HeightField; if (mesh != null) { Node = InitializeMesh(mesh); } else if (heightField != null) { Node = InitializeHeightField(heightField); } else { Node = PrefabLoader.Instantiate <GameObject>(PrefabName); Node.transform.localScale = GetShape().GetScale(); } if (Node != null) { var renderers = Node.GetComponentsInChildren <Renderer>(); foreach (var renderer in renderers) { renderer.sharedMaterial = manager.ShapeRenderMaterial; } } return(Node != null); }
/// <summary> /// If no "Node" instance, this method tries to create one /// given the Collide.Shape component in this game object. /// </summary> /// <returns>True if the node was created - otherwise false.</returns> private bool TryInitialize(Shape shape, DebugRenderManager manager) { if (Node != null) { return(false); } Collide.Mesh mesh = shape as Collide.Mesh; HeightField heightField = shape as HeightField; Cone cone = shape as Cone; HollowCone hollowCone = shape as HollowCone; HollowCylinder hollowCylinder = shape as HollowCylinder; if (mesh != null) { Node = InitializeMesh(mesh); } else if (heightField != null) { Node = InitializeHeightField(heightField); } else if (hollowCone != null) { Node = new GameObject(PrefabName); Node.AddComponent <MeshRenderer>().sharedMaterial = manager.ShapeRenderMaterial; Node.AddComponent <MeshFilter>().sharedMesh = ShapeVisualHollowCone.GenerateMesh(shape); } else if (hollowCylinder != null) { Node = new GameObject(PrefabName); Node.AddComponent <MeshRenderer>().sharedMaterial = manager.ShapeRenderMaterial; Node.AddComponent <MeshFilter>().sharedMesh = ShapeVisualHollowCylinder.GenerateMesh(shape); } else if (cone != null) { Node = new GameObject(PrefabName); Node.AddComponent <MeshRenderer>().sharedMaterial = manager.ShapeRenderMaterial; Node.AddComponent <MeshFilter>().sharedMesh = ShapeVisualCone.GenerateMesh(shape); } else { Node = PrefabLoader.Instantiate <GameObject>(PrefabName); Node.transform.localScale = GetShape().GetScale(); } if (Node != null) { var renderers = Node.GetComponentsInChildren <Renderer>(); foreach (var renderer in renderers) { renderer.sharedMaterial = manager.ShapeRenderMaterial; } } return(Node != null); }
/// <summary> /// Creates debug rendering node if it doesn't already exist and /// synchronizes the rendered object transform to be the same as the shape. /// </summary> /// <param name="manager"></param> public override void Synchronize(DebugRenderManager manager) { try { Shape shape = GetShape(); bool nodeCreated = TryInitialize(shape, manager); if (Node == null) { return; } // Node created - set properties and extra components. if (nodeCreated) { Node.hideFlags = HideFlags.DontSave; Node.transform.hideFlags = HideFlags.DontSave | HideFlags.HideInInspector; Node.GetOrCreateComponent <OnSelectionProxy>().Component = shape; foreach (Transform child in Node.transform) { child.gameObject.GetOrCreateComponent <OnSelectionProxy>().Component = shape; } } // Forcing the debug render node to be parent to the static DebugRenderManger. if (Node.transform.parent != manager.gameObject.transform) { manager.gameObject.AddChild(Node); } Node.transform.position = shape.transform.position; Node.transform.rotation = shape.transform.rotation; SynchronizeScale(shape); } catch (System.Exception) { } }
/// <summary> /// Callback from the DebugRenderManager each editor "Update" or /// after each simulation step when the application is running. /// /// Synchronize the transform of the "Node" game object - create the "Node" /// instance if it's null. /// </summary> public abstract void Synchronize(DebugRenderManager manager);