示例#1
0
    private static Contact?GetClosestContact(OpenCog.Map.OCMap map, CharacterController controller)
    {
        Vector3 pos = controller.transform.position;
        int     x1  = Mathf.FloorToInt(pos.x - controller.radius);
        int     y1  = Mathf.FloorToInt(pos.y);
        int     z1  = Mathf.FloorToInt(pos.z - controller.radius);

        int x2 = Mathf.CeilToInt(pos.x + controller.radius);
        int y2 = Mathf.CeilToInt(pos.y + controller.height);
        int z2 = Mathf.CeilToInt(pos.z + controller.radius);

        Contact?contact = null;

        for (int x = x1; x <= x2; x++)
        {
            for (int y = y1; y <= y2; y++)
            {
                for (int z = z1; z <= z2; z++)
                {
                    OpenCog.Map.OCBlockData block = map.GetBlock(x, y, z);
                    if (block.IsSolid())
                    {
                        Contact?_newContact = BlockCharacterCollision.GetContactBlockCharacter(new Vector3i(x, y, z), pos, controller);
                        if (_newContact.HasValue && _newContact.Value.delta.magnitude > float.Epsilon)
                        {
                            Contact newContact = _newContact.Value;
                            if (!contact.HasValue || newContact.sqrDistance > contact.Value.sqrDistance)
                            {
                                contact = newContact;
                            }
                        }
                    }
                }
            }
        }

        return(contact);
//		return null;
    }
示例#2
0
    // Update is called once per frame
    void Update()
    {
        if (Screen.showCursor)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            Vector3i?point = GetCursor(false);
            if (point.HasValue)
            {
                byte sun   = map.GetSunLightmap().GetLight(point.Value);
                byte light = map.GetLightmap().GetLight(point.Value);
                Debug.Log("Sun " + " " + sun + "  Light " + light);
            }
        }

        if (Input.GetKeyDown(KeyCode.RightControl))
        {
            Vector3i?point = GetCursor(true);
            if (point.HasValue)
            {
                byte sun   = map.GetSunLightmap().GetLight(point.Value);
                byte light = map.GetLightmap().GetLight(point.Value);
                Debug.Log("Sun " + sun + "  Light " + light);
            }
        }

        if (Input.GetMouseButtonDown(0))
        {
            Vector3i?point = GetCursor(true);
            if (point.HasValue)
            {
                map.SetBlockAndRecompute(new BlockData(), point.Value);
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Vector3i?point = GetCursor(false);
            if (point.HasValue)
            {
                bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, characterCollider).HasValue;
                if (empty)
                {
                    BlockData block = new BlockData(selectedBlock);
                    block.SetDirection(GetDirection(-transform.forward));
                    map.SetBlockAndRecompute(block, point.Value);
                }
            }
        }

        Vector3i?cursor = GetCursor(true);

        this.cursor.active = cursor.HasValue;
        if (cursor.HasValue)
        {
            this.cursor.transform.position = cursor.Value;
        }
    }
示例#3
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            if (UnityEngine.Screen.showCursor)
            {
                return;
            }

            if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.LeftControl))
            {
                Vector3i?point = GetCursor(false);
                if (point.HasValue)
                {
                    byte sun   = _map.GetSunLightmap().GetLight(point.Value);
                    byte light = _map.GetLightmap().GetLight(point.Value);
                    Debug.Log(OCLogSymbol.DETAILEDINFO + "Sun " + " " + sun + "  Light " + light);
                }
            }

            if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.RightControl))
            {
                Vector3i?point = GetCursor(true);
                if (point.HasValue)
                {
                    byte sun   = _map.GetSunLightmap().GetLight(point.Value);
                    byte light = _map.GetLightmap().GetLight(point.Value);
                    Debug.Log(OCLogSymbol.DETAILEDINFO + "Sun " + sun + "  Light " + light);
                }
            }

            if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                Vector3i?point = GetCursor(true);
                if (point.HasValue)
                {
//				Vector3i above = point.Value;
//				above.y += 1;
//				OCBlockData blockAbove = _map.GetBlock(above);
//				OCBlockData blockData = _map.GetBlock (point.Value);
//				if(blockAbove.IsEmpty() && !blockData.IsEmpty())
//				{
//					_map.SetBlockAndRecompute(blockData, above);
//					_map.SetBlockAndRecompute(OCBlockData.CreateInstance<OCBlockData>().Init(null, point.Value), point.Value);
//				}
//				else

                    Debug.Log(OCLogSymbol.DEBUG + "DeleteSelectedVoxel called from CreateBlockEffect");
                    GameManager.world.voxels.DeleteSelectedVoxel(point.Value);
                }
            }

            if (UnityEngine.Input.GetMouseButtonDown(1))
            {
                Vector3i?point = GetCursor(false);
                if (point.HasValue)
                {
                    bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, gameObject.GetComponent <CharacterController>()).HasValue;
                    if (empty)
                    {
                        Debug.Log(OCLogSymbol.DEBUG + "AddSelectedVoxel called from OCBuilder");
                        GameManager.world.voxels.AddSelectedVoxel(point.Value, -transform.forward, _selectedBlock);


                        OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController));

                        foreach (OCGoalController goalController in goalControllers)
                        {
                            if (goalController.GoalBlockType == _selectedBlock)
                            {
                                Vector3 sourcePos      = goalController.gameObject.transform.position;
                                Vector3 oldDistanceVec = ((Vector3)goalController.GoalBlockPos) - sourcePos;
                                Vector3 newDistanceVec = point.Value - sourcePos;
                                if (newDistanceVec.sqrMagnitude < oldDistanceVec.sqrMagnitude)
                                {
                                    goalController.GoalBlockPos = point.Value;
                                    goalController.MoveTargetsIfNecessary();
                                }
                            }
                        }
                    }
                }
            }

            Vector3i?cursor = GetCursor(true);

            _cursor.SetActive(cursor.HasValue);
            if (cursor.HasValue)
            {
                _cursor.transform.position = cursor.Value;
            }
            //System.Console.WriteLine(OCLogSymbol.DETAILEDINFO +gameObject.name + " is updated.");
        }
