AddProperty() public method

Adds a custom property to a given frame
public AddProperty ( int atFrame, string propertyName, string propertyValue ) : void
atFrame int /// At frame. ///
propertyName string /// Property name. ///
propertyValue string /// Property value as string. ///
return void
コード例 #1
0
ファイル: InputVCR.cs プロジェクト: ly774508966/VRDAT
    void LateUpdate()
    {
        if (_mode == InputVCRMode.Playback)
        {
            // update last frame and this frame
            // this way, all changes are transmitted, even if a button press lasts less than a frame (like in Input)
            lastFrameInputs = thisFrameInputs;

            int lastFrame = currentFrame;
            currentFrame = currentRecording.GetClosestFrame(playbackTime);

            if (currentFrame > currentRecording.totalFrames)
            {
                // end of recording
                if (finishedPlayback != null)
                {
                    finishedPlayback( );
                }
                Stop();
            }
            else
            {
                // go through all changes in recorded input since last frame
                var changedInputs = new Dictionary <string, InputInfo>();
                for (int frame = lastFrame + 1; frame <= currentFrame; frame++)
                {
                    foreach (InputInfo input in currentRecording.GetInputs(frame))
                    {
                        // thisFrameInputs only updated once per game frame, so all changes, no matter how brief, will be marked
                        // if button has changed
                        if (!thisFrameInputs.ContainsKey(input.inputName) || !thisFrameInputs[input.inputName].Equals(input))
                        {
                            if (changedInputs.ContainsKey(input.inputName))
                            {
                                changedInputs[input.inputName] = input;
                            }
                            else
                            {
                                changedInputs.Add(input.inputName, input);
                            }
                        }
                    }

                    if (snapToSyncedLocation)                           // custom code more effective, but this is enough sometimes
                    {
                        string posString = currentRecording.GetProperty(frame, "position");
                        if (!string.IsNullOrEmpty(posString))
                        {
                            transform.position = ParseVector3(posString);
                        }

                        string rotString = currentRecording.GetProperty(frame, "rotation");
                        if (!string.IsNullOrEmpty(rotString))
                        {
                            transform.eulerAngles = ParseVector3(rotString);
                        }
                    }
                }

                // update input to be used tihs frame
                foreach (KeyValuePair <string, InputInfo> changedInput in changedInputs)
                {
                    if (thisFrameInputs.ContainsKey(changedInput.Key))
                    {
                        thisFrameInputs[changedInput.Key] = changedInput.Value;
                    }
                    else
                    {
                        thisFrameInputs.Add(changedInput.Key, changedInput.Value);
                    }
                }

                playbackTime += Time.deltaTime;
            }
        }
        else if (_mode == InputVCRMode.Record)
        {
            realRecordingTime += Time.deltaTime;
            // record current input to frames, until recording catches up with realtime
            while (currentTime < realRecordingTime)
            {
                // mouse position & buttons if required
                if (recordMouseEvents)
                {
                    currentRecording.AddProperty(currentFrame, new FrameProperty("mousePos", Input.mousePosition.x.ToString() + "," + Input.mousePosition.y));

                    for (int i = 0; i < 3; i++)
                    {
                        InputInfo mouseInput = new InputInfo();
                        mouseInput.inputName      = "mousebutton" + i;
                        mouseInput.isAxis         = false;
                        mouseInput.mouseButtonNum = i;
                        currentRecording.AddInput(currentFrame, mouseInput);
                    }
                }

                // and buttons
                foreach (InputInfo input in inputsToRecord)
                {
                    if (input.isAxis)
                    {
                        input.axisValue = Input.GetAxis(input.inputName);
                    }
                    else if (input.mouseButtonNum >= 0)                         // mouse buttons recorded above
                    {
                        input.buttonState = Input.GetButton(input.inputName);
                    }
                    currentRecording.AddInput(currentFrame, input);
                }

                // synced location
                if (syncRecordLocations && Time.time > nextPosSyncTime)
                {
                    SyncPosition();                             // add position to properties
                    nextPosSyncTime = Time.time + 1f / autoSyncLocationRate;
                }

                // and any other properties
                foreach (FrameProperty prop in nextPropertiesToRecord)
                {
                    currentRecording.AddProperty(currentFrame, prop);
                }
                nextPropertiesToRecord.Clear();

                currentFrame++;
            }
        }
    }
