예제 #1
0
    public ISSCBlockVector SurroundingBlock(ISSCBlockVector position, BlockDirection direction)
    {
        ISSCBlockVector tmpBV = new ISSCBlockVector();

        tmpBV = position;
        switch (direction)
        {
        case BlockDirection.Up:
            tmpBV.y += 1;
            return(tmpBV);

        case BlockDirection.Down:
            tmpBV.y -= 1;
            return(tmpBV);

        case BlockDirection.Right:
            tmpBV.x += 1;
            return(tmpBV);

        case BlockDirection.Left:
            tmpBV.x -= 1;
            return(tmpBV);

        case BlockDirection.Forward:
            tmpBV.z += 1;
            return(tmpBV);

        case BlockDirection.Back:
            tmpBV.z -= 1;
            return(tmpBV);
        }
        return(tmpBV);
    }
 void DestroyTmpGOAndPlacing(RaycastHit hit)
 {
     if (!moving)
     {
         return;
     }
     moving = false;
     Destroy(tmpGO);
     if (fallBackGO == null)
     {
         return;
     }
     if (hit.collider.gameObject.Equals(fallBackGO))
     {
         fallBackGO.SetActive(true);
         return;
     }
     if (hit.collider)
     {
         ISSCBlockVector bv = core.CalPlacingPosition(hit.point, hit.collider.transform.position);
         core.data.MoveBlock(tmpVector1, bv, false);
         fallBackGO.SetActive(true);
     }
     else
     {
         fallBackGO.SetActive(true);
     }
 }
예제 #3
0
    //Check Block's Direction Nearby Is Empty ,Empty Return True, Or Not Return False
    public bool IsNearByEmpty(ISSCBlockVector position, BlockDirection direction)
    {
        ISSCBlockVector tmpBV = position;

        switch (direction)
        {
        case BlockDirection.Up:
            tmpBV.y += 1;
            return(IsBlockEmpty(tmpBV));

        case BlockDirection.Down:
            tmpBV.y -= 1;
            return(IsBlockEmpty(tmpBV));

        case BlockDirection.Right:
            tmpBV.x += 1;
            return(IsBlockEmpty(tmpBV));

        case BlockDirection.Left:
            tmpBV.x -= 1;
            return(IsBlockEmpty(tmpBV));

        case BlockDirection.Forward:
            tmpBV.z += 1;
            return(IsBlockEmpty(tmpBV));

        case BlockDirection.Back:
            tmpBV.z -= 1;
            return(IsBlockEmpty(tmpBV));

        default:
            return(false);
        }
    }
예제 #4
0
    public void MoveBlock(ISSCBlockVector position, ISSCBlockVector destination, bool forceMove)
    {
        if (!IsBlockAvailable(destination) || !IsBlockAvailable(position))
        {
            position    = EnsureSafeAccess2Data(destination);
            destination = EnsureSafeAccess2Data(destination);
        }
        int encodePosition    = EncodeIndex(position);
        int encodeDestination = EncodeIndex(destination);

        if (forceMove)
        {
            SetBlock(destination, blocks [encodePosition]);
            SetBlock(position, 0);
        }
        else
        {
            if (!IsBlockEmpty(destination))
            {
                return;
            }
            else
            {
                SetBlock(destination, blocks [encodePosition]);
                SetBlock(position, 0);
            }
        }
    }
예제 #5
0
    public static ISSCBlockVector WorldPositionToGridPosition(Vector3 position, Vector3 gridOriginInWorld)
    {
        float           f = ISSC_BLOCK_UNIT_SIZE;
        ISSCBlockVector v = new ISSCBlockVector(gridOriginInWorld.x + position.x / f, gridOriginInWorld.y + position.y / f, gridOriginInWorld.z + position.z / f);

        return(v);
    }