示例#4
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            if (UnityEngine.Screen.showCursor)
            {
                return;
            }

            if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.LeftControl))
            {
                Vector3i?point = GetCursor(false);
                if (point.HasValue)
                {
                    byte sun   = _map.GetSunLightmap().GetLight(point.Value);
                    byte light = _map.GetLightmap().GetLight(point.Value);
                    OCLogger.Info("Sun " + " " + sun + "  Light " + light);
                }
            }

            if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.RightControl))
            {
                Vector3i?point = GetCursor(true);
                if (point.HasValue)
                {
                    byte sun   = _map.GetSunLightmap().GetLight(point.Value);
                    byte light = _map.GetLightmap().GetLight(point.Value);
                    OCLogger.Info("Sun " + sun + "  Light " + light);
                }
            }

            if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                Vector3i?point = GetCursor(true);
                if (point.HasValue)
                {
                    _map.SetBlockAndRecompute(new OpenCog.Map.OCBlockData(), point.Value);
                }
            }

            if (UnityEngine.Input.GetMouseButtonDown(1))
            {
                Vector3i?point = GetCursor(false);
                if (point.HasValue)
                {
                    bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, gameObject.GetComponent <CharacterController>()).HasValue;
                    if (empty)
                    {
                        OpenCog.Map.OCBlockData block = new OpenCog.Map.OCBlockData(_selectedBlock, OpenCog.Utility.VectorUtil.Vector3ToVector3i(point.Value));
                        block.SetDirection(GetDirection(-transform.forward));
                        _map.SetBlockAndRecompute(block, point.Value);
                    }
                }
            }

            Vector3i?cursor = GetCursor(true);

            _cursor.SetActive(cursor.HasValue);
            if (cursor.HasValue)
            {
                _cursor.transform.position = cursor.Value;
            }
            OCLogger.Fine(gameObject.name + " is updated.");
        }
示例#5
0
    // Update is called once per frame
    void OnGUI()
    {
        if (GameStateManager.IsPaused)
        {
            return;
        }

        if (InputManager.inputManager().IsKeyDown(KeyCode.LeftControl))
        {
            Vector3i?point = GetCursor(false);
            if (point.HasValue)
            {
                byte sun   = map.GetSunLightmap().GetLight(point.Value);
                byte light = map.GetLightmap().GetLight(point.Value);
                Debug.Log("Sun " + " " + sun + "  Light " + light);
            }
        }

        if (InputManager.inputManager().IsKeyDown(KeyCode.RightControl))
        {
            Vector3i?point = GetCursor(true);
            if (point.HasValue)
            {
                byte sun   = map.GetSunLightmap().GetLight(point.Value);
                byte light = map.GetLightmap().GetLight(point.Value);
                Debug.Log("Sun " + sun + "  Light " + light);
            }
        }

        //Remove block
        if (InputManager.inputManager().canBreakBlocks&& ((InputManager.inputManager().LeftClick&& (Time.time - lastTimeDestroy > 0.1f)) || (InputManager.inputManager().isLeftClickHold&& (Time.time - lastTimeDestroy > 0.200f))))
        {
            Vector3i?point = GetCursor(true);
            if (point.HasValue && point.Value.y >= 2)
            {
                if (Network.peerType == NetworkPeerType.Disconnected)
                {
                    map.SetBlockAndRecompute(new BlockData(), point.Value);
                }
                else
                {
                    this.DestroyBlock(point.Value);
                }

                Vector3i around = new Vector3i(point.Value.x, point.Value.y, point.Value.z);

                around.y += 1;
                if (map.GetBlock(around).IsFluid())
                {
                    spreadingList.Add(new SpreadingInstruction(0.5f, around, this, map, map.GetBlock(around), 15));
                }
                around.y -= 1;

                for (int j = -1; j <= 1; j += 2)
                {
                    around.x += j;
                    if (map.GetBlock(around).IsFluid())
                    {
                        spreadingList.Add(new SpreadingInstruction(0.5f, around, this, map, map.GetBlock(around), 15));
                    }
                    around.x -= j;
                }
                for (int j = -1; j <= 1; j += 2)
                {
                    around.z += j;
                    if (map.GetBlock(around).IsFluid())
                    {
                        spreadingList.Add(new SpreadingInstruction(0.5f, around, this, map, map.GetBlock(around), 15));
                    }
                    around.z -= j;
                }
            }
            lastTimeDestroy = Time.time;
        }

        //Spawn block
        if ((InputManager.inputManager().RightClick&& (Time.time - lastTimeBuild > 0.1f)) || (InputManager.inputManager().isRightClickHold&& (Time.time - lastTimeBuild > 0.200f)))
        {
            Vector3i?point = GetCursor(false);
            if (point.HasValue)
            {
                bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, characterCollider).HasValue;
                if (empty && selectedBlock != null)
                {
                    BlockData block = new BlockData(selectedBlock);
                    block.SetDirection(GetDirection(-transform.forward));

                    if (Network.peerType == NetworkPeerType.Disconnected)
                    {
                        map.SetBlockAndRecompute(block, point.Value);
                    }
                    else
                    {
                        this.SpawnBlock(point.Value);
                    }

                    if (block.IsFluid())
                    {
                        spreadingList.Add(new SpreadingInstruction(0.5f, point.Value, this, map, block, 15));
                    }
                }
            }
            lastTimeBuild = Time.time;
        }

        ArrayList delList = new ArrayList();

        foreach (SpreadingInstruction si in spreadingList)
        {
            if (si.canSpread())
            {
                si.spreading();
            }
            else
            {
                delList.Add(si);
            }
        }

        foreach (SpreadingInstruction si in delList)
        {
            spreadingList.Remove(si);
        }

        Vector3i?cursor = GetCursor(true);

        this.cursor.SetActive(cursor.HasValue);
        if (cursor.HasValue)
        {
            this.cursor.transform.position = cursor.Value;
        }
    }
