Exemple #1
0
        public virtual PlacedBlock Place(World world)
        {
            if (this.CanBePlaced(world))
            {
                var newBlockObject = this.InstantiateCopy();
                newBlockObject.transform.parent = world.transform;

                var placedBlock = PlacedBlock.Add(newBlockObject, this, sideSnapping);
                foreach (var item in placedBlock.GetComponents <ISelector>())
                {
                    var isComponent = item as MonoBehaviour;
                    if (isComponent != null)
                    {
                        MonoBehaviour.Destroy(isComponent);
                    }
                }

                world.Add(this, sideSnapping);

                EventHandler <EventArgs> handler = Placed;
                if (handler != null)
                {
                    handler(this, EventArgs.Empty);
                }
                return(placedBlock);
            }
            return(null);
        }
Exemple #2
0
        public virtual void UpdateBlock()
        {
#if MOBILE_INPUT // ignore touches over UI on mobile devices
            if (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#endif
            {
                RaycastHit hit;
                if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
                {
                    var placed = hit.collider.gameObject.GetComponent <PlacedBlock>();
                    if (placed == null)
                    {
                        if (selectedObject != null)
                        {
                            Deselect(selectedObject.gameObject);
                        }
                        selectedObject = null;
                    }
                    else
                    {
                        //removing added material from previously selected object
                        if (selectedObject != null)
                        {
                            Deselect(selectedObject.gameObject);
                        }
                        selectedObject = placed;

                        Select(selectedObject.gameObject);
                    }
                }
            }
        }
Exemple #3
0
        public virtual void Remove(PlacedBlock selectedObject)
        {
            var coords = GetIntegerCoords(selectedObject.transform.position);

            if (IsCellExists(coords.x, coords.y, coords.z))
            {
                if (selectedObject.Placeable.IsFullBlock)// fill all sides
                {
                    foreach (Placeable.Side eachSide in Enum.GetValues(typeof(Placeable.Side)))
                    {
                        map[coords.x, coords.y, coords.z].Remove(eachSide);
                    }
                }
                else
                {
                    map[coords.x, coords.y, coords.z].Remove(selectedObject.SideSnapping);
                }
                Destroy(selectedObject.gameObject);
            }
        }