예제 #6
0
    //Get Blocks' Position In A Cube Zone Between Position1 And Position2
    public ISSCBlockVector[] BlocksOverlapCube(ISSCBlockVector position1, ISSCBlockVector position2)
    {
        ISSCBlockVector tmpBV = new ISSCBlockVector(Mathf.Min(position1.x, position2.x), Mathf.Min(position1.y, position2.y), Mathf.Min(position1.z, position2.z));

        ISSCBlockVector loopTmpBV;

        int xSize = Mathf.Abs(position1.x - position2.x) + 1;
        int ySize = Mathf.Abs(position1.y - position2.y) + 1;
        int zSize = Mathf.Abs(position1.z - position2.z) + 1;

        List <ISSCBlockVector> l = new List <ISSCBlockVector> ();

        for (int z = 0; z < zSize; z++)
        {
            for (int y = 0; y < ySize; y++)
            {
                for (int x = 0; x < xSize; x++)
                {
                    loopTmpBV = new ISSCBlockVector(tmpBV.x + x, tmpBV.y + y, tmpBV.z + z);
                    if (IsBlockAvailable(loopTmpBV))
                    {
                        l.Add(loopTmpBV);
                    }
                }
            }
        }
        return(l.ToArray());
    }
예제 #7
0
    static string EncodeJson(ISSCBGrid grid)
    {
        int[] data = grid.GetRawData();

        JsonData json   = new JsonData();
        JsonData size   = new JsonData();
        JsonData blocks = new JsonData();

        ISSCBlockVector bv = grid.gridSize;

        size["x"] = bv.x.ToString();
        size["y"] = bv.y.ToString();
        size["z"] = bv.z.ToString();

        json["name"] = grid.name;
        json["size"] = size;

        for (int i = 0; i < data.Length; i++)
        {
            blocks [i.ToString()] = data [i];
        }
        json["blocks"] = blocks;

        string str = json.ToJson();

        return(str);
    }
예제 #8
0
	public static ISSCBlockVector WorldPositionToGridPosition (Vector3 position, Vector3 gridOriginInWorld)
	{
		float f = ISSC_BLOCK_UNIT_SIZE;
		ISSCBlockVector v = new ISSCBlockVector (gridOriginInWorld.x + position.x / f, gridOriginInWorld.y + position.y / f, gridOriginInWorld.z + position.z / f);

		return v;
	}
예제 #9
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);
	}
예제 #10
0
	/// <summary>
	/// Determines whether this position is available in grid.
	/// </summary>
	/// <returns><c>true</c> if this position is available; otherwise, <c>false</c>.</returns>
	/// <param name="position">Position.</param>
	public bool IsBlockAvailable (ISSCBlockVector position)
	{
		bool result = ISMath.Contains (position.x, 0, gridSize.x-1)
		              && ISMath.Contains (position.y, 0, gridSize.y-1)
		              && ISMath.Contains (position.z, 0, gridSize.z-1);

		return result;
	}
예제 #11
0
    static public int Distance(ISSCBlockVector a, ISSCBlockVector b)
    {
        int distancex = a.x - b.x;
        int distancey = a.y - b.y;
        int distancez = a.z - b.z;

        return((int)Mathf.Sqrt(Mathf.Pow(distancex, 2f) + Mathf.Pow(distancey, 2f) + Mathf.Pow(distancez, 2f)));
    }
예제 #12
0
    static public float RealWorldDistance(ISSCBlockVector a, ISSCBlockVector b)
    {
        float distancex = (float)(a.x - b.x);
        float distancey = (float)(a.y - b.y);
        float distancez = (float)(a.z - b.z);

        return(Mathf.Sqrt(Mathf.Pow(distancex, 2f) + Mathf.Pow(distancey, 2f) + Mathf.Pow(distancez, 2f)));
    }
예제 #13
0
    /// <summary>
    /// Determines whether this position is available in grid.
    /// </summary>
    /// <returns><c>true</c> if this position is available; otherwise, <c>false</c>.</returns>
    /// <param name="position">Position.</param>
    public bool IsBlockAvailable(ISSCBlockVector position)
    {
        bool result = ISMath.Contains(position.x, 0, gridSize.x - 1) &&
                      ISMath.Contains(position.y, 0, gridSize.y - 1) &&
                      ISMath.Contains(position.z, 0, gridSize.z - 1);

        return(result);
    }
