private void ImplantObject(ImplantObject io, ref RaycastHit hit) { GameObject obj = PrefabUtility.InstantiatePrefab(io.Prefab) as GameObject; ImplantObject pr = _Asset.DefaultObject; if (io.OverrideProperties) { pr = io; } if (obj != null) { // scale float scale = UnityEngine.Random.Range(pr.MinScalePercent, pr.MaxScalePercent); obj.transform.localScale *= scale; // position obj.transform.position = hit.point + (hit.normal * (_Implant.OffsetY * scale)); // rotation Quaternion rotation = obj.transform.rotation; if (pr.Rotation == ImplantObjectRotation.Random) { Vector3 euler = obj.transform.eulerAngles; euler.x = UnityEngine.Random.Range(pr.MinRandomRotation.x, pr.MaxRandomRotation.x); euler.y = UnityEngine.Random.Range(pr.MinRandomRotation.y, pr.MaxRandomRotation.y); euler.z = UnityEngine.Random.Range(pr.MinRandomRotation.z, pr.MaxRandomRotation.z); rotation = Quaternion.Euler(euler); } else if (pr.Rotation == ImplantObjectRotation.Custom) { rotation = Quaternion.Euler(pr.CustomRotation); } else { rotation *= Quaternion.FromToRotation(obj.transform.up, hit.normal); if (pr.RandomYaw) { rotation *= Quaternion.Euler(0, UnityEngine.Random.Range(0.0f, 360.0f), 0); } } obj.transform.rotation = rotation; obj.transform.parent = _Implant.Root != null ? _Implant.Root : _Implant.transform; Undo.RegisterCreatedObjectUndo(obj, "Create Object"); } }
private void ImplantObjects() { bool valid = false; Ray ray = new Ray(); Event e = Event.current; if (_ReferenceEnable) { valid = true; } else { ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); if (Physics.Raycast(ray, out _ReferenceHit, float.MaxValue, _Layers.Layers)) { valid = true; } } if (valid) { Vector3 center = _ReferenceHit.point + (_ReferenceHit.normal * 100); ray.direction = -_ReferenceHit.normal; RaycastHit hit; for (int i = 0; i < _Implant.Points.Length; i++) { ray.origin = center + _Rotation * _Implant.Points[i]; if (Physics.Raycast(ray, out hit, float.MaxValue, _Layers.Layers)) { ImplantObject randomObj = GetRandomImplantObject(); if (randomObj != null && randomObj.Prefab != null) { ImplantObject(randomObj, ref hit); } else { Debug.LogWarning("Please set valid prefab to implant"); return; } } } e.Use(); } }
public ImplantObjectListItem(ImplantAssetEditor editor, ImplantObject obj) : base(editor) { this.Object = obj; }
public ImplantObjectPropertiesField() { this.Margin = new Thickness(0, 0, 0, 8); this.Width = 300; this._MinScaleField = new FloatField() { Margin = new Thickness(2, 2, 2, 0) }; this._MinScaleField.Label.text = "Min Scale Percent"; this._MaxScaleField = new FloatField() { Margin = new Thickness(2, 2, 2, 0) }; this._MaxScaleField.Label.text = "Max Scale Percent"; this._ChanceField = new Skill.Editor.UI.Slider() { MinValue = 0.1f, MaxValue = 1.0f, Margin = new Thickness(2, 2, 2, 2) }; this._ChanceField.Label.text = "Chance"; _RandomRotationPanel = new Grid() { Height = 45 }; _RandomRotationPanel.ColumnDefinitions.Add(30, GridUnitType.Pixel); _RandomRotationPanel.ColumnDefinitions.Add(1, GridUnitType.Star); _RandomRotationPanel.RowDefinitions.Add(1, GridUnitType.Star); _RandomRotationPanel.RowDefinitions.Add(1, GridUnitType.Star); _MinRandomRotation = new Vector3Field() { Row = 0, Column = 1 }; _MaxRandomRotation = new Vector3Field() { Row = 1, Column = 1 }; _RandomRotationPanel.Controls.Add(_MinRandomRotation); _RandomRotationPanel.Controls.Add(_MaxRandomRotation); Label lblMin = new Label() { Row = 0, Column = 0, Text = "Min" }; Label lblMax = new Label() { Row = 1, Column = 0, Text = "Max" }; _RandomRotationPanel.Controls.Add(lblMin); _RandomRotationPanel.Controls.Add(lblMax); _CustomRotation = new Skill.Editor.UI.Vector3Field(); _RandomYaw = new Skill.Framework.UI.ToggleButton() { HorizontalAlignment = Skill.Framework.UI.HorizontalAlignment.Left, Margin = new Thickness(20, 0, 0, 0) }; _RandomYaw.Content.text = "Random Yaw"; _RotationSF = new Skill.Editor.UI.SelectionField() { Margin = new Thickness(2) }; _RotationSF.Label.Width = 110; _RotationSF.Background.Visibility = Skill.Framework.UI.Visibility.Hidden; _RotationSF.AddField(_RandomYaw, "Surface Normal "); _RotationSF.AddField(_CustomRotation, "Custom "); _RotationSF.AddField(_RandomRotationPanel, "Random "); _RotationLabel = new DropShadowLabel() { Text = "Rotation", Margin = new Thickness(4, 0, 0, 0) }; this.Orientation = Orientation.Vertical; this.Controls.Add(_MinScaleField); this.Controls.Add(_MaxScaleField); this.Controls.Add(_ChanceField); this.Controls.Add(_RotationLabel); this.Controls.Add(_RotationSF); this._MinScaleField.ValueChanged += new EventHandler(_MinScaleField_ValueChanged); this._MaxScaleField.ValueChanged += new EventHandler(_MaxScaleField_ValueChanged); this._ChanceField.ValueChanged += new EventHandler(_ChanceField_ValueChanged); this._RotationSF.SelectedFieldChanged += new EventHandler(_RotationSF_SelectedFieldChanged); this._MinRandomRotation.ValueChanged += _MinRandomRotation_ValueChanged; this._MaxRandomRotation.ValueChanged += _MaxRandomRotation_ValueChanged; this._CustomRotation.ValueChanged += new EventHandler(_CustomRotation_ValueChanged); this._RandomYaw.Changed += new EventHandler(_RandomYaw_Changed); this.Object = null; this.Height = _MinScaleField.LayoutHeight + _MinScaleField.Margin.Vertical + _MaxScaleField.LayoutHeight + _MaxScaleField.Margin.Vertical + _ChanceField.LayoutHeight + _ChanceField.Margin.Vertical + _RotationLabel.LayoutHeight + _RotationLabel.Margin.Vertical + _RotationSF.LayoutHeight + _RotationSF.Margin.Vertical + 20; }