示例#6
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        public void Update()
        {
            if (UnityEngine.Screen.showCursor)
            {
                return;
            }

            if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.LeftControl))
            {
                Vector3i?point = GetCursor(false);
                if (point.HasValue)
                {
                    byte sun   = _map.GetSunLightmap().GetLight(point.Value);
                    byte light = _map.GetLightmap().GetLight(point.Value);
                    OCLogger.Info("Sun " + " " + sun + "  Light " + light);
                }
            }

            if (UnityEngine.Input.GetKeyDown(UnityEngine.KeyCode.RightControl))
            {
                Vector3i?point = GetCursor(true);
                if (point.HasValue)
                {
                    byte sun   = _map.GetSunLightmap().GetLight(point.Value);
                    byte light = _map.GetLightmap().GetLight(point.Value);
                    OCLogger.Info("Sun " + sun + "  Light " + light);
                }
            }

            if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                Vector3i?point = GetCursor(true);
                if (point.HasValue)
                {
//				Vector3i above = point.Value;
//				above.y += 1;
//				OCBlockData blockAbove = _map.GetBlock(above);
//				OCBlockData blockData = _map.GetBlock (point.Value);
//				if(blockAbove.IsEmpty() && !blockData.IsEmpty())
//				{
//					_map.SetBlockAndRecompute(blockData, above);
//					_map.SetBlockAndRecompute(OCBlockData.CreateInstance<OCBlockData>().Init(null, point.Value), point.Value);
//				}
//				else
                    _map.SetBlockAndRecompute(OCBlockData.CreateInstance <OCBlockData>().Init(null, point.Value), point.Value);
                }
            }

            if (UnityEngine.Input.GetMouseButtonDown(1))
            {
                Vector3i?point = GetCursor(false);
                if (point.HasValue)
                {
                    bool empty = !BlockCharacterCollision.GetContactBlockCharacter(point.Value, transform.position, gameObject.GetComponent <CharacterController>()).HasValue;
                    if (empty)
                    {
                        OpenCog.Map.OCBlockData block = OCBlockData.CreateInstance <OCBlockData>().Init(_selectedBlock, OpenCog.Utility.VectorUtil.Vector3ToVector3i(point.Value));
                        block.SetDirection(GetDirection(-transform.forward));
                        _map.SetBlockAndRecompute(block, point.Value);

                        OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController));

                        foreach (OCGoalController goalController in goalControllers)
                        {
                            if (goalController.GoalBlockType == _selectedBlock)
                            {
                                Vector3 sourcePos      = goalController.gameObject.transform.position;
                                Vector3 oldDistanceVec = ((Vector3)goalController.GoalBlockPos) - sourcePos;
                                Vector3 newDistanceVec = point.Value - sourcePos;
                                if (newDistanceVec.sqrMagnitude < oldDistanceVec.sqrMagnitude)
                                {
                                    goalController.GoalBlockPos = point.Value;
                                    goalController.MoveTargetsIfNecessary();
                                }
                            }
                        }
                    }
                }
            }

            Vector3i?cursor = GetCursor(true);

            _cursor.SetActive(cursor.HasValue);
            if (cursor.HasValue)
            {
                _cursor.transform.position = cursor.Value;
            }
            OCLogger.Fine(gameObject.name + " is updated.");
        }