private void Awake() { if (m_current != null) { Debug.LogWarning("Another instance of BoxSelection exists"); } if (!GetComponent <PersistentIgnore>()) { gameObject.AddComponent <PersistentIgnore>(); } m_current = this; m_image = gameObject.AddComponent <Image>(); m_image.type = Image.Type.Sliced; if (Graphics == null) { Graphics = Resources.Load <Sprite>("BoxSelection"); } m_image.sprite = Graphics; m_image.raycastTarget = false; m_rectTransform = GetComponent <RectTransform>(); m_rectTransform.sizeDelta = new Vector2(0, 0); m_rectTransform.pivot = new Vector2(0, 0); m_rectTransform.anchoredPosition = new Vector3(0, 0); if (SceneCamera == null) { SceneCamera = Camera.main; } }
private void Start() { if (m_boxSelection == null) { m_boxSelection = GetComponent <BoxSelection>(); } m_editor = m_boxSelection.Editor; }
private void OnDestroy() { if (RuntimeTools.ActiveTool == this) { RuntimeTools.ActiveTool = null; } if (m_current == this) { m_current = null; } }
protected override void AwakeOverride() { base.AwakeOverride(); Window.IOCContainer.RegisterFallback <IScenePivot>(this); Window.IOCContainer.RegisterFallback <IRuntimeSelectionComponent>(this); if (m_boxSelection == null) { m_boxSelection = GetComponentInChildren <BoxSelection>(true); } if (m_positionHandle == null) { m_positionHandle = GetComponentInChildren <PositionHandle>(true); } if (m_rotationHandle == null) { m_rotationHandle = GetComponentInChildren <RotationHandle>(true); } if (m_scaleHandle == null) { m_scaleHandle = GetComponentInChildren <ScaleHandle>(true); } if (m_boxSelection != null) { if (m_boxSelection.Window == null) { m_boxSelection.Window = Window; } m_boxSelection.Filtering += OnBoxSelectionFiltering; } if (m_positionHandle != null) { if (m_positionHandle.Window == null) { m_positionHandle.Window = Window; } m_positionHandle.gameObject.SetActive(true); m_positionHandle.gameObject.SetActive(false); } if (m_rotationHandle != null) { if (m_rotationHandle.Window == null) { m_rotationHandle.Window = Window; } m_rotationHandle.gameObject.SetActive(true); m_rotationHandle.gameObject.SetActive(false); } if (m_scaleHandle != null) { if (m_scaleHandle.Window == null) { m_scaleHandle.Window = Window; } m_scaleHandle.gameObject.SetActive(true); m_scaleHandle.gameObject.SetActive(false); } if (m_grid != null) { if (m_grid.Window == null) { m_grid.Window = Window; } } Editor.Selection.SelectionChanged += OnRuntimeSelectionChanged; Editor.Tools.ToolChanged += OnRuntimeToolChanged; if (m_pivot == null) { GameObject pivot = new GameObject("Pivot"); pivot.transform.SetParent(transform, true); pivot.transform.position = Vector3.zero; m_pivot = pivot.transform; } if (m_secondaryPivot == null) { GameObject secondaryPivot = new GameObject("SecondaryPivot"); secondaryPivot.transform.SetParent(transform, true); secondaryPivot.transform.position = Vector3.zero; m_secondaryPivot = secondaryPivot.transform; } Window.Camera.transform.LookAt(m_pivot); OnRuntimeSelectionChanged(null); }
protected override void AwakeOverride() { base.AwakeOverride(); Window.IOCContainer.RegisterFallback <IScenePivot>(this); Window.IOCContainer.RegisterFallback <IRuntimeSelectionComponent>(this); if (m_outlineManager == null) { m_outlineManager = GetComponentInChildren <OutlineManager>(true); if (m_outlineManager != null) { m_outlineManager.Camera = Window.Camera; } } if (m_boxSelection == null) { m_boxSelection = GetComponentInChildren <BoxSelection>(true); } if (m_positionHandle == null) { m_positionHandle = GetComponentInChildren <PositionHandle>(true); } if (m_rotationHandle == null) { m_rotationHandle = GetComponentInChildren <RotationHandle>(true); } if (m_scaleHandle == null) { m_scaleHandle = GetComponentInChildren <ScaleHandle>(true); } if (m_rectTool == null) { m_rectTool = GetComponentInChildren <RectTool>(true); } if (m_grid == null) { m_grid = GetComponentInChildren <SceneGrid>(true); } if (m_boxSelection != null) { if (m_boxSelection.Window == null) { m_boxSelection.Window = Window; } m_boxSelection.Filtering += OnBoxSelectionFiltering; m_boxSelection.Selection += OnBoxSelection; } if (m_positionHandle != null) { if (m_positionHandle.Window == null) { m_positionHandle.Window = Window; } m_positionHandle.gameObject.SetActive(true); m_positionHandle.gameObject.SetActive(false); m_positionHandle.BeforeDrag.AddListener(OnBeforeDrag); m_positionHandle.Drop.AddListener(OnDrop); } if (m_rotationHandle != null) { if (m_rotationHandle.Window == null) { m_rotationHandle.Window = Window; } m_rotationHandle.gameObject.SetActive(true); m_rotationHandle.gameObject.SetActive(false); m_rotationHandle.BeforeDrag.AddListener(OnBeforeDrag); m_rotationHandle.Drop.AddListener(OnDrop); } if (m_scaleHandle != null) { if (m_scaleHandle.Window == null) { m_scaleHandle.Window = Window; } m_scaleHandle.gameObject.SetActive(true); m_scaleHandle.gameObject.SetActive(false); m_scaleHandle.BeforeDrag.AddListener(OnBeforeDrag); m_scaleHandle.Drop.AddListener(OnDrop); } if (m_rectTool != null) { if (m_rectTool.Window == null) { m_rectTool.Window = Window; } m_rectTool.gameObject.SetActive(true); m_rectTool.gameObject.SetActive(false); m_rectTool.BeforeDrag.AddListener(OnBeforeDrag); m_rectTool.Drop.AddListener(OnDrop); } if (m_grid != null) { if (m_grid.Window == null) { m_grid.Window = Window; } } Editor.Selection.SelectionChanged += OnRuntimeSelectionChanged; Editor.Tools.ToolChanged += OnRuntimeToolChanged; if (m_pivot == null) { GameObject pivot = new GameObject("Pivot"); pivot.transform.SetParent(transform, true); pivot.transform.position = Vector3.zero; m_pivot = pivot.transform; } if (m_secondaryPivot == null) { GameObject secondaryPivot = new GameObject("SecondaryPivot"); secondaryPivot.transform.SetParent(transform, true); secondaryPivot.transform.position = Vector3.zero; m_secondaryPivot = secondaryPivot.transform; } ApplySizeOfGrid(); ApplyIsGridEnabled(); OnRuntimeSelectionChanged(null); }
protected override void AwakeOverride() { base.AwakeOverride(); if (m_boxSelection == null) { m_boxSelection = GetComponentInChildren <BoxSelection>(true); } if (m_positionHandle == null) { m_positionHandle = GetComponentInChildren <PositionHandle>(true); } if (m_rotationHandle == null) { m_rotationHandle = GetComponentInChildren <RotationHandle>(true); } if (m_scaleHandle == null) { m_scaleHandle = GetComponentInChildren <ScaleHandle>(true); } if (m_boxSelection != null) { if (m_boxSelection.Window == null) { m_boxSelection.Window = Window; } m_boxSelection.Filtering += OnBoxSelectionFiltering; } if (m_positionHandle != null) { if (m_positionHandle.Window == null) { m_positionHandle.Window = Window; } m_positionHandle.gameObject.SetActive(true); m_positionHandle.gameObject.SetActive(false); } if (m_rotationHandle != null) { if (m_rotationHandle.Window == null) { m_rotationHandle.Window = Window; } m_rotationHandle.gameObject.SetActive(true); m_rotationHandle.gameObject.SetActive(false); } if (m_scaleHandle != null) { if (m_scaleHandle.Window == null) { m_scaleHandle.Window = Window; } m_scaleHandle.gameObject.SetActive(true); m_scaleHandle.gameObject.SetActive(false); } Editor.Selection.SelectionChanged += OnRuntimeSelectionChanged; Editor.Tools.ToolChanged += OnRuntimeToolChanged; if (GetComponent <RuntimeSelectionInputBase>() == null) { gameObject.AddComponent <RuntimeSelectionInput>(); } RuntimeSelectionComponentUI ui = Window.GetComponentInChildren <RuntimeSelectionComponentUI>(true); if (ui == null && !Editor.IsVR) { GameObject runtimeSelectionComponentUI = new GameObject("SelectionComponentUI"); runtimeSelectionComponentUI.transform.SetParent(Window.transform, false); ui = runtimeSelectionComponentUI.AddComponent <RuntimeSelectionComponentUI>(); RectTransform rt = runtimeSelectionComponentUI.GetComponent <RectTransform>(); rt.SetSiblingIndex(0); rt.anchorMin = new Vector2(0, 0); rt.anchorMax = new Vector2(1, 1); rt.pivot = new Vector2(0.5f, 0.5f); rt.offsetMax = new Vector2(0, 0); rt.offsetMin = new Vector2(0, 0); } if (ui != null) { ui.Selected += OnUISelected; ui.Unselected += OnUIUnselected; } }