void UpdatePosition(Transform camera) { if (m_bHandEnable) { if (Input.GetMouseButtonDown(m_nMoveInputIndex)) { m_OldMousePos = Input.mousePosition; m_bLeftClick = true; } if (m_bLeftClick && Input.GetMouseButton(m_nMoveInputIndex)) { Vector3 currMousePos = Input.mousePosition; float worldlen = NgLayout.GetWorldPerScreenPixel(m_TargetTrans.transform.position); m_MovePostion += (m_OldMousePos - currMousePos) * worldlen; m_OldMousePos = currMousePos; } if (Input.GetMouseButtonUp(m_nMoveInputIndex)) { m_bLeftClick = false; } } camera.Translate(m_MovePostion, Space.Self); }
void DrawGuiGizmo() { float fLineLen = NgLayout.GetWorldPerScreenPixel(FXMakerEffect.inst.m_CurrentEffectRoot.transform.position) * (Screen.width * m_fGizmoLinePerScreen * m_fLocalLineRatio); // draw Selected gizmo DrawGuiGizmoAxis(AXIS.Z, fLineLen, false); DrawGuiGizmoAxis(AXIS.X, fLineLen, false); DrawGuiGizmoAxis(AXIS.Y, fLineLen, false); }
void AddRotation(float x, float y, float z, bool bLocal) { float scale = NgLayout.GetWorldPerScreenPixel(m_SelectedTransform.transform.position); m_SaveRotate += new Vector3(x / scale, y / scale, z / scale); List <FxmInfoIndexing> indexComs = FxmInfoIndexing.FindInstanceIndexings(m_SelectedTransform.transform, false); foreach (FxmInfoIndexing indexCom in indexComs) { indexCom.transform.Rotate(x / scale, y / scale, z / scale, (bLocal ? Space.Self : Space.World)); } m_SelectedTransform.Rotate(x / scale, y / scale, z / scale, (bLocal ? Space.Self : Space.World)); }
private void UpdatePosition(Transform camera) { if (this.m_bHandEnable) { if (Input.GetMouseButtonDown(this.m_nMoveInputIndex)) { this.m_OldMousePos = Input.mousePosition; this.m_bLeftClick = true; } if (this.m_bLeftClick && Input.GetMouseButton(this.m_nMoveInputIndex)) { Vector3 mousePosition = Input.mousePosition; float worldPerScreenPixel = NgLayout.GetWorldPerScreenPixel(this.m_TargetTrans.transform.position); this.m_MovePostion += (this.m_OldMousePos - mousePosition) * worldPerScreenPixel; this.m_OldMousePos = mousePosition; } if (Input.GetMouseButtonUp(this.m_nMoveInputIndex)) { this.m_bLeftClick = false; } } camera.Translate(this.m_MovePostion, Space.Self); }
bool DrawOriginalGizmo(Transform selTrans, bool bLocal) { float fLineLen = NgLayout.GetWorldPerScreenPixel(FXMakerEffect.inst.m_CurrentEffectRoot.transform.position) * (Screen.width * m_fGizmoLinePerScreen * m_fWorldLineRatio); float fCapSize = fLineLen * 0.07f * m_fCapSizeRatio; Vector3 cubeSize = Vector3.one * fCapSize; bool bSelected = false; // check active if ((((GIZMO_TYPE)m_nGizmoTypeIndex) != GIZMO_TYPE.HAND && ((GIZMO_TYPE)m_nGizmoTypeIndex) != GIZMO_TYPE.NONE) && m_bClick == false) { AXIS nActiveAxis = AXIS.NONE; float fStartClickLen = fLineLen / 4.0f; if (HandleUtility.DistanceToLine(GetPosition(selTrans) + GetDirect(selTrans, AXIS.X, bLocal) * fStartClickLen, GetPosition(selTrans) + GetDirect(selTrans, AXIS.X, bLocal) * fLineLen) < m_fActiveDist) { nActiveAxis = AXIS.X; } if (HandleUtility.DistanceToLine(GetPosition(selTrans) + GetDirect(selTrans, AXIS.Y, bLocal) * fStartClickLen, GetPosition(selTrans) + GetDirect(selTrans, AXIS.Y, bLocal) * fLineLen) < m_fActiveDist) { nActiveAxis = AXIS.Y; } if (HandleUtility.DistanceToLine(GetPosition(selTrans) + GetDirect(selTrans, AXIS.Z, bLocal) * fStartClickLen, GetPosition(selTrans) + GetDirect(selTrans, AXIS.Z, bLocal) * fLineLen) < m_fActiveDist) { nActiveAxis = AXIS.Z; } if (((GIZMO_TYPE)m_nGizmoTypeIndex) == GIZMO_TYPE.SCALE) { if (HandleUtility.DistanceToLine(GetPosition(selTrans), GetPosition(selTrans)) < m_fActiveDist) { nActiveAxis = AXIS.A; } } if (nActiveAxis != AXIS.NONE) { m_nActiveAxis = nActiveAxis; m_bActiveLocal = bLocal; bSelected = true; } else { m_nActiveAxis = AXIS.NONE; } } // draw Selected gizmo DrawGizmoAxis(AXIS.X, bLocal, fLineLen, fCapSize); DrawGizmoAxis(AXIS.Y, bLocal, fLineLen, fCapSize); DrawGizmoAxis(AXIS.Z, bLocal, fLineLen, fCapSize); // World Center Sphere Gizmos.color = Color.yellow; if (((GIZMO_TYPE)m_nGizmoTypeIndex) == GIZMO_TYPE.HAND) { Gizmos.color = new Color(Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, m_fHandAlpha); } Gizmos.DrawSphere(Vector3.zero, cubeSize.x / 2.0f); // selected center if (((GIZMO_TYPE)m_nGizmoTypeIndex) == GIZMO_TYPE.SCALE) { if (m_nActiveAxis == AXIS.A && m_bActiveLocal == bLocal) { Gizmos.color = Color.white; } else { Gizmos.color = Color.cyan; } Gizmos.DrawCube(GetPosition(selTrans), cubeSize); } // Gizmo tooltip if (IsLocalSpace()) { m_GizmoTooltip = "GizmosLength = " + fLineLen.ToString("0.000") + " , long=Local"; } else { m_GizmoTooltip = "GizmosLength = " + fLineLen.ToString("0.000") + " , long=World, shot=Local"; } FXMakerMain.inst.SetEmptyTooltip(m_GizmoTooltip); return(bSelected); }
// Update is called once per frame void Update() { m_bUnityGizmos = false; // check shotkey if (GUI.GetNameOfFocusedControl() != "TextField") { if (Input.GetKeyDown(KeyCode.Q)) { SetGizmoType(0); } if (Input.GetKeyDown(KeyCode.W)) { SetGizmoType(1); } if (Input.GetKeyDown(KeyCode.E)) { SetGizmoType(2); } if (Input.GetKeyDown(KeyCode.R)) { SetGizmoType(3); } if (Input.GetKeyDown(KeyCode.T)) { SetGizmoType(4); } if (Input.GetKeyDown(KeyCode.Y)) { m_bWorldSpace = !m_bWorldSpace; } } GameObject selObj = FXMakerMain.inst.GetFXMakerHierarchy().GetSelectedGameObject(); if (selObj == null) { return; } m_SelectedTransform = selObj.transform; // check click if (m_nActiveAxis != AXIS.NONE) { if (Input.GetMouseButtonDown(0)) { m_OldMousePos = Input.mousePosition; m_OldOriScale = m_SelectedTransform.localScale; m_OldInsScale = (GetInstanceObject() == null ? Vector3.one : GetInstanceObject().transform.localScale); m_OldGizmoLineLength = NgLayout.GetWorldPerScreenPixel(FXMakerEffect.inst.m_CurrentEffectRoot.transform.position) * (Screen.width * m_fGizmoLinePerScreen * m_fWorldLineRatio); m_SaveRotate = Vector3.zero; m_bClick = true; if (m_nGizmoTypeIndex == (int)GIZMO_TYPE.POSITION || m_nGizmoTypeIndex == (int)GIZMO_TYPE.ROTATION || m_nGizmoTypeIndex == (int)GIZMO_TYPE.SCALE) { FXMakerEffect.inst.SetChangePrefab(); } } if (m_bClick && Input.GetMouseButton(0)) { Vector3 currMousePos = Input.mousePosition; Vector3 prevWorldPos = NgLayout.GetScreenToWorld(m_SelectedTransform.transform.position, m_OldMousePos); Vector3 currWorldPos = NgLayout.GetScreenToWorld(m_SelectedTransform.transform.position, currMousePos); if (IsLocalSpace()) { Transform tempTrans = GetTempTransform(); tempTrans.rotation = m_SelectedTransform.rotation; currWorldPos = tempTrans.InverseTransformPoint(currWorldPos); prevWorldPos = tempTrans.InverseTransformPoint(prevWorldPos); } switch (((GIZMO_TYPE)m_nGizmoTypeIndex)) { case GIZMO_TYPE.POSITION: { switch (m_nActiveAxis) { case AXIS.X: AddTranslate(currWorldPos.x - prevWorldPos.x, 0, 0, m_bActiveLocal); break; case AXIS.Y: AddTranslate(0, currWorldPos.y - prevWorldPos.y, 0, m_bActiveLocal); break; case AXIS.Z: { if (m_bFixedSide) { AddTranslate(currWorldPos.x - prevWorldPos.x, 0, 0, m_bActiveLocal); AddTranslate(0, currWorldPos.y - prevWorldPos.y, 0, m_bActiveLocal); } else { AddTranslate(0, 0, currWorldPos.z - prevWorldPos.z, m_bActiveLocal); } break; } } break; } case GIZMO_TYPE.ROTATION: { switch (m_bFixedSide ? AXIS.Z : m_nActiveAxis) { case AXIS.X: AddRotation(currWorldPos.z - prevWorldPos.z, 0, 0, m_bActiveLocal); break; case AXIS.Y: AddRotation(0, currWorldPos.x - prevWorldPos.x, 0, m_bActiveLocal); break; case AXIS.Z: AddRotation(0, 0, prevWorldPos.x - currWorldPos.x, m_bActiveLocal); break; } break; } case GIZMO_TYPE.SCALE: { float fScaleDist; switch (m_nActiveAxis) { case AXIS.X: fScaleDist = currWorldPos.x - prevWorldPos.x; AddScale(fScaleDist / m_OldGizmoLineLength, 0, 0); break; case AXIS.Y: fScaleDist = currWorldPos.y - prevWorldPos.y; AddScale(0, fScaleDist / m_OldGizmoLineLength, 0); break; case AXIS.Z: fScaleDist = currWorldPos.z - prevWorldPos.z; AddScale(0, 0, fScaleDist / m_OldGizmoLineLength); break; case AXIS.A: { fScaleDist = (currMousePos.x - m_OldMousePos.x) * NgLayout.GetWorldPerScreenPixel(selObj.transform.position); if (m_bFixedSide) { AddScale(fScaleDist / m_OldGizmoLineLength, fScaleDist / m_OldGizmoLineLength, 0); } else { AddScale(fScaleDist / m_OldGizmoLineLength, fScaleDist / m_OldGizmoLineLength, fScaleDist / m_OldGizmoLineLength); } break; } } break; } } m_OldMousePos = currMousePos; } if (Input.GetMouseButtonUp(0)) { m_nActiveAxis = AXIS.NONE; m_bClick = false; } FXMakerMain.inst.GetFXMakerMouse().SetHandControl(m_bClick == false); } }