public override void Submit() { ParametersController controller = gObject.GetComponent <ParametersController>(); if (null != controller && !controller.IsDeletable()) { return; } ToolsUIManager.Instance.SpawnDeleteInstanceVFX(gObject); CommandGroup constraintGroup = null; List <Constraint> constraints = ConstraintManager.GetObjectConstraints(gObject); if (constraints.Count > 0) { constraintGroup = new CommandGroup("Constraints"); foreach (Constraint constraint in constraints) { new CommandRemoveConstraint(constraint.constraintType, constraint.gobject).Submit(); } } Redo(); CommandManager.AddCommand(this); if (null != constraintGroup) { constraintGroup.Submit(); } }
private void AddObject(GameObject gobject) { if (!items.TryGetValue(selectedItem, out AssetBankItem item)) { Debug.LogWarning($"Item {gobject.name} not found in Asset Bank (id: {selectedItem})"); return; } // Get the position of the mouthpiece into matrix Matrix4x4 matrix = SceneManager.RightHanded.worldToLocalMatrix * mouthpiece.localToWorldMatrix; Maths.DecomposeMatrix(matrix, out Vector3 t, out _, out _); Vector3 scale = Vector3.one; CommandGroup group = new CommandGroup("Instantiate Bank Object"); try { // Add the object to scene ClearSelection(); CommandAddGameObject command = new CommandAddGameObject(gobject); command.Submit(); GameObject newObject = command.newObject; if (item.imported) { ParametersController controller = newObject.GetComponent <ParametersController>(); if (null == controller) { controller = newObject.AddComponent <ParametersController>(); controller.isImported = true; controller.importPath = item.assetName; } } // Set the object size to 20cm in the user space Bounds bounds = new Bounds(); foreach (var subMeshFilter in newObject.GetComponentsInChildren <MeshFilter>()) { if (!useDefaultInstantiationScale) { bounds.Encapsulate(subMeshFilter.mesh.bounds); } } if (bounds.size.magnitude > 0) { scale *= (0.2f / bounds.size.magnitude) / GlobalState.WorldScale; // 0.2: 20cm } AddToSelection(newObject); SceneManager.SetObjectMatrix(newObject, Matrix4x4.TRS(t, Quaternion.identity, scale)); Selection.HoveredObject = newObject; } finally { group.Submit(); } }
public override void CopyParameters(ParametersController otherController) { base.CopyParameters(otherController); CameraController other = otherController as CameraController; focal = other.focal; near = other.near; far = other.far; focus = other.focus; aperture = other.aperture; enableDOF = other.enableDOF; filmHeight = other.filmHeight; filmWidth = other.filmWidth; gateFit = other.gateFit; }
void UpdateTransformUI(GameObject gobject) { GameObject selected = null; foreach (GameObject o in Selection.SelectedObjects) { selected = o; break; } if (null == selected || gobject != selected) { return; } // Transform Vector3 localPosition = selected.transform.localPosition; posXButton.Text = localPosition.x.ToString(); posYButton.Text = localPosition.y.ToString(); posZButton.Text = localPosition.z.ToString(); Vector3 localRotation = selected.transform.localEulerAngles; rotXButton.Text = localRotation.x.ToString(); rotYButton.Text = localRotation.y.ToString(); rotZButton.Text = localRotation.z.ToString(); Vector3 localScale = selected.transform.localScale; scaleXButton.Text = localScale.x.ToString(); scaleYButton.Text = localScale.y.ToString(); scaleZButton.Text = localScale.z.ToString(); ParametersController parametersController = selected.GetComponent <ParametersController>(); if (null != parametersController) { posLockButton.Checked = parametersController.lockPosition; SetLockPosition(parametersController.lockPosition); rotLockButton.Checked = parametersController.lockRotation; SetLockRotation(parametersController.lockRotation); scaleLockButton.Checked = parametersController.lockScale; SetLockScale(parametersController.lockScale); } }
public override void CopyParameters(ParametersController otherController) { base.CopyParameters(otherController); LightController other = otherController as LightController; Intensity = other.Intensity; minIntensity = other.minIntensity; maxIntensity = other.maxIntensity; Color = other.Color; CastShadows = other.CastShadows; ShadowNearPlane = other.ShadowNearPlane; Range = other.Range; minRange = other.minRange; maxRange = other.maxRange; OuterAngle = other.OuterAngle; Sharpness = other.Sharpness; }
public static void RemoveConstraint <T>(GameObject gobject) where T : UnityEngine.Component { T component = gobject.GetComponent <T>(); IConstraint constraint = component as IConstraint; ParametersController parametersController = gobject.GetComponent <ParametersController>(); if (null != parametersController) { ConstraintType constraintType = ConstraintType.Unknown; switch (component) { case ParentConstraint _: constraintType = ConstraintType.Parent; break; case LookAtConstraint _: constraintType = ConstraintType.LookAt; break; } foreach (Constraint con in constraints) { if (con.gobject == gobject && con.constraintType == constraintType) { GameObject.Destroy(con.lineGameObject); constraints.Remove(con); break; } } } GameObject source = constraint.GetSource(0).sourceTransform.gameObject; ParametersController sourceParametersController = source.GetComponent <ParametersController>(); if (null != sourceParametersController) { sourceParametersController.RemoveConstraintHolder(gobject); } constraint.RemoveSource(0); GameObject.Destroy(component); GlobalState.FireObjectConstraint(gobject); }
public void SetLockScale(bool value) { foreach (GameObject gobject in Selection.SelectedObjects) { if (value) { ParametersController controller = gobject.GetComponent <ParametersController>(); if (null == controller) { controller = gobject.AddComponent <ParametersController>(); } controller.lockScale = value; } else { ParametersController controller = gobject.GetComponent <ParametersController>(); if (null != controller) { controller.lockScale = value; } } } }
/// <summary> /// For imported objects, if something has changed (transform, material, sub-object...) mark it /// as non imported, so we can save and load it with all its modifications. /// </summary> /// <param name="gobject"></param> private static void SetAsNonImported(GameObject gobject, bool checkRoot = true) { ParametersController controller = gobject.GetComponent <ParametersController>(); if (null != controller && controller.isImported && !checkRoot) { return; } // Search for an imported object in the object's hierarchy (parents) Transform parent = gobject.transform; while (null != parent && parent != RightHanded) { controller = parent.GetComponent <ParametersController>(); if (null != controller && controller.isImported) { controller.isImported = false; controller.importPath = null; return; } parent = parent.parent; } }
protected override void DoUpdate() { // Base selection update base.DoUpdate(); // Deform if (deformEnabled && activePlane != null) { VRInput.ButtonEvent(VRInput.primaryController, CommonUsages.trigger, () => { InitDeformerMatrix(); InitTransforms(); planeControllerDelta = FilterControllerDirection() - activePlane.transform.position; // in absolute coordinates Vector3 initDelta = activePlane.transform.position - activePlane.opposite.position; initMagnitude = initDelta.magnitude; // initial scale value OnStartDeform(); }, () => { OnEndDeform(); }); } if (deformEnabled && deforming) { Vector3 controllerPosition = FilterControllerDirection(); controllerPosition -= planeControllerDelta; Vector3 delta = controllerPosition - activePlane.opposite.position; float magnitude = delta.magnitude; float scaleFactor = magnitude / initMagnitude; Vector3 scale = new Vector3(scaleFactor, scaleFactor, scaleFactor); int selectionCount = Selection.ActiveObjects.Count; bool foundLightOrCamera = false; if (selectionCount == 1) { foundLightOrCamera = IsHierarchical(Selection.ActiveObjects); } bool scaleAll = selectionCount != 1 || foundLightOrCamera || uniformScale; if (!scaleAll) { scale = new Vector3( activePlane.direction.x == 0f ? 1f : scale.x, activePlane.direction.y == 0f ? 1f : scale.y, activePlane.direction.z == 0f ? 1f : scale.z ); } Matrix4x4 scaleMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale); Matrix4x4 transformationMatrix = initOppositeMatrix * scaleMatrix; TransformSelection(transformationMatrix * initMouthPieceWorldToLocal); } // Bounds if (deformEnabled) { ComputeSelectionBounds(); bool enable = Selection.ActiveObjects.Count != 0; if (Selection.ActiveObjects.Count == 1) { foreach (GameObject gobject in Selection.ActiveObjects) { ParametersController controller = gobject.GetComponent <ParametersController>(); if (null != controller && !controller.IsDeformable()) { enable = false; } } } boundingBox.SetActive(enable); } // Move grid with object(s), enable/disable it. UpdateGrid(); }
public static void AddLookAtConstraint(GameObject gobject, GameObject target, int index = -1) { LookAtConstraint constraint = gobject.GetComponent <LookAtConstraint>(); if (null == constraint) { constraint = gobject.AddComponent <LookAtConstraint>(); ParametersController parametersController = gobject.GetComponent <ParametersController>(); if (null == parametersController) { gobject.AddComponent <ParametersController>(); } Constraint newConstraint = new Constraint { gobject = gobject, target = target.transform, constraintType = ConstraintType.LookAt }; if (index == -1) { constraints.Add(newConstraint); } else { constraints.Insert(index, newConstraint); } ParametersController targetParametersController = target.GetComponent <ParametersController>(); if (null == targetParametersController) { targetParametersController = target.AddComponent <ParametersController>(); } targetParametersController.AddConstraintHolder(gobject); } else { // update visual target for LineRenderer foreach (Constraint c in constraints) { if (c.gobject == gobject && c.constraintType == ConstraintType.LookAt) { c.target = target.transform; break; } } } ConstraintSource source; if (constraint.sourceCount == 0) { source = new ConstraintSource(); constraint.AddSource(source); } else { source = constraint.GetSource(0); } source.sourceTransform = target.transform; source.weight = 1f; constraint.SetSource(0, source); constraint.rotationOffset = new Vector3(0, 180, 0); constraint.constraintActive = true; GlobalState.FireObjectConstraint(gobject); }
public static void AddParentConstraint(GameObject gobject, GameObject target, int index = -1) { ParentConstraint constraint = gobject.GetComponent <ParentConstraint>(); if (null == constraint) { constraint = gobject.AddComponent <ParentConstraint>(); ParametersController parametersController = gobject.GetComponent <ParametersController>(); if (null == parametersController) { gobject.AddComponent <ParametersController>(); } Constraint newConstraint = new Constraint { gobject = gobject, target = target.transform, constraintType = ConstraintType.Parent }; if (index == -1) { constraints.Add(newConstraint); } else { constraints.Insert(index, newConstraint); } ParametersController targetParametersController = target.GetComponent <ParametersController>(); if (null == targetParametersController) { targetParametersController = target.AddComponent <ParametersController>(); } targetParametersController.AddConstraintHolder(gobject); } else { // update visual target for LineRenderer foreach (Constraint c in constraints) { if (c.gobject == gobject && c.constraintType == ConstraintType.Parent) { c.target = target.transform; break; } } } ConstraintSource source; if (constraint.sourceCount == 0) { source = new ConstraintSource(); constraint.AddSource(source); } else { source = constraint.GetSource(0); } source.sourceTransform = target.transform; source.weight = 1f; constraint.SetSource(0, source); constraint.translationAtRest = gobject.transform.localPosition; constraint.rotationAtRest = gobject.transform.localRotation.eulerAngles; Vector3 offset = Vector3.Scale(target.transform.InverseTransformPoint(gobject.transform.position), target.transform.lossyScale); constraint.SetTranslationOffset(0, offset); Quaternion quat = Quaternion.Inverse(target.transform.rotation) * gobject.transform.rotation; constraint.SetRotationOffset(0, quat.eulerAngles); constraint.constraintActive = true; GlobalState.FireObjectConstraint(gobject); }
public override void CopyParameters(ParametersController sourceController) { lockPosition = sourceController.lockPosition; lockRotation = sourceController.lockRotation; lockScale = sourceController.lockScale; }
void SetRecursiveLayerSmart(GameObject gObject, LayerType layerType, bool isChild = false) { string layerName = LayerMask.LayerToName(gObject.layer); bool isSkinMesh = gObject.TryGetComponent <SkinnedMeshRenderer>(out SkinnedMeshRenderer mesh); // // SELECT // if (layerType == LayerType.Selection) { if (layerName == "Default") { if (isChild && !Selection.IsSelected(gObject) && !isSkinMesh) { layerName = "SelectionChild"; } else { layerName = "Selection"; } } else if (layerName == "Hover" || layerName == "HoverChild") { if (isChild && !Selection.IsSelected(gObject) && !isSkinMesh) { layerName = "SelectionChild"; } else { layerName = "Selection"; } } else if (layerName == "CameraHidden") { layerName = "SelectionCameraHidden"; } else if (layerName == "HoverCameraHidden") { layerName = "SelectionCameraHidden"; } } // // HOVER // else if (layerType == LayerType.Hover) { if (layerName == "Default") { if (isChild && !Selection.IsSelected(gObject) && !isSkinMesh) { layerName = "HoverChild"; } else { layerName = "Hover"; } } else if (layerName == "Selection" || layerName == "SelectionChild") { if (isChild && !Selection.IsSelected(gObject) && !isSkinMesh) { layerName = "HoverChild"; } else { layerName = "Hover"; } } else if (layerName == "CameraHidden") { layerName = "HoverCameraHidden"; } else if (layerName == "SelectionCameraHidden") { layerName = "HoverCameraHidden"; } } // // RESET layer // else if (layerType == LayerType.Default) { if (layerName == "SelectionCameraHidden") { layerName = "CameraHidden"; } else if (layerName == "Hover" || layerName == "HoverChild") { string parentLayer = ""; if (HasParentOrConstraintSelected(gObject.transform, ref parentLayer)) { layerName = parentLayer + "Child"; } else { layerName = "Default"; } } else if (layerName == "HoverCameraHidden") { layerName = "CameraHidden"; } else if (layerName == "Selection" || layerName == "SelectionChild") { string parentLayer = ""; if (HasParentOrConstraintSelected(gObject.transform, ref parentLayer)) { layerName = parentLayer + "Child"; } else { layerName = "Default"; } } } gObject.layer = LayerMask.NameToLayer(layerName); for (int i = 0; i < gObject.transform.childCount; i++) { SetRecursiveLayerSmart(gObject.transform.GetChild(i).gameObject, layerType, true); } ParametersController parametersConstroller = gObject.GetComponent <ParametersController>(); if (null != parametersConstroller) { foreach (GameObject sourceConstraint in parametersConstroller.constraintHolders) { if (!Selection.IsSelected(sourceConstraint)) { SetRecursiveLayerSmart(sourceConstraint, layerType, true); } } } }