Example #1
0
    public void LoadGameObjects()
    {
        sceneObjs = new List <SceneObject>();

        string jsonPath = Path.Combine(Application.streamingAssetsPath, Configurations.jsonFilename);

        id = DataUtil.GetCurrentRoomId();
        ParseJson(jsonPath, id);
        logPath   = Path.Combine(Application.persistentDataPath, "Logs/CSG/CSG.txt");
        startTime = Time.time;
        CSGLog.Log(logPath, id, "Entered Level");

        /*SceneObject cube = Instantiate(CSGObjectPrefab) as SceneObject;
         * SceneObject sphere = Instantiate(CSGObjectPrefab) as SceneObject;
         * cube.name = "Cube";
         * sphere.name = "Sphere";
         * PrimitiveHelper.SetAsType(cube, PrimitiveType.Cube);
         * PrimitiveHelper.SetAsType(sphere, PrimitiveType.Sphere);
         * //GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
         * //GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         *
         *
         * //Mesh cubeMesh = cube.GetComponent<MeshFilter>().mesh;
         * //cube.GetComponent<MeshFilter>().sharedMesh = cubeMesh;
         * cube.transform.localPosition = new Vector3(-2,2,0);
         * sphere.transform.localPosition = new Vector3(-2,-2,0);
         * sphere.transform.localScale = new Vector3(1.3f, 1.3f, 1.3f);
         * sceneObjs.Add(cube);
         * sceneObjs.Add(sphere);*/

        //targetObj = Instantiate(targetPrefab) as GameObject;
        //targetObj.name = "Target";
        //targetObj.GetComponent<MeshFilter>().sharedMesh = Instantiate(targetMesh) as Mesh;
    }
Example #2
0
    public void Check()
    {
        if (sceneObjs.Count == 1)
        {
            GameObject composite       = sceneObjs[0].gameObject;
            float      compositeVolume = CSGUtil.VolumeOfMesh(composite);
            float      targetVolume    = CSGUtil.VolumeOfMesh(targetObj);
            //GameObject flagObj = Instantiate(composite) as GameObject;
            CSGUtil.Union(targetObj, composite);
            float unionVolume = CSGUtil.VolumeOfMesh(targetObj);

            //Debug.Log(unionVolume + " " + targetVolume + " " + compositeVolume);
            if ((unionVolume - targetVolume < 1e-3) && (unionVolume - compositeVolume < 1e-3))
            {
                //Debug.Log(unionVolume + " " + targetVolume + " " + compositeVolume);
                //Debug.Log("You win...!!!");
                CSGLog.Log(logPath, id, "Completed Level...!!!");
                levelCompleteText.enabled = true;
                Destroy(composite);
                Destroy(targetObj);
                DataUtil.UnlockCurrentRoom();
                return;
            }
            CSGLog.Log(logPath, id, "Check failed");
            targetObj.GetComponent <MeshFilter>().sharedMesh = Instantiate(targetMesh) as Mesh;
            targetObj.GetComponent <MeshRenderer>().materials
                           = new Material[] { targetMaterial };
            targetObj.name = "Target";
        }
    }
Example #3
0
 public void ResetScene()
 {
     opA         = null;
     opB         = null;
     selectedObj = null;
     StopAllCoroutines();
     foreach (SceneObject obj in sceneObjs)
     {
         Destroy(obj.gameObject);
     }
     Destroy(targetObj);
     LoadGameObjects();
     CSGLog.Log(logPath, id, "Reset");
 }
Example #4
0
    public void Union()
    {
        if (opA && opB)
        {
            CSGUtil.Union(opA.gameObject, opB.gameObject);
            sceneObjs.Remove(opB);
            Destroy(opB.gameObject);

            //Need to set to default because this is no longer opA
            opA.Init();
            opA = null;
            opB = null;
            selectedObj.OnDeselect();
            selectedObj = null;

            CSGLog.Log(logPath, id, "A+B");
        }
    }