Пример #1
0
        void OnEnable()
        {
            //When this inspector is created, also create the built-in inspector
            defaultEditor = CreateEditor(targets, Type.GetType("UnityEditor.Texture3DInspector, UnityEditor"));

            //Find all types of I3DMaterialOverride, and query whether there's a valid material for the current target.

                        #if UNITY_2018_1_OR_NEWER
            IEnumerable <Type> i3DMaterialOverrideTypes = (IEnumerable <Type>)Type.GetType("UnityEditor.EditorAssemblies, UnityEditor").GetMethod(
                "GetAllTypesWithInterface", BindingFlags.NonPublic | BindingFlags.Static, null, new[] { typeof(Type) }, null
                ).Invoke(null, new object[] { typeof(I3DMaterialOverride) });
                        #else
            IEnumerable <Type> i3DMaterialOverrideTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where(p => p != typeof(I3DMaterialOverride) && typeof(I3DMaterialOverride).IsAssignableFrom(p));
                        #endif

            foreach (Type i3DMaterialOverrideType in i3DMaterialOverrideTypes)
            {
                I3DMaterialOverride i3DMaterialOverride = (I3DMaterialOverride)Activator.CreateInstance(i3DMaterialOverrideType);
                m_Material = i3DMaterialOverride.GetMaterial((Texture3D)target);
                if (m_Material != null)
                {
                    materialOverride = i3DMaterialOverride;
                    break;
                }
            }

            rCallback = r => { material.SetFloat("_R", r ? 1 : 0); };
            gCallback = g => { material.SetFloat("_G", g ? 1 : 0); };
            bCallback = b => { material.SetFloat("_B", b ? 1 : 0); };
            x         = 1;
            y         = 1;
            z         = 1;
            SetXYZFloats();
        }
        void OnEnable()
        {
            //When this inspector is created, also create the built-in inspector
            defaultEditor = CreateEditor(targets, Type.GetType("UnityEditor.Texture3DInspector, UnityEditor"));

            //Find all types of I3DMaterialOverride, and query whether there's a valid material for the current target.
            IEnumerable <Type> i3DMaterialOverrideTypes = (IEnumerable <Type>)Type.GetType("UnityEditor.EditorAssemblies, UnityEditor").GetMethod(
                "GetAllTypesWithInterface", BindingFlags.NonPublic | BindingFlags.Static, null, new[] { typeof(Type) }, null
                ).Invoke(null, new object[] { typeof(I3DMaterialOverride) });

            //Safe cast to allow Render Texture 3D to fall-back to this class.
            Texture3D texture3D = target as Texture3D;

            if (texture3D != null)
            {
                foreach (Type i3DMaterialOverrideType in i3DMaterialOverrideTypes)
                {
                    I3DMaterialOverride i3DMaterialOverride = (I3DMaterialOverride)Activator.CreateInstance(i3DMaterialOverrideType);
                    m_Material3D = i3DMaterialOverride.GetMaterial(texture3D);
                    if (m_Material3D != null)
                    {
                        materialOverride = i3DMaterialOverride;
                        break;
                    }
                }
            }

            rCallback = r => { material3D.SetFloat(R, r ? 1 : 0); };
            gCallback = g => { material3D.SetFloat(G, g ? 1 : 0); };
            bCallback = b => { material3D.SetFloat(B, b ? 1 : 0); };
            x         = 1;
            y         = 1;
            z         = 1;
            SetXYZFloats();
        }
Пример #3
0
        protected override void OnEnable()
        {
            //Find all types of I3DMaterialOverride, and query whether there's a valid material for the current target.
            IEnumerable <Type> i3DMaterialOverrideTypes = (IEnumerable <Type>)Type.GetType("UnityEditor.EditorAssemblies, UnityEditor").GetMethod(
                "GetAllTypesWithInterface", BindingFlags.NonPublic | BindingFlags.Static, null, new[] { typeof(Type) }, null
                ).Invoke(null, new object[] { typeof(I3DMaterialOverride) });

            //Safe cast to allow Render Texture 3D to fall-back to this class.
            Texture texture3D = target as Texture;

            if (texture3D != null)
            {
                foreach (Type i3DMaterialOverrideType in i3DMaterialOverrideTypes)
                {
                    I3DMaterialOverride i3DMaterialOverride = (I3DMaterialOverride)Activator.CreateInstance(i3DMaterialOverrideType);
                    override3DMaterial = i3DMaterialOverride.GetMaterial(texture3D);
                    if (override3DMaterial == null)
                    {
                        continue;
                    }
                    materialOverride = i3DMaterialOverride;
                    break;
                }
            }

            rCallback = r => {
                Material m = override3DMaterial != null ? override3DMaterial : material3D;
                m.SetFloat(R, r ? 1 : 0);
            };
            gCallback = g =>
            {
                Material m = override3DMaterial != null ? override3DMaterial : material3D;
                m.SetFloat(G, g ? 1 : 0);
            };
            bCallback = b =>
            {
                Material m = override3DMaterial != null ? override3DMaterial : material3D;
                m.SetFloat(B, b ? 1 : 0);
            };
            x = 1;
            y = 1;
            z = 1;
            SetXYZFloats();
            base.OnEnable();
        }