Пример #1
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.");
        }
Пример #2
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.");
        }