void StartRecording(Vector3 wantedVectorValue) { for (int i = 0; i < targets.Length; i++) { UIAnimation uiAnimation = target as UIAnimation; UIElement element = uiAnimation.GetComponent <UIElement>(); RectTransform elementRT = element.GetComponent <RectTransform>(); RectTransform holderRT = curLocalCustomPosition ? element.transform.parent.GetComponent <RectTransform>() : element.GetComponentInParent <Canvas>().GetComponent <RectTransform>(); float canvasWidth = holderRT.lossyScale.x * holderRT.rect.width; float canvasHeight = holderRT.lossyScale.y * holderRT.rect.height; if (wantedVectorValue == new Vector3(9999, 9999)) { float canvasStartX = holderRT.position.x - canvasWidth / 2; float canvasStartY = holderRT.position.y - canvasHeight / 2; Undo.RecordObject(uiAnimation, "Position"); wantedVectorValue = new Vector3((elementRT.position.x - canvasStartX) / canvasWidth, (elementRT.position.y - canvasStartY) / canvasHeight, elementRT.position.z); } element.MovementSection.startVectorValue = elementRT.position; Vector3 chp = wantedVectorValue; elementRT.position = new Vector3( holderRT.position.x + (chp.x - 0.5f) * canvasWidth, holderRT.position.y + (chp.y - 0.5f) * canvasHeight, elementRT.position.z); } }
void DiscardRecording() { UIAnimation uiAnimation = target as UIAnimation; UIElement element = uiAnimation.GetComponent <UIElement>(); RectTransform elementRT = element.GetComponent <RectTransform>(); elementRT.position = element.MovementSection.startVectorValue; lastRecordingState = recordingPosition = false; }
void EndRecording() { UIAnimation uiAnimation = target as UIAnimation; UIElement element = uiAnimation.GetComponent <UIElement>(); RectTransform elementRT = element.GetComponent <RectTransform>(); RectTransform holderRT = curLocalCustomPosition ? element.transform.parent.GetComponent <RectTransform>() : element.GetComponentInParent <Canvas>().GetComponent <RectTransform>(); Undo.RecordObject(element, "Record Hiding Position"); float canvasWidth = holderRT.lossyScale.x * holderRT.rect.width; float canvasHeight = holderRT.lossyScale.y * holderRT.rect.height; float canvasStartX = holderRT.position.x - canvasWidth / 2; float canvasStartY = holderRT.position.y - canvasHeight / 2; uiAnimation.AnimationFrames[chosenFrame].MovementSection.WantedVectorValue = new Vector3((elementRT.position.x - canvasStartX) / canvasWidth, (elementRT.position.y - canvasStartY) / canvasHeight, elementRT.position.z); elementRT.position = element.MovementSection.startVectorValue; }