private void OnUnselected(object sender, System.EventArgs e)
 {
     if (m_selectedPrefab != null)
     {
         m_selectedPrefab.IsSelected = false;
         m_selectedPrefab            = null;
     }
 }
        private void OnDestroy()
        {
            if (GLRenderer.Instance != null)
            {
                GLRenderer.Instance.Remove(this);
            }

            if (m_console != null)
            {
                m_console.Command -= OnConsoleCommand;
            }

            for (int i = 0; i < m_mapEditorPrefabs.Count; i++)
            {
                MapEditorPrefab mapEditorPrefab = m_mapEditorPrefabs[i];
                if (mapEditorPrefab != null)
                {
                    mapEditorPrefab.Selected   -= OnSelected;
                    mapEditorPrefab.Unselected -= OnUnselected;
                }
            }

            if (m_closeButton != null)
            {
                m_closeButton.onClick.RemoveListener(OnClose);
            }

            if (m_topViewButton != null)
            {
                m_topViewButton.onClick.RemoveListener(OnTopView);
            }

            if (m_brushSizeSlider != null)
            {
                m_brushSizeSlider.onValueChanged.RemoveListener(OnBrushSizeChanged);
            }

            if (m_brushWeightSlider != null)
            {
                m_brushWeightSlider.onValueChanged.RemoveListener(OnBrushWeightChanged);
            }

            if (m_brushHeightInput)
            {
                m_brushHeightInput.onValidateInput -= OnBrushHeightValidateInput;
                m_brushHeightInput.onValueChanged.RemoveListener(OnBrushHeightChanged);
                m_brushHeightInput.onEndEdit.RemoveListener(OnBrushHeightEndEdit);
            }

            if (m_ownerInput != null)
            {
                m_ownerInput.onValidateInput -= OnOwnerValidateInput;
                m_ownerInput.onValueChanged.RemoveListener(OnOwnerChanged);
            }

            m_isOpened = false;
        }
        private void OnSelected(object sender, System.EventArgs e)
        {
            if (m_selectedPrefab != null)
            {
                m_selectedPrefab.IsSelected = false;
            }
            m_selectedPrefab    = (MapEditorPrefab)sender;
            m_selectedAbilities = new VoxelAbilities(m_selectedPrefab.Prefab.Type);

            SetupTools();

            BrushHeight = m_selectedAbilities.MinHeight;
            BrushWeight = m_selectedAbilities.MinWeight;
        }
        private void Start()
        {
            GetDependencies();

            Voxel[] prefabs = m_factory.GetPrefabs();
            for (int i = 0; i < prefabs.Length; ++i)
            {
                MapEditorPrefab mapEditorPrefab = Instantiate(m_mapEditorPrefab);
                mapEditorPrefab.Prefab = prefabs[i];
                mapEditorPrefab.transform.SetParent(m_prefabPanel);
                if (prefabs[i].Type == (int)KnownVoxelTypes.Ground)
                {
                    VoxelAbilities abilities = new VoxelAbilities(prefabs[i].Type);

                    mapEditorPrefab.IsSelected         = true;
                    mapEditorPrefab.AllowHeightEditing = true;
                    m_selectedPrefab    = mapEditorPrefab;
                    m_selectedAbilities = abilities;

                    BrushHeight = abilities.MinHeight;
                    BrushWeight = abilities.MinWeight;// m_selectedPrefab.Prefab.Weight;
                }

                m_mapEditorPrefabs.Add(mapEditorPrefab);
                mapEditorPrefab.Selected   += OnSelected;
                mapEditorPrefab.Unselected += OnUnselected;
            }

            //OnIsOpenedChanged(IsOpened);
            SetupTools();

            if (m_isOpened)
            {
                m_pivot.transform.position = Vector3.zero;
                OnTopView();
            }

            if (m_closeButton != null)
            {
                m_closeButton.onClick.AddListener(OnClose);
            }
            if (m_topViewButton != null)
            {
                m_topViewButton.onClick.AddListener(OnTopView);
            }
            if (m_brushSizeSlider != null)
            {
                m_brushSizeSlider.onValueChanged.AddListener(OnBrushSizeChanged);
            }
            if (m_brushWeightSlider != null)
            {
                m_brushWeightSlider.onValueChanged.AddListener(OnBrushWeightChanged);
            }
            if (m_brushHeightInput != null)
            {
                m_brushHeightInput.onValidateInput += OnBrushHeightValidateInput;
                m_brushHeightInput.onValueChanged.AddListener(OnBrushHeightChanged);
                m_brushHeightInput.onEndEdit.AddListener(OnBrushHeightEndEdit);
            }
            if (m_ownerInput != null)
            {
                m_ownerInput.onValidateInput += OnOwnerValidateInput;
                m_ownerInput.onValueChanged.AddListener(OnOwnerChanged);
            }
        }