Ejemplo n.º 1
0
 public static void RemoveSources(this IConstraint self)
 {
     for (var i = self.sourceCount - 1; i >= 0; --i)
     {
         self.RemoveSource(i);
     }
 }
Ejemplo n.º 2
0
        public static void RemoveConstraint <T>(GameObject gobject) where T : UnityEngine.Component
        {
            T           component  = gobject.GetComponent <T>();
            IConstraint constraint = component as IConstraint;

            ParametersController parametersController = gobject.GetComponent <ParametersController>();

            if (null != parametersController)
            {
                ConstraintType constraintType = ConstraintType.Unknown;
                switch (component)
                {
                case ParentConstraint _:
                    constraintType = ConstraintType.Parent;
                    break;

                case LookAtConstraint _:
                    constraintType = ConstraintType.LookAt;
                    break;
                }

                foreach (Constraint con in constraints)
                {
                    if (con.gobject == gobject && con.constraintType == constraintType)
                    {
                        GameObject.Destroy(con.lineGameObject);
                        constraints.Remove(con);
                        break;
                    }
                }
            }

            GameObject           source = constraint.GetSource(0).sourceTransform.gameObject;
            ParametersController sourceParametersController = source.GetComponent <ParametersController>();

            if (null != sourceParametersController)
            {
                sourceParametersController.RemoveConstraintHolder(gobject);
            }

            constraint.RemoveSource(0);
            GameObject.Destroy(component);
            GlobalState.FireObjectConstraint(gobject);
        }