예제 #14
0
    ISSCBlockVector EnsureSafeAccess2Data(ISSCBlockVector point)
    {
        point.x = Mathf.Clamp(point.x, 0, gridSize.x - 1);
        point.y = Mathf.Clamp(point.y, 0, gridSize.y - 1);
        point.z = Mathf.Clamp(point.z, 0, gridSize.z - 1);

        return(point);
    }
예제 #15
0
    public static ISSCBlockVector operator *(ISSCBlockVector bv1, int i)
    {
        ISSCBlockVector bv = new ISSCBlockVector(bv1);

        bv.x *= i;
        bv.y *= i;
        bv.z *= i;
        return(bv);
    }
예제 #16
0
    public static ISSCBlockVector operator -(ISSCBlockVector bv1, int i)
    {
        ISSCBlockVector bv = new ISSCBlockVector(bv1);

        bv.x -= i;
        bv.y -= i;
        bv.z -= i;
        return(bv);
    }
예제 #17
0
    //-Lag 12060414
    public static ISSCBlockVector operator /(ISSCBlockVector bv1, ISSCBlockVector bv2)
    {
        ISSCBlockVector bv = new ISSCBlockVector(bv1);

        bv.x /= bv2.x;
        bv.y /= bv2.y;
        bv.z /= bv2.z;
        return(bv);
    }
예제 #18
0
    public static ISSCBlockVector operator /(ISSCBlockVector bv1, int i)
    {
        ISSCBlockVector bv = new ISSCBlockVector(bv1);

        bv.x /= i;
        bv.y /= i;
        bv.z /= i;
        return(bv);
    }
예제 #19
0
    public int EncodeIndex(ISSCBlockVector position)
    {
        ISSCBlockVector v      = EnsureSafeAccess2Data(position);
        int             xIndex = v.x;
        int             yIndex = v.y * gridSize.x;
        int             zIndex = v.z * gridSize.x * gridSize.y;

        return(xIndex + yIndex + zIndex);
    }
예제 #20
0
    public static ISSCBlockVector operator +(ISSCBlockVector bv1, int i)
    {
        ISSCBlockVector bv = new ISSCBlockVector(bv1);

        bv.x += i;
        bv.y += i;
        bv.z += i;
        return(bv);
    }
예제 #21
0
	//Stores the version cod

	public static Vector3 GridPositionToWorldPosition (ISSCBlockVector position, Vector3 gridOriginInWorld)
	{
		
		

		return new Vector3 (gridOriginInWorld.x + position.x * ISSC_BLOCK_UNIT_SIZE,
			gridOriginInWorld.y + position.y * ISSC_BLOCK_UNIT_SIZE,
			gridOriginInWorld.z + position.z * ISSC_BLOCK_UNIT_SIZE);
	}
예제 #22
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);
 }
예제 #23
0
    /// <summary>
    /// Get blocks's ID with a specific position
    /// </summary>
    /// <returns>ID of the block.</returns>
    /// <param name="position">Position.</param>
    public int GetBlock(ISSCBlockVector position)
    {
        if (!IsBlockAvailable(position))
        {
            Debug.LogWarning("Block IO Exception: Out of range.");
            return(-1);
        }

        return(blocks [EncodeIndex(position)]);
    }
예제 #24
0
 public bool IsBlockVisiable(ISSCBlockVector position)
 {
     for (int i = 0; i < 6; i++)
     {
         if (IsNearByEmpty(position, (BlockDirection)i))
         {
             return(true);
         }
     }
     return(false);
 }
 void StopCamGLRenderAndPlacingCube()
 {
     if (cameraScript.selecting)
     {
         Vector3         v1           = selectTipBlock.transform.position;
         ISSCBlockVector fromPosition = ISSCBGrid.WorldPositionToGridPosition(v1 + Vector3.one * length, core.moniter.transform.position);
         ISSCBlockVector toPosition   = ISSCBGrid.WorldPositionToGridPosition(v1 - Vector3.one * length, core.moniter.transform.position);
         ISSCGridPrimitiveShapeUtilities.CreateCube(core.data, core.currentFillingBlock, fromPosition, toPosition);
         cameraScript.selecting = false;
         length = 0;
     }
 }
	public static void CreateCube (ISSCBGrid grid, int fillWith, ISSCBlockVector from, ISSCBlockVector to)
	{
		if (!grid.IsBlockAvailable (from)) return;
		if (!grid.IsBlockAvailable (to)) return;
			
		ISSCBlockVector[] bvs = grid.BlocksOverlapCube(from,to);
		foreach(ISSCBlockVector bv in bvs){
			grid.SetBlock(bv,fillWith);
		}

		return;
	}
