/// <summary> /// Create a cable given route, radius, resolution and material. /// </summary> /// <param name="radius">Radius of the cable.</param> /// <param name="resolutionPerUnitLength">Resolution of the cable.</param> /// <param name="material">Shape material of the cable.</param> /// <returns>Cable component.</returns> public static Cable CreateCable(float radius = 0.05f, float resolutionPerUnitLength = 5.0f, ShapeMaterial material = null) { GameObject go = new GameObject(CreateName <Cable>()); Cable cable = go.AddComponent <Cable>(); cable.Radius = radius; cable.ResolutionPerUnitLength = resolutionPerUnitLength; cable.Material = material; return(cable); }
public bool IsListening(Cable cable) { var invocationList = OnPropertyUpdated.GetInvocationList(); foreach (var listener in invocationList) { if (cable.Equals(listener.Target)) { return(true); } } return(false); }
private Data CollectData(bool propagateToChildren) { Data data = new Data(); RigidBody rb = GetComponent <RigidBody>(); Collide.Shape shape = rb != null ? null : GetComponent <Collide.Shape>(); Wire wire = rb != null || shape != null ? null : GetComponent <Wire>(); Cable cable = rb != null || shape != null || wire != null ? null : GetComponent <Cable>(); bool allPredefinedAreNull = rb == null && shape == null && wire == null && cable == null; if (allPredefinedAreNull && propagateToChildren) { data.Shapes = GetComponentsInChildren <Collide.Shape>(); data.Wires = GetComponentsInChildren <Wire>(); data.Cables = GetComponentsInChildren <Cable>(); } // A wire is by definition independent of PropagateToChildren, since // it's not defined to add children to a wire game object. else if (wire != null) { data.Wires = new Wire[] { wire }; } // Same logics for Cable. else if (cable != null) { data.Cables = new Cable[] { cable }; } // Bodies have shapes so if 'rb' != null we should collect all shape children // independent of 'propagate' flag. // If 'shape' != null and propagate is true we have the same condition as for bodies. else if (rb != null || shape != null || (rb == null && shape == null && propagateToChildren)) { data.Shapes = shape != null && !propagateToChildren?GetComponents <Collide.Shape>() : shape != null || rb != null?GetComponentsInChildren <Collide.Shape>() : // Both shape and rb == null and PropagateToChildren == true. GetComponentsInChildren <Collide.Shape>(); } else { // These groups has no effect. Debug.LogWarning("Collision groups has no effect. Are you missing a PropagateToChildren = true?", this); } return(data); }