virtual public float convertSizeToPixels(float inputScalar, MUnits units, bool isOffset = false) { var sz = Vector3.one * inputScalar; sz = convertSizeToPixels(sz, units, isOffset); return(sz[0]); }
virtual public float[] convertSizeToPixels(float[] inputSz, MUnits units, bool isOffset = false) { float[] sz = new float[inputSz.Length]; inputSz.CopyTo(sz, 0); // relative units are assumed to be relative to parent, not this switch (units) { case MUnits.pixels: return(sz); case MUnits.normalized: if (mParent == null) { Debug.LogWarning("Unable to convert normalized size without parent"); return(sz); } var parentSize = convertSizeToPixels(mParent._Size, mParent._Units); for (int i = 0; i < sz.Length; i++) { sz[i] = parentSize[i] * sz[i]; } //Debug.LogFormat("Size: {0}", sz); return(sz); case MUnits.data: if (mParent == null) { Debug.LogWarning("Unable to convert data units without parent"); return(sz); } // look for [XYZ]Lim fields in parent to determine data span MAxes parentAxes = transform.parent.GetComponent <MAxes>(); if (parentAxes == null) { sz = mParent.convertSizeToPixels(inputSz, units, isOffset); //Debug.LogWarning("Unable to convert data units without an MAxes parent"); return(sz); } var tmp = new Vector3(sz[0], sz[1], sz[2]); tmp = parentAxes.convertFromDataToPixelSpace(tmp, isOffset); sz = new float[] { tmp.x, tmp.y, tmp.z }; return(sz); case MUnits.Unity: return(_Position); default: Debug.LogErrorFormat("Unable to handle units: {0}", units); return(sz); } }
virtual public Vector3 convertSizeToPixels(Vector3 inputSz, MUnits units, bool isOffset = false) { var toReturn = convertSizeToPixels(new float[] { inputSz.x, inputSz.y, inputSz.z }, units, isOffset); return(new Vector3(toReturn[0], toReturn[1], toReturn[2])); }