// merges constraints from a given actor with this one. public void Merge(ObiActor actor, IObiConstraints other) { var others = other as ObiConstraints <T>; if (others == null || !other.GetConstraintType().HasValue) { return; } int constraintType = (int)other.GetConstraintType().Value; // clear batch offsets for this constraint type: actor.solverBatchOffsets[constraintType].Clear(); // create new empty batches if needed: int newBatches = Mathf.Max(0, others.GetBatchCount() - GetBatchCount()); for (int i = 0; i < newBatches; ++i) { AddBatch(CreateBatch()); } for (int i = 0; i < other.GetBatchCount(); ++i) { // store this batch's offset: actor.solverBatchOffsets[constraintType].Add(batches[i].activeConstraintCount); // merge both batches: batches[i].Merge(actor, others.batches[i]); } }
private void LoadBlueprintConstraints(ObiActorBlueprint bp) { m_Constraints = new IObiConstraints[Oni.ConstraintTypeCount]; // Iterate trough all non-null constraint types in the blueprint that have at least 1 batch: foreach (IObiConstraints constraintData in bp.GetConstraints()) { // Create runtime counterpart IObiConstraints runtimeConstraints = constraintData.Clone(this); if (runtimeConstraints.GetConstraintType().HasValue) { // Store a reference to it in the constraint map, so that they can be accessed by type enum: m_Constraints[(int)runtimeConstraints.GetConstraintType().Value] = runtimeConstraints; // Add it to solver: runtimeConstraints.AddToSolver(); } } }