private void OnSceneGUI() { if (Application.isPlaying) { return; } this.StoreSceneCamData(); if (!this._src.gameObject.activeInHierarchy || !this._sceneCamStored) { return; } if (this._wpsByDepth.Count != this._src.wps.Count) { this.FillWpIndexByDepth(); } EditorGUIUtils.SetGUIStyles(null); Event current = Event.current; Undo.RecordObject(this._src, "DOTween Path"); if (current.type == EventType.MouseDown) { if (current.shift) { if (EditorGUI.actionKey) { Vector3 vector = (this._lastCreatedWpIndex != -1) ? this._src.wps[this._lastCreatedWpIndex] : ((this._selectedWpIndex != -1) ? this._src.wps[this._selectedWpIndex] : ((this._lastSelectedWpIndex != -1) ? this._src.wps[this._lastSelectedWpIndex] : this._src.transform.position)); Matrix4x4 worldToCameraMatrix = this._sceneCam.worldToCameraMatrix; float z = -(worldToCameraMatrix.m20 * vector.x + worldToCameraMatrix.m21 * vector.y + worldToCameraMatrix.m22 * vector.z + worldToCameraMatrix.m23); Vector3 item = this._sceneCam.ViewportToWorldPoint(new Vector3(current.mousePosition.x / this._sceneCam.pixelRect.width, 1f - current.mousePosition.y / this._sceneCam.pixelRect.height, z)); if (this._selectedWpIndex != -1 && this._selectedWpIndex < this._src.wps.Count - 1) { this._src.wps.Insert(this._selectedWpIndex + 1, item); this._lastCreatedWpIndex = this._selectedWpIndex + 1; this._selectedWpIndex = this._lastCreatedWpIndex; } else { this._src.wps.Add(item); this._lastCreatedWpIndex = this._src.wps.Count - 1; this._selectedWpIndex = this._lastCreatedWpIndex; } this.RefreshPath(RepaintMode.Scene, true); return; } if (current.alt && this._src.wps.Count > 1) { this.FindSelectedWaypointIndex(); if (this._selectedWpIndex != -1) { this._src.wps.RemoveAt(this._selectedWpIndex); this.ResetIndexes(); this.RefreshPath(RepaintMode.Scene, true); return; } } } this.FindSelectedWaypointIndex(); } if (this._src.wps.Count < 1) { return; } if (current.type == EventType.MouseDrag) { this._isDragging = true; if (this._src.livePreview) { bool flag = this.CheckTargetMove(); if (this._selectedWpIndex != -1) { flag = true; } if (flag) { this.RefreshPath(RepaintMode.Scene, false); } } } else if (this._isDragging && current.rawType == EventType.MouseUp) { if (this._isDragging && this._selectedWpIndex != -1) { this._reselectAfterDrag = true; } this._isDragging = false; if (this._selectedWpIndex != -1 || this.CheckTargetMove()) { EditorUtility.SetDirty(this._src); this.RefreshPath(RepaintMode.Scene, true); } } else if (this.CheckTargetMove()) { this.RefreshPath(RepaintMode.Scene, false); } if (this._changed && !this._isDragging) { this.FillWpIndexByDepth(); this._changed = false; } int count = this._src.wps.Count; for (int i = 0; i < count; i++) { WpHandle wpHandle = this._wpsByDepth[i]; bool flag2 = wpHandle.wpIndex == this._selectedWpIndex; Vector3 vector2 = this._src.wps[wpHandle.wpIndex]; float num = (this._src.handlesDrawMode == HandlesDrawMode.Orthographic) ? (HandleUtility.GetHandleSize(vector2) * 0.2f) : this._src.perspectiveHandleSize; bool expr_40C = wpHandle.wpIndex >= 0 && wpHandle.wpIndex < (this._src.isClosedPath ? count : (count - 1)); Vector3 vector3 = expr_40C ? ((wpHandle.wpIndex >= count - 1) ? this._src.transform.position : this._src.wps[wpHandle.wpIndex + 1]) : Vector3.zero; bool flag3 = expr_40C && Vector3.Distance(this._sceneCamTrans.position, vector2) < Vector3.Distance(this._sceneCamTrans.position, vector2 + Vector3.ClampMagnitude(vector3 - vector2, num * 1.75f)); if (flag2) { Handles.color = Color.yellow; } else if (wpHandle.wpIndex == count - 1 && !this._src.isClosedPath) { Handles.color = this._wpColorEnd; } else { Handles.color = this._wpColor; } if (expr_40C & flag3) { this.DrawArrowFor(wpHandle.wpIndex, num, vector3); } int controlID = GUIUtility.GetControlID(FocusType.Passive); if (i == 0) { this._minHandleControlId = controlID; } if (this._src.handlesType == HandlesType.Free) { vector2 = Handles.FreeMoveHandle(vector2, Quaternion.identity, num, Vector3.one, new Handles.DrawCapFunction(Handles.SphereCap)); } else { vector2 = Handles.PositionHandle(vector2, Quaternion.identity); } this._src.wps[wpHandle.wpIndex] = vector2; int controlID2 = GUIUtility.GetControlID(FocusType.Passive); wpHandle.controlId = ((i == 0) ? (controlID2 - 1) : (controlID + 1)); this._maxHandleControlId = controlID2; if (expr_40C && !flag3) { this.DrawArrowFor(wpHandle.wpIndex, num, vector3); } Vector3 position = this._sceneCamTrans.InverseTransformPoint(vector2) + new Vector3(num * 0.75f, 0.1f, 0f); position = this._sceneCamTrans.TransformPoint(position); if (this._src.showIndexes || this._src.showWpLength) { string text = (this._src.showIndexes && this._src.showWpLength) ? string.Concat(new object[] { wpHandle.wpIndex + 1, "(", this._src.path.wpLengths[wpHandle.wpIndex + 1].ToString("N2"), ")" }) : (this._src.showIndexes ? (wpHandle.wpIndex + 1).ToString() : this._src.path.wpLengths[wpHandle.wpIndex + 1].ToString("N2")); Handles.Label(position, text, flag2 ? EditorGUIUtils.handleSelectedLabelStyle : EditorGUIUtils.handlelabelStyle); } } Handles.color = this._src.pathColor; if (this._src.pathType == PathType.Linear) { Handles.DrawPolyLine(this._src.path.wps); } else if (this._src.path.nonLinearDrawWps != null) { Handles.DrawPolyLine(this._src.path.nonLinearDrawWps); } if (this._reselectAfterDrag && current.type == EventType.Repaint) { this._reselectAfterDrag = false; } if (!this._changed) { this._changed = this.Changed(); } if (this._changed) { EditorUtility.SetDirty(this._src); } }
private void OnSceneGUI() { if (!Application.isPlaying) { this.StoreSceneCamData(); if (this._src.gameObject.activeInHierarchy && this._sceneCamStored) { if (this._wpsByDepth.Count != this._src.wps.Count) { this.FillWpIndexByDepth(); } EditorGUIUtils.SetGUIStyles(null); Event current = Event.current; Undo.RecordObject(this._src, "DOTween Path"); if (current.type == EventType.MouseDown) { if (current.shift) { if (EditorGUI.actionKey) { Vector3 vector = (this._lastCreatedWpIndex != -1) ? this._src.wps[this._lastCreatedWpIndex] : ((this._selectedWpIndex != -1) ? this._src.wps[this._selectedWpIndex] : ((this._lastSelectedWpIndex != -1) ? this._src.wps[this._lastSelectedWpIndex] : this._src.transform.position)); Matrix4x4 worldToCameraMatrix = this._sceneCam.worldToCameraMatrix; float z = -((((worldToCameraMatrix.m20 * vector.x) + (worldToCameraMatrix.m21 * vector.y)) + (worldToCameraMatrix.m22 * vector.z)) + worldToCameraMatrix.m23); Vector3 item = this._sceneCam.ViewportToWorldPoint(new Vector3(current.mousePosition.x / this._sceneCam.pixelRect.width, 1f - (current.mousePosition.y / this._sceneCam.pixelRect.height), z)); if ((this._selectedWpIndex != -1) && (this._selectedWpIndex < (this._src.wps.Count - 1))) { this._src.wps.Insert(this._selectedWpIndex + 1, item); this._lastCreatedWpIndex = this._selectedWpIndex + 1; this._selectedWpIndex = this._lastCreatedWpIndex; } else { this._src.wps.Add(item); this._lastCreatedWpIndex = this._src.wps.Count - 1; this._selectedWpIndex = this._lastCreatedWpIndex; } this.RefreshPath(RepaintMode.Scene, true); return; } if (current.alt && (this._src.wps.Count > 1)) { this.FindSelectedWaypointIndex(); if (this._selectedWpIndex != -1) { this._src.wps.RemoveAt(this._selectedWpIndex); this.ResetIndexes(); this.RefreshPath(RepaintMode.Scene, true); return; } } } this.FindSelectedWaypointIndex(); } if (this._src.wps.Count >= 1) { if (current.type == EventType.MouseDrag) { this._isDragging = true; if (this._src.livePreview) { bool flag = this.CheckTargetMove(); if (this._selectedWpIndex != -1) { flag = true; } if (flag) { this.RefreshPath(RepaintMode.Scene, false); } } } else if (this._isDragging && (current.rawType == EventType.MouseUp)) { if (this._isDragging && (this._selectedWpIndex != -1)) { this._reselectAfterDrag = true; } this._isDragging = false; if ((this._selectedWpIndex != -1) || this.CheckTargetMove()) { EditorUtility.SetDirty(this._src); this.RefreshPath(RepaintMode.Scene, true); } } else if (this.CheckTargetMove()) { this.RefreshPath(RepaintMode.Scene, false); } if (this._changed && !this._isDragging) { this.FillWpIndexByDepth(); this._changed = false; } int count = this._src.wps.Count; for (int i = 0; i < count; i++) { WpHandle handle = this._wpsByDepth[i]; bool flag2 = handle.wpIndex == this._selectedWpIndex; Vector3 position = this._src.wps[handle.wpIndex]; float handleSize = (this._src.handlesDrawMode == HandlesDrawMode.Orthographic) ? (HandleUtility.GetHandleSize(position) * 0.2f) : this._src.perspectiveHandleSize; bool flag1 = (handle.wpIndex >= 0) && (handle.wpIndex < (this._src.isClosedPath ? count : (count - 1))); Vector3 arrowPointsAt = flag1 ? ((handle.wpIndex >= (count - 1)) ? this._src.transform.position : this._src.wps[handle.wpIndex + 1]) : Vector3.zero; bool flag3 = flag1 && (Vector3.Distance(this._sceneCamTrans.position, position) < Vector3.Distance(this._sceneCamTrans.position, position + Vector3.ClampMagnitude(arrowPointsAt - position, handleSize * 1.75f))); if (flag2) { Handles.color = Color.yellow; } else if ((handle.wpIndex == (count - 1)) && !this._src.isClosedPath) { Handles.color = this._wpColorEnd; } else { Handles.color = this._wpColor; } if (flag1 & flag3) { this.DrawArrowFor(handle.wpIndex, handleSize, arrowPointsAt); } int controlID = GUIUtility.GetControlID(FocusType.Passive); if (i == 0) { this._minHandleControlId = controlID; } if (this._src.handlesType == HandlesType.Free) { position = Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.one, new Handles.CapFunction(Handles.SphereHandleCap)); //position = Handles.FreeMoveHandle(position, Quaternion.identity, handleSize, Vector3.one, new Handles.DrawCapFunction(Handles.SphereCap)); } else { position = Handles.PositionHandle(position, Quaternion.identity); } this._src.wps[handle.wpIndex] = position; int num6 = GUIUtility.GetControlID(FocusType.Passive); handle.controlId = (i == 0) ? (num6 - 1) : (controlID + 1); this._maxHandleControlId = num6; if (flag1 && !flag3) { this.DrawArrowFor(handle.wpIndex, handleSize, arrowPointsAt); } Vector3 vector5 = this._sceneCamTrans.InverseTransformPoint(position) + new Vector3(handleSize * 0.75f, 0.1f, 0f); vector5 = this._sceneCamTrans.TransformPoint(vector5); if (this._src.showIndexes) { Handles.Label(vector5, (handle.wpIndex + 1).ToString(), flag2 ? EditorGUIUtils.handleSelectedLabelStyle : EditorGUIUtils.handlelabelStyle); } } Handles.color = this._src.pathColor; if (this._src.pathType == PathType.Linear) { Handles.DrawPolyLine(this._src.path.wps); } else if (this._src.path.nonLinearDrawWps != null) { Handles.DrawPolyLine(this._src.path.nonLinearDrawWps); } if (this._reselectAfterDrag && (current.type == EventType.Repaint)) { this._reselectAfterDrag = false; } if (!this._changed) { this._changed = this.Changed(); } if (this._changed) { EditorUtility.SetDirty(this._src); } } } } }