예제 #27
0
    public ISSCBlockVector ClosestEmptyBlock(ISSCBlockVector position)
    {
        for (int i = 0; i < 6; i++)
        {
            if (IsNearByEmpty(position, (BlockDirection)i))
            {
                return(SurroundingBlock(position, (BlockDirection)i));
            }
        }

        return(position);
    }
예제 #28
0
    public ISSCBlockVector[] SurroundingBlocks(ISSCBlockVector position)
    {
        ISSCBlockVector[] bs = new ISSCBlockVector[6];

        bs [0] = position + ISSCBlockVector.up;
        bs [1] = position + ISSCBlockVector.down;
        bs [2] = position + ISSCBlockVector.forward;
        bs [3] = position + ISSCBlockVector.back;
        bs [4] = position + ISSCBlockVector.right;
        bs [5] = position + ISSCBlockVector.left;

        return(bs);
    }
//	public static bool CreatePrimitive (ISSCBGrid grid, ModuleType moduleType, ISSCBlockVector origin, float radius, float height,Vector3 direction)
//	{
//		if (moduleType != ModuleType.Cone)
//			return false;
//		if (!grid.IsBlockAvailable (origin))
//			return false;
//		if (radius <= 0 || height <= 0)
//			return false;
//		return true;
//
//		
//	}

	public static void CreateCylinder (ISSCBGrid grid, int fillWith, ISSCBlockVector origin, float radius, float height)
	{
		if (!grid.IsBlockAvailable (origin)) return;
		if (radius <= 0 || height <= 0) return;
			
		ISSCBlockVector[] bvs = grid.BlocksOverlapCylinder(origin,radius,height);
		foreach(ISSCBlockVector bv in bvs){
			grid.SetBlock(bv,fillWith);
		}
		
		return;

	}
예제 #30
0
	/// <summary>
	/// Initializes a new instance of the <see cref="ISSCBGrid"/> class with specific size.
	/// </summary>
	/// <param name="size">Size.</param>
	public ISSCBGrid (ISSCBlockVector size)
	{
		if (!(size.x > 0))
			size.x = 1;
		if (!(size.y > 0))
			size.y = 1;
		if (!(size.z > 0))
			size.z = 1;

		gridSize = size;

		blocks = new int[gridSize.Length ()];
	}
예제 #31
0
	public ISSCBGrid (ISSCBGridDescriber describer)
	{
		if (!(describer.size.x > 0))
			describer.size.x = 1;
		if (!(describer.size.y > 0))
			describer.size.y = 1;
		if (!(describer.size.z > 0))
			describer.size.z = 1;

		gridSize = describer.size;
		
		blocks = new int[gridSize.Length ()];
		SetBlock (GetCenterBlock (), describer.centerBlock);
	}
	public static void CreateSphere (ISSCBGrid grid, ISSCBlockVector origin, int fillWith, float radius)
	{

		if (!grid.IsBlockAvailable (origin)) {
			Debug.LogError("Failed to create primitive : Not enough spaces");
			return;
		}
		if (radius <= 0) return;
			
		ISSCBlockVector[] bvs = grid.BlocksOverlapSphere(origin,radius);
		foreach(ISSCBlockVector bv in bvs){
			grid.SetBlock(bv,fillWith);
		}
	}
