Exemple #1
0
    //as this is not derived from MonoBehaviour, we have a constructor
    public SavedState(GameObject go, Object2PropertiesMapping o2m)
    {
        if (o2m.isParent())
        {
            isParent = true;
        }
        else
        {
            isParent = false;
        }

        if (go != null)
        {
            if (o2m.isParent())
            {
                this.pos   = new SerVector3(go.transform.position);
                this.scale = new SerVector3(go.transform.lossyScale);
                this.rot   = new SerQuaternion(go.transform.rotation);
                isParent   = true;
            }
            else
            {
                this.pos   = new SerVector3(go.transform.localPosition);
                this.scale = new SerVector3(go.transform.localScale);
                this.rot   = new SerQuaternion(go.transform.localRotation);
            }

            this.isActive = go.activeInHierarchy;
        }
        else
        {
            this.pos      = new SerVector3(Vector3.zero);
            this.scale    = new SerVector3(Vector3.one);
            this.rot      = new SerQuaternion(Quaternion.identity);
            this.isActive = false;
        }
    }
Exemple #2
0
    //switch to different mode.. so far there are MODE_LIVE for viewing a normal game action and MODE_REPLAY for viewing a replay of a recording
    public void switchModeTo(ViewMode newMode)
    {
        if (newMode == ViewMode.LIVE)
        {
            sendCallback2All("__EZR_live_prepare", null);

            //reset game object (i.e. rigidbody state)
            foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings)
            {
                //GameObject go = entry.Key;
                Object2PropertiesMapping propMapping = entry.Value;
                if (propMapping.getGameObject() != null)
                {
                    propMapping.resetObject();
                }
            }

            bool tmpWasLoading = false;
            if (isLoadingSlotInUse())
            {
                tmpWasLoading = true;
            }

            useRecordingSlot();

            if (tmpWasLoading)             //repeat to avoid a bug
            {
                switchModeTo(ViewMode.LIVE);
            }

            //COUNTFRAMES
            maxPositions = getMaxFrames(gOs2propMappings);


            sendCallback2All("__EZR_live_ready", null);
        }
        else
        {
            sendCallback2All("__EZR_replay_prepare", null);

            if (maxPositions > 0)
            {
                //prepare parents first
                foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings)
                {
                    //GameObject go = entry.Key;
                    Object2PropertiesMapping propMapping = entry.Value;
                    if (propMapping.isParent())
                    {
                        //if (propMapping.getGameObject() != null)
                        propMapping.prepareObjectForReplay();
                    }
                }
                //..then childs
                foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings)
                {
                    //GameObject go = entry.Key;
                    Object2PropertiesMapping propMapping = entry.Value;
                    if (!propMapping.isParent())
                    {
                        //if (propMapping.getGameObject() != null)
                        propMapping.prepareObjectForReplay();
                    }
                }

                sendCallback2All("__EZR_replay_ready", null);
            }
            else
            {
                newMode = ViewMode.LIVE;
                if (showWarnings)
                {
                    print("EZReplayManager WARNING: You have not recorded anything yet. Will not replay.");
                }
            }
        }

        currentMode = newMode;
        stop();
    }