void TmpGOAndSelectCubeDragingBehaviour(RaycastHit hit)
    {
        if (!moving)
        {
            return;
        }
        Vector3 position;

        if (!hit.collider)
        {
            return;
        }
        else if (hit.collider.gameObject.Equals(fallBackGO))
        {
            return;
        }
        else
        {
            position = ISSCBGrid.GridPositionToWorldPosition(core.CalPlacingPosition(hit.point, hit.collider.transform.position), core.moniter.transform.position);
            core.SelectBlock(position);
            if (!tmpGO)
            {
                return;
            }
            tmpGO.transform.Rotate(tmpGO.transform.up, 45 * Time.deltaTime);
            tmpGO.transform.position = position;
        }
    }
    void UpdateUI()
    {
        if (core.currentFillingBlock != 0)
        {
            tipsImage.color = blockList.blocks [core.currentFillingBlock].GetComponent <MeshRenderer> ().sharedMaterial.color;
        }
        else
        {
            tipsImage.color = new Color(0, 0, 0, 0);
        }

        stateTips.sprite = GetStateSprite();
        selectTipBlock.transform.position = ISSCBGrid.GridPositionToWorldPosition(core.CurrentSelection(), core.moniter.transform.position);

        /*
         * if (userSelectionState == SelectionOperations.Cube) {
         *      cubeWidth.enabled = true;
         *      cubeWidth.text = "S :\t" + ((int)length).ToString () + " px";
         * } else {
         *      cubeWidth.enabled = false;
         * }
         *
         * if (userSelectionState == SelectionOperations.Sphere) {
         *      sphereRadius.enabled = true;
         *      sphereRadius.text = "R :\t" + ((int)radius).ToString () + " px";
         * } else {
         *      sphereRadius.enabled = false;
         * }
         */
    }
Ejemplo n.º 3
0
 public void NewScene(ISSCBlockVector size, string name)
 {
     data      = new ISSCBGrid(size);
     data.name = name;
     data.SetBlock(data.GetCenterBlock(), rootBlock);
     Debug.Log("New Scene Created");
     editorCamera.SetViewPoint(ISSCBGrid.GridPositionToWorldPosition(data.GetCenterBlock(), moniter.transform.position));
     moniter.SwitchDataSet(data);
 }
Ejemplo n.º 4
0
    void UpdateEntireScene()
    {
        int versionCheckResult = gridData.IsLastestVersion(currentVersion);

        if (versionCheckResult == -1)
        {
            return;
        }

        Debug.Log("New version detected, updating " + (versionCheckResult - currentVersion).ToString() + " changes...");

        int[] data = gridData.GetRawData();

        for (int i = 0; i < data.Length; i++)
        {
            if (data [i] == versionDataCache [i])
            {
                continue;
            }

            //Once a block is changed(otherwise, loop is continued), check the surrounding blocks and see if some of them also need to be updated.
            UpdateBlocksCacheIgroned(gridData.SurroundingBlocks(gridData.DecodeIndex(i)));

            versionDataCache [i] = data [i];

            ISSCBlockVector b = gridData.DecodeIndex(i);

            if (blockObjects [i])
            {
                ISObjectPoolManager.Unspawn(blockObjects [i]);
            }
            if (data [i] <= 1)
            {
                continue;
            }
            if (!gridData.IsBlockVisiable(b))
            {
                continue;
            }

            Vector3 position = ISSCBGrid.GridPositionToWorldPosition(b, transform.position);
            blockObjects [i] = ISObjectPoolManager.Spawn(blockList.blocks [data [i]].gameObject, position, Quaternion.identity) as GameObject;
        }

        currentVersion = versionCheckResult;
    }
Ejemplo n.º 5
0
    void LightSetting()
    {
        lights = GetComponentsInChildren <Light> ();
        lights [0].transform.position = ISSCBGrid.GridPositionToWorldPosition(new ISSCBlockVector(0, 0, 0), transform.position);
        lights [1].transform.position = ISSCBGrid.GridPositionToWorldPosition(new ISSCBlockVector(0, gridData.gridSize.y - 1, 0), transform.position);
        lights [2].transform.position = ISSCBGrid.GridPositionToWorldPosition(new ISSCBlockVector(gridData.gridSize.x - 1, 0, 0), transform.position);
        lights [3].transform.position = ISSCBGrid.GridPositionToWorldPosition(new ISSCBlockVector(gridData.gridSize.x - 1, gridData.gridSize.y - 1, 0), transform.position);
        lights [4].transform.position = ISSCBGrid.GridPositionToWorldPosition(new ISSCBlockVector(gridData.gridSize.x - 1, 0, gridData.gridSize.z - 1), transform.position);
        lights [5].transform.position = ISSCBGrid.GridPositionToWorldPosition(new ISSCBlockVector(gridData.gridSize.x - 1, gridData.gridSize.y - 1, gridData.gridSize.z - 1), transform.position);
        lights [6].transform.position = ISSCBGrid.GridPositionToWorldPosition(new ISSCBlockVector(0, 0, gridData.gridSize.z - 1), transform.position);
        lights [7].transform.position = ISSCBGrid.GridPositionToWorldPosition(new ISSCBlockVector(0, gridData.gridSize.y - 1, gridData.gridSize.z - 1), transform.position);

        for (int i = 0; i < lights.Length; i++)
        {
//		lights[i].transform.LookAt(ISSCBGrid.GridPositionToWorldPosition(gridData.GetCenterBlock(),transform.position));
            lights[i].range = Mathf.Sqrt(Mathf.Pow(gridData.gridSize.x - 1, 2) + Mathf.Pow(gridData.gridSize.y - 1, 2) + Mathf.Pow(gridData.gridSize.z - 1, 2));
//			lights[i].spotAngle = 90;
        }
    }
Ejemplo n.º 6
0
    public void UpdateBlockCacheIgroned(ISSCBlockVector block)
    {
        int id = gridData.EncodeIndex(block);

        if (blockObjects [id])
        {
            ISObjectPoolManager.Unspawn(blockObjects [id]);
        }

        if (!gridData.IsBlockVisiable(block))
        {
            return;
        }
        int[] data = gridData.GetRawData();

        if (data [id] <= 1)
        {
            return;
        }

        Vector3 position = ISSCBGrid.GridPositionToWorldPosition(block, transform.position);

        blockObjects [id] = ISObjectPoolManager.Spawn(blockList.blocks [data [id]].gameObject, position, Quaternion.identity) as GameObject;
    }
 void StartCamGLRender()
 {
     cameraScript.selecting        = true;
     cameraScript.selectStartPoint = new Vector3(mouseCasterForLayerSelectingBlock.inputPosition.x / Screen.width, mouseCasterForLayerSelectingBlock.inputPosition.y / Screen.height, 0);
     depth = Vector3.Distance(viewingCamera.ScreenToWorldPoint(mouseCasterForLayerSelectingBlock.inputPosition), ISSCBGrid.GridPositionToWorldPosition(core.CurrentSelection(), core.moniter.transform.position));
 }
Ejemplo n.º 8
0
    static void LoadFromSCB()
    {
        //First, we ask user to select a .scb file to load.w

        EditorUtility.DisplayProgressBar("Load from SCB", "Waiting for user action...", 0);

        string path = EditorUtility.OpenFilePanel("Choose SCB", Application.dataPath, "scb");

        if (string.IsNullOrEmpty(path))
        {
            EditorUtility.ClearProgressBar();
            return;
        }

        int shouldFill             = EditorUtility.DisplayDialogComplex("Fill ?", "Do you want to fill the model ?", "Yep", "NO !", "Nevermind !");
        int shouldConnectWithJoint = EditorUtility.DisplayDialogComplex("Apply Physic Connections ?", "Do you want to apply physic connections to blocks ?", "Yep", "NO !", "Nevermind !");

        EditorUtility.DisplayProgressBar("Load from SCB", "Reading file...", 0);

        //Once we have the file path, we parse its name, and use FileUtilities to load it.
        string    fileName = path.Substring(path.LastIndexOf("/"));
        ISSCBGrid dataSet  = ISSCDGridFileUtilities.LoadFromFile(path);

        /*
         * if (!dataSet) {
         *      Debug.Log ("Failed to create : could not open data set...");
         *      EditorUtility.ClearProgressBar ();
         *      return;
         * }
         */

        EditorUtility.DisplayProgressBar("Load from SCB", "Loading files...", 0.5f);

        //FileUntilities return the data set means the file is vaild, so now we can start the creation process,
        //First, create the root object, and load all blocks

        ISSCDBlocksList   blockList = ISSCDBlocksList.LoadList();
        GameObject        rootObj   = new GameObject(string.IsNullOrEmpty(dataSet.name) ? fileName : dataSet.name);
        List <GameObject> childrens = new List <GameObject> ();
        Transform         rootTrans = rootObj.transform;

        //It should be zero, just make sure.
        rootTrans.position = Vector3.zero;

        EditorUtility.DisplayProgressBar("Load from SCB", "Loading files...", 1);

        int[]   rawData        = dataSet.GetRawData();
        Vector3 centerPosition = ISSCBGrid.GridPositionToWorldPosition(dataSet.GetCenterBlock(), rootTrans.position);

        EditorUtility.DisplayProgressBar("Load from SCB", "Creating GameObjects...", 0);

        for (int i = 0; i < rawData.Length; i++)
        {
            if (rawData [i] <= 1)
            {
                continue;
            }

            ISSCBlockVector b = dataSet.DecodeIndex(i);

            if (shouldFill != 0 && !dataSet.IsBlockVisiable(b))
            {
                continue;
            }

            Vector3    position = ISSCBGrid.GridPositionToWorldPosition(b, rootTrans.position) - centerPosition;
            GameObject obj      = ISObjectPoolManager.Spawn(blockList.blocks [rawData [i]].gameObject, position, Quaternion.identity) as GameObject;
            obj.GetComponent <ISSCBlock> ().blockID = i;
            obj.name             = "Block " + i.ToString();
            obj.transform.parent = rootObj.transform;
            childrens.Add(obj);

            EditorUtility.DisplayProgressBar("Load from SCB", "Creating GameObjects...", (float)i / (float)rawData.Length);
        }

        Selection.activeObject = rootObj;

        EditorUtility.ClearProgressBar();

        //Now, if we need to apply physic connects, continue !
        if (shouldConnectWithJoint != 0)
        {
            return;
        }
        EditorUtility.DisplayProgressBar("Applying Physic Connections", "Processing...", 0);

        //Since we're using data set ID to create blocks, ID in list would be its ID of data set.
        for (int i = 0; i < childrens.Count; i++)
        {
            GameObject        operatingObj = childrens [i];
            int               objectID     = operatingObj.GetComponent <ISSCBlock> ().blockID;
            ISSCBlockVector   bv           = dataSet.DecodeIndex(objectID);
            ISSCBlockVector[] surrounds    = dataSet.SurroundingBlocks(bv);

            for (int j = 0; j < surrounds.Length; j++)
            {
                int toConnectObjectID = dataSet.EncodeIndex(surrounds [j]);
                if (rawData [toConnectObjectID] <= 1)
                {
                    continue;
                }
                GameObject toConnect = null;

                foreach (GameObject obj in childrens)
                {
                    if (obj.GetComponent <ISSCBlock>().blockID == toConnectObjectID)
                    {
                        toConnect = obj;
                        break;
                    }
                }

                if (!toConnect)
                {
                    continue;
                }

                FixedJoint joint = operatingObj.AddComponent <FixedJoint> ();
                joint.connectedBody = toConnect.GetComponent <Rigidbody> () ? toConnect.GetComponent <Rigidbody> () : toConnect.AddComponent <Rigidbody> ();
            }

            EditorUtility.DisplayProgressBar("Applying Physic Connections", "Processing " + i.ToString() + " of " + childrens.Count + " objects..", (float)i / (float)childrens.Count);
        }


        //Start validing, in another word, this will make me programs easier :)
        for (int i = 0; i < childrens.Count; i++)
        {
            Rigidbody r = childrens [i].GetComponent <Rigidbody> ();
            if (r)
            {
                r.isKinematic = false;
            }
            else
            {
                Debug.LogError("Failed to vaild : Unknown error");
            }

            FixedJoint[] joints = childrens [i].GetComponents <FixedJoint> ();
            for (int j = 0; j < joints.Length; j++)
            {
                if (!joints [j].connectedBody)
                {
                    DestroyImmediate(joints [j]);
                }
            }

            EditorUtility.DisplayProgressBar("Applying Physic Connections", "Vailding " + i.ToString() + " of " + childrens.Count + " objects..", (float)i / (float)childrens.Count);
        }

        EditorUtility.ClearProgressBar();
    }
Ejemplo n.º 9
0
    public void Submit(string command)
    {
        if (command.StartsWith("select block"))
        {
            string argu = command.Substring(12);
            core.currentFillingBlock = int.Parse(argu);
        }
        else if (command.StartsWith("sb"))
        {
            string argu = command.Substring(2);
            core.currentFillingBlock = int.Parse(argu);
        }
        else if (command.StartsWith("save"))
        {
            string argu = command.Substring(command.IndexOf("\"") + 1, command.LastIndexOf("\"") - command.IndexOf("\"") - 1);
            core.SaveCurrentScene(Application.dataPath + "/Resources/SavedDatas/" + argu);
        }
        else if (command.StartsWith("load"))
        {
            string argu = command.Substring(command.IndexOf("\"") + 1, command.LastIndexOf("\"") - command.IndexOf("\"") - 1);
            core.OpenScene(Application.dataPath + "/Resources/SavedDatas/" + argu);
        }
        else if (command.StartsWith("new"))
        {
            string[] argus = ParseArguments(command);
            int      size  = int.Parse(argus [0]);
            core.NewScene(new ISSCBlockVector(size, size, size), "New Scene");
        }
        else if (command.StartsWith("sphere"))
        {
            string[]        argus        = ParseArguments(command);
            ISSCBlockVector center       = ParseBlockVector(argus [0]);
            int             r            = int.Parse(argus [1]);
            int             fillingBlock = int.Parse(argus [2]);

            ISSCGridPrimitiveShapeUtilities.CreateSphere(core.data, center, fillingBlock, r);
        }
        else if (command.StartsWith("cube"))
        {
            string[]        argus        = ParseArguments(command);
            ISSCBlockVector a            = ParseBlockVector(argus [0]);
            ISSCBlockVector b            = ParseBlockVector(argus [1]);
            int             fillingBlock = int.Parse(argus [2]);

            ISSCGridPrimitiveShapeUtilities.CreateCube(core.data, fillingBlock, a, b);
        }
        else if (command.StartsWith("move"))
        {
            string[]        argus = ParseArguments(command);
            ISSCBlockVector a     = ParseBlockVector(argus [0]);
            ISSCBlockVector b     = ParseBlockVector(argus [1]);
            bool            forceMove;
            switch (argus [2])
            {
            case "true":
                forceMove = true;
                break;

            case "false":
                forceMove = false;
                break;

            default:
                forceMove = true;
                break;
            }

            core.data.MoveBlock(a, b, forceMove);
        }
        else if (command.StartsWith("currentmoveto"))
        {
            string[]        argus = ParseArguments(command);
            ISSCBlockVector a     = ParseBlockVector(argus [0]);
            bool            forceMove;
            switch (argus [1])
            {
            case "true":
                forceMove = true;
                break;

            case "false":
                forceMove = false;
                break;

            default:
                forceMove = true;
                break;
            }
            ISSCBlockVector currentBlock = ISSCBGrid.WorldPositionToGridPosition(core.tipsBlock.transform.position, core.moniter.transform.position);
            core.data.MoveBlock(currentBlock, a, forceMove);
            core.tipsBlock.transform.position = ISSCBGrid.GridPositionToWorldPosition(a, core.moniter.transform.position);
            Debug.Log(ISSCBGrid.GridPositionToWorldPosition(a, core.moniter.transform.position));
        }
    }
Ejemplo n.º 10
0
 public void OpenScene(ISSCBGrid newDataSet)
 {
     data = newDataSet;
     editorCamera.SetViewPoint(ISSCBGrid.GridPositionToWorldPosition(data.GetCenterBlock(), moniter.transform.position));
     moniter.SwitchDataSet(data);
 }