private void ClearAction()
 {
     extender.ClearAction();
     foreach (GameObject go in ReplayBehavior.GetGameObjectsWithRAETag(ReplayBehavior.RAETag.Action))
     {
         GameObject.Destroy(go);
     }
 }
Example #2
0
    IEnumerator WaitForStop(StudentAction action)
    {
        List <GameObject> state = new List <GameObject>(ReplayBehavior.GetGameObjectsWithRAETag(ReplayBehavior.RAETag.State));

        state.AddRange(ReplayBehavior.GetGameObjectsWithRAETag(ReplayBehavior.RAETag.Action));
        Rigidbody rigidbody;
        float     callTime = Time.time;

        switch (stopCondition)
        {
        case StoppingCondition.Instant:
            break;

        case StoppingCondition.WaitForStop:
            bool allSleeping = false;
            while (!allSleeping)
            {
                allSleeping = true;
                if (Time.time - callTime > timeOut)
                {
                    break;
                }

                foreach (GameObject go in state)
                {
                    rigidbody = go.GetComponent <Rigidbody>();
                    if (go != null && rigidbody != null && rigidbody.IsSleeping())
                    {
                        allSleeping = false;
                        yield return(null);

                        break;
                    }
                }
            }
            break;

        case StoppingCondition.Time:
            while (Time.time - callTime < timeOut)
            {
                yield return(null);
            }
            break;

        case StoppingCondition.Custom:
            yield return(extender.StoppingCoroutine());

            break;
        }
        Stop(action);
    }
    // Use this for initialization
    void Start()
    {
        dictionary = GetComponent <PrefabDictionary>();

        reader = GetComponent <LogReader>();
        if (reader == null)
        {
            Debug.LogError("No LogReader attached to the Replay Analysis Engine.");
        }

        calculator = GetComponent <Calculator>();
        if (calculator == null)
        {
            Debug.LogError("No Calculator attached to the Replay Analysis Engine.");
        }

        writer = GetComponent <AnalysisWriter>();
        if (writer == null)
        {
            Debug.LogError("No LogWriter attached to the Replay Analysis Engine.");
        }

        extender = GetComponent <ReplayExtender>();
        if (extender == null)
        {
            Debug.LogWarning("No ReplayExtender attached to the Replay Analysis Engine. Adding a DummyExtender.");
        }
        this.gameObject.AddComponent <ReplayExtender>();

        foreach (GameObject go in (FindObjectsOfType(typeof(GameObject)) as GameObject[]))
        {
            if (go != this.gameObject && go.GetComponent <ReplayBehavior>() == null)
            {
                ReplayBehavior rb = go.AddComponent <ReplayBehavior>();
                rb.ReplayTag      = ReplayBehavior.RAETag.Given;
                rb.RecordTouching = false;
            }
        }
    }
    private GameObject SpawnObject(XmlNode node, StudentAction action)
    {
        string key = extender.LookupPrefab(node, action);

        if (string.IsNullOrEmpty(key))
        {
            if (node[Logger.PREFAB] == null)
            {
                Debug.LogWarning("XmlNode contains no <Prefab> element, attempting to use the <Name> element instead.");
                if (node[Logger.NAME] == null)
                {
                    Debug.LogWarning("XmlNode contains no <Name> element. Giving up. Consider writing an extension to the LookupPrefab() " +
                                     "method in the ReplayExtender class if your log files do not conform to the standard format.\nNode:" + node.OuterXml);
                    return(null);
                }
                key = node[Logger.NAME].InnerText;
            }
            else
            {
                key = node[Logger.PREFAB].InnerText;
            }
        }

        GameObject prefab = dictionary.GetPrefab(key);

        if (prefab == null)
        {
            Debug.LogWarning("No Prefab found in dictionary for name:" + key + ", did you forget to add it, or spell the (case-sensative) key wrong? Giving up.");
            return(null);
        }

        GameObject gob = null;

        float   posX = float.Parse(node[Logger.TRANSFORM][Logger.POSITION]["X"].InnerText);
        float   posY = float.Parse(node[Logger.TRANSFORM][Logger.POSITION]["Y"].InnerText);
        Vector3 pos  = new Vector3(posX, posY, 0f);

        float      rotZ = float.Parse(node[Logger.TRANSFORM][Logger.ROTATION].InnerText);
        Quaternion rot  = Quaternion.Euler(0f, 0f, rotZ);

        gob = GameObject.Instantiate(prefab, pos, rot) as GameObject;

        gob.name = node[Logger.NAME].InnerText;
        ReplayBehavior rb = gob.AddComponent <ReplayBehavior>();

        if (node[Logger.PREFAB] != null)
        {
            rb.PrefabName = node[Logger.PREFAB].InnerText;
        }
        else
        {
            rb.PrefabName = ReplayBehavior.NO_PREFAB_TAG;
        }

        if (node[Logger.UNITY_TAG] != null)
        {
            rb.UnityTag = node[Logger.UNITY_TAG].InnerText;
        }
        else
        {
            rb.UnityTag = ReplayBehavior.NO_UNITY_TAG;
        }

        if (node[Logger.EXTRA_TAGS] != null)
        {
            List <string> newTags = new List <string>();
            foreach (XmlNode subNode in node[Logger.EXTRA_TAGS])
            {
                if (subNode[Logger.TAG] != null)
                {
                    newTags.Add(subNode[Logger.TAG].InnerText);
                }
            }
            rb.AddTags(newTags);
        }

        return(gob);
    }