示例#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
		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);
			}
		}
示例#3
0
        public void OnEnable()
        {
            mset.Sky sky = target as mset.Sky;
            if (sky.SH == null)
            {
                sky.SH = new mset.SHEncoding();
            }
            if (sky.CustomSH != null)
            {
                sky.SH.copyFrom(sky.CustomSH.SH);
            }
            sky.SH.copyToBuffer();

            camExposure     = sky.CamExposure;
            masterIntensity = sky.MasterIntensity;
            skyIntensity    = sky.SkyIntensity;
            diffIntensity   = sky.DiffIntensity;
            specIntensity   = sky.SpecIntensity;
            diffIntensityLM = sky.DiffIntensityLM;
            specIntensityLM = sky.SpecIntensityLM;

            refSKY.HDR = sky.HDRSky;
            refSIM.HDR = sky.HDRSpec;

            refSKY.sky = sky;
            refSIM.sky = sky;

            if (sky.HasDimensions)
            {
                projCenter = sky.Dimensions.center;
            }
            else
            {
                projCenter = sky.transform.position;
            }

            mset.SkyApplicator app = sky.gameObject.GetComponent <mset.SkyApplicator>();
            if (app)
            {
                appCenter = app.TriggerDimensions.center;
            }
            else
            {
                appCenter = sky.transform.position;
            }
            //forceDirty = true;
        }