コード例 #2
0
ファイル: InputVCR.cs プロジェクト: chewingF/TheWay
    void LateUpdate()
    {
        if (_mode == InputVCRMode.Playback)
        {
            // update last frame and this frame
            // this way, all changes are transmitted, even if a button press lasts less than a frame (like in Input)

            lastFrameInputs = new Dictionary <string, InputInfo>(thisFrameInputs);

            int lastFrame = currentFrame;

            currentFrame = currentRecording.GetClosestFrame(playbackTime);

            if (currentFrame >= currentRecording.totalFrames)
            {
                imputRecorder.GetComponent <PlayButton>().SpawnCloneCopy(this.name, recordingNumber, 1, startPos, startRot);
                imputRecorder.GetComponent <PlayButton>().DestroyClone(this.gameObject);
                _mode = InputVCRMode.Pause;
            }
            else
            {
                if (firstLoopPlayback)
                {
                    // float[] camRot = System.Array.ConvertAll(currentRecording.GetProperty(0, "camRot").Split(','), float.Parse);
                    // this.GetComponent<CameraBehaviour>().SetRotationX(camRot[0]);
                    // this.GetComponent<CameraBehaviour>().SetRotationZ(camRot[1]);
                    this.gameObject.GetComponent <PlayerBehaviour>().transformToRotate.rotation  = startRot;
                    this.gameObject.GetComponent <PlayerBehaviour>().playerAnimator.rootRotation = startRot;
                    this.transform.GetChild(1).transform.localRotation = startRot;
                    this.transform.position = startPos;
                    firstLoopPlayback       = false;
                    // currentFrame = 0;
                    // playbackTime = 0;
                    // thisFrameInputs.Clear();
                    // lastFrameInputs.Clear();
                }
                else
                {
                    // go through all changes in recorded input since last frame
                    var changedInputs = new Dictionary <string, InputInfo>();
                    for (int frame = lastFrame + 1; frame <= currentFrame; frame++)
                    {
                        foreach (InputInfo input in currentRecording.GetInputs(frame))
                        {
                            if (!thisFrameInputs.ContainsKey(input.inputName) || !thisFrameInputs[input.inputName].Equals(input))
                            {
                                if (changedInputs.ContainsKey(input.inputName))
                                {
                                    changedInputs[input.inputName] = input;
                                }
                                else
                                {
                                    changedInputs.Add(input.inputName, input);
                                }
                            }
                        }

                        // Updates the camera rotation
                        try
                        {
                            if (playerObject != null)
                            {
                                if (playerObject.GetComponent <InputVCR>().recordMouseEvents == true)
                                {
                                    float[] camRot = System.Array.ConvertAll(currentRecording.GetProperty(frame, "camRot").Split(','), float.Parse);
                                    //Debug.Log("This is Playback - X: " + camRot[0] + " Y: " + camRot[1]);
                                    this.GetComponent <CameraBehaviour>().SetRotationX(camRot[0]);
                                    this.GetComponent <CameraBehaviour>().SetRotationZ(camRot[1]);
                                }
                            }
                            else
                            {
                                Debug.Log("No Player object found! Precise camera rotation not used!");
                            }
                        }
                        catch
                        {
                            Debug.Log("Try failed! Precise camera rotation not used!");
                        }


                        // if (currentFrame == 0)   // custom code more effective, but this is enough sometimes
                        // {
                        //     string posString = currentRecording.GetProperty(0, "position");
                        //     if (!string.IsNullOrEmpty(posString))
                        //         transform.position = ParseVector3(posString);

                        //     string rotString = currentRecording.GetProperty(0, "rotation");
                        //     if (!string.IsNullOrEmpty(rotString))
                        //         transform.GetChild(1).transform.eulerAngles = ParseVector3(rotString);
                        // }
                    }

                    // update input to be used this frame
                    foreach (KeyValuePair <string, InputInfo> changedInput in changedInputs)
                    {
                        if (thisFrameInputs.ContainsKey(changedInput.Key))
                        {
                            thisFrameInputs[changedInput.Key] = changedInput.Value;
                        }
                        else
                        {
                            thisFrameInputs.Add(changedInput.Key, changedInput.Value);
                        }

                        //Debug.Log("Input: " + changedInput.Key + ", ButtonState: " + changedInput.Value.ToString());
                    }

                    playbackTime += Time.deltaTime;
                }
            }
        }
        else if (_mode == InputVCRMode.Record)
        {
            realRecordingTime += Time.deltaTime;
            // record current input to frames, until recording catches up with realtime
            while (currentTime < realRecordingTime)
            {
                if (currentRecording.totalFrames > (maxRecordTime * recordingFrameRate) * 2)
                {
                    //currentRecording.RemoveOldestFrame();

                    //currentRecording.frames.RemoveRange(0, (int)(currentRecording.totalFrames - (maxRecordTime * recordingFrameRate)));

                    //currentFrame = currentRecording.frames.Count;
                    //realRecordingTime -= Time.deltaTime;

                    //realRecordingTime -= (1000 - maxRecordTime);
                    //Debug.Log("After: " + currentRecording.totalFrames);
                    //Debug.Log("Current Frame: " + currentFrame);
                    //Debug.Log("Recording Time: " + realRecordingTime);
                }

                //Debug.Log("Total Rec Frames: " + currentRecording.totalFrames); // This is the current recorded fram count.

                // Camera Rotation & Buttons if Required
                if (recordMouseEvents)
                {
                    currentRecording.AddProperty(currentFrame, new FrameProperty("camRot", this.GetComponent <CameraBehaviour>().GetRotationX().ToString() + "," + this.GetComponent <CameraBehaviour>().GetRotationZ().ToString()));
                    //currentRecording.AddProperty(currentFrame, new FrameProperty("position", Vector3ToString(transform.position)));
                    //currentRecording.AddProperty(currentFrame, new FrameProperty("rotation", Vector3ToString(transform.GetChild(1).transform.eulerAngles)));
                    //Debug.Log(currentRecording.GetProperty(currentFrame, "camRot"));
                    //currentRecording.AddProperty(currentFrame, new FrameProperty("mousePos", Input.mousePosition.x.ToString() + "," + Input.mousePosition.y));

                    // for (int i = 0; i < 3; i++)
                    // {
                    //     InputInfo mouseInput = new InputInfo();
                    //     mouseInput.inputName = "mousebutton" + i;
                    //     mouseInput.isAxis = false;
                    //     mouseInput.mouseButtonNum = i;
                    //     currentRecording.AddInput(currentFrame, mouseInput);
                    // }
                }

                // and buttons
                foreach (InputInfo input in inputsToRecord)
                {
                    if (input.isAxis)
                    {
                        input.axisValue = hardInput.GetAxis(input.inputName, 1);
                    }
                    else
                    {
                        input.buttonState = hardInput.GetKey(input.inputName);
                    }
                    // else if (input.mouseButtonNum >= 0) // mouse buttons recorded above
                    // {
                    //     input.buttonState = hardInput.GetKey(input.inputName);
                    // }
                    currentRecording.AddInput(currentFrame, input);
                }

                // synced location
                //SyncPosition(); // add position to properties

                // if (Time.time > nextPosSyncTime)
                // {
                //     SyncPosition(); // add position to properties
                //     nextPosSyncTime = Time.time + 1f / autoSyncLocationRate;
                // }

                // and any other properties
                foreach (FrameProperty prop in nextPropertiesToRecord)
                {
                    currentRecording.AddProperty(currentFrame, prop);
                }
                nextPropertiesToRecord.Clear();

                currentFrame++;
                //Debug.Log("Recording Current Frames: " + currentRecording.totalFrames);
            }
        }
    }