{"action":"opened","issue":{"url":"https://api.github.com/repos/lovedna/note/issues/10","repository_url":"https://api.github.com/repos/lovedna/note","labels_url":"https://api.github.com/repos/lovedna/note/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/lovedna/note/issues/10/comments","events_url":"https://api.github.com/repos/lovedna/note/issues/10/events","html_url":"https://github.com/lovedna/note/issues/10","id":350687527,"node_id":"MDU6SXNzdWUzNTA2ODc1Mjc=","number":10,"title":"Scene 视图和Game视图的相机同步","user":{"login":"lovedna","id":3175783,"node_id":"MDQ6VXNlcjMxNzU3ODM=","avatar_url":"https://avatars2.githubusercontent.com/u/3175783?v=4","gravatar_id":"","url":"https://api.github.com/users/lovedna","html_url":"https://github.com/lovedna","followers_url":"https://api.github.com/users/lovedna/followers","following_url":"https://api.github.com/users/lovedna/following{/other_user}","gists_url":"https://api.github.com/users/lovedna/gists{/gist_id}","starred_url":"https://api.github.com/users/lovedna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lovedna/subscriptions","organizations_url":"https://api.github.com/users/lovedna/orgs","repos_url":"https://api.github.com/users/lovedna/repos","events_url":"https://api.github.com/users/lovedna/events{/privacy}","received_events_url":"https://api.github.com/users/lovedna/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-15T05:08:45Z","updated_at":"2018-08-15T05:08:45Z","closed_at":null,"author_association":"OWNER","body":"using UnityEngine;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\n \r\n[ExecuteInEditMode]\r\npublic class SceneViewCameraFollower : MonoBehaviour\r\n{\r\n#if UNITY_EDITOR\r\n \r\n\tpublic bool on = true;\r\n\tpublic bool onlyInPlayMode = false;\r\n\tpublic SceneViewFollower[] sceneViewFollowers;\r\n\tprivate ArrayList sceneViews;\r\n \r\n\tvoid LateUpdate()\r\n\t{\r\n\t\tif(sceneViewFollowers != null && sceneViews != null)\r\n\t\t{\r\n\t\t\tforeach(SceneViewFollower svf in sceneViewFollowers)\r\n\t\t\t{\r\n\t\t\t\tif(svf.targetTransform == null) svf.targetTransform = transform;\r\n\t\t\t\tsvf.size = Mathf.Clamp(svf.size, .01f, float.PositiveInfinity);\r\n\t\t\t\tsvf.sceneViewIndex = Mathf.Clamp(svf.sceneViewIndex, 0, sceneViews.Count-1);\r\n\t\t\t}\r\n\t\t}\r\n \r\n\t\tif(Application.isPlaying)\r\n\t\t\tFollow();\r\n\t}\r\n \r\n\tpublic void OnDrawGizmos()\r\n\t{\r\n\t\tif(!Application.isPlaying)\r\n\t\t\tFollow();\r\n\t}\r\n \r\n\tvoid Follow()\r\n\t{\r\n\t\tsceneViews = UnityEditor.SceneView.sceneViews;\r\n\t\tif(sceneViewFollowers == null || !on || sceneViews.Count == 0) return;\r\n \r\n\t\tforeach(SceneViewFollower svf in sceneViewFollowers)\r\n\t\t{\t\r\n\t\t\tif(!svf.enable) continue;\r\n\t\t\tUnityEditor.SceneView sceneView = (UnityEditor.SceneView) sceneViews[svf.sceneViewIndex];\r\n\t\t\tif(sceneView != null)\r\n\t\t\t{\r\n\t\t\t\tif((Application.isPlaying && onlyInPlayMode) || !onlyInPlayMode)\r\n\t\t\t\t{\r\n\t\t\t\t\tsceneView.orthographic = svf.orthographic;\r\n\t\t\t\t\tsceneView.LookAtDirect(svf.targetTransform.position + svf.positionOffset, (svf.enableFixedRotation) ? Quaternion.Euler(svf.fixedRotation) : svf.targetTransform.rotation, svf.size);\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\t\r\n\t}\r\n \r\n\t[System.Serializable]\r\n\tpublic class SceneViewFollower\r\n\t{\r\n\t\tpublic bool enable;\r\n\t\tpublic Vector3 positionOffset;\r\n\t\tpublic bool enableFixedRotation;\r\n\t\tpublic Vector3 fixedRotation;\r\n\t\tpublic Transform targetTransform;\r\n\t\tpublic float size;\r\n\t\tpublic bool orthographic;\r\n\t\tpublic int sceneViewIndex;\r\n \r\n\t\tSceneViewFollower()\r\n\t\t{\r\n\t\t\tenable = false;\r\n\t\t\tpositionOffset = Vector3.zero;\r\n\t\t\tenableFixedRotation = false;\r\n\t\t\tfixedRotation = Vector3.zero;\r\n\t\t\tsize = 5;\r\n\t\t\torthographic = true;\r\n\t\t\tsceneViewIndex = 0;\r\n\t\t}\r\n\t}\r\n \r\n#endif\r\n}"}}
{"actor":{"display_login":"lovedna"}}