//=============================================================================================== // Private methods //=============================================================================================== protected override void CheckCollider(Component component) { var effectorType = effector != null?effector.GetType() : null; //get existing TempEffectors.Clear(); component.GetComponents(TempEffectors); //find target Effector2D targetEffector = null; for (var i = TempEffectors.Count - 1; i >= 0; i--) { var tempEffector = TempEffectors[i]; if (effectorType == tempEffector.GetType()) { targetEffector = tempEffector; } else { BGCurve.DestroyIt(tempEffector); } } TempEffectors.Clear(); if (effector == null) { return; } if (targetEffector == null) { targetEffector = (Effector2D)component.gameObject.AddComponent(effectorType); } //copy values var fields = GetFields(effectorType); foreach (var field in fields) { if (field.IsStatic) { continue; } field.SetValue(targetEffector, field.GetValue(effector)); } var props = GetProperties(effectorType); foreach (var prop in props) { if (!prop.CanWrite || !prop.CanWrite || prop.Name == "name") { continue; } prop.SetValue(targetEffector, prop.GetValue(effector, null), null); } }
public static void CheckEffectorWarnings(Collider2D collider) { if (!collider.usedByEffector) { return; } Effector2D component = collider.GetComponent <Effector2D>(); if (component == null || !component.enabled) { EditorGUILayout.HelpBox("This collider will not function with an effector until there is at least one enabled 2D effector on this GameObject.", MessageType.Warning); if (component == null) { return; } } if (component.designedForNonTrigger && collider.isTrigger) { EditorGUILayout.HelpBox("This collider has 'Is Trigger' checked but this should be unchecked when used with the '" + component.GetType().Name + "' component which is designed to work with collisions.", MessageType.Warning); } else if (component.designedForTrigger && !collider.isTrigger) { EditorGUILayout.HelpBox("This collider has 'Is Trigger' unchecked but this should be checked when used with the '" + component.GetType().Name + "' component which is designed to work with triggers.", MessageType.Warning); } }