// MANAGE SAMPLING // // // Does the actual sampling. override public void ManageSampling(int particleIndex) { Vector3 testedPosition = Vector3.zero; Collider theCollider; // If this is the first frame of a new particle then we skip sampling and wait for the next round // when the position stack will have been evaluated and updated from its default (0,0,0) value. if (particleIndex >= 0 && ownerBlueprint.ownerEmitter.particleTimes[particleIndex] < 0.1) { return; // HACK: There are misses when it's less than 0.1 for some reason. } if ((particleIndex < 0 && ShouldSample()) || (particleIndex >= 0 && ShouldSample(particleIndex))) { if (particleIndex < 0) { testedPosition = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, AmpsHelpers.eCurveInputs.EmitterPosition); } else { testedPosition = AmpsHelpers.GetSystemProperty(ownerBlueprint, particleIndex, AmpsHelpers.eCurveInputs.Position); } theCollider = sampledObject.GetValue().GetComponent <Collider>(); if (theCollider != null) { Vector3 theRayVector = theCollider.transform.position - testedPosition; Ray theRay = new Ray(testedPosition, Vector3.Normalize(theRayVector)); RaycastHit theRaycastHit = new RaycastHit(); bool gotIntersection = theCollider.Raycast(theRay, out theRaycastHit, theRayVector.magnitude); //Debug.DrawLine(theCollider.transform.position, testedPosition); if (gotIntersection) { isInsideFlags[particleIndex] = false; } else { isInsideFlags[particleIndex] = true; } } } }
// MANAGE SAMPLING // // // Does the actual sampling. override public void ManageSampling(int particleIndex) { Vector3 v = Vector3.zero; bool shouldIndeedSample = (particleIndex < 0 && ShouldSample()) || (particleIndex >= 0 && ShouldSample(particleIndex)); // Leave if it's not time yet to sample. if (shouldIndeedSample == false) { return; } // INVALID SAMPLE: Referenced GameObject is not available. GameObject theGameObject = sampledObject.GetValue(); if (theGameObject == null) { isValidSample[particleIndex] = false; return; } switch (sampledTransformElement.GetValue()) { case (int)eTransformElements.Position: v = theGameObject.transform.position; break; case (int)eTransformElements.Rotation: v = theGameObject.transform.rotation.eulerAngles; break; case (int)eTransformElements.Scale: v = theGameObject.transform.localScale; break; } vectors[particleIndex] = new Vector4(v.x, v.y, v.z, 0); isValidSample[particleIndex] = true; }