示例#4
0
        public override void OnInspectorGUI()
        {
            GUI.changed = false;
            bool dirty    = false;              //flag for changed sky parameters
            bool dirtyRef = false;              //flag for changed sky cubemap references (causes SH recompute and preview refresh)

            mset.Sky           sky    = target as mset.Sky;
            mset.SkyApplicator app    = sky.gameObject.GetComponent <mset.SkyApplicator>();
            mset.SkyManager    skymgr = mset.SkyManager.Get();

            //sync GUI from sky
            camExposure     = sky.CamExposure;
            masterIntensity = sky.MasterIntensity;
            skyIntensity    = sky.SkyIntensity;
            diffIntensity   = sky.DiffIntensity;
            specIntensity   = sky.SpecIntensity;
            diffIntensityLM = sky.DiffIntensityLM;
            specIntensityLM = sky.SpecIntensityLM;

            //sync and sync from CubeGUIs
            refSIM.computeSH = (sky.CustomSH == null);

            dirtyRef |= skyToGUI(sky.SkyboxCube, sky.HDRSky, sky.SH, refSKY, sky.name, true);
            bool    prevHDR = sky.HDRSky;
            bool    currHDR = sky.HDRSky;
            Texture refCube = sky.SkyboxCube;

            dirtyRef |= GUIToSky(ref refCube, ref currHDR, null, refSKY);
            if (refCube != sky.SkyboxCube)
            {
                sky.SkyboxCube = refCube;
            }
            if (currHDR != prevHDR)
            {
                sky.HDRSky = currHDR;
            }

            dirtyRef |= skyToGUI(sky.SpecularCube, sky.HDRSpec, sky.SH, refSIM, sky.name, true);
            prevHDR   = sky.HDRSpec;
            currHDR   = sky.HDRSpec;
            refCube   = sky.SpecularCube;
            dirtyRef |= GUIToSky(ref refCube, ref currHDR, sky.SH, refSIM);
            if (refCube != sky.SpecularCube)
            {
                sky.SpecularCube = refCube;
            }
            if (currHDR != prevHDR)
            {
                sky.HDRSpec = currHDR;
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();

            string ashTip = "Accepts custom diffuse irradiance .asset files generated in other software (such as Knald Lys: www.knaldtech.com)\n\nWill override diffuse light generated from the specular cubemap.";

            EditorGUILayout.LabelField(new GUIContent("Custom Diffuse SH (Optional)", ashTip), GUILayout.Width(248));
            if (GUILayout.Button("None", GUILayout.Width(50), GUILayout.Height(14)))
            {
                sky.CustomSH     = null;
                refSIM.computeSH = true;
                refSIM.reloadReference();
            }
            EditorGUILayout.EndHorizontal();

            sky.CustomSH = EditorGUILayout.ObjectField(sky.CustomSH, typeof(mset.SHEncodingFile), false, GUILayout.Width(320)) as mset.SHEncodingFile;
            if (sky.CustomSH != null)
            {
                sky.SH.copyFrom(sky.CustomSH.SH);
                sky.SH.copyToBuffer();
            }
            refSIM.computeSH = (sky.CustomSH == null);

            GUIStyle buttonStyle = new GUIStyle("Button");

            buttonStyle.padding.top  = buttonStyle.padding.bottom = 0;
            buttonStyle.padding.left = buttonStyle.padding.right = 0;

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GUILayout.BeginHorizontal();
            //Global button
            if (skymgr != null)
            {
                bool alreadyGlobal = skymgr.GlobalSky == sky;
                EditorGUI.BeginDisabledGroup(alreadyGlobal);
                bool setAsGlobal = GUILayout.Button(new GUIContent("Make Global Sky", "Sets this sky as the global sky in the Sky Manager."), GUILayout.Width(120));
                if (setAsGlobal)
                {
                    skymgr.GlobalSky = sky;
                    SceneView.RepaintAll();
                }
                EditorGUI.EndDisabledGroup();
            }
            //Local Apply button
            EditorGUI.BeginDisabledGroup(app == null || !app.TriggerIsActive);
            string trigTip = "Applies this sky locally only to renderers contained within its Sky Applicator trigger volume.";

            if (app == null || !app.TriggerIsActive)
            {
                trigTip = "Requires Sky Applicator component with active trigger.";
            }

            if (GUILayout.Button(new GUIContent("Preview Apply", trigTip), GUILayout.Width(100)))
            {
                Renderer[] all = GameObject.FindObjectsOfType <Renderer>();
                foreach (Renderer r in all)
                {
                    app.ApplyInside(r);
                }
            }
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            //color detection is always on, but still required for LDR skies to function

            /*bool detect = EditorGUILayout.Toggle(new GUIContent("Auto-Detect Color Space","If enabled, attempts to detect the project's gamma correction setting and enables/disables the Linear Space option accordingly"), sky.AutoDetectColorSpace);
             * if( detect != sky.AutoDetectColorSpace ) {
             *      mset.EditorUtil.RegisterUndo(sky, "Color-Space Detection Change");
             *      sky.AutoDetectColorSpace = detect;
             * }
             * bool prevLinear = sky.LinearSpace;
             */

            sky.AutoDetectColorSpace = true;
            if (sky.AutoDetectColorSpace)
            {
                detectColorSpace(ref sky);
            }


            /*
             * EditorGUI.BeginDisabledGroup(sky.AutoDetectColorSpace);
             *      bool userLinearSpace = EditorGUILayout.Toggle(new GUIContent("Linear Space","Enable if gamma correction is enabled for this project (Edit -> Project Settings -> Player -> Color Space: Linear)"), sky.LinearSpace);
             *      if( userLinearSpace != sky.LinearSpace ) {
             *              mset.EditorUtil.RegisterUndo(sky, "Color-Space Change");
             *              sky.LinearSpace = userLinearSpace;
             *      }
             * EditorGUI.EndDisabledGroup();
             * if( prevLinear != sky.LinearSpace ){
             * //	dirty = true;
             * }
             */

            sky.IsProbe = EditorGUILayout.Toggle(new GUIContent("Is Probe", "Enable if this sky has been rendered from within the scene. The \"Probe All Skies\" feature will only process skies marked as probes."), sky.IsProbe);

            bool prevProj = sky.HasDimensions;
            bool boxProj  = EditorGUILayout.Toggle(new GUIContent("Box Projected", "Assign box dimensions to this sky for parallaxed specular reflection."), sky.HasDimensions);

            if (boxProj != prevProj)
            {
                mset.EditorUtil.RegisterUndo(sky, "Box Projection Toggle");
                sky.HasDimensions = boxProj;
            }

            EditorGUILayout.BeginHorizontal();
            if (skymgr != null)
            {
                skymgr.ProbeOnlyStatic = EditorGUILayout.Toggle(new GUIContent("Probe Only Static Objects", ""), skymgr.ProbeOnlyStatic);
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.LabelField("(Global Setting)", GUILayout.Width(320));
                EditorGUI.EndDisabledGroup();
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.Toggle(new GUIContent("Probe Only Static Objects", "Requires a Sky Manager object to be present in the scene."), false);
                EditorGUILayout.LabelField("(Missing Sky Manager in scene)", GUILayout.Width(320));
                EditorGUI.EndDisabledGroup();
            }
            EditorGUILayout.EndHorizontal();

            bool hasTrigger = app && app.TriggerIsActive;

            EditMode prevMode = editMode;

            EditorGUILayout.Space();
            Bounds dim = sky.Dimensions;

            dim.center     = EditorGUILayout.Vector3Field("Projector Center", dim.center);
            dim.size       = EditorGUILayout.Vector3Field("Projector Size", dim.size);
            sky.Dimensions = dim;

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            GUIStyle style = new GUIStyle();

            style.richText = true;
            GUILayout.Label("<b>Viewport Edit Mode</b>", style);

            if (editIconListFull == null)
            {
                editIconListFull = new Texture2D[] {
                    Resources.Load <Texture2D>("editTrans"),
                    Resources.Load <Texture2D>("editProbe"),
                    Resources.Load <Texture2D>("editProjection"),
                    Resources.Load <Texture2D>("editTrigger")
                };

                editIconListAdd = new Texture2D[] {
                    editIconListFull[0],
                    editIconListFull[1],
                    Resources.Load <Texture2D>("addProjection"),
                    Resources.Load <Texture2D>("addTrigger")
                };

                editIconListProj = new Texture2D[] {
                    editIconListFull[0],
                    editIconListFull[1],
                    editIconListFull[2],
                    editIconListAdd[3]                     //no trigger
                };

                editIconListTrigger = new Texture2D[] {
                    editIconListFull[0],
                    editIconListFull[1],
                    editIconListAdd[2],                     //no projection
                    editIconListFull[3]
                };
            }

            int barWidth = 340;

            //reset edit mode if we've lost the tools we need for this sky configuration
            if (editMode == EditMode.PROJECTOR && !boxProj)
            {
                editMode = EditMode.TRANSFORM;
            }
            if (editMode == EditMode.TRIGGER && !hasTrigger)
            {
                editMode = EditMode.TRANSFORM;
            }

            if (hasTrigger && boxProj)
            {
                editMode = (EditMode)GUILayout.Toolbar((int)editMode, editIconListFull, GUILayout.Width(barWidth));
            }
            else if (boxProj)
            {
                editMode = (EditMode)GUILayout.Toolbar((int)editMode, editIconListProj, GUILayout.Width(barWidth));
            }
            else if (hasTrigger)
            {
                editMode = (EditMode)GUILayout.Toolbar((int)editMode, editIconListTrigger, GUILayout.Width(barWidth));
            }
            else
            {
                editMode = (EditMode)GUILayout.Toolbar((int)editMode, editIconListAdd, GUILayout.Width(barWidth));
            }

            if (!boxProj && editMode == EditMode.PROJECTOR)
            {
                boxProj           = true;
                sky.HasDimensions = true;
                editMode          = EditMode.PROJECTOR;
            }

            if (!hasTrigger && editMode == EditMode.TRIGGER)
            {
                hasTrigger = true;
                if (!app)
                {
                    app = sky.gameObject.AddComponent <mset.SkyApplicator>();
                }
                app.TriggerIsActive = true;
            }

            EditorGUILayout.BeginHorizontal(GUILayout.Width(barWidth));
            GUILayout.Label("Transform", GUILayout.Width(82));
            GUILayout.Label("Probe Origin", GUILayout.Width(82));
            if (boxProj)
            {
                GUILayout.Label("Projector", GUILayout.Width(86));
            }
            else
            {
                GUILayout.Label("Add Projector", GUILayout.Width(86));
            }
            if (hasTrigger)
            {
                GUILayout.Label("Trigger", GUILayout.Width(60));
            }
            else
            {
                GUILayout.Label("Add Trigger", GUILayout.Width(80));
            }
            EditorGUILayout.EndHorizontal();

            //edit mode has changed, sync or sync from stored bound centers
            if (prevMode != editMode)
            {
                projCenter = sky.transform.localToWorldMatrix.MultiplyPoint(sky.Dimensions.center);
                if (app)
                {
                    appCenter = sky.transform.localToWorldMatrix.MultiplyPoint(app.TriggerDimensions.center);
                }
                else
                {
                    appCenter = sky.transform.position;
                }
            }
            //turn on applicator resize handle drawing
            mset.SkyApplicatorInspector.triggerEdit = editMode == EditMode.TRIGGER;

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            //sync sky from GUI
            EditorGUILayout.LabelField(new GUIContent("Master Intensity", "Multiplier on the Sky, Diffuse, and Specular cube intensities"));
            masterIntensity = EditorGUILayout.Slider(masterIntensity, 0f, 10f);
            if (sky.MasterIntensity != masterIntensity)
            {
                mset.EditorUtil.RegisterUndo(sky, "Intensity Change");
                sky.MasterIntensity = masterIntensity;
            }

            EditorGUILayout.LabelField(new GUIContent("Skybox Intensity", "Brightness of the skybox"));
            skyIntensity = EditorGUILayout.Slider(skyIntensity, 0f, 10f);
            if (sky.SkyIntensity != skyIntensity)
            {
                mset.EditorUtil.RegisterUndo(sky, "Intensity Change");
                sky.SkyIntensity = skyIntensity;
            }

            EditorGUILayout.LabelField(new GUIContent("Diffuse Intensity", "Multiplier on the diffuse light put out by this sky"));
            diffIntensity = EditorGUILayout.Slider(diffIntensity, 0f, 10f);
            if (sky.DiffIntensity != diffIntensity)
            {
                mset.EditorUtil.RegisterUndo(sky, "Intensity Change");
                sky.DiffIntensity = diffIntensity;
            }

            EditorGUILayout.LabelField(new GUIContent("Specular Intensity", "Multiplier on the specular light put out by this sky"));
            specIntensity = EditorGUILayout.Slider(specIntensity, 0f, 10f);
            if (sky.SpecIntensity != specIntensity)
            {
                mset.EditorUtil.RegisterUndo(sky, "Intensity Change");
                sky.SpecIntensity = specIntensity;
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.LabelField(new GUIContent("Camera Exposure", "Multiplier on all light coming into the camera, including IBL, direct light, and glow maps"));
            camExposure = EditorGUILayout.Slider(camExposure, 0f, 10f);
            if (sky.CamExposure != camExposure)
            {
                mset.EditorUtil.RegisterUndo(sky, "Exposure Change");
                sky.CamExposure = camExposure;
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.LabelField(new GUIContent("Lightmapped Diffuse Multiplier", "Multiplier on the diffuse intensity for lightmapped surfaces"));
            diffIntensityLM = EditorGUILayout.Slider(diffIntensityLM, 0f, 1f);
            if (sky.DiffIntensityLM != diffIntensityLM)
            {
                mset.EditorUtil.RegisterUndo(sky, "Multiplier Change");
                sky.DiffIntensityLM = diffIntensityLM;
            }

            EditorGUILayout.LabelField(new GUIContent("Lightmapped Specular Multiplier", "Multiplier on the specular intensity for lightmapped surfaces"));
            specIntensityLM = EditorGUILayout.Slider(specIntensityLM, 0f, 1f);
            if (sky.SpecIntensityLM != specIntensityLM)
            {
                mset.EditorUtil.RegisterUndo(sky, "Multiplier Change");
                sky.SpecIntensityLM = specIntensityLM;
            }

            dirty |= GUI.changed;

            if (forceDirty)
            {
                refSKY.reloadReference();
                refSIM.reloadReference();

                dirtyRef   = true;
                forceDirty = false;
                dirty      = true;
                Repaint();
            }

            //guess input path
            if (dirtyRef)
            {
                string inPath = refSKY.fullPath;
                if (inPath.Length == 0)
                {
                    inPath = refSIM.fullPath;
                }
                if (inPath.Length > 0)
                {
                    int uscore = inPath.LastIndexOf("_");
                    if (uscore > -1)
                    {
                        inPath = inPath.Substring(0, uscore);
                    }
                    else
                    {
                        inPath = Path.GetDirectoryName(inPath) + "/" + Path.GetFileNameWithoutExtension(inPath);
                    }
                    refSKY.inputPath     =
                        refSIM.inputPath = inPath;
                }
                else
                {
                    refSKY.inputPath     =
                        refSIM.inputPath = "";
                }
                dirty = true;
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }

            //reapply and repaint with manager
            mset.SkyManager mgr = mset.SkyManager.Get();

            if (!Application.isPlaying)
            {
                if (dirty || mgr && mgr.GlobalSky)
                {
                    sky.EditorUpdate();
                    if (mgr)
                    {
                        mgr.EditorUpdate(true);
                        SceneView.RepaintAll();
                    }
                }
            }
        }
示例#5
0
        //	Vector3 dotPos;
        public void OnSceneGUI()
        {
            mset.Sky sky = target as mset.Sky;

            if (this.editMode == EditMode.TRIGGER)
            {
                return;
            }

            if (sky.HasDimensions)
            {
                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 = sky.Dimensions.size.x * 0.5f * skyScale.x;
                yscale = y2scale = sky.Dimensions.size.y * 0.5f * skyScale.y;
                zscale = z2scale = sky.Dimensions.size.z * 0.5f * skyScale.z;

                if (this.editMode == EditMode.PROJECTOR)
                {
                    Handles.color = new Color(0.2f, 0.8f, 1f, 0.9f);
                    Vector3 dotpos;

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

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

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

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

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

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

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

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

                    Bounds dim = sky.Dimensions;
                    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.Equals(sky.Dimensions.center) || !dim.size.Equals(sky.Dimensions.size))
                    {
                        Undo.RecordObject(sky, "Sky Projection Resize");
                        sky.Dimensions = dim;
                        mset.SkyManager mgr = mset.SkyManager.Get();
                        if (mgr)
                        {
                            mgr.EditorUpdate(true);
                        }
                    }
                }
            }

            mset.SkyApplicator app = sky.gameObject.GetComponent <mset.SkyApplicator>();
            if (this.editMode == EditMode.PROBE)
            {
                //moving probe around, recompute local-space sky dimensions from world-space, cached centers
                Bounds dim = sky.Dimensions;
                dim.center = sky.transform.worldToLocalMatrix.MultiplyPoint(projCenter);

                if (dim.center != sky.Dimensions.center)
                {
                    if (app)
                    {
                        UnityEngine.Object[] undoList = { sky, app };
                        Undo.RecordObjects(undoList, "Probe Center Move");
                    }
                    else
                    {
                        Undo.RecordObject(sky, "Probe Center Move");
                    }
                }

                sky.Dimensions = dim;
                if (app)
                {
                    dim                   = app.TriggerDimensions;
                    dim.center            = sky.transform.worldToLocalMatrix.MultiplyPoint(appCenter);
                    app.TriggerDimensions = dim;
                }
            }
            else
            {
                //moving everything around, cache world-space centers of bounds
                projCenter = sky.transform.localToWorldMatrix.MultiplyPoint(sky.Dimensions.center);
                if (app)
                {
                    appCenter = sky.transform.localToWorldMatrix.MultiplyPoint(app.TriggerDimensions.center);
                }
                else
                {
                    appCenter = sky.transform.position;
                }
            }
        }