private void OnEnable() { ObjectSelection.CategoryChanged += CategoryChanged; ObjectSelection.ClearList(); PopulateList(); }
private void OnMouseLeftClick(float x, float y) { if (ViewPortContains(x, y)) { if (CurrentOperation == ObjectOperation.Placing && newObject != null) { newObject.Pos = new Vector2(x, y) - parent.camera.CurrentOffset; WorldObjects.Add(newObject); newObject = new WorldObject(newObject, newObject.Pos); } if (CurrentOperation == ObjectOperation.None && !parent.grid.EditModeEnabled) { currentSelection = null; MouseLeftPressed?.Invoke(x, y); ObjectSelection?.Invoke(ref currentSelection); if (currentSelection != null) { InputStateChanged?.Invoke(false); } else { InputStateChanged?.Invoke(true); } } if (CurrentOperation == ObjectOperation.Placing && currentSelection != null) { currentSelection.Pos = new Vector2(x, y) + mousePadding - parent.camera.CurrentOffset; parent.inputHandler.MouseMovedEvent -= OnMousePosChanged; CurrentOperation = ObjectOperation.None; InputStateChanged?.Invoke(true); } } }
protected void EndAction() { if (this.action == ObjectEditorAction.None) { return; } Point mouseLoc = this.PointToClient(Cursor.Position); if (this.action == ObjectEditorAction.RectSelect) { this.activeRectSel = new ObjectSelection(); } if (Sandbox.State == SandboxState.Playing) { Sandbox.UnFreeze(); } this.OnEndAction(this.action); this.action = ObjectEditorAction.None; if (this.actionIsClone) { this.actionIsClone = false; UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromFirst); } UndoRedoManager.Finish(); }
internal protected override void OnEnterState() { base.OnEnterState(); DualityEditorApp.SelectionChanged += this.EditorForm_SelectionChanged; DualityEditorApp.ObjectPropertyChanged += this.EditorForm_ObjectPropertyChanged; // Initial selection update ObjectSelection current = DualityEditorApp.Selection; this.allObjSel = current.GameObjects.Select(g => new SelGameObj(g) as SelObj).ToList(); { var selectedGameObj = current.GameObjects; var indirectViaCmpQuery = current.Components.GameObject(); var indirectViaChildQuery = selectedGameObj.ChildrenDeep(); var indirectQuery = indirectViaCmpQuery.Concat(indirectViaChildQuery).Except(selectedGameObj).Distinct(); this.indirectObjSel = indirectQuery.Select(g => new SelGameObj(g) as SelObj).ToList(); } { var parentlessGameObj = current.GameObjects.Where(g => !current.GameObjects.Any(g2 => g.IsChildOf(g2))).ToList(); this.actionObjSel = parentlessGameObj.Select(g => new SelGameObj(g) as SelObj).Where(s => s.HasTransform).ToList(); } this.InvalidateSelectionStats(); }
private void OnKeyPress(Keys key) { if (key == Keys.G) { MoveSelectedItem(); } if (key == Keys.Escape) { if (CurrentOperation == ObjectOperation.None && currentSelection != null) { currentSelection = null; ObjectSelection?.Invoke(ref currentSelection); InputStateChanged?.Invoke(true); } } if (key == Keys.Delete) { if (CurrentOperation == ObjectOperation.None && currentSelection != null) { WorldObjects.Remove(currentSelection); currentSelection.Destroy(); currentSelection = null; InputStateChanged?.Invoke(true); ObjectSelection?.Invoke(ref currentSelection); } } if (key == Keys.D) { if (CurrentOperation == ObjectOperation.None && currentSelection != null) { DuplicateObject(); } } }
private void DragBeginAction(DragEventArgs e) { DataObject data = e.Data as DataObject; var dragObjQuery = new ConvertOperation(data, ConvertOperation.Operation.All).Perform <GameObject>(); if (dragObjQuery != null) { List <GameObject> dragObj = dragObjQuery.ToList(); bool lockZ = this.CameraComponent.FocusDist <= 0.0f; Point mouseLoc = this.PointToClient(new Point(e.X, e.Y)); Vector3 spaceCoord = this.GetSpaceCoord(new Vector3( mouseLoc.X, mouseLoc.Y, lockZ ? 0.0f : this.CameraObj.Transform.Pos.Z + MathF.Abs(this.CameraComponent.FocusDist))); // Setup GameObjects CreateGameObjectAction createAction = new CreateGameObjectAction(null, dragObj); DropGameObjectInSceneAction dropAction = new DropGameObjectInSceneAction(dragObj, spaceCoord, this.CameraObj.Transform.Angle); UndoRedoManager.BeginMacro(dropAction.Name); UndoRedoManager.Do(createAction); UndoRedoManager.Do(dropAction); // Select them & begin action this.selBeforeDrag = DualityEditorApp.Selection; this.SelectObjects(createAction.Result.Select(g => new SelGameObj(g) as SelObj)); this.BeginAction(ObjectAction.Move); // Get focused this.Focus(); e.Effect = e.AllowedEffect; } }
public void AddToProduction(UnitType unitType, int count, int delay, ObjectSelection objectSelection) { switch (unitType) { case UnitType.Worker: if (factory == null) { factory = new GameObject("Worker Factory"); WorkerFactory workerFactory = factory.AddComponent(typeof(WorkerFactory)) as WorkerFactory; timer = new Timer().CreateRepeatablTimer(count, delay); // To ask Arman this.objectSelection = objectSelection; timer.OnEndLap += OnUnitCreation; timer.OnEndLap += CreateUnit; timer.OnComplete += workerFactory.DestroyFactory; timer.StartTimer(); } else { timer.AddToQueue(count); } break; } }
void CreateObjectSelected(object userdata) { if (userdata != null) { ObjectSelection objSel = (ObjectSelection)userdata; AdvancedScriptableObject newObj = ScriptableObject.CreateInstance(objSel.Selected) as AdvancedScriptableObject; if (newObj == null) { Debug.Log("New obj is null"); } newObj.name = objSel.Selected; newObj.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.AddObjectToAsset(newObj, parentASO); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(newObj)); AdvancedScriptableObject newASO = (AdvancedScriptableObject)newObj; SerializedObject sObjAso = new SerializedObject(newASO); sObjAso.FindProperty("_parentAsset").objectReferenceValue = parentASO; sObjAso.ApplyModifiedProperties(); if (objSel.Property == null) { Debug.Log("Property is null"); } AlterProperty(objSel.Property, newObj); EditorUtility.SetDirty(objSel.Property.serializedObject.targetObject); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
private static void GlobalUpdateSelection(object sender, SelectionChangedEventArgs e) { ObjectInspector target = null; foreach (ObjectSelection.Category cat in ObjectSelection.EnumerateCategories(e.AffectedCategories)) { var objViews = from v in ObjectInspectorPlugin.Instance.ObjViews where v.AcceptsSelection(e.Current) select new { View = v, Empty = v.EmptySelection, PerfectFit = v.EmptySelection || (cat & v.DisplayedCategory) != ObjectSelection.Category.None, TypeShare = ObjectSelection.GetTypeShareLevel(e.Current.Exclusive(cat), v.DisplayedSelection), NumSameCatViews = ObjectInspectorPlugin.Instance.ObjViews.Count(o => o.AcceptsSelection(e.Current) && o.DisplayedCategory == v.DisplayedCategory) }; var sortedQuery = from o in objViews orderby o.PerfectFit descending, o.Empty ascending, o.NumSameCatViews descending, o.TypeShare ascending select o; var targetItem = sortedQuery.FirstOrDefault(); if (targetItem == null) { return; } target = targetItem.View; // If a mouse button is pressed, reschedule the selection for later - there might be a drag in progress if (Control.MouseButtons != System.Windows.Forms.MouseButtons.None) { target.selSchedMouse = e.Current; target.selSchedMouseCat = cat; target.timerSelectSched.Enabled = true; } else { target.UpdateSelection(e.Current, cat); } } // Make sure disposed objects are deselected in non-target views (locked, etc.) foreach (ObjectInspector v in ObjectInspectorPlugin.Instance.ObjViews) { if (v.EmptySelection) { continue; } if (v == target) { continue; } var disposedObj = e.Removed.OfType <IManageableObject>().Where(o => o.Disposed); if (disposedObj.Any()) { ObjectSelection disposedSel = new ObjectSelection(disposedObj); v.UpdateSelection(v.DisplayedSelection - disposedSel, v.DisplayedCategory); } } }
private void UpdateSelection(ObjectSelection sel, ObjectSelection.Category showCat) { this.selSchedMouse = null; this.selSchedMouseCat = ObjectSelection.Category.None; this.displaySel = sel; this.displayCat = showCat; if (showCat == ObjectSelection.Category.None) { return; } this.gridExpandState.UpdateFrom(this.propertyGrid.MainEditor); if ((showCat & ObjectSelection.Category.GameObjCmp) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.GameObjects.Union(sel.Components.GameObject())); this.displayCat = ObjectSelection.Category.GameObjCmp; this.propertyGrid.SelectObjects(this.displaySel, false); } else if ((showCat & ObjectSelection.Category.Resource) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.Resources); this.displayCat = ObjectSelection.Category.Resource; this.propertyGrid.SelectObjects(this.displaySel, this.displaySel.Resources.Any(r => r.IsDefaultContent)); } else if ((showCat & ObjectSelection.Category.Other) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.OtherObjects); this.displayCat = ObjectSelection.Category.Other; this.propertyGrid.SelectObjects(this.displaySel, false); } this.gridExpandState.ApplyTo(this.propertyGrid.MainEditor); this.buttonClone.Enabled = this.propertyGrid.Selection.Any(); }
public void SetSelectedItem(ObjectSelection selectedItem) { if (selectedItem != m_selectedItem) { DeselectLastItem(); m_selectedItem = selectedItem; } }
public bool AcceptsSelection(ObjectSelection sel) { if (this.LockedSelection) { return(false); } return(true); }
void MergeTypeSelected(object userData) { ObjectSelection selection = (ObjectSelection)userData; ASOReferenceData[] toMergeReferences = ASOManager.Me.GetReferencesOn(propertyASO); if (selection.Selected == "Current") { if (toMergeReferences.Length > 1) { if (!EditorUtility.DisplayDialog( "Object is referenced", string.Format("Merging this object will lose references on {0} objects. Continue?", toMergeReferences.Length - 1), "Confirm", "Cancel")) { return; } } AlterProperty(selection.Property, AdvancedScriptableObjectUtility.MergeCurrent( parentASO, propertyASO)); } else if (selection.Selected == "All") { if (toMergeReferences.Length > 1) { if (!EditorUtility.DisplayDialog( "Object is referenced", string.Format("Merging this object will lose references on multiple objects. Continue?"), "Confirm", "Cancel")) { return; } } AlterProperty(selection.Property, AdvancedScriptableObjectUtility.MergeAll( parentASO, parentASO, propertyASO)); } else if (selection.Selected == "Current Copy") { AlterProperty(selection.Property, AdvancedScriptableObjectUtility.MergeCurrent( parentASO, propertyASO, true)); } else if (selection.Selected == "All Copy") { AlterProperty(selection.Property, AdvancedScriptableObjectUtility.MergeAll( parentASO, parentASO, propertyASO, true)); } }
public void DeselectLastItem() { if (null == m_selectedItem) { return; } m_selectedItem.Deselect(); m_selectedItem = null; }
public ObjectPropertyChangedEventArgs(ObjectSelection obj, IEnumerable<PropertyInfo> infos, bool persistenceCritical = true) { if (infos == null) infos = new PropertyInfo[0]; this.obj = obj; this.propInfos = infos.ToList(); this.completeChange = this.propInfos.Count == 0; this.persistCritical = persistenceCritical; }
private void DuplicateObject() { currentSelection = new WorldObject(currentSelection, parent.inputHandler.GetMousePos() + mousePadding - parent.camera.CurrentOffset); WorldObjects.Add(currentSelection); CurrentOperation = ObjectOperation.Placing; parent.inputHandler.MouseMovedEvent += OnMousePosChanged; InputStateChanged?.Invoke(false); ObjectSelection?.Invoke(ref currentSelection); }
private void ApplyEditorSelection(ObjectSelection selection) { // Update the list of all selected objects this.allObjSel = selection.GameObjects .Select(g => new SceneEditorSelGameObj(g) as ObjectEditorSelObj) .ToList(); // Update the list of indirectly selected objects { IEnumerable <GameObject> selectedGameObj = selection.GameObjects; IEnumerable <GameObject> indirectViaCmpQuery = selection.Components.GameObject(); IEnumerable <GameObject> indirectViaChildQuery = selectedGameObj.ChildrenDeep(); IEnumerable <GameObject> indirectQuery = indirectViaCmpQuery .Concat(indirectViaChildQuery) .Except(selectedGameObj) .Distinct(); this.indirectObjSel = indirectQuery .Select(g => new SceneEditorSelGameObj(g) as ObjectEditorSelObj) .ToList(); } // Update (parent-free) action list based on the selection changes { // Start by assuming all selected objects to be part of the action this.actionObjSel.Clear(); this.actionObjSel.AddRange(this.allObjSel); // Remove GameObjects from the action list if their parent is part of // the selection as well, so we can avoid moving the same object twice. for (int i = this.actionObjSel.Count - 1; i >= 0; i--) { bool parentInSelection = false; for (int j = 0; j < this.actionObjSel.Count; j++) { parentInSelection = this.IsAffectedByParent( this.actionObjSel[i].ActualObject as GameObject, this.actionObjSel[j].ActualObject as GameObject); if (parentInSelection) { break; } } if (parentInSelection) { this.actionObjSel.RemoveAt(i); } } } this.InvalidateSelectionStats(); this.UpdateAction(); this.Invalidate(); }
public override BlueSoldier CreateUnit(ObjectSelection objectSelection) { var prefab = Resources.Load("Prefabs/BlueSoldier") as GameObject; var circlePrefab = Resources.Load("Prefabs/SelectionCircle", typeof(ISelectionIndicationWithShape)) as ISelectionIndicationWithShape; var soldier = UnityEngine.Object.Instantiate(prefab, Vector3.zero, Quaternion.identity); soldier.GetComponent <UnitCharacter>().Init(circlePrefab); objectSelection.AddNewInitsObject(soldier); return(soldier.GetComponent <BlueSoldier>()); }
public override Worker CreateUnit(ObjectSelection objectSelection) { var prefab = Resources.Load <UnitCharacter>("Prefabs/Worker"); var circlePrefab = Resources.Load("Prefabs/SelectionCircle", typeof(ISelectionIndicationWithShape)) as ISelectionIndicationWithShape; var worker = UnityEngine.Object.Instantiate(prefab, Vector3.zero, Quaternion.identity); worker.Init(circlePrefab); objectSelection.AddNewInitsObject(worker.gameObject); return(worker.GetComponent <Worker>()); }
public SelectionChangedEventArgs(ObjectSelection current, ObjectSelection previous, ObjectSelection.Category changedCategoryFallback) { this.current = current; this.previous = previous; this.diffCat = ObjectSelection.GetAffectedCategories(this.previous, this.current); if (this.diffCat == ObjectSelection.Category.None) this.diffCat = changedCategoryFallback; this.added = this.current - this.previous; this.removed = this.previous - this.current; }
public override void DeleteObjects(IEnumerable<SelObj> objEnum) { var objList = objEnum.Select(s => s.ActualObject as GameObject).ToList(); if (objList.Count == 0) return; // Ask user if he really wants to delete stuff ObjectSelection objSel = new ObjectSelection(objList); if (!DualityEditorApp.DisplayConfirmDeleteObjects(objSel)) return; if (!DualityEditorApp.DisplayConfirmBreakPrefabLinkStructure(objSel)) return; UndoRedoManager.Do(new DeleteGameObjectAction(objList)); }
public void Execute(object parameter) { ObjectSelection selection = m_selectionService.CurrentSelection as ObjectSelection; if (null == selection) { return; } TreeNode treeNode = selection.SelectedElement as TreeNode; DoWork(treeNode); }
public void deselect(ObjectSelection.Model objectSelectionModel) { switch (objectSelectionModel) { case ObjectSelection.Model.InfoDisplay: actualColor = defaultColor; obj.GetComponent<SpriteRenderer>().color = actualColor; break; default: obj.GetComponent<SpriteRenderer>().color = actualColor; break; } }
private void UpdateSelection(ObjectSelection sel, ObjectSelection.Category showCat) { this.selSchedMouse = null; this.selSchedMouseCat = ObjectSelection.Category.None; this.displaySel = sel; this.displayCat = showCat; if (showCat == ObjectSelection.Category.None) { return; } this.gridExpandState.UpdateFrom(this.propertyGrid.MainEditor); // Selection update may change MainEditor, unsubscribe from events if (this.propertyGrid.MainEditor is GroupedPropertyEditor) { GroupedPropertyEditor groupedMainEditor = this.propertyGrid.MainEditor as GroupedPropertyEditor; groupedMainEditor.EditorAdded -= this.MainEditor_EditorAdded; } if ((showCat & ObjectSelection.Category.GameObjCmp) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.GameObjects.Union(sel.Components.GameObject())); this.displayCat = ObjectSelection.Category.GameObjCmp; this.propertyGrid.SelectObjects(this.displaySel, false); } else if ((showCat & ObjectSelection.Category.Resource) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.Resources); this.displayCat = ObjectSelection.Category.Resource; this.propertyGrid.SelectObjects(this.displaySel, this.displaySel.Resources.Any(r => r.IsDefaultContent)); } else if ((showCat & ObjectSelection.Category.Other) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.OtherObjects); this.displayCat = ObjectSelection.Category.Other; this.propertyGrid.SelectObjects(this.displaySel, false); } if (this.propertyGrid.MainEditor is GroupedPropertyEditor) { GroupedPropertyEditor groupedMainEditor = this.propertyGrid.MainEditor as GroupedPropertyEditor; groupedMainEditor.EditorAdded += this.MainEditor_EditorAdded; } this.gridExpandState.ApplyTo(this.propertyGrid.MainEditor); this.buttonClone.Enabled = this.propertyGrid.Selection.Any(); }
private void Start() { _self = transform.gameObject; _user = GameObject.Find("HMD Camera"); _microSelectionOrigin = GameObject.Find("MicroSelectionOrigin"); _lerpTarget = GameObject.Find("IndActScaled"); _objectSelection = _user.GetComponent <ObjectSelection>(); _indirectManipulation = GameObject.Find("SceneController").GetComponent <IndirectManipulation>(); OriginalParent = transform.parent; if (_objectSelection.GlobalSelectableObjects.Contains(_self) == false) { _objectSelection.GlobalSelectableObjects.Add(_self); } }
public void Update(CamViewState state, Point mouseLoc, Point beginLoc, Vector3 beginLocSpace, Vector3 lastLocSpace, Vector3 selectionCenter, float selectionRadius, CamViewState.LockedAxis lockedAxis) { if (DualityEditorApp.IsSelectionChanging) { return; // Prevent Recursion in case SelectObjects triggers UpdateAction. } bool shift = (Control.ModifierKeys & Keys.Shift) != Keys.None; bool ctrl = (Control.ModifierKeys & Keys.Control) != Keys.None; // Determine picked rect int pX = Math.Max(Math.Min(mouseLoc.X, beginLoc.X), 0); int pY = Math.Max(Math.Min(mouseLoc.Y, beginLoc.Y), 0); int pX2 = Math.Max(mouseLoc.X, beginLoc.X); int pY2 = Math.Max(mouseLoc.Y, beginLoc.Y); int pW = Math.Max(pX2 - pX, 1); int pH = Math.Max(pY2 - pY, 1); // Check which renderers are picked List <CamViewState.SelObj> picked = state.PickSelObjIn(pX, pY, pW, pH); // Store in internal rect selection ObjectSelection oldRectSel = state.ActiveRectSel; state.ActiveRectSel = new ObjectSelection(picked); // Apply internal selection to actual editor selection if (shift || ctrl) { if (state.ActiveRectSel.ObjectCount > 0) { ObjectSelection added = (state.ActiveRectSel - oldRectSel) + (oldRectSel - state.ActiveRectSel); state.SelectObjects(added.OfType <CamViewState.SelObj>(), shift ? SelectMode.Append : SelectMode.Toggle); } } else if (state.ActiveRectSel.ObjectCount > 0) { state.SelectObjects(state.ActiveRectSel.OfType <CamViewState.SelObj>()); } else { state.ClearSelection(); } state.Invalidate(); }
private void UpdateRectSelection(Point mouseLoc) { if (DualityEditorApp.IsSelectionChanging) { return; // Prevent Recursion in case SelectObjects triggers UpdateAction. } bool shift = (Control.ModifierKeys & Keys.Shift) != Keys.None; bool ctrl = (Control.ModifierKeys & Keys.Control) != Keys.None; // Determine picked rect int pX = Math.Max(Math.Min(mouseLoc.X, this.actionBeginLoc.X), 0); int pY = Math.Max(Math.Min(mouseLoc.Y, this.actionBeginLoc.Y), 0); int pX2 = Math.Max(mouseLoc.X, this.actionBeginLoc.X); int pY2 = Math.Max(mouseLoc.Y, this.actionBeginLoc.Y); int pW = Math.Max(pX2 - pX, 1); int pH = Math.Max(pY2 - pY, 1); // Check which renderers are picked List <ObjectEditorSelObj> picked = this.PickSelObjIn(pX, pY, pW, pH); // Store in internal rect selection ObjectSelection oldRectSel = this.activeRectSel; this.activeRectSel = new ObjectSelection(picked); // Apply internal selection to actual editor selection if (shift || ctrl) { if (this.activeRectSel.ObjectCount > 0) { ObjectSelection added = (this.activeRectSel - oldRectSel) + (oldRectSel - this.activeRectSel); this.SelectObjects(added.OfType <ObjectEditorSelObj>(), shift ? SelectMode.Append : SelectMode.Toggle); } } else if (this.activeRectSel.ObjectCount > 0) { this.SelectObjects(this.activeRectSel.OfType <ObjectEditorSelObj>()); } else { this.ClearSelection(); } this.Invalidate(); }
private void contextMenu_RemoveComponent(object sender, EventArgs e) { Component[] values = this.GetValue().Cast <Component>().NotNull().ToArray(); // Ask user if he really wants to delete stuff ObjectSelection objSel = new ObjectSelection(values); if (!DualityEditorApp.DisplayConfirmDeleteObjects(objSel)) { return; } if (!DualityEditorApp.DisplayConfirmBreakPrefabLinkStructure(objSel)) { return; } // Delete Components UndoRedoManager.Do(new DeleteComponentAction(values)); }
private void PopulateList() { ObjectSelection.ClearList(); var spawnablesByType = SpawnableManager.Prefabs.Where(x => x.Type == (Enumerations.SpawnableType)ObjectSelection.CurrentCategoryIndex).ToList(); if (spawnablesByType.Any()) { foreach (var spawnable in spawnablesByType) { string displayText = string.IsNullOrEmpty(spawnable.MenuText) ? spawnable.Prefab.name.Replace("selectable", string.Empty) : spawnable.MenuText; ObjectSelection.AddToList(displayText, spawnable.PreviewTexture, () => ObjectClicked(spawnable), () => ListItemSelected(spawnable)); } if (ObjectSelection.ListContent.transform.childCount > 0) { EventSystem.current.SetSelectedGameObject(ObjectSelection.ListContent.transform.GetChild(0).gameObject); } } }
void UnmergeTypeSelected(object userData) { ObjectSelection selection = (ObjectSelection)userData; if (selection.Selected == "Current") { AlterProperty(selection.Property, AdvancedScriptableObjectUtility.UnmergeCurrent( parentASO, propertyASO)); AddReferenceData(selection.Property); } else if (selection.Selected == "All") { //Need to first remove the object from serialized object AlterProperty(selection.Property, AdvancedScriptableObjectUtility.UnmergeAll( parentASO, propertyASO)); AddReferenceData(selection.Property); } }
private void Start() { _self = transform.gameObject; _user = GameObject.Find("HMD Camera"); _objectSelection = _user.GetComponent <ObjectSelection>(); _selectionTarget = GameObject.Find("MultiSelectTarget"); _posXRef = GameObject.Find("MSObjXRef"); _posYRef = GameObject.Find("MSObjYRef"); _xAngRef = GameObject.Find("MSXAngRef"); _yAngRef = GameObject.Find("MSYAngRef"); _xRRef = GameObject.Find("MSXRRef"); _xLRef = GameObject.Find("MSXLRef"); _yTRef = GameObject.Find("MSYTRef"); _yBRef = GameObject.Find("MSYBRef"); _objProx = GameObject.Find("MSObjProx"); _grab = GameObject.Find("MSIndAct"); _lr = GetComponent <LineRenderer>(); _lerpTarget = GameObject.Find("IndActScaled"); _indirectManipulation = GameObject.Find("SceneController").GetComponent <IndirectManipulation>(); _mf = GetComponent <MeshFilter>(); _m = _mf.mesh; }
public override void DeleteObjects(IEnumerable <SelObj> objEnum) { var objList = objEnum.Select(s => s.ActualObject as GameObject).ToList(); if (objList.Count == 0) { return; } // Ask user if he really wants to delete stuff ObjectSelection objSel = new ObjectSelection(objList); if (!DualityEditorApp.DisplayConfirmDeleteObjects(objSel)) { return; } if (!DualityEditorApp.DisplayConfirmBreakPrefabLinkStructure(objSel)) { return; } UndoRedoManager.Do(new DeleteGameObjectAction(objList)); }
private void Start() { _user = GameObject.Find("HMD Camera"); _ctrlMidpointRef = GameObject.Find("CtrlMidpointRef"); _ctrlProx = GameObject.Find("CtrlProx"); _ctrlAct = GameObject.Find("CtrlAct"); _ctrlText = GameObject.Find("CtrlText"); _indProx = GameObject.Find("IndProx"); _indAct = GameObject.Find("IndAct"); _indText = GameObject.Find("IndText"); _ctrlRefNorm = GameObject.Find("CtrlRefNorm"); _indRefNorm = GameObject.Find("IndRefNorm"); _ctrlRatMax = GameObject.Find("CtrlRatMax"); _indRatMax = GameObject.Find("IndRatMax"); _indActScaled = GameObject.Find("IndActScaled"); _objectText = GameObject.Find("ActiveObjectText"); _ctrlLine = _ctrlProx.GetComponent <LineRenderer>(); _indLine = _indProx.GetComponent <LineRenderer>(); _joinLine = transform.GetComponent <LineRenderer>(); _objectSelection = _user.GetComponent <ObjectSelection>(); }
// Start is called before the first frame update void Start() { Selectionmanager = GameObject.Find("Main Camera").gameObject.GetComponent <ObjectSelection>(); Count = 0; radius = radius * 2; var agParent = GameObject.Find("AgentCreator"); for (int i = 0; i < agentCount; i++) { location = new Vector3((Random.value - 0.5f) * radius, 0.5f, (Random.value - 0.5f) * radius); var newAgent = Instantiate(agent, location, Quaternion.identity); //var a = newAgent.GetComponent<Rigidbody>(); //a.AddForce(100,0,0); //newAgent.transform.position = new Vector3((Random.value - 0.5f) * radius, 0.5f, ((Random.value - 0.5f)) * radius); newAgent.name = "a" + i; newAgent.transform.parent = agParent.transform; CreatedAgents.Add(newAgent); Count++; } }
public ObjectPropertyChangedEventArgs(ObjectSelection obj, bool persistenceCritical = true) : this(obj, null, persistenceCritical) {}
protected void EndAction() { if (this.action == ObjectEditorAction.None) return; Point mouseLoc = this.PointToClient(Cursor.Position); if (this.action == ObjectEditorAction.RectSelect) { this.activeRectSel = new ObjectSelection(); } if (Sandbox.State == SandboxState.Playing) Sandbox.UnFreeze(); this.OnEndAction(this.action); this.action = ObjectEditorAction.None; if (this.actionIsClone) { this.actionIsClone = false; UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromFirst); } UndoRedoManager.Finish(); }
private void DragBeginAction(DragEventArgs e) { DataObject data = e.Data as DataObject; var dragObjQuery = new ConvertOperation(data, ConvertOperation.Operation.All).Perform<GameObject>(); if (dragObjQuery != null) { List<GameObject> dragObj = dragObjQuery.ToList(); bool lockZ = this.CameraComponent.FocusDist <= 0.0f; Point mouseLoc = this.PointToClient(new Point(e.X, e.Y)); Vector3 spaceCoord = this.GetSpaceCoord(new Vector3( mouseLoc.X, mouseLoc.Y, lockZ ? 0.0f : this.CameraObj.Transform.Pos.Z + MathF.Abs(this.CameraComponent.FocusDist))); // Setup GameObjects CreateGameObjectAction createAction = new CreateGameObjectAction(null, dragObj); DropGameObjectInSceneAction dropAction = new DropGameObjectInSceneAction(dragObj, spaceCoord, this.CameraObj.Transform.Angle); UndoRedoManager.BeginMacro(dropAction.Name); UndoRedoManager.Do(createAction); UndoRedoManager.Do(dropAction); // Select them & begin action this.selBeforeDrag = DualityEditorApp.Selection; this.SelectObjects(createAction.Result.Select(g => new SelGameObj(g) as SelObj)); this.BeginAction(ObjectAction.Move); // Get focused this.Focus(); e.Effect = e.AllowedEffect; } }
private void UpdateRectSelection(Point mouseLoc) { if (DualityEditorApp.IsSelectionChanging) return; // Prevent Recursion in case SelectObjects triggers UpdateAction. bool shift = (Control.ModifierKeys & Keys.Shift) != Keys.None; bool ctrl = (Control.ModifierKeys & Keys.Control) != Keys.None; // Determine picked rect int pX = Math.Max(Math.Min(mouseLoc.X, this.actionBeginLoc.X), 0); int pY = Math.Max(Math.Min(mouseLoc.Y, this.actionBeginLoc.Y), 0); int pX2 = Math.Max(mouseLoc.X, this.actionBeginLoc.X); int pY2 = Math.Max(mouseLoc.Y, this.actionBeginLoc.Y); int pW = Math.Max(pX2 - pX, 1); int pH = Math.Max(pY2 - pY, 1); // Check which renderers are picked List<ObjectEditorSelObj> picked = this.PickSelObjIn(pX, pY, pW, pH); // Store in internal rect selection ObjectSelection oldRectSel = this.activeRectSel; this.activeRectSel = new ObjectSelection(picked); // Apply internal selection to actual editor selection if (shift || ctrl) { if (this.activeRectSel.ObjectCount > 0) { ObjectSelection added = (this.activeRectSel - oldRectSel) + (oldRectSel - this.activeRectSel); this.SelectObjects(added.OfType<ObjectEditorSelObj>(), shift ? SelectMode.Append : SelectMode.Toggle); } } else if (this.activeRectSel.ObjectCount > 0) this.SelectObjects(this.activeRectSel.OfType<ObjectEditorSelObj>()); else this.ClearSelection(); this.Invalidate(); }
public HighlightObjectEventArgs(ObjectSelection target, HighlightMode mode) { this.target = target; this.mode = mode; }
void Awake() { image = GetComponent<Image>(); objectSelection = GameObject.Find("ObjectSelectionMenu").GetComponent<ObjectSelection>(); }
void Start() { Instance = this; }
public PrefabAppliedEventArgs(ObjectSelection obj) : base(obj.HierarchyExpand(), new PropertyInfo[0]) {}
private void contextMenu_RemoveComponent(object sender, EventArgs e) { Component[] values = this.GetValue().Cast<Component>().NotNull().ToArray(); // Ask user if he really wants to delete stuff ObjectSelection objSel = new ObjectSelection(values); if (!DualityEditorApp.DisplayConfirmDeleteObjects(objSel)) return; if (!DualityEditorApp.DisplayConfirmBreakPrefabLinkStructure(objSel)) return; // Delete Components UndoRedoManager.Do(new DeleteComponentAction(values)); }
protected void DeleteNodes(IEnumerable<TreeNodeAdv> nodes) { var nodeQuery = from viewNode in nodes select this.objectModel.FindNode(this.objectView.GetPath(viewNode)) as NodeBase; var cmpQuery = from cmpNode in nodeQuery where cmpNode is ComponentNode select (cmpNode as ComponentNode).Component; var objQuery = from objNode in nodeQuery where objNode is GameObjectNode select (objNode as GameObjectNode).Obj; var objList = objQuery.ToList(); for (int i = objList.Count - 1; i >= 0; i--) { if (objList.Any(p => objList[i].IsChildOf(p))) objList.RemoveAt(i); } var cmpList = cmpQuery.Where(c => !objList.Any(p => c.GameObj == p || c.GameObj.IsChildOf(p))).ToList(); // Check which Components may be removed and which not Component conflictComp = this.CheckComponentsRemovable(cmpList, objList); if (conflictComp != null) { this.FlashNode(this.FindNode(conflictComp)); System.Media.SystemSounds.Beep.Play(); } if (objList.Count == 0 && cmpList.Count == 0) return; // Ask user if he really wants to delete stuff ObjectSelection objSel = new ObjectSelection(objList.AsEnumerable<object>().Concat(cmpList)); if (!DualityEditorApp.DisplayConfirmDeleteObjects(objSel)) return; if (!DualityEditorApp.DisplayConfirmBreakPrefabLinkStructure(objSel)) return; // Delete objects this.objectView.BeginUpdate(); UndoRedoManager.BeginMacro(string.Format(SceneViewRes.UndoRedo_DeleteObjects, objList.Count + cmpList.Count)); UndoRedoManager.Do(new DeleteGameObjectAction(objList)); UndoRedoManager.Do(new DeleteComponentAction(cmpList)); UndoRedoManager.EndMacro(); this.objectView.EndUpdate(); }
public static HelpInfo FromSelection(ObjectSelection sel) { if (sel == null || sel.GameObjectCount != 1) return null; return FromGameObject(sel.GameObjects.First()); // ToDo: Probably improve later }
private void UpdateSelection(ObjectSelection sel, ObjectSelection.Category showCat) { this.selSchedMouse = null; this.selSchedMouseCat = ObjectSelection.Category.None; this.displaySel = sel; this.displayCat = showCat; if (showCat == ObjectSelection.Category.None) return; this.gridExpandState.UpdateFrom(this.propertyGrid.MainEditor); if ((showCat & ObjectSelection.Category.GameObjCmp) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.GameObjects.Union(sel.Components.GameObject())); this.displayCat = ObjectSelection.Category.GameObjCmp; this.propertyGrid.SelectObjects(this.displaySel, false); } else if ((showCat & ObjectSelection.Category.Resource) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.Resources); this.displayCat = ObjectSelection.Category.Resource; this.propertyGrid.SelectObjects(this.displaySel, this.displaySel.Resources.Any(r => r.IsDefaultContent)); } else if ((showCat & ObjectSelection.Category.Other) != ObjectSelection.Category.None) { this.displaySel = new ObjectSelection(sel.OtherObjects); this.displayCat = ObjectSelection.Category.Other; this.propertyGrid.SelectObjects(this.displaySel, false); } this.gridExpandState.ApplyTo(this.propertyGrid.MainEditor); this.buttonClone.Enabled = this.propertyGrid.Selection.Any(); }
private static void GlobalUpdateSelection(object sender, SelectionChangedEventArgs e) { ObjectInspector target = null; foreach (ObjectSelection.Category cat in ObjectSelection.EnumerateCategories(e.AffectedCategories)) { var objViews = from v in ObjectInspectorPlugin.Instance.ObjViews where v.AcceptsSelection(e.Current) select new { View = v, Empty = v.EmptySelection, PerfectFit = v.EmptySelection || (cat & v.DisplayedCategory) != ObjectSelection.Category.None, TypeShare = ObjectSelection.GetTypeShareLevel(e.Current.Exclusive(cat), v.DisplayedSelection), NumSameCatViews = ObjectInspectorPlugin.Instance.ObjViews.Count(o => o.AcceptsSelection(e.Current) && o.DisplayedCategory == v.DisplayedCategory) }; var sortedQuery = from o in objViews orderby o.PerfectFit descending, o.Empty ascending, o.NumSameCatViews descending, o.TypeShare ascending select o; var targetItem = sortedQuery.FirstOrDefault(); if (targetItem == null) return; target = targetItem.View; // If a mouse button is pressed, reschedule the selection for later - there might be a drag in progress if (Control.MouseButtons != System.Windows.Forms.MouseButtons.None) { target.selSchedMouse = e.Current; target.selSchedMouseCat = cat; target.timerSelectSched.Enabled = true; } else { target.UpdateSelection(e.Current, cat); } } // Make sure disposed objects are deselected in non-target views (locked, etc.) foreach (ObjectInspector v in ObjectInspectorPlugin.Instance.ObjViews) { if (v.EmptySelection) continue; if (v == target) continue; var disposedObj = e.Removed.OfType<IManageableObject>().Where(o => o.Disposed); if (disposedObj.Any()) { ObjectSelection disposedSel = new ObjectSelection(disposedObj); v.UpdateSelection(v.DisplayedSelection - disposedSel, v.DisplayedCategory); } } }
public void select(ObjectSelection.Model objectSelectionModel) { switch (objectSelectionModel) { case ObjectSelection.Model.ColonyTarget: obj.GetComponent<SpriteRenderer>().color = new Color(0.15f, 0.96f, 0.17f, 1); break; case ObjectSelection.Model.BoosterApplication: obj.GetComponent<SpriteRenderer>().color = new Color(0.79f, 0.24f, 1f, 1); break; case ObjectSelection.Model.InfoDisplay: actualColor = new Color(1, 0, 0, 1); obj.GetComponent<SpriteRenderer>().color = actualColor; break; } }
public bool AcceptsSelection(ObjectSelection sel) { if (this.LockedSelection) return false; return true; }
private void ApplyEditorSelection(ObjectSelection selection) { // Update the list of all selected objects this.allObjSel = selection.GameObjects .Select(g => new SceneEditorSelGameObj(g) as ObjectEditorSelObj) .ToList(); // Update the list of indirectly selected objects { IEnumerable<GameObject> selectedGameObj = selection.GameObjects; IEnumerable<GameObject> indirectViaCmpQuery = selection.Components.GameObject(); IEnumerable<GameObject> indirectViaChildQuery = selectedGameObj.ChildrenDeep(); IEnumerable<GameObject> indirectQuery = indirectViaCmpQuery .Concat(indirectViaChildQuery) .Except(selectedGameObj) .Distinct(); this.indirectObjSel = indirectQuery .Select(g => new SceneEditorSelGameObj(g) as ObjectEditorSelObj) .ToList(); } // Update (parent-free) action list based on the selection changes { // Start by assuming all selected objects to be part of the action this.actionObjSel.Clear(); this.actionObjSel.AddRange(this.allObjSel); // Remove GameObjects from the action list if their parent is part of // the selection as well, so we can avoid moving the same object twice. for (int i = this.actionObjSel.Count - 1; i >= 0; i--) { bool parentInSelection = false; for (int j = 0; j < this.actionObjSel.Count; j++) { parentInSelection = this.IsAffectedByParent( this.actionObjSel[i].ActualObject as GameObject, this.actionObjSel[j].ActualObject as GameObject); if (parentInSelection) break; } if (parentInSelection) { this.actionObjSel.RemoveAt(i); } } } this.InvalidateSelectionStats(); this.UpdateAction(); this.Invalidate(); }