/// <summary> /// Takes this legacy elementary constraint, creates a new instance (added to gameObject) and /// copies all values/objects to the new instance. /// </summary> /// <param name="gameObject">Game object to add the new version of the elementary constraint to.</param> /// <returns>New added elementary constraint instance.</returns> public ElementaryConstraint FromLegacy(GameObject gameObject) { ElementaryConstraint target = gameObject.AddComponent(GetType()) as ElementaryConstraint; target.Construct(this); return(target); }
/// <summary> /// Create instance given temporary native elementary constraint. /// </summary> /// <param name="tmpEc">Temporary elementary constraint.</param> /// <returns>New instance, as similar as possible, to the given native elementary constraint.</returns> public static ElementaryConstraint Create(GameObject gameObject, agx.ElementaryConstraint tmpEc) { if (tmpEc == null) { return(null); } ElementaryConstraint elementaryConstraint = null; // It's possible to know the type of controllers. We're basically not // interested in knowing the type of the ordinary ones. Type controllerType = null; if (agx.RangeController.safeCast(tmpEc) != null) { controllerType = agx.RangeController.safeCast(tmpEc).GetType(); } else if (agx.TargetSpeedController.safeCast(tmpEc) != null) { controllerType = agx.TargetSpeedController.safeCast(tmpEc).GetType(); } else if (agx.LockController.safeCast(tmpEc) != null) { controllerType = agx.LockController.safeCast(tmpEc).GetType(); } else if (agx.ScrewController.safeCast(tmpEc) != null) { controllerType = agx.ScrewController.safeCast(tmpEc).GetType(); } else if (agx.ElectricMotorController.safeCast(tmpEc) != null) { controllerType = agx.ElectricMotorController.safeCast(tmpEc).GetType(); } // This is a controller, instantiate the controller. if (controllerType != null) { elementaryConstraint = gameObject.AddComponent(Type.GetType("AgXUnity." + controllerType.Name)) as ElementaryConstraint; } // This is an ordinary elementary constraint. else { elementaryConstraint = gameObject.AddComponent <ElementaryConstraint>(); } // Copies data from the native instance. elementaryConstraint.Construct(tmpEc); return(elementaryConstraint); }