public void OnSelected(ExposeToEditor obj) { EditorDemo editorDemo = IOC.Resolve <EditorDemo>(); if (editorDemo != null && editorDemo.EnableCharacters) { EnableCharacter(obj.gameObject); } }
private static bool CanHidePrefab() { EditorDemo editor = Object.FindObjectOfType <EditorDemo>(); if (editor == null) { return(false); } return(Selection.gameObjects != null && Selection.gameObjects.Any(go => go.IsPrefab() && editor.Prefabs != null && editor.Prefabs.Contains(go))); }
public void Spawn() { m_editor = EditorDemo.Instance; if (m_editor == null) { Debug.LogError("Editor.Instance is null"); return; } Vector3 point; m_dragPlane = new Plane(Vector3.up, m_editor.Pivot); if (GetPointOnDragPlane(out point)) { m_instance = Prefab.InstantiatePrefab(point, Quaternion.identity); enabled = true; m_spawn = true; } else { m_instance = Prefab.InstantiatePrefab(m_editor.Pivot, Quaternion.identity); } ExposeToEditor exposeToEditor = m_instance.GetComponent <ExposeToEditor>(); if (!exposeToEditor) { exposeToEditor = m_instance.AddComponent <ExposeToEditor>(); } exposeToEditor.SetName(Prefab.name); m_instance.SetActive(true); RuntimeUndo.BeginRecord(); RuntimeUndo.RecordSelection(); RuntimeUndo.BeginRegisterCreateObject(m_instance); RuntimeUndo.EndRecord(); bool isEnabled = RuntimeUndo.Enabled; RuntimeUndo.Enabled = false; RuntimeSelection.activeGameObject = m_instance; RuntimeUndo.Enabled = isEnabled; RuntimeUndo.BeginRecord(); RuntimeUndo.RegisterCreatedObject(m_instance); RuntimeUndo.RecordSelection(); RuntimeUndo.EndRecord(); }
private void Awake() { Instance = this; ExposeToEditor[] editorObjects = ExposeToEditor.FindAll(ExposeToEditorObjectType.Undefined, false).Select(go => go.GetComponent <ExposeToEditor>()).ToArray(); for (int i = 0; i < editorObjects.Length; ++i) { editorObjects[i].ObjectType = ExposeToEditorObjectType.EditorMode; } RuntimeTools.SnappingMode = SnappingMode.BoundingBox; RuntimeEditorApplication.IsOpened = !IsInPlayMode; RuntimeEditorApplication.SceneCameras = new[] { EditorCamera }; RuntimeEditorApplication.PlaymodeStateChanged += OnPlaymodeStateChanged; RuntimeEditorApplication.IsOpenedChanged += OnIsOpenedChanged; RuntimeSelection.SelectionChanged += OnRuntimeSelectionChanged; RuntimeTools.ToolChanged += OnRuntimeToolChanged; RuntimeTools.PivotRotationChanged += OnPivotRotationChanged; RuntimeUndo.UndoCompleted += OnUndoCompleted; RuntimeUndo.RedoCompleted += OnRedoCompleted; RuntimeUndo.StateChanged += OnUndoRedoStateChanged; TransformPanel.SetActive(RuntimeSelection.activeTransform != null); if (Prefabs != null && PrefabsPanel != null && PrefabPresenter != null) { Prefabs = Prefabs.Where(p => p != null).ToArray(); for (int i = 0; i < Prefabs.Length; ++i) { GameObject presenter = Instantiate(PrefabPresenter); presenter.transform.SetParent(PrefabsPanel.transform); presenter.transform.position = Vector3.zero; presenter.transform.localScale = Vector3.one; InstantiatePrefab instantiatePrefab = presenter.GetComponentInChildren <InstantiatePrefab>(); if (instantiatePrefab != null) { instantiatePrefab.Prefab = Prefabs[i]; } TakeSnapshot takeSnapshot = presenter.GetComponentInChildren <TakeSnapshot>(); if (takeSnapshot != null) { takeSnapshot.TargetPrefab = Prefabs[i]; } } } }
private void OnDestroy() { if (Instance == this) { Instance = null; RuntimeEditorApplication.Reset(); } RuntimeEditorApplication.PlaymodeStateChanged -= OnPlaymodeStateChanged; RuntimeEditorApplication.IsOpenedChanged -= OnIsOpenedChanged; RuntimeSelection.SelectionChanged -= OnRuntimeSelectionChanged; RuntimeTools.ToolChanged -= OnRuntimeToolChanged; RuntimeTools.PivotRotationChanged -= OnPivotRotationChanged; RuntimeUndo.RedoCompleted -= OnUndoCompleted; RuntimeUndo.RedoCompleted -= OnRedoCompleted; RuntimeUndo.StateChanged -= OnUndoRedoStateChanged; ExposeToEditor.Awaked -= OnAwaked; ExposeToEditor.Destroyed -= OnDestroyed; }
private static void HidePrefab() { EditorDemo editor = Object.FindObjectOfType <EditorDemo>(); Undo.RecordObject(editor, "Battlehub.RTEditor.ExposeToEditor"); List <GameObject> prefabs = editor.Prefabs.ToList(); foreach (GameObject go in Selection.gameObjects) { if (go.IsPrefab()) { if (editor.Prefabs != null && editor.Prefabs.Contains(go)) { prefabs.Remove(go); } } } editor.Prefabs = prefabs.ToArray(); EditorUtility.SetDirty(editor); }