コード例 #1
0
        void OnEnable()
        {
            gameObject.isStatic = true;
            transform.root.gameObject.isStatic = true;
            LastPosition = transform.position;

            if (ParentApplicator == null && transform.parent != null)
            {
                if (transform.parent.GetComponent <SkyApplicator>() != null)
                {
                    ParentApplicator = transform.parent.GetComponent <SkyApplicator>();
                }
            }

            if (ParentApplicator != null)
            {
                ParentApplicator.Children.Add(this);
            }
            else
            {
                mset.SkyManager skymgr = mset.SkyManager.Get();
                if (skymgr != null)
                {
                    skymgr.RegisterApplicator(this);
                }
            }
        }
コード例 #2
0
        // Use this for initialization
        void Start()
        {
            if (BindType != AnchorBindType.TargetSky)
            {
                                #if USE_PROPERTY_BLOCKS
                //HACK: clear the property block for this renderer, good catch-all for old data
                GetComponent <Renderer>().SetPropertyBlock(new MaterialPropertyBlock());
                                #endif

                //instantly register and hook up skies to this anchor on creation
                mset.SkyManager skymgr = mset.SkyManager.Get();
                skymgr.RegisterNewRenderer(GetComponent <Renderer>());
                skymgr.ApplyCorrectSky(GetComponent <Renderer>());
                BlendTime = skymgr.LocalBlendTime;
                if (Blender.CurrentSky)
                {
                    Blender.SnapToSky(Blender.CurrentSky);
                }
                else
                {
                    Blender.SnapToSky(skymgr.GlobalSky);
                }
            }
            //instance and keep around the list of materials in this renderer
            materials    = GetComponent <Renderer>().materials;
            LastPosition = transform.position;
            HasChanged   = true;
        }
コード例 #3
0
 public static mset.SkyManager Get()
 {
     if (_Instance == null)
     {
         _Instance = GameObject.FindObjectOfType <mset.SkyManager>();
     }
     return(_Instance);
 }
コード例 #4
0
ファイル: FreeProbe.cs プロジェクト: Nikita11121/KataScene
 private void Awake()
 {
     sceneSkybox = RenderSettings.skybox;
     mset.SkyManager mgr = mset.SkyManager.Get();
     if (mgr && mgr.ProbeCamera)
     {
         GetComponent <Camera>().CopyFrom(mgr.ProbeCamera);
     }
     else if (Camera.main)
     {
         GetComponent <Camera>().CopyFrom(Camera.main);
     }
 }
コード例 #5
0
        public void blur(Cubemap targetCube, Texture sourceCube, bool dstRGBM, bool srcRGBM, bool linear)
        {
            if (sourceCube == null || targetCube == null)
            {
                return;
            }
            //buildRandomValueCode();

            GameObject go = new GameObject("_temp_probe");

            go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
            go.SetActive(true);
            Camera cam = go.AddComponent <Camera>();

            cam.renderingPath       = renderPath;
            cam.useOcclusionCulling = false;

            //render cubeRT converting it to RGBM
            Material  skyMat = new Material(Shader.Find("Hidden/Marmoset/RGBM Cube"));
            Matrix4x4 matrix = Matrix4x4.identity;
            int       me     = this.maxExponent;
            bool      mip    = this.generateMipChain;

            //HACK: run the convolution twice at a higher exponent, better results on older shader models with fewer samples
            this.maxExponent      = 8 * me;
            this.generateMipChain = false;
            this.convolve_internal(targetCube, sourceCube, dstRGBM, srcRGBM, linear, cam, skyMat, matrix);
            this.convolve_internal(targetCube, targetCube, dstRGBM, dstRGBM, linear, cam, skyMat, matrix);

                #if UNITY_EDITOR
            //HACK: force reimport to rebuild mipmap because RenderToCubemap destroys our mipmap and pixel copy gamma is broken in d3d11
            string path = UnityEditor.AssetDatabase.GetAssetPath(targetCube);
            if (path != null && path.Length > 0)
            {
                UnityEditor.AssetDatabase.ImportAsset(path);
            }
                #endif

            this.maxExponent      = me;
            this.generateMipChain = mip;

            //make sure the old sky and matrix vars are bound again
            mset.SkyManager mgr = mset.SkyManager.Get();
            if (mgr)
            {
                mgr.GlobalSky = mgr.GlobalSky;
            }
            Material.DestroyImmediate(skyMat);

            GameObject.DestroyImmediate(go);
        }
コード例 #6
0
        void OnDisable()
        {
            if (ParentApplicator != null)
            {
                ParentApplicator.Children.Remove(this);
            }

            mset.SkyManager skymgr = mset.SkyManager.Get();
            if (skymgr)
            {
                skymgr.UnregisterApplicator(this, AffectedRenderers);
                AffectedRenderers.Clear();
            }
        }
コード例 #7
0
ファイル: FreeProbe.cs プロジェクト: Nikita11121/KataScene
        public void RunQueue()
        {
            //mark end of queue with a null probe
            this.probeQueue.Enqueue(null);

            //uses same shader and importance sample table as SkyProbe class
            mset.SkyProbe.buildRandomValueTable();

            mset.SkyManager mgr = mset.SkyManager.Get();
            if (mgr.ProbeCamera)
            {
                GetComponent <Camera>().CopyFrom(mgr.ProbeCamera);
                defaultCullMask = mgr.ProbeCamera.cullingMask;
            }
            else if (Camera.main)
            {
                GetComponent <Camera>().CopyFrom(Camera.main);
                defaultCullMask = GetComponent <Camera>().cullingMask;
            }

            disabledCameras.Clear();
            foreach (Camera cam in Camera.allCameras)
            {
                if (cam.enabled)
                {
                    cam.enabled = false;
                    disabledCameras.Add(cam);
                }
            }

            GetComponent <Camera>().enabled             = true;
            GetComponent <Camera>().fieldOfView         = 90;
            GetComponent <Camera>().clearFlags          = CameraClearFlags.Skybox;
            GetComponent <Camera>().cullingMask         = defaultCullMask;
            GetComponent <Camera>().useOcclusionCulling = false;

            StartStage(Stage.NEXTSKY);
        }
コード例 #8
0
ファイル: Sky.cs プロジェクト: elephantatwork/Secret-Game
        private void OnDrawGizmos()
        {
            //The most reliable place to bind shader variables in the editor

            if (SkyManagerCheck && !Application.isPlaying)
            {
                SkyManagerCheck = false;
                mset.SkyManager mgr = mset.SkyManager.Get();
                if (mgr == null)
                {
                    string title = "Missing SkyManager";
                    string text  = "An object with a Sky Manager component is required for Skyshop to function properly.\n\nWould you like to create one?";
                    if (UnityEditor.EditorUtility.DisplayDialog(title, text, "Create", "Ignore"))
                    {
                        GameObject go = new GameObject("Sky Manager");
                        go.AddComponent <mset.SkyManager>();
                        go.transform.position = this.transform.position + Vector3.up * 10f;
                    }
                }
            }

            if (!this.blendIDs[0].valid || !this.blendIDs[1].valid)
            {
                this.UpdatePropertyIDs();
            }

            Gizmos.DrawIcon(transform.position, "cubelight.tga", true);
            if (this.HasDimensions)
            {
                Color c = new Color(0.4f, 0.7f, 1f, 0.333f);
                Gizmos.color = c;

                Matrix4x4 mat = new Matrix4x4();
                mat.SetTRS(this.transform.position, this.transform.rotation, this.transform.localScale);
                Gizmos.matrix = mat;
                Gizmos.DrawWireCube(dimensions.center, dimensions.size);
            }
        }
コード例 #9
0
        public static void DrawGUI()
        {
            if (!ConfigGUI())
            {
                return;
            }
            SerializedObject   serializedConfig       = getSerializedConfig();
            SerializedProperty giEnvironment          = serializedConfig.FindProperty("config.environmentSettings.giEnvironment");
            SerializedProperty giEnvironmentIntensity = serializedConfig.FindProperty("config.environmentSettings.giEnvironmentIntensity");
            SerializedProperty iblImageFile           = serializedConfig.FindProperty("config.environmentSettings.iblImageFile");
            SerializedProperty iblSwapYZ         = serializedConfig.FindProperty("config.environmentSettings.iblSwapYZ");
            SerializedProperty iblTurnDome       = serializedConfig.FindProperty("config.environmentSettings.iblTurnDome");
            SerializedProperty iblGIEnvBlur      = serializedConfig.FindProperty("config.environmentSettings.iblGIEnvBlur");
            SerializedProperty iblEmitLight      = serializedConfig.FindProperty("config.environmentSettings.iblEmitLight");
            SerializedProperty iblSamples        = serializedConfig.FindProperty("config.environmentSettings.iblSamples");
            SerializedProperty iblIntensity      = serializedConfig.FindProperty("config.environmentSettings.iblIntensity");
            SerializedProperty iblEmitDiffuse    = serializedConfig.FindProperty("config.environmentSettings.iblEmitDiffuse");
            SerializedProperty iblEmitSpecular   = serializedConfig.FindProperty("config.environmentSettings.iblEmitSpecular");
            SerializedProperty iblSpecularBoost  = serializedConfig.FindProperty("config.environmentSettings.iblSpecularBoost");
            SerializedProperty iblShadows        = serializedConfig.FindProperty("config.environmentSettings.iblShadows");
            SerializedProperty iblBandingVsNoise = serializedConfig.FindProperty("config.environmentSettings.iblBandingVsNoise");

            EditorGUILayout.PropertyField(giEnvironment, new GUIContent("Environment Type", ""), GUILayout.Width(300));
            EditorGUI.BeginDisabledGroup(sc.config.environmentSettings.giEnvironment == mset.ILConfig.EnvironmentSettings.Environment.None);
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(giEnvironmentIntensity, new GUIContent("Intensity", ""), GUILayout.Width(300));

            if (sc.config.environmentSettings.giEnvironment == mset.ILConfig.EnvironmentSettings.Environment.SkyLight)
            {
                // FIXME add undo
                LMColorPicker("Sky Light Color", ref sc.config.environmentSettings.skyLightColor, "It is often a good idea to keep the color below 1.0 in intensity to avoid boosting by gamma correction. Boost the intensity instead with the giEnvironmentIntensity setting.");
            }
            else if (sc.config.environmentSettings.giEnvironment == mset.ILConfig.EnvironmentSettings.Environment.IBL)
            {
                GUILayout.Label("IBL Image", EditorStyles.boldLabel);
                EditorGUILayout.PrefixLabel(new GUIContent("Image Path", ""));
                GUILayout.BeginHorizontal(); {
                    EditorGUILayout.PropertyField(iblImageFile, new GUIContent("", "The absolute image file path to use for IBL. Accepts hdr or OpenEXR format. The file should be long-lat. Use giEnvironmentIntensity to boost the intensity of the image."));
                    GUILayout.Space(10);
                } GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    //GUILayout.FlexibleSpace();
                    GUILayout.Space(10);
                    if (!string.IsNullOrEmpty(sc.config.environmentSettings.iblImageFile))
                    {
                        if (GUILayout.Button("Reveal", GUILayout.Width(55)))
                        {
                            EditorUtility.OpenWithDefaultApp(Path.GetDirectoryName(sc.config.environmentSettings.iblImageFile));
                        }
                        if (GUILayout.Button("Edit", GUILayout.Width(55)))
                        {
                            EditorUtility.OpenWithDefaultApp(sc.config.environmentSettings.iblImageFile);
                        }
                    }
                    if (GUILayout.Button("Open...", GUILayout.Width(60)))
                    {
                        string file = EditorUtility.OpenFilePanel("Select EXR or HDR file", "", "");
                        string ext  = Path.GetExtension(file);
                        if (!string.IsNullOrEmpty(file))
                        {
                            if (ext == ".exr" || ext == ".hdr")
                            {
                                sc.config.environmentSettings.iblImageFile = file;
                                iblImageFile.stringValue = file;
                                GUI.changed = true;
                                SaveConfig();
                            }
                            else
                            {
                                Debug.LogError("IBL image files must use the extension .exr or .hdr");
                            }
                        }
                    }
                }
                GUILayout.EndHorizontal();
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(iblGIEnvBlur,
                                              new GUIContent("Image Blur", "Pre-blur the environment image for Global Illumination calculations. Can help to reduce noise and flicker in images rendered with Final Gather. May increase render time as it is blurred at render time. It is always cheaper to pre-blur the image itself in an external application before loading it into Beast."),
                                              GUILayout.Width(300)
                                              );

                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(iblSwapYZ, new GUIContent("Dome Swap Y/Z", "Swap the Up Axis. Default value is false, meaning that Y is up."));
                EditorGUILayout.Slider(iblTurnDome,
                                       0, 360,
                                       new GUIContent("Dome Rotation", "The sphere that the image is projected on can be rotated around the up axis. The amount of rotation is given in degrees."),
                                       GUILayout.Width(300)
                                       );
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(10);
                    if (GUILayout.Button(new GUIContent("Align to Active Sky", "Matches Dome Rotation to the active Skyshop Sky. Note: Skyshop at 0 degrees is Beast at 90."), GUILayout.Width(135)))
                    {
                        float           theta = 90;
                        mset.SkyManager mgr   = mset.SkyManager.Get();
                        if (mgr && mgr.GlobalSky)
                        {
                            theta += mgr.GlobalSky.transform.rotation.eulerAngles.y;
                        }
                        iblTurnDome.floatValue = Mathf.Repeat(theta, 360f);
                        GUI.changed            = true;
                    }
                }
                GUILayout.EndHorizontal();

                EditorGUILayout.Space();
                GUILayout.Label("IBL Light", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(
                    iblEmitLight,
                    new GUIContent("Emit Light", "Turns on the expensive IBL implementation. This will generate a number of(iblSamples) directional lights from the image."),
                    GUILayout.Width(300)
                    );
                if (sc.config.environmentSettings.iblEmitLight)
                {
                    EditorGUILayout.HelpBox("The scene will be lit by a number of directional lights with colors sampled from the IBL image. Very expensive.", MessageType.None);
                }
                else
                {
                    EditorGUILayout.HelpBox("The scene will be lit with Global Illumination using the IBL image as a simple environment.", MessageType.None);
                }

                EditorGUI.BeginDisabledGroup(!sc.config.environmentSettings.iblEmitLight);
                {
                    EditorGUILayout.PropertyField(iblSamples, new GUIContent("Samples", "The number of samples to be taken from the image. This will affect how soft the shadows will be, as well as the general lighting. The higher number of samples, the better the shadows and lighting."), GUILayout.Width(300));
                    EditorGUILayout.PropertyField(iblIntensity, new GUIContent("IBL Intensity", "Sets the intensity of the lighting."), GUILayout.Width(300));
                    EditorGUILayout.PropertyField(iblEmitDiffuse, new GUIContent("Diffuse", "To remove diffuse lighting from IBL, set this to false. To get the diffuse lighting Final Gather could be used instead."), GUILayout.Width(300));
                    EditorGUILayout.PropertyField(iblEmitSpecular, new GUIContent("Specular", "To remove specular highlights from IBL, set this to false."), GUILayout.Width(300));
                    EditorGUI.indentLevel++;
                    {
                        if (!sc.config.environmentSettings.iblEmitSpecular)
                        {
                            GUI.enabled = false;
                        }
                        EditorGUILayout.PropertyField(iblSpecularBoost, new GUIContent("Specular Boost", "Further tweak the intensity by boosting the specular component."), GUILayout.Width(300));
                        if (sc.config.environmentSettings.iblEmitLight)
                        {
                            GUI.enabled = true;
                        }
                    }
                    EditorGUI.indentLevel--;
                    EditorGUILayout.PropertyField(iblShadows, new GUIContent("Shadows", "Controls whether shadows should be created from IBL when this is used."), GUILayout.Width(300));
                    {
                        EditorGUI.indentLevel++;
                        if (!sc.config.environmentSettings.iblShadows)
                        {
                            GUI.enabled = false;
                        }
                        EditorGUILayout.PropertyField(iblBandingVsNoise, new GUIContent("Shadow Noise", "Controls the appearance of the shadows, banded shadows look more aliased, but noisy shadows flicker more in animations."), GUILayout.Width(300));
                        if (sc.config.environmentSettings.iblEmitLight)
                        {
                            GUI.enabled = true;
                        }
                    }
                    EditorGUI.indentLevel--;
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.Space();
            }
            EditorGUI.indentLevel--;
            EditorGUI.EndDisabledGroup();

            if (GUI.changed)
            {
                serializedConfig.ApplyModifiedProperties();
                SaveConfig();
            }

            float width    = 80;
            float height   = 30;
            bool  disabled = !InternalEditorUtility.HasPro();

            if (disabled)
            {
                EditorGUILayout.HelpBox("Global Illumination baking is a Unity Pro feature :(", MessageType.Error);
            }
            EditorGUI.BeginDisabledGroup(disabled);
            {
                EditorGUILayout.Space();
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(10);
                    EditorGUI.BeginDisabledGroup(Lightmapping.isRunning);
                    if (GUILayout.Button("Clear", GUILayout.Width(width)))
                    {
                        if (EditorUtility.DisplayDialog("Clear Lightmapping Data", "Do you want to clear all lightmap and probe data from the scene?", "OK", "Cancel"))
                        {
                            Lightmapping.Clear();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal(); {
                    if (!Lightmapping.isRunning)
                    {
                        GUILayout.Space(10);
                        bool scene    = GUILayout.Button("Bake Scene", GUILayout.Height(height));
                        bool selected = GUILayout.Button("Bake Selected", GUILayout.Height(height));
                        bool probes   = GUILayout.Button("Bake Probes", GUILayout.Height(height));

                        if ((scene || selected || probes) && CheckSettingsIntegrity())
                        {
                            if (scene)
                            {
                                Lightmapping.BakeAsync();
                            }
                            else if (selected)
                            {
                                Lightmapping.BakeAsync();
                            }
                            else if (probes)
                            {
                                Lightmapping.BakeAsync();
                            }
                        }
                        GUILayout.Space(10);
                    }
                    else
                    {
                        GUILayout.Space(10);
                        if (GUILayout.Button("Cancel", GUILayout.Width(width), GUILayout.Height(height)))
                        {
                            Lightmapping.Cancel();
                        }
                    }
                } GUILayout.EndHorizontal();
            }
            EditorGUI.EndDisabledGroup();
        }
コード例 #10
0
        public bool capture(Texture targetCube, Vector3 position, Quaternion rotation, bool HDR, bool linear, bool convolve)
        {
            if (targetCube == null)
            {
                return(false);
            }

            bool tempRT = false;

            if (cubeRT == null)
            {
                tempRT = true;
                //everything's captured to an HDR buffer right now
                cubeRT              = RenderTexture.GetTemporary(targetCube.width, targetCube.width, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
                cubeRT.isCubemap    = true;
                cubeRT.useMipMap    = true;
                cubeRT.generateMips = true;
                if (!cubeRT.IsCreated() && !cubeRT.Create())
                {
                    cubeRT              = RenderTexture.GetTemporary(targetCube.width, targetCube.width, 24, RenderTextureFormat.Default, RenderTextureReadWrite.Linear);
                    cubeRT.isCubemap    = true;
                    cubeRT.useMipMap    = true;
                    cubeRT.generateMips = true;
                }
            }

            if (!cubeRT.IsCreated() && !cubeRT.Create())
            {
                return(false);
            }

            GameObject go  = null;
            Camera     cam = null;

            go  = new GameObject("_temp_probe");
            cam = go.AddComponent <Camera>();

            mset.SkyManager mgr = mset.SkyManager.Get();
            if (mgr && mgr.ProbeCamera)
            {
                cam.CopyFrom(mgr.ProbeCamera);
            }
            else if (Camera.main)
            {
                cam.CopyFrom(Camera.main);
            }
            cam.renderingPath       = renderPath;
            cam.useOcclusionCulling = false;
            cam.hdr = true;

            go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
            go.SetActive(true);
            go.transform.position = position;

            //capture entire scene in HDR
            Shader.SetGlobalVector("_UniformOcclusion", this.exposures);
            cam.RenderToCubemap(cubeRT);
            Shader.SetGlobalVector("_UniformOcclusion", Vector4.one);

            Matrix4x4 matrix = Matrix4x4.identity;

            matrix.SetTRS(position, rotation, Vector3.one);

            //render cubeRT converting it to RGBM
            Material skyMat = new Material(Shader.Find("Hidden/Marmoset/RGBM Cube"));

            bool dstRGBM = HDR;
            bool srcRGBM = false;

            copy_internal(targetCube, cubeRT, dstRGBM, srcRGBM, linear, cam, skyMat, matrix);
            if (convolve)
            {
                convolve_internal(targetCube, cubeRT, HDR, false, linear, cam, skyMat, matrix);
            }

            //make sure the old sky and matrix vars are bound again
            if (mgr)
            {
                mgr.GlobalSky = mgr.GlobalSky;
            }
            Material.DestroyImmediate(skyMat);

            GameObject.DestroyImmediate(go);

            if (tempRT)
            {
                RenderTexture.ReleaseTemporary(cubeRT);
            }
            return(true);
        }
コード例 #11
0
        public void convolve(Cubemap targetCube, Texture sourceCube, bool dstRGBM, bool srcRGBM, bool linear)
        {
            if (targetCube == null)
            {
                return;
            }
            //buildRandomValueCode();

            /*
             * bool tempRT = false;
             * if(cubeRT == null) {
             *      tempRT = true;
             *      //everything's rendered in HDR render buffer for now
             *      cubeRT = RenderTexture.GetTemporary(targetCube.width, targetCube.width, 24, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
             *      cubeRT.isCubemap = true;
             *      cubeRT.useMipMap = true;
             *      cubeRT.generateMips = true;
             * }
             */

            GameObject go = new GameObject("_temp_probe");

            go.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideAndDontSave;
            go.SetActive(true);
            Camera cam = go.AddComponent <Camera>();

            cam.renderingPath       = renderPath;
            cam.useOcclusionCulling = false;

            Material skyMat = new Material(Shader.Find("Hidden/Marmoset/RGBM Cube"));

            Matrix4x4 matrix = Matrix4x4.identity;

            this.copy_internal(targetCube, sourceCube, dstRGBM, srcRGBM, linear, cam, skyMat, matrix);
            //NOTE: cubeRT is needed to make sure sourceCube is mipmapped (for importance sampling), however cubeRT cannot be used because D3D9 renders skybox gamma wrong >_<

            /*
             * this.copy_internal(cubeRT,       sourceCube, false,   srcRGBM, linear, cam, skyMat, matrix);
             * this.convolve_internal(targetCube,	cubeRT,	dstRGBM, false,   linear, cam, skyMat, matrix);
             * this.copy_internal		(targetCube, sourceCube, dstRGBM, srcRGBM, linear, cam, skyMat, matrix);
             */
            int me = this.maxExponent;

            //HACK: dx11 seems to be the only shader model that supports 128 texture samples, convolve twice on all other platforms
            this.maxExponent = 2 * me;
            this.convolve_internal(targetCube, sourceCube, dstRGBM, srcRGBM, linear, cam, skyMat, matrix);
            this.maxExponent = 8 * me;
            this.convolve_internal(targetCube, targetCube, dstRGBM, dstRGBM, linear, cam, skyMat, matrix);
            this.maxExponent = me;

            //make sure the old sky and matrix vars are bound again
            mset.SkyManager mgr = mset.SkyManager.Get();
            if (mgr)
            {
                mgr.GlobalSky = mgr.GlobalSky;
            }
            Material.DestroyImmediate(skyMat);

            //if(tempRT) RenderTexture.ReleaseTemporary(cubeRT);
            GameObject.DestroyImmediate(go);
        }
コード例 #12
0
ファイル: SkyManager.cs プロジェクト: keyward/EnemyOfMyEnemy
		public static mset.SkyManager Get() {
			if(_Instance == null) _Instance = GameObject.FindObjectOfType<mset.SkyManager>();
			return _Instance;
		}
コード例 #13
0
        public void OnSceneGUI()
        {
            myapp = this.target as mset.SkyApplicator;

            if (mset.SkyApplicatorInspector.triggerEdit && myapp.TriggerIsActive)
            {
                mset.Sky sky    = myapp.GetComponent <mset.Sky>();
                Vector3  campos = Vector3.zero;
                if (Camera.current != null)
                {
                    campos = Camera.current.transform.position;
                }

                Vector3 skyScale = sky.transform.lossyScale;
                if (skyScale.x == 0)
                {
                    skyScale.x = 0.001f;
                }
                if (skyScale.y == 0)
                {
                    skyScale.y = 0.001f;
                }
                if (skyScale.z == 0)
                {
                    skyScale.z = 0.001f;
                }

                xscale = x2scale = myapp.TriggerDimensions.size.x * 0.5f * skyScale.x;
                yscale = y2scale = myapp.TriggerDimensions.size.y * 0.5f * skyScale.y;
                zscale = z2scale = myapp.TriggerDimensions.size.z * 0.5f * skyScale.z;

                Handles.color = new Color(1.0f, 0.5f, 0.0f, 0.9f);
                Vector3 dotpos;

                Vector3 boxcenter = sky.transform.localToWorldMatrix.MultiplyPoint(myapp.TriggerDimensions.center);

                dotpos = xscale * sky.transform.right + boxcenter;
                dotpos = Handles.Slider(dotpos, sky.transform.right, (dotpos - campos).magnitude / 10.0f, Handles.ArrowCap, 0.05f);
                xscale = (dotpos - boxcenter).magnitude;

                dotpos  = (x2scale * -sky.transform.right) + boxcenter;
                dotpos  = Handles.Slider(dotpos, -sky.transform.right, (dotpos - campos).magnitude / 10.0f, Handles.ArrowCap, 0.05f);
                x2scale = (dotpos - boxcenter).magnitude;

                dotpos = yscale * sky.transform.up + boxcenter;
                dotpos = Handles.Slider(dotpos, sky.transform.up, (dotpos - campos).magnitude / 10.0f, Handles.ArrowCap, 0.05f);
                yscale = (dotpos - boxcenter).magnitude;

                dotpos  = y2scale * -sky.transform.up + boxcenter;
                dotpos  = Handles.Slider(dotpos, -sky.transform.up, (dotpos - campos).magnitude / 10.0f, Handles.ArrowCap, 0.05f);
                y2scale = (dotpos - boxcenter).magnitude;

                dotpos = zscale * sky.transform.forward + boxcenter;
                dotpos = Handles.Slider(dotpos, sky.transform.forward, (dotpos - campos).magnitude / 10.0f, Handles.ArrowCap, 0.05f);
                zscale = (dotpos - boxcenter).magnitude;

                dotpos  = z2scale * -sky.transform.forward + boxcenter;
                dotpos  = Handles.Slider(dotpos, -sky.transform.forward, (dotpos - campos).magnitude / 10.0f, Handles.ArrowCap, 0.05f);
                z2scale = (dotpos - boxcenter).magnitude;

                Bounds dim = myapp.TriggerDimensions;

                float xposDiff = dim.size.x - (xscale / skyScale.x) * 2 - (dim.size.x - (x2scale / skyScale.x) * 2);
                float yposDiff = dim.size.y - (yscale / skyScale.y) * 2 - (dim.size.y - (y2scale / skyScale.y) * 2);
                float zposDiff = dim.size.z - (zscale / skyScale.z) * 2 - (dim.size.z - (z2scale / skyScale.z) * 2);

                dim.center += new Vector3(-xposDiff * 0.25f, -yposDiff * 0.25f, -zposDiff * 0.25f);
                dim.size    = new Vector3((xscale + x2scale) / skyScale.x, (yscale + y2scale) / skyScale.y, (zscale + z2scale) / skyScale.z);

                if (dim.center != myapp.TriggerDimensions.center || dim.size != myapp.TriggerDimensions.size)
                {
                    Undo.RecordObject(myapp, "Sky Trigger Resize");
                    myapp.TriggerDimensions = dim;

                    mset.SkyManager mgr = mset.SkyManager.Get();
                    if (mgr)
                    {
                        mgr.EditorUpdate(true);
                    }
                    EditorUtility.SetDirty(target);
                }

                //Hammer this for now
                myapp.HasChanged = true;
            }
        }