protected override void Awake() { base.Awake(); m_editor = IOC.Resolve <IRuntimeEditor>(); m_pivotPoint = new GameObject("MeshEditorPivotPoint"); m_pivotPoint.hideFlags = HideFlags.HideInHierarchy; m_pivotPoint.transform.SetParent(transform); ExposeToEditor exposeToEditor = m_pivotPoint.AddComponent <ExposeToEditor>(); exposeToEditor.CanInspect = false; exposeToEditor.CanDelete = false; exposeToEditor.CanDuplicate = false; exposeToEditor.CanRename = false; exposeToEditor.CanCreatePrefab = false; LockAxes la = m_pivotPoint.AddComponent <LockAxes>(); la.PositionZ = true; la.RotationX = la.RotationY = la.RotationScreen = la.RotationFree = true; la.ScaleZ = true; la.PivotRotation = true; la.PivotRotationValue = RuntimePivotRotation.Local; IOC.RegisterFallback <IMeshEditor>(this); if (m_editor != null) { m_editor.Selection.SelectionChanged += OnEditorSelectionChanged; } }
public static Vector3 GetSingleDirection(LockAxes direction, Transform transform = null) { Vector3 returnedDirection; if ((direction & LockAxes.up) != 0) { returnedDirection = transform != null ? transform.up : Vector3.up; } else if ((direction & LockAxes.down) != 0) { returnedDirection = transform != null ? -transform.up : Vector3.down; } else if ((direction & LockAxes.left) != 0) { returnedDirection = transform != null ? -transform.right : Vector3.left; } else if ((direction & LockAxes.right) != 0) { returnedDirection = transform != null ? transform.right : Vector3.right; } else if ((direction & LockAxes.forward) != 0) { returnedDirection = transform != null ? transform.forward : Vector3.forward; } else if ((direction & LockAxes.back) != 0) { returnedDirection = transform != null ? -transform.forward : Vector3.back; } else { returnedDirection = Vector3.zero; } return(returnedDirection); }
private void Awake() { m_pivot = new GameObject("PolyShapePivot").transform; LockAxes axes = m_pivot.gameObject.AddComponent <LockAxes>(); axes.PositionY = true; axes.RotationFree = axes.RotationScreen = axes.RotationX = axes.RotationY = axes.RotationZ = true; axes.ScaleX = axes.ScaleY = axes.ScaleZ = true; m_pivot.transform.SetParent(transform); }
public void ApplyPositionalLock(LockAxes lockedWorldDirections, LockAxes lockedLocalDirections) { Vector3 originalLocalPosition = GetAnchorPositionInLocalCoords(); IterateDirections((lockedDirection) => { Vector3 positionDifference = transform.localPosition - originalLocalPosition; //float totalPosDifference = positionDifference.magnitude; Vector3 lockInverse = Vector3.one - lockedDirection.Abs(); Vector3 positionalOffsetInDirection = positionDifference.Multiply(lockedDirection); float distance = positionalOffsetInDirection.magnitude; float percentInDirection = positionDifference.PercentDirection(lockedDirection); //float percentInDirection = totalPosDifference * positionDifference.PercentDirection(lockedDirection); if (percentInDirection > 0 && distance >= localLinearLimit) { transform.localPosition = transform.localPosition.Multiply(lockInverse) + originalLocalPosition.Multiply(lockedDirection); /*Vector3 localVelocity = AffectedBody.velocity.normalized; * if (parent != null) * localVelocity = parent.InverseTransformDirection(localVelocity); * //float totalSpeed = velocity.magnitude; * float speedInDirection = localVelocity.Multiply(lockedDirection).magnitude; * if (speedInDirection >= minimumSpeedToBlock) * { * Vector3 adjustedVelocity = localVelocity.Multiply(lockInverse); * float percentMagnitude = adjustedVelocity.magnitude; * if (parent != null) * adjustedVelocity = parent.TransformDirection(adjustedVelocity.normalized); * AffectedBody.velocity = adjustedVelocity * AffectedBody.velocity.magnitude * percentMagnitude; * //Vector3 velocityInDirection = lockedDirection * speedInDirection; * //AffectedBody.velocity = velocity - velocityInDirection; * }*/ } }, lockedLocalDirections); //}, lockedWorldDirections, lockedLocalDirections, parent); //I don't like that I have the same code here twice, but what can I do Vector3 originalWorldPosition = GetAnchorPositionInWorldCoords(); IterateDirections((lockedDirection) => { Vector3 positionDifference = transform.position - originalWorldPosition; Vector3 lockInverse = Vector3.one - lockedDirection.Abs(); Vector3 positionalOffsetInDirection = positionDifference.Multiply(lockedDirection); float distance = positionalOffsetInDirection.magnitude; float percentInDirection = positionDifference.PercentDirection(lockedDirection); if (percentInDirection > 0 && distance >= localLinearLimit) { transform.position = transform.position.Multiply(lockInverse) + originalWorldPosition.Multiply(lockedDirection); } }, lockedWorldDirections); }
protected virtual void OnEnable() { if (m_selectionComponentState != null) { Enable(true); } LockAxes la = m_pivotPoint.GetComponent <LockAxes>(); la.PositionY = la.PositionX = false; la.ScaleX = la.ScaleY = false; la.RotationZ = false; }
private void Awake() { IOC.RegisterFallback <IProBuilderTool>(this); m_rte = IOC.Resolve <IRuntimeEditor>(); m_wm = IOC.Resolve <IWindowManager>(); m_wm.WindowCreated += OnWindowCreated; m_materialEditor = gameObject.AddComponent <PBMaterialEditor>(); m_autoUVEditor = gameObject.AddComponent <PBAutoUVEditor>(); m_uv = new PBAutoUnwrapSettings(); m_uv.Changed += OnUVChanged; PBVertexEditor vertexEditor = gameObject.AddComponent <PBVertexEditor>(); PBEdgeEditor edgeEditor = gameObject.AddComponent <PBEdgeEditor>(); PBFaceEditor faceEditor = gameObject.AddComponent <PBFaceEditor>(); m_meshEditors = new IMeshEditor[4]; m_meshEditors[(int)ProBuilderToolMode.Vertex] = vertexEditor; m_meshEditors[(int)ProBuilderToolMode.Edge] = edgeEditor; m_meshEditors[(int)ProBuilderToolMode.Face] = faceEditor; foreach (IMeshEditor editor in m_meshEditors) { if (editor == null) { continue; } editor.CenterMode = m_rte.Tools.PivotMode == RuntimePivotMode.Center; } UpdateGlobalMode(); m_pivot = new GameObject("Pivot").transform; LockAxes lockAxes = m_pivot.gameObject.AddComponent <LockAxes>(); lockAxes.RotationFree = true; m_pivot.SetParent(transform, false); ExposeToEditor exposed = m_pivot.gameObject.AddComponent <ExposeToEditor>(); exposed.CanDelete = false; exposed.CanDuplicate = false; exposed.CanInspect = false; }
private void InitHandles() { m_prevInterpolation = m_state.Interpolation; InitLerpGrid(); if (m_handles != null) { foreach (KeyValuePair <GameObject, int> kvp in m_handles) { GameObject handle = kvp.Key; int z = kvp.Value / m_count; int x = kvp.Value % m_count; float y = m_state.Grid[kvp.Value] * m_activeTerrain.terrainData.heightmapScale.y; handle.transform.position = new Vector3(x * m_state.Spacing, y, z * m_state.Spacing); } } else { m_handles = new Dictionary <GameObject, int>(m_state.Grid.Length); for (int x = 0; x < m_count; ++x) { for (int z = 0; z < m_count; ++z) { m_handlePrefab.gameObject.SetActive(false); TerrainToolHandle handle = Instantiate(m_handlePrefab, transform); handle.gameObject.hideFlags = HideFlags.HideInHierarchy; LockAxes lockAxes = handle.gameObject.AddComponent <LockAxes>(); lockAxes.PositionX = true; lockAxes.PositionZ = true; float y = m_state.Grid[z * m_count + x] * m_activeTerrain.terrainData.heightmapScale.y; handle.transform.localPosition = new Vector3(x * m_state.Spacing, y, z * m_state.Spacing); handle.name = "h " + x + "," + z; handle.gameObject.SetActive(true); m_handles.Add(handle.gameObject, z * m_count + x); } } } }
private void Awake() { IOC.RegisterFallback <IManualUVEditor>(this); m_editor = IOC.Resolve <IRuntimeEditor>(); m_tool = IOC.Resolve <IProBuilderTool>(); m_tool.SelectionChanged += OnSelectionChanged; m_tool.ModeChanged += OnModeChanged; m_pivotPointSelection = new RuntimeSelection(IOC.Resolve <IRTE>()); m_pivotPoint = new GameObject("ManualUVEditorPivotPoint").transform; m_pivotPoint.SetParent(transform, false); LockAxes la = m_pivotPoint.gameObject.AddComponent <LockAxes>(); la.PositionZ = true; la.RotationX = la.RotationY = la.RotationFree = la.RotationScreen = true; la.ScaleZ = true; la.PivotRotationValue = RuntimePivotRotation.Global; la.PivotRotation = true; }
public static void IterateDirections(System.Action <Vector3> directionAction, LockAxes worldDirections, LockAxes localDirections = LockAxes.none, Transform transform = null) { LockAxes[] allDirections = (LockAxes[])System.Enum.GetValues(typeof(LockAxes)); for (int i = 0; i < allDirections.Length; i++) { var currentDirection = allDirections[i]; if ((worldDirections & currentDirection) != 0) { directionAction.Invoke(GetSingleDirection(currentDirection)); } if ((localDirections & currentDirection) != 0) { directionAction.Invoke(GetSingleDirection(currentDirection, transform)); } } }
private void Awake() { IOC.RegisterFallback <IProBuilderTool>(this); m_rte = IOC.Resolve <IRuntimeEditor>(); m_wm = IOC.Resolve <IWindowManager>(); m_wm.WindowCreated += OnWindowCreated; foreach (RuntimeWindow window in m_rte.Windows) { if (window.WindowType == RuntimeWindowType.Scene) { SetCullingMask(window); } } m_materialEditor = gameObject.AddComponent <PBMaterialEditor>(); m_autoUVEditor = gameObject.AddComponent <PBAutoUVEditor>(); m_polyShapeEditor = gameObject.AddComponent <ProBuilderPolyShapeEditor>(); m_uv = new PBAutoUnwrapSettings(); m_uv.Changed += OnUVChanged; bool wasActive = gameObject.activeSelf; gameObject.SetActive(false); PBVertexEditor vertexEditor = gameObject.AddComponent <PBVertexEditor>(); PBEdgeEditor edgeEditor = gameObject.AddComponent <PBEdgeEditor>(); PBFaceEditor faceEditor = gameObject.AddComponent <PBFaceEditor>(); m_meshEditors = new IMeshEditor[5]; m_meshEditors[(int)ProBuilderToolMode.Vertex] = vertexEditor; m_meshEditors[(int)ProBuilderToolMode.Edge] = edgeEditor; m_meshEditors[(int)ProBuilderToolMode.Face] = faceEditor; foreach (IMeshEditor editor in m_meshEditors) { if (editor == null) { continue; } editor.GraphicsLayer = m_rte.CameraLayerSettings.ExtraLayer1; editor.CenterMode = m_rte.Tools.PivotMode == RuntimePivotMode.Center; } UpdateGlobalMode(); m_pivot = new GameObject("Pivot").transform; LockAxes lockAxes = m_pivot.gameObject.AddComponent <LockAxes>(); lockAxes.RotationFree = true; m_pivot.SetParent(transform, false); ExposeToEditor exposed = m_pivot.gameObject.AddComponent <ExposeToEditor>(); exposed.CanDelete = false; exposed.CanDuplicate = false; exposed.CanInspect = false; gameObject.SetActive(wasActive); }