예제 #33
0
    /// <summary>
    /// Check if the block is empty.
    /// </summary>
    /// <returns><c>true</c>, if blocks ID is 0, <c>false</c> otherwise.</returns>
    /// <param name="position">Position.</param>
    public bool IsBlockEmpty(ISSCBlockVector position)
    {
        int blockID = GetBlock(position);

        try {
            if (blockID == -1)
            {
                throw new System.Exception("Block position out of grid.");
            }
        } catch (System.Exception e) {
            Debug.Log(e.Message);
            return(true);
        }


        return(blockID == 0);
    }
    void CreateTmpGO(RaycastHit hit)
    {
        if (!hit.collider)
        {
            return;
        }
        moving = true;

        tmpVector1 = ISSCBGrid.WorldPositionToGridPosition(hit.transform.position, core.moniter.transform.position);
        tmpID      = core.data.GetRawData() [core.data.EncodeIndex(tmpVector1)];
        fallBackGO = hit.collider.gameObject;
        fallBackGO.SetActive(false);
        tmpGO = Instantiate(fallBackGO) as GameObject;
        tmpGO.SetActive(true);
        tmpGO.transform.localScale *= 0.8f;
        tmpGO.layer = ISSCLayerManager.tmpBlockLayer;
    }
예제 #35
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;
    }
예제 #36
0
    //Get Blocks' Position In A Sphere Zone Around Position In Radius
    public ISSCBlockVector[] BlocksOverlapSphere(ISSCBlockVector position, float radius)
    {
        ISSCBlockVector position1 = new ISSCBlockVector(position.x - (int)radius, position.y - (int)radius, position.z - (int)radius);
        ISSCBlockVector position2 = new ISSCBlockVector(position.x + (int)radius, position.y + (int)radius, position.z + (int)radius);

        ISSCBlockVector[]      bvs = BlocksOverlapCube(position1, position2);
        List <ISSCBlockVector> l   = new List <ISSCBlockVector> ();

        foreach (ISSCBlockVector bv in bvs)
        {
            if (ISSCBlockVector.Distance(position, bv) < radius && IsBlockAvailable(bv))
            {
                l.Add(bv);
            }
        }
        return(l.ToArray());
    }
예제 #37
0
	static ISSCBGrid DecodeJson(string data){
		JsonData json = JsonMapper.ToObject (data);

		int vectorX,vectorY,vectorZ;
		vectorX = int.Parse(json["size"]["x"].ToString());
		vectorY = int.Parse(json["size"]["y"].ToString());
		vectorZ = int.Parse(json["size"]["z"].ToString());
		ISSCBlockVector size = new ISSCBlockVector(vectorX,vectorY,vectorZ);

		ISSCBGrid grid = new ISSCBGrid(size);
		grid.name = json ["name"].ToString ();

		for(int i =0 ;i< grid.GetRawData().Length;i++){
			grid.SetBlock(grid.DecodeIndex(i),int.Parse(json["blocks"][i.ToString()].ToString()));//?
		}

		return grid;
	}
    public static void CreateSphere(ISSCBGrid grid, ISSCBlockVector origin, int fillWith, float radius)
    {
        if (!grid.IsBlockAvailable(origin))
        {
            Debug.LogError("Failed to create primitive : Not enough spaces");
            return;
        }
        if (radius <= 0)
        {
            return;
        }

        ISSCBlockVector[] bvs = grid.BlocksOverlapSphere(origin, radius);
        foreach (ISSCBlockVector bv in bvs)
        {
            grid.SetBlock(bv, fillWith);
        }
    }
//	public static bool CreatePrimitive (ISSCBGrid grid, ModuleType moduleType, ISSCBlockVector origin, float radius, float height,Vector3 direction)
//	{
//		if (moduleType != ModuleType.Cone)
//			return false;
//		if (!grid.IsBlockAvailable (origin))
//			return false;
//		if (radius <= 0 || height <= 0)
//			return false;
//		return true;
//
//
//	}

    public static void CreateCylinder(ISSCBGrid grid, int fillWith, ISSCBlockVector origin, float radius, float height)
    {
        if (!grid.IsBlockAvailable(origin))
        {
            return;
        }
        if (radius <= 0 || height <= 0)
        {
            return;
        }

        ISSCBlockVector[] bvs = grid.BlocksOverlapCylinder(origin, radius, height);
        foreach (ISSCBlockVector bv in bvs)
        {
            grid.SetBlock(bv, fillWith);
        }

        return;
    }
    public static void CreateCube(ISSCBGrid grid, int fillWith, ISSCBlockVector from, ISSCBlockVector to)
    {
        if (!grid.IsBlockAvailable(from))
        {
            return;
        }
        if (!grid.IsBlockAvailable(to))
        {
            return;
        }

        ISSCBlockVector[] bvs = grid.BlocksOverlapCube(from, to);
        foreach (ISSCBlockVector bv in bvs)
        {
            grid.SetBlock(bv, fillWith);
        }

        return;
    }
예제 #41
0
	public void DeleteBlock(ISSCBlockVector block){
		data.SetBlock (block, 0);
	}
예제 #42
0
	public void MoveBlocks (ISSCBlockVector[] positions, ISSCBlockVector[] destinations, bool forceMove)
	{
		if (positions.Length == destinations.Length) {//Check Length Match
			int[] IDs = new int[positions.Length + 1];
			if (forceMove) {
				for (int i = 0; i < positions.Length; i++) {
					IDs [i] = blocks [EncodeIndex (positions [i])];
					SetBlock (positions [i], 0);
				}
				for (int i = 0; i < destinations.Length; i++) {
					if (!IsBlockAvailable (destinations [i])) {
						destinations [i] = EnsureSafeAccess2Data (destinations [i]);
					}
					SetBlock (destinations [i], IDs [i]);
				}
			} else {//Load Selected List
				for (int i = 0; i < positions.Length; i++) {
					IDs [i] = blocks [EncodeIndex (positions [i])];
					SetBlock (positions [i], 0);
				}
				for (int i = 0; i < destinations.Length; i++) {
					if (!IsBlockAvailable (destinations [i])) {//Check Destination List
						destinations [i] = EnsureSafeAccess2Data (destinations [i]);
					}
					if (!IsBlockEmpty(destinations[i])) {//Resume Selected List
						for (int j = 0; j < positions.Length; j++) {
							SetBlock (positions [j], IDs [j]);
						}
						return;
					}
				}
				for (int i = 0; i < destinations.Length; i++) {//Set Destination List
					SetBlock (destinations [i], IDs [i]);
				}
			}
		} else {
			Debug.Log ("Current positions' counts not match with destinations'!");
		}
	}
예제 #43
0
	/// <summary>
	/// Set block's ID to change a block in specific position to another block.
	/// </summary>
	/// <returns>Error code if any error ocurred, otherwise return the previous ID of the block.</returns>
	/// <param name="position">Position.</param>
	/// <param name="blockID">Block ID.</param>
	public int SetBlock (ISSCBlockVector position, int blockID)
	{
		
		if (!IsBlockAvailable (position)) {
			Debug.LogWarning ("Block IO Exception: Out of range.");
			return -1;
		}

		int encodedIndex = EncodeIndex (position);

		int previousID = blocks [encodedIndex];
		blocks [encodedIndex] = blockID;

		//Update the version.
		version++;

		return previousID;
	}
예제 #44
0
	public void MoveBlock (ISSCBlockVector position, ISSCBlockVector destination, bool forceMove)
	{
		if (!IsBlockAvailable (destination) || !IsBlockAvailable (position)) {
			position = EnsureSafeAccess2Data (destination);
			destination = EnsureSafeAccess2Data (destination);
		}
		int encodePosition = EncodeIndex (position);
		int encodeDestination = EncodeIndex (destination);
		if (forceMove) {
			SetBlock (destination, blocks [encodePosition]);
			SetBlock (position, 0);
		} else {
			if (!IsBlockEmpty(destination)) {
				return;
			} else {
				SetBlock (destination, blocks [encodePosition]);
				SetBlock (position, 0);
			}
		}
	}
예제 #45
0
	/// <summary>
	/// Check if the block is empty.
	/// </summary>
	/// <returns><c>true</c>, if blocks ID is 0, <c>false</c> otherwise.</returns>
	/// <param name="position">Position.</param>
	public bool IsBlockEmpty (ISSCBlockVector position)
	{
		int blockID = GetBlock (position);

		try {
			if (blockID == -1)
				throw new System.Exception ("Block position out of grid.");
		} catch (System.Exception e) {
			Debug.Log (e.Message);
			return true;
		}


		return blockID == 0;
	}
예제 #46
0
	public void UpdateBlocksCacheIgroned (ISSCBlockVector[] blocks)
	{
		for (int i = 0; i < blocks.Length; i++) {
			UpdateBlockCacheIgroned (blocks [i]);
		}
	}
예제 #47
0
	public int EncodeIndex (ISSCBlockVector position)
	{
		ISSCBlockVector v = EnsureSafeAccess2Data (position);
		int xIndex = v.x;
		int yIndex = v.y * gridSize.x;
		int zIndex = v.z * gridSize.x * gridSize.y;
		return xIndex + yIndex + zIndex;
	}
예제 #48
0
	public ISSCBlockVector[] SurroundingBlocks (ISSCBlockVector position)
	{
		ISSCBlockVector[] bs = new ISSCBlockVector[6];

		bs [0] = position + ISSCBlockVector.up;
		bs [1] = position + ISSCBlockVector.down;
		bs [2] = position + ISSCBlockVector.forward;
		bs [3] = position + ISSCBlockVector.back;
		bs [4] = position + ISSCBlockVector.right;
		bs [5] = position + ISSCBlockVector.left;

		return bs;
	}
예제 #49
0
	public ISSCBlockVector SurroundingBlock (ISSCBlockVector position, BlockDirection direction)
	{
		ISSCBlockVector tmpBV = new ISSCBlockVector ();
		tmpBV = position;
		switch (direction) {
		case BlockDirection.Up: 
			tmpBV.y += 1;
			return tmpBV;
		case BlockDirection.Down: 
			tmpBV.y -= 1;
			return tmpBV;
		case BlockDirection.Right: 
			tmpBV.x += 1;
			return tmpBV;
		case BlockDirection.Left: 
			tmpBV.x -= 1;
			return tmpBV;
		case BlockDirection.Forward: 
			tmpBV.z += 1;
			return tmpBV;
		case BlockDirection.Back: 
			tmpBV.z -= 1;
			return tmpBV;
		}
		return tmpBV;
	}
예제 #50
0
	/// <summary>
	/// Get blocks's ID with a specific position
	/// </summary>
	/// <returns>ID of the block.</returns>
	/// <param name="position">Position.</param>
	public int GetBlock (ISSCBlockVector position)
	{
		if (!IsBlockAvailable (position)) {
			Debug.LogWarning ("Block IO Exception: Out of range.");
			return -1;
		}
	
		return blocks [EncodeIndex (position)];
	}
예제 #51
0
	//Set Block Near Position's Direction With BlockID
	public void SetBlockNearBy (ISSCBlockVector position, BlockDirection direction, int blockID)
	{
		ISSCBlockVector tmpBV = new ISSCBlockVector ();
		tmpBV = position;
		switch (direction) {
		case BlockDirection.Up: 
			tmpBV.y += 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Down: 
			tmpBV.y -= 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Right: 
			tmpBV.x += 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Left: 
			tmpBV.x -= 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Forward: 
			tmpBV.z += 1;
			SetBlock (tmpBV, blockID);
			break;
		case BlockDirection.Back: 
			tmpBV.z -= 1;
			SetBlock (tmpBV, blockID);
			break;
		}
	}
예제 #52
0
	public bool IsBlockVisiable (ISSCBlockVector position)
	{
		for (int i = 0; i < 6; i++) {
			if (IsNearByEmpty (position, (BlockDirection)i))
				return true;
		}
		return false;
	}
예제 #53
0
	//Check Block's Direction Nearby Is Empty ,Empty Return True, Or Not Return False
	public bool IsNearByEmpty (ISSCBlockVector position, BlockDirection direction)
	{
		ISSCBlockVector tmpBV = position;

		switch (direction) {
		case BlockDirection.Up: 
			tmpBV.y += 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Down: 
			tmpBV.y -= 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Right: 
			tmpBV.x += 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Left: 
			tmpBV.x -= 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Forward: 
			tmpBV.z += 1;
			return IsBlockEmpty (tmpBV);
		case BlockDirection.Back: 
			tmpBV.z -= 1;
			return IsBlockEmpty (tmpBV);
		default :
			return false;
		}
	}
	void CreateTmpGO (RaycastHit hit)
	{
		if (!hit.collider)
			return;
		moving = true;

		tmpVector1 = ISSCBGrid.WorldPositionToGridPosition (hit.transform.position, core.moniter.transform.position);
		tmpID = core.data.GetRawData () [core.data.EncodeIndex (tmpVector1)];
		fallBackGO = hit.collider.gameObject;
		fallBackGO.SetActive (false);
		tmpGO = Instantiate (fallBackGO) as GameObject;
		tmpGO.SetActive (true);
		tmpGO.transform.localScale *= 0.8f;
		tmpGO.layer = ISSCLayerManager.tmpBlockLayer;
	}
예제 #55
0
	ISSCBlockVector EnsureSafeAccess2Data (ISSCBlockVector point)
	{
		point.x = Mathf.Clamp (point.x, 0, gridSize.x - 1);
		point.y = Mathf.Clamp (point.y, 0, gridSize.y - 1);
		point.z = Mathf.Clamp (point.z, 0, gridSize.z - 1);

		return point;
	}
예제 #56
0
	public ISSCBlockVector ClosestEmptyBlock (ISSCBlockVector position)
	{
		for (int i = 0; i < 6; i++) {
			if (IsNearByEmpty (position, (BlockDirection)i)) {
				return SurroundingBlock (position, (BlockDirection)i);
			}
		}

		return position;
	}
예제 #57
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;
	}
예제 #58
0
	//Get Blocks' Position In A Cube Zone Between Position1 And Position2
	public ISSCBlockVector[] BlocksOverlapCube (ISSCBlockVector position1, ISSCBlockVector position2)
	{
		ISSCBlockVector tmpBV = new ISSCBlockVector (Mathf.Min (position1.x, position2.x), Mathf.Min (position1.y, position2.y), Mathf.Min (position1.z, position2.z));
		
		ISSCBlockVector loopTmpBV;
		
		int xSize = Mathf.Abs (position1.x - position2.x) + 1;
		int ySize = Mathf.Abs (position1.y - position2.y) + 1;
		int zSize = Mathf.Abs (position1.z - position2.z) + 1;
		
		List<ISSCBlockVector> l = new List<ISSCBlockVector> ();
				
		for (int z = 0; z < zSize; z++) {
			for (int y = 0; y < ySize; y++) {
				for (int x = 0; x < xSize; x++) {
					loopTmpBV = new ISSCBlockVector (tmpBV.x + x, tmpBV.y + y, tmpBV.z + z);
					if (IsBlockAvailable (loopTmpBV)) {
						l.Add (loopTmpBV);
					}
				}
			}
		}
		return l.ToArray ();
	}
예제 #59
0
	//-L 12062000
	public ISSCBlockVector[] BlocksOverlapCylinder (ISSCBlockVector position, float radius, float height)
	{
		ISSCBlockVector position1 = new ISSCBlockVector (position.x + (int)radius, position.y, position.z + (int)radius);
		ISSCBlockVector position2 = new ISSCBlockVector (position.x - (int)radius, position.y + (int)height, position.z - (int)radius);
		ISSCBlockVector[] bvs = BlocksOverlapCube (position1, position2);
		List<ISSCBlockVector> l = new List<ISSCBlockVector> ();
		foreach (ISSCBlockVector bv in bvs) {
			position.y = bv.y;
			if (ISSCBlockVector.Distance (position, bv) < radius && IsBlockAvailable (bv)) {
				l.Add (bv);
			}
		}
		return l.ToArray ();
	}
예제 #60
0
	public void PlaceBlockWithCurrentSetting(ISSCBlockVector block){
		data.SetBlock (block, currentFillingBlock);
	}