Example #1
0
        public List <ShaderInformations> GetAllShaderProperties()
        {
            Shader shader = GetComponent <Renderer>().sharedMaterial.shader;

            List <ShaderInformations> allInfos = new List <ShaderInformations>();


            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            for (int i = 0; i < propertyCount; i++)
            {
                string description = ShaderUtil.GetPropertyDescription(shader, i);

                string name = ShaderUtil.GetPropertyName(shader, i);

                ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(shader, i);

                ShaderInformations shaderInfo = new ShaderInformations(name, description, type);


                if (type == ShaderUtil.ShaderPropertyType.Range)
                {
                    shaderInfo.SetRange(ShaderUtil.GetRangeLimits(shader, i, 0), ShaderUtil.GetRangeLimits(shader, i, 1), ShaderUtil.GetRangeLimits(shader, i, 2));
                }

                allInfos.Add(shaderInfo);
            }

            return(allInfos);
        }
    public static Spaces.Core.ShaderInterface GenerateShaderInterface(Shader shader)
    {
        var shaderInterface = Spaces.Core.ShaderInterface.CreateInterface(shader);

        int count = ShaderUtil.GetPropertyCount(shader);

        for (int i = 0; i < count; i++)
        {
            var prop = new Spaces.Core.ShaderInterface.ShaderProperty()
            {
                name   = ShaderUtil.GetPropertyName(shader, i),
                type   = (Spaces.Core.ShaderInterface.ShaderPropertyType)ShaderUtil.GetPropertyType(shader, i),
                hidden = ShaderUtil.IsShaderPropertyHidden(shader, i),
                texDim = ShaderUtil.GetTexDim(shader, i),
                range  = new Spaces.Core.ShaderInterface.ShaderRangeProperty()
                {
                    def = ShaderUtil.GetRangeLimits(shader, i, 0),
                    min = ShaderUtil.GetRangeLimits(shader, i, 1),
                    max = ShaderUtil.GetRangeLimits(shader, i, 2)
                }
            };

            shaderInterface.properties.Add(prop);
        }

        string path = AssetDatabase.GetAssetPath(shader);

        path = path.EndsWith(".shader") ? path.Replace(".shader", ".asset") : "Assets/_Spaces SDK/Client/Interface/" + shader.name.Replace("/", "_") + ".asset";
        AssetDatabase.CreateAsset(shaderInterface, path);

        return(shaderInterface);
    }
 public ShaderPropertyRange(Material _material, int _index) :
     base(_material, _index, ShaderUtil.ShaderPropertyType.Range)
 {
     value = _material.GetFloat(id);
     min   = ShaderUtil.GetRangeLimits(material.shader, _index, 1);
     max   = ShaderUtil.GetRangeLimits(material.shader, _index, 2);
 }
        protected void updateKeys()
        {
            if (mTarget.replaceMaterial != null)
            {
                Shader shader = mTarget.replaceMaterial.shader;
                int    len    = ShaderUtil.GetPropertyCount(shader);
                keys.Clear();
                max.Clear();
                max.Clear();
                def.Clear();
                for (int i = 0; i < len; i++)
                {
                    string g = ShaderUtil.GetPropertyName(shader, i);
                    ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(shader, i);
                    if (type == ShaderUtil.ShaderPropertyType.Range)
                    {
                        def[g] = ShaderUtil.GetRangeLimits(shader, i, 0);
                        min[g] = ShaderUtil.GetRangeLimits(shader, i, 1);
                        max[g] = ShaderUtil.GetRangeLimits(shader, i, 2);

                        keys.Add(g);
                    }

                    if (type == ShaderUtil.ShaderPropertyType.Color)
                    {
                        Color color = mTarget.replaceMaterial.GetColor(g);
                        colors.Add(g, color);
                        colorKeys = colors.Keys.ToArray();
                    }
                }
            }
        }
Example #5
0
 private Vector3 GetLimits(Shader shader, int index)
 {
     return(new Vector3(
                ShaderUtil.GetRangeLimits(shader, index, 0),
                ShaderUtil.GetRangeLimits(shader, index, 1),
                ShaderUtil.GetRangeLimits(shader, index, 2)));
 }
Example #6
0
    private void GUIShaderRange(string p, SerializedProperty sp)
    {
        float leftValue  = ShaderUtil.GetRangeLimits(s, properties.IndexOf(p), 1);
        float rightValue = ShaderUtil.GetRangeLimits(s, properties.IndexOf(p), 2);

        EditorGUILayout.Slider(sp, leftValue, rightValue);
    }
Example #7
0
    // Caches the list of properties
    public static List <ShaderPropertyInfo> GetShaderProperties(Shader s)
    {
        if (shaderProps.ContainsKey(s.GetInstanceID()))
        {
            return(shaderProps[s.GetInstanceID()]);
        }

        var res = new List <ShaderPropertyInfo>();
        var pc  = ShaderUtil.GetPropertyCount(s);

        for (var i = 0; i < pc; i++)
        {
            var sp = new ShaderPropertyInfo();
            sp.property    = ShaderUtil.GetPropertyName(s, i);
            sp.type        = (ShaderPropertyType)ShaderUtil.GetPropertyType(s, i);
            sp.description = ShaderUtil.GetPropertyDescription(s, i);
            if (sp.type == ShaderPropertyType.Range)
            {
                sp.rangeMin = ShaderUtil.GetRangeLimits(s, i, 1);
                sp.rangeMax = ShaderUtil.GetRangeLimits(s, i, 2);
            }
            res.Add(sp);
        }
        return(shaderProps[s.GetInstanceID()] = res);
    }
Example #8
0
        protected override void OnDrawSubclass()
        {
            serializedObject.Update();

            min = ShaderUtil.GetRangeLimits(shader, propertyIndex[menuIndex], 1);
            max = ShaderUtil.GetRangeLimits(shader, propertyIndex[menuIndex], 2);

            DrawSliderLayout(from.floatValue, min, max, value => from.floatValue = value, "From");
            DrawSliderLayout(to.floatValue, min, max, value => to.floatValue     = value, "To");

            serializedObject.ApplyModifiedProperties();
        }
    // this is the same as the ShaderProperty function, show here so
    // you can see how it works
    private void ShaderPropertyImpl(Shader shader, int propertyIndex)
    {
        int    i            = propertyIndex;
        string label        = ShaderUtil.GetPropertyDescription(shader, i);
        string propertyName = ShaderUtil.GetPropertyName(shader, i);

        switch (ShaderUtil.GetPropertyType(shader, i))
        {
        case ShaderUtil.ShaderPropertyType.Range:         // float ranges
        {
            GUILayout.BeginHorizontal();
            float v2 = ShaderUtil.GetRangeLimits(shader, i, 1);
            float v3 = ShaderUtil.GetRangeLimits(shader, i, 2);
            RangeProperty(propertyName, label, v2, v3);
            GUILayout.EndHorizontal();

            break;
        }

        case ShaderUtil.ShaderPropertyType.Float:         // floats
        {
            FloatProperty(propertyName, label);
            break;
        }

        case ShaderUtil.ShaderPropertyType.Color:         // colors
        {
            ColorProperty(propertyName, label);
            break;
        }

        case ShaderUtil.ShaderPropertyType.TexEnv:         // textures
        {
            ShaderUtil.ShaderPropertyTexDim desiredTexdim = (ShaderUtil.ShaderPropertyTexDim)ShaderUtil.GetTexDim(shader, i);
            TextureProperty(propertyName, label, desiredTexdim);

            GUILayout.Space(6);
            break;
        }

        case ShaderUtil.ShaderPropertyType.Vector:         // vectors
        {
            VectorProperty(propertyName, label);
            break;
        }

        default:
        {
            GUILayout.Label("ARGH" + label + " : " + ShaderUtil.GetPropertyType(shader, i));
            break;
        }
        }
    }
Example #10
0
    void OnGUI_HelperPropInfo(Shader shader, ref string propName, ref Vector4 param, ref MaterialAnimHelper.PropertyType propType, List <string> propNames, Dictionary <string, ShaderPropInfo> props, string lable)
    {
        int propIndex = propNames.IndexOf(propName);

        if (propIndex < 0)
        {
            propIndex = 0;
        }

        propIndex = EditorGUILayout.Popup("PropName:" + lable, propIndex, propNames.ToArray());
        if (propIndex >= 1)
        {
            propName = propNames[propIndex];
        }
        else
        {
            propName = "";
        }

        if (propIndex >= 1)
        {
            var info = props[propName];
            switch (info.type)
            {
            case ShaderUtil.ShaderPropertyType.Color:
                var colValue = EditorGUILayout.ColorField("value:", param);
                propType = MaterialAnimHelper.PropertyType.Color;
                param    = colValue;
                break;

            case ShaderUtil.ShaderPropertyType.Vector:
                var vectValue = EditorGUILayout.Vector4Field("value:", param);
                propType = MaterialAnimHelper.PropertyType.Vector;
                param    = vectValue;
                break;

            case ShaderUtil.ShaderPropertyType.Float:
                var fValue = EditorGUILayout.FloatField("value:", param.x);
                propType = MaterialAnimHelper.PropertyType.Float;
                param.x  = fValue;
                break;

            case ShaderUtil.ShaderPropertyType.Range:
                var min     = ShaderUtil.GetRangeLimits(shader, info.index, 1);
                var max     = ShaderUtil.GetRangeLimits(shader, info.index, 2);
                var rfValue = EditorGUILayout.Slider("value:", param.x, min, max);
                propType = MaterialAnimHelper.PropertyType.Float;
                param.x  = Mathf.Clamp(rfValue, min, max);
                break;
            }
        }
    }
Example #11
0
		protected override void DrawExtraFields()
		{
			EditorGUILayout.PropertyField(_serializedProperty);
			EditorGUILayout.Space();

			int index = _property.editor_propertyIndex;
            if (index >= 0)
			{
				DrawClampedFromToValuesWithSlider(
					ShaderUtil.GetRangeLimits(_property.editor_shader, index, 1),
					ShaderUtil.GetRangeLimits(_property.editor_shader, index, 2));
			}
			else DrawFromToValues();
		}
Example #12
0
        void UpdatePropertySet()
        {
#if UNITY_EDITOR
            _propertySet.Clear();
            if (_material != null)
            {
                var shader = _material.shader;
                var count  = ShaderUtil.GetPropertyCount(shader);
                for (var i = 0; i < count; ++i)
                {
                    var name = ShaderUtil.GetPropertyName(shader, i);
                    if (!_ignoreProperties.Contains(name))
                    {
                        var type = ShaderUtil.GetPropertyType(shader, i);
                        switch (type)
                        {
                        case ShaderUtil.ShaderPropertyType.Color: _propertySet.colors.Add(name); break;

                        case ShaderUtil.ShaderPropertyType.Vector: _propertySet.vectors.Add(name); break;

                        case ShaderUtil.ShaderPropertyType.Float: _propertySet.floats.Add(name); break;

                        case ShaderUtil.ShaderPropertyType.Range:
                        {
                            var rangeData = new PropertySet.RangeData()
                            {
                                name = name,
                                min  = ShaderUtil.GetRangeLimits(shader, i, 1),
                                max  = ShaderUtil.GetRangeLimits(shader, i, 2),
                            };
                            _propertySet.ranges.Add(rangeData);
                        }
                        break;

                        case ShaderUtil.ShaderPropertyType.TexEnv:
                        {
                            if (!_ignoreTexEnv && _material.GetTexture(name) != null)
                            {
                                _propertySet.texEnvs.Add(name);
                            }
                        }
                        break;
                        }
                    }
                }
            }
#endif
        }
Example #13
0
        public static void      SerializeShaderProperty(Shader shader, int i, ByteBuffer buffer)
        {
            string description = ShaderUtil.GetPropertyDescription(shader, i);
            string name        = ShaderUtil.GetPropertyName(shader, i);

            ShaderUtil.ShaderPropertyType propertyType = ShaderUtil.GetPropertyType(shader, i);
            bool hidden = ShaderUtil.IsShaderPropertyHidden(shader, i);

            buffer.AppendUnicodeString(description);
            buffer.AppendUnicodeString(name);
            buffer.Append((int)propertyType);
            buffer.Append(hidden);

            buffer.Append(ShaderUtil.GetRangeLimits(shader, i, 1));
            buffer.Append(ShaderUtil.GetRangeLimits(shader, i, 2));
        }
Example #14
0
        private static RuntimeShaderInfo Create(Shader shader)
        {
            if (shader == null)
            {
                throw new System.ArgumentNullException("shader");
            }

            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            RuntimeShaderInfo shaderInfo = new RuntimeShaderInfo();

            shaderInfo.Name                 = shader.name;
            shaderInfo.PropertyCount        = propertyCount;
            shaderInfo.PropertyDescriptions = new string[propertyCount];
            shaderInfo.PropertyNames        = new string[propertyCount];
            shaderInfo.PropertyRangeLimits  = new RuntimeShaderInfo.RangeLimits[propertyCount];
            shaderInfo.PropertyTexDims      = new TextureDimension[propertyCount];
            shaderInfo.PropertyTypes        = new RTShaderPropertyType[propertyCount];
            shaderInfo.IsHidden             = new bool[propertyCount];

            for (int i = 0; i < propertyCount; ++i)
            {
                shaderInfo.PropertyDescriptions[i] = ShaderUtil.GetPropertyDescription(shader, i);
                shaderInfo.PropertyNames[i]        = ShaderUtil.GetPropertyName(shader, i);
                shaderInfo.PropertyRangeLimits[i]  = new RuntimeShaderInfo.RangeLimits(
                    ShaderUtil.GetRangeLimits(shader, i, 0),
                    ShaderUtil.GetRangeLimits(shader, i, 1),
                    ShaderUtil.GetRangeLimits(shader, i, 2));
                shaderInfo.PropertyTexDims[i] = ShaderUtil.GetTexDim(shader, i);

                RTShaderPropertyType          rtType = RTShaderPropertyType.Unknown;
                ShaderUtil.ShaderPropertyType type   = ShaderUtil.GetPropertyType(shader, i);
                if (m_typeToType.ContainsKey(type))
                {
                    rtType = m_typeToType[type];
                }

                shaderInfo.PropertyTypes[i] = rtType;
                shaderInfo.IsHidden[i]      = ShaderUtil.IsShaderPropertyHidden(shader, i);
            }
            return(shaderInfo);
        }
        static Vector3?GetDefaultRange(Shader shader, String name)
        {
            var index = ShaderUtils.FindPropertyIndex(shader, name, ShaderUtil.ShaderPropertyType.Range);

            if (index >= 0)
            {
                return(new Vector3(
                           ShaderUtil.GetRangeLimits(shader, index, 0),
                           ShaderUtil.GetRangeLimits(shader, index, 1),
                           ShaderUtil.GetRangeLimits(shader, index, 2)));
            }
            else
            {
                index = ShaderUtils.FindPropertyIndex(shader, name, ShaderUtil.ShaderPropertyType.Float);
                if (index >= 0)
                {
                    return(new Vector3(ShaderUtil.GetRangeLimits(shader, index, 0), float.MinValue, float.MaxValue));
                }
            }
            return(null);
        }
Example #16
0
    private void ShaderPropertyImpl(Material owner, Shader shader, int propertyIndex)
    {
        int    i            = propertyIndex;
        string label        = ShaderUtil.GetPropertyDescription(shader, i);
        string propertyName = ShaderUtil.GetPropertyName(shader, i);

        switch (ShaderUtil.GetPropertyType(shader, i))
        {
        case ShaderUtil.ShaderPropertyType.Range:     // float ranges
        {
            GUILayout.BeginHorizontal();
            float v2 = ShaderUtil.GetRangeLimits(shader, i, 1);
            float v3 = ShaderUtil.GetRangeLimits(shader, i, 2);
            RangeProperty(propertyName, label, v2, v3);
            GUILayout.EndHorizontal();

            break;
        }

        case ShaderUtil.ShaderPropertyType.Float:     // floats
        {
            FloatProperty(propertyName, label);
            break;
        }

        case ShaderUtil.ShaderPropertyType.Color:     // colors
        {
            ColorProperty(propertyName, label);
            break;
        }

        case ShaderUtil.ShaderPropertyType.TexEnv:     // textures
        {
            var fxTextureType = FXMaterialHelper.GetFXTextureType(ShaderUtil.GetPropertyDescription(shader, i));
            if (fxTextureType != null)
            {
                if (!(Selection.activeObject is GameObject))
                {
                    if (DisplayHelpTexts)
                    {
                        GUILayout.Label(label);
                        EditorGUILayout.HelpBox(label + " is a FXTexture, you can use a FXTextureAssigner or a FXPostProcess component to set this Texture.", MessageType.Info);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    var             match              = Regex.Match(label, @"(.*)\(\w*\).*", RegexOptions.IgnoreCase);
                    var             description        = match.Groups[1].Value.Trim();
                    var             name               = ShaderUtil.GetPropertyName(shader, i);
                    FXRenderTexture oldFxRenderTexture = GetRenderTextureForProperty(owner, shader, name);
                    var             newFxRenderTexture = (FXRenderTexture)EditorGUILayout.ObjectField(description + " (FXRenderTexture)", oldFxRenderTexture, typeof(FXRenderTexture), false);
                    SetRenderTextureForProperty(owner, shader, name, description, newFxRenderTexture);
                }
            }
            else
            {
                ShaderUtil.ShaderPropertyTexDim desiredTexdim = ShaderUtil.GetTexDim(shader, i);
                TextureProperty(propertyName, label, desiredTexdim);
            }

            GUILayout.Space(6);
            break;
        }

        case ShaderUtil.ShaderPropertyType.Vector:     // vectors
        {
            VectorProperty(propertyName, label);
            break;
        }

        default:
        {
            GUILayout.Label("Unknown " + label + " : " + ShaderUtil.GetPropertyType(shader, i));
            break;
        }
        }
    }
Example #17
0
    public override void OnInspectorGUI()
    {
        OZOPlayer player = (OZOPlayer)target;

        EditorGUI.BeginDisabledGroup(true);
        MonoScript ozoplayer = MonoScript.FromMonoBehaviour(player);
        MonoScript script    = EditorGUILayout.ObjectField("Script", ozoplayer, typeof(MonoScript), false) as MonoScript;

        script.GetType();
        EditorGUI.EndDisabledGroup();

        Undo.RecordObject(player, "OZO Player settings");         //enable undo for everything

        {
            string licenseId = EditorGUILayout.TextField("OZO Player SDK License ID", player.licenseId);
            if (licenseId != player.licenseId)
            {
                player.licenseId = licenseId;
            }
            EditorGUILayout.Space();
        }
        {
            //Camera Settings
            EditorGUILayout.LabelField("Camera Settings", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;
            Color clearColor = EditorGUILayout.ColorField("OZO Render Clear Color", player.OZORendererClearColor);
            if (clearColor != player.OZORendererClearColor)
            {
                player.OZORendererClearColor = clearColor;
                player.SetClearColor(clearColor); //the SDK
            }
            float cameraDepth = EditorGUILayout.FloatField("OZO Camera Depth", player.OZOCameraDepth);
            if (cameraDepth != player.OZOCameraDepth)
            {
                player.OZOCameraDepth = cameraDepth;
                if (null != player.OZOViewCameras)
                {
                    foreach (Camera cam in player.OZOViewCameras)
                    {
                        cam.depth = cameraDepth;
                    }
                }
            }
            Vector2 cameraClipPlanes = EditorGUILayout.Vector2Field("OZO Camera Clip Planes", player.OZOCameraClipPlanes);
            if (cameraClipPlanes != player.OZOCameraClipPlanes)
            {
                player.OZOCameraClipPlanes = cameraClipPlanes;
                if (null != player.OZOViewCameras)
                {
                    foreach (Camera cam in player.OZOViewCameras)
                    {
                        cam.nearClipPlane = cameraClipPlanes.x;
                        cam.farClipPlane  = cameraClipPlanes.x;
                    }
                }
            }
            CameraClearFlags flags = (CameraClearFlags)EditorGUILayout.EnumPopup("OZO Camera Clear Flags", player.OZOCameraClearFlags);
            if (flags != player.OZOCameraClearFlags)
            {
                player.OZOCameraClearFlags = flags;
                if (null != player.OZOViewCameras)
                {
                    foreach (Camera cam in player.OZOViewCameras)
                    {
                        cam.clearFlags = flags;
                    }
                }
            }
            Undo.RecordObject(player.OZOCameraMaterial, "Changed Material Settings");
            Material mat = player.OZOCameraMaterial;
            player.OZOCameraMaterial = (Material)EditorGUILayout.ObjectField("OZO Camera Material", player.OZOCameraMaterial, typeof(Material), true);
            if (mat != player.OZOCameraMaterial)
            {
                if (null != player.OZOViewRenderer) //runtime params
                {
                    foreach (OZORender r in player.OZOViewRenderer)
                    {
                        r.material = null;
                        r.material = new Material(player.OZOCameraMaterial);
                        r.material.SetTexture("_MainTex", r.renderTexture);
                        r.material.SetTexture("_DepthTex", r.renderTextureDepth);
                    }
                }
            }

            EditorGUILayout.BeginVertical();
            if (null != player.OZOCameraMaterial)
            {
                Shader sh = player.OZOCameraMaterial.shader;
                if (sh.name != "OZO/OZODefault")
                {
                    EditorGUI.indentLevel++;
                    EditorGUILayout.LabelField("(The following setting changes will be stored also in runtime)", EditorStyles.miniLabel);

                    for (int i = 0; i < ShaderUtil.GetPropertyCount(sh); ++i)
                    {
                        ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(sh, i);
                        if (ShaderUtil.ShaderPropertyType.Range == type)
                        {
                            string name     = ShaderUtil.GetPropertyName(sh, i);
                            float  value    = player.OZOCameraMaterial.GetFloat(name);
                            float  selValue = EditorGUILayout.Slider(name, value, ShaderUtil.GetRangeLimits(sh, i, 1), ShaderUtil.GetRangeLimits(sh, i, 2));
                            if (value != selValue)
                            {
                                player.OZOCameraMaterial.SetFloat(name, selValue);
                                if (null != player.OZOViewRenderer) //runtime params
                                {
                                    foreach (OZORender r in player.OZOViewRenderer)
                                    {
                                        r.material.SetFloat(name, selValue);
                                    }
                                }
                            }
                        }
                        else if (ShaderUtil.ShaderPropertyType.Color == type)
                        {
                            string name     = ShaderUtil.GetPropertyName(sh, i);
                            Color  color    = player.OZOCameraMaterial.GetColor(name);
                            Color  selColor = EditorGUILayout.ColorField(name, color);

                            if (color != selColor)
                            {
                                player.OZOCameraMaterial.SetColor(name, selColor);
                                if (null != player.OZOViewRenderer) //runtime params
                                {
                                    foreach (OZORender r in player.OZOViewRenderer)
                                    {
                                        r.material.SetColor(name, selColor);
                                    }
                                }
                            }
                        }
                    }
                    EditorGUI.indentLevel--;
                }
            }
            EditorGUILayout.EndVertical();
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();

            //Clip areas
            SerializedProperty clipProperty = serializedObject.FindProperty("clipAreas");
            if (null != clipProperty)
            {
                clipFoldout = EditorGUILayout.Foldout(clipFoldout, "Clip Areas: " + player.clipAreas.Count);
                if (clipFoldout)
                {
                    EditorGUI.indentLevel++;

                    bool modified = false;
                    EditorGUILayout.LabelField("(Clip Areas  define the areas of the video that will be rendered, if none the whole video will be rendered)", EditorStyles.miniLabel);

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField("Areas", "" + player.clipAreas.Count);
                    //buttons
                    GUI.enabled = player.clipAreas.Count < MAX_CLIP_AREAS;
                    if (GUILayout.Button("+", EditorStyles.miniButtonLeft, GUILayout.Width(20)))
                    {
                        OZO.ClipArea area = new OZO.ClipArea();
                        area.centerLongitude = 0.0f;
                        area.centerLatitude  = 0.0f;
                        area.spanLongitude   = 90.0f;
                        area.spanLatitude    = 90.0f;
                        area.opacity         = 1.0f;
                        player.clipAreas.Add(area);
                        modified = true;
                    }
                    GUI.enabled = player.clipAreas.Count > 0;
                    if (GUILayout.Button("-", EditorStyles.miniButtonRight, GUILayout.Width(20)))
                    {
                        if (0 < player.clipAreas.Count)
                        {
                            player.clipAreas.RemoveAt(player.clipAreas.Count - 1);
                            modified = true;
                        }
                    }
                    GUI.enabled = true;
                    EditorGUILayout.EndHorizontal();

                    //draw property fields
                    int numAreas = clipProperty.arraySize;
                    for (int areaIdx = 0; areaIdx < numAreas; ++areaIdx)
                    {
                        SerializedProperty areaProp = clipProperty.GetArrayElementAtIndex(areaIdx);
                        //EditorGUILayout.PropertyField(areaProp);
                        if (areaProp.hasChildren)
                        {
                            EditorGUILayout.LabelField("Area #" + areaIdx, EditorStyles.boldLabel);
                            string root = areaProp.propertyPath;
                            EditorGUI.indentLevel++;
                            SerializedProperty it = areaProp.Copy();
                            bool hasMore          = it.Next(true);
                            while (hasMore)
                            {
                                //only children
                                if (!it.propertyPath.Contains(root))
                                {
                                    break;
                                }
                                string type = it.type;
                                if ("float" == type)
                                {
                                    EditorGUILayout.PropertyField(it, EditorStyles.miniFont);
                                    if (player.clipAreas.Count > areaIdx)
                                    {
                                        var   prop = typeof(OZO.ClipArea).GetField(it.name);
                                        float val  = (float)prop.GetValue(player.clipAreas[areaIdx]);
                                        if (val != it.floatValue)
                                        {
                                            prop.SetValue(player.clipAreas[areaIdx], it.floatValue);
                                            modified = true;
                                        }
                                    }
                                }
                                it.Next(false);
                            }
                            EditorGUI.indentLevel--;
                        }
                    }
                    EditorGUI.indentLevel--;
                    if (modified)
                    {
                        player.SetClipAreas(player.clipAreas.ToArray());
                    }
                }
            }
            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
    }
Example #18
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var drawingPosition = position;

            drawingPosition.height = EditorGUIUtility.singleLineHeight;

            var shaderProperty = property.FindPropertyRelative("shader");

            var currentShaderReference = shaderProperty.objectReferenceValue as Shader;
            var prefix    = "Hidden/EPO/Fill/";
            var fillLabel = currentShaderReference == null ? "none" : currentShaderReference.name.Substring(prefix.Length);

            if (shaderProperty.hasMultipleDifferentValues)
            {
                fillLabel = "-";
            }

            if (EditorGUI.DropdownButton(position, new GUIContent("Fill type: " + fillLabel), FocusType.Passive))
            {
                var menu = new GenericMenu();

                menu.AddItem(new GUIContent("none"), currentShaderReference == null && !shaderProperty.hasMultipleDifferentValues, () =>
                {
                    shaderProperty.objectReferenceValue = null;
                    shaderProperty.serializedObject.ApplyModifiedProperties();
                });

                var shaders = AssetDatabase.FindAssets("t:Shader");
                foreach (var shader in shaders)
                {
                    var loadedShader = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(shader), typeof(Shader)) as Shader;
                    if (!loadedShader.name.StartsWith(prefix))
                    {
                        continue;
                    }

                    menu.AddItem(new GUIContent(loadedShader.name.Substring(prefix.Length)), loadedShader == shaderProperty.objectReferenceValue && !shaderProperty.hasMultipleDifferentValues, () =>
                    {
                        shaderProperty.objectReferenceValue = loadedShader;
                        shaderProperty.serializedObject.ApplyModifiedProperties();
                    });
                }

                menu.ShowAsContext();
            }

            if (shaderProperty.hasMultipleDifferentValues)
            {
                return;
            }

            if (currentShaderReference != null)
            {
                position.x     += EditorGUIUtility.singleLineHeight;
                position.width -= EditorGUIUtility.singleLineHeight;
                var properties = new Dictionary <string, SerializedProperty>();

                var serializedProperties = property.FindPropertyRelative("serializedProperties");

                for (var index = 0; index < serializedProperties.arraySize; index++)
                {
                    var subProperty = serializedProperties.GetArrayElementAtIndex(index);

                    var propertyName  = subProperty.FindPropertyRelative("PropertyName");
                    var propertyValue = subProperty.FindPropertyRelative("Property");

                    if (propertyName == null || propertyValue == null)
                    {
                        break;
                    }

                    properties.Add(propertyName.stringValue, propertyValue);
                }

                var fillParametersPosition = position;
                for (var index = 0; index < ShaderUtil.GetPropertyCount(currentShaderReference); index++)
                {
                    var propertyName = ShaderUtil.GetPropertyName(currentShaderReference, index);
                    if (!propertyName.StartsWith("_Public"))
                    {
                        continue;
                    }

                    fillParametersPosition.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

                    SerializedProperty currentProperty;
                    if (!properties.TryGetValue(propertyName, out currentProperty))
                    {
                        serializedProperties.InsertArrayElementAtIndex(serializedProperties.arraySize);
                        currentProperty = serializedProperties.GetArrayElementAtIndex(serializedProperties.arraySize - 1);
                        currentProperty.FindPropertyRelative("PropertyName").stringValue = propertyName;
                        currentProperty = currentProperty.FindPropertyRelative("Property");

                        var tempMaterial = new Material(currentShaderReference);

                        switch (ShaderUtil.GetPropertyType(currentShaderReference, index))
                        {
                        case ShaderUtil.ShaderPropertyType.Color:
                            currentProperty.FindPropertyRelative("ColorValue").colorValue = tempMaterial.GetColor(propertyName);
                            break;

                        case ShaderUtil.ShaderPropertyType.Vector:
                            currentProperty.FindPropertyRelative("VectorValue").vector4Value = tempMaterial.GetVector(propertyName);
                            break;

                        case ShaderUtil.ShaderPropertyType.Float:
                            currentProperty.FindPropertyRelative("FloatValue").floatValue = tempMaterial.GetFloat(propertyName);
                            break;

                        case ShaderUtil.ShaderPropertyType.Range:
                            currentProperty.FindPropertyRelative("FloatValue").floatValue = tempMaterial.GetFloat(propertyName);
                            break;

                        case ShaderUtil.ShaderPropertyType.TexEnv:
                            currentProperty.FindPropertyRelative("TextureValue").objectReferenceValue = tempMaterial.GetTexture(propertyName);
                            break;
                        }

                        GameObject.DestroyImmediate(tempMaterial);

                        properties.Add(propertyName, currentProperty);
                    }

                    if (currentProperty == null)
                    {
                        continue;
                    }

                    var content = new GUIContent(ShaderUtil.GetPropertyDescription(currentShaderReference, index));

                    switch (ShaderUtil.GetPropertyType(currentShaderReference, index))
                    {
                    case ShaderUtil.ShaderPropertyType.Color:
                        var colorProperty = currentProperty.FindPropertyRelative("ColorValue");
                        colorProperty.colorValue = EditorGUI.ColorField(fillParametersPosition, content, colorProperty.colorValue, true, true, true);
                        break;

                    case ShaderUtil.ShaderPropertyType.Vector:
                        var vectorProperty = currentProperty.FindPropertyRelative("VectorValue");
                        vectorProperty.vector4Value = EditorGUI.Vector4Field(fillParametersPosition, content, vectorProperty.vector4Value);
                        break;

                    case ShaderUtil.ShaderPropertyType.Float:
                        EditorGUI.PropertyField(fillParametersPosition, currentProperty.FindPropertyRelative("FloatValue"), content);
                        break;

                    case ShaderUtil.ShaderPropertyType.Range:
                        var floatProperty = currentProperty.FindPropertyRelative("FloatValue");
                        floatProperty.floatValue = EditorGUI.Slider(fillParametersPosition, content, floatProperty.floatValue,
                                                                    ShaderUtil.GetRangeLimits(currentShaderReference, index, 1),
                                                                    ShaderUtil.GetRangeLimits(currentShaderReference, index, 2));
                        break;

                    case ShaderUtil.ShaderPropertyType.TexEnv:
                        EditorGUI.PropertyField(fillParametersPosition, currentProperty.FindPropertyRelative("TextureValue"), content);
                        break;
                    }

                    currentProperty.FindPropertyRelative("PropertyType").intValue = (int)ShaderUtil.GetPropertyType(currentShaderReference, index);
                }
            }
        }
        public void DrawGUI(Material material)
        {
            if (!ShaderGUIHelper.IsModeMatched(this, m_args) || !GetBoolTestResult(material, null))
            {
                if (m_autoReset && m_parent.template != null)
                {
                    if (m_dirty == null || m_dirty.Value == true)
                    {
                        m_dirty = false;
                        ResetToDefaultValue(m_parent.template);
                    }
                }
                return;
            }
            m_dirty = true;
            var gui_enabled = GUI.enabled;

            try {
                GUI.enabled = m_keep == null;
                if (!GUI.enabled && (m_prop.flags & MaterialProperty.PropFlags.HideInInspector) != 0)
                {
                    return;
                }
                m_MaterialEditor.SetDefaultGUIWidths();
                var   label = m_label ?? m_prop.displayName;
                float h     = m_MaterialEditor.GetPropertyHeight(m_prop, label);
                Rect  r     = EditorGUILayout.GetControlRect(true, h, EditorStyles.layerMaskField);
                for (; ;)
                {
                    if (m_guiType == Cfg.Value_PropGUIType_Toggle && (m_prop.type == MaterialProperty.PropType.Float || m_prop.type == MaterialProperty.PropType.Range))
                    {
                        m_prop.floatValue = EditorGUI.Toggle(r, label, m_prop.floatValue > 0) ? 1 : 0;
                        break;
                    }
                    if (m_guiType == Cfg.Value_PropGUIType_Rect && (m_prop.type == MaterialProperty.PropType.Vector))
                    {
                        var v      = m_prop.vectorValue;
                        var bounds = new Rect();
                        bounds.xMin = v.x;
                        bounds.xMax = v.y;
                        bounds.yMin = v.z;
                        bounds.yMax = v.w;
                        EditorGUI.LabelField(r, m_prop.displayName);
                        EditorGUI.indentLevel++;
                        bounds = EditorGUILayout.RectField(bounds);
                        EditorGUI.indentLevel--;
                        m_prop.vectorValue = new Vector4(bounds.xMin, bounds.xMax, bounds.yMin, bounds.yMax);
                        break;
                    }
                    if (m_prop.type == MaterialProperty.PropType.Color)
                    {
                        var precision = m_precision;
                        if (precision <= 0)
                        {
                            precision = 256;
                        }
                        if (m_guiType == Cfg.Value_PropGUIType_ColorR)
                        {
                            var c = m_prop.colorValue;
                            c.r = DrawRangeProperty(r, m_prop, m_prop.colorValue.r, label, 0, 1, precision);
                            m_prop.colorValue = c;
                            break;
                        }
                        else if (m_guiType == Cfg.Value_PropGUIType_ColorG)
                        {
                            var c = m_prop.colorValue;
                            c.g = DrawRangeProperty(r, m_prop, m_prop.colorValue.g, label, 0, 1, precision);
                            m_prop.colorValue = c;
                            break;
                        }
                        else if (m_guiType == Cfg.Value_PropGUIType_ColorB)
                        {
                            var c = m_prop.colorValue;
                            c.b = DrawRangeProperty(r, m_prop, m_prop.colorValue.b, label, 0, 1, precision);
                            m_prop.colorValue = c;
                            break;
                        }
                        else if (m_guiType == Cfg.Value_PropGUIType_ColorA)
                        {
                            var c = m_prop.colorValue;
                            c.a = DrawRangeProperty(r, m_prop, m_prop.colorValue.a, label, 0, 1, precision);
                            m_prop.colorValue = c;
                            break;
                        }
                    }
                    m_MaterialEditor.ShaderProperty(r, m_prop, label);
                    if (m_precision >= 0)
                    {
                        var range = new Vector3(0, float.MinValue, float.MaxValue);
                        if (m_prop.type == MaterialProperty.PropType.Float)
                        {
                            var index = ShaderUtils.FindPropertyIndex(material.shader, m_prop.name, ShaderUtil.ShaderPropertyType.Float);
                            if (index >= 0)
                            {
                                range.x = ShaderUtil.GetRangeLimits(material.shader, index, 0);
                            }
                            m_prop.floatValue = _RoundFloat(m_prop.floatValue, range);
                        }
                        else if (m_prop.type == MaterialProperty.PropType.Range)
                        {
                            range.y = m_prop.rangeLimits.x;
                            range.z = m_prop.rangeLimits.y;
                            var index = ShaderUtils.FindPropertyIndex(material.shader, m_prop.name, ShaderUtil.ShaderPropertyType.Range);
                            if (index >= 0)
                            {
                                range.x = ShaderUtil.GetRangeLimits(material.shader, index, 0);
                            }
                            m_prop.floatValue = _RoundFloat(m_prop.floatValue, range);
                        }
                        else if (m_prop.type == MaterialProperty.PropType.Color)
                        {
                            if (m_parent.template != null)
                            {
                                var _type = FindShaderPropertyType(m_parent.template.shader, m_prop.name);
                                if (_type != null && _type.Value == ShaderUtil.ShaderPropertyType.Color)
                                {
                                    var defaultColor = m_parent.template.GetColor(m_prop.name);
                                    var c            = m_prop.colorValue;
                                    c.r = _RoundColorFixed(c.r, new Vector3(defaultColor.r, 0, 1), m_precision);
                                    c.g = _RoundColorFixed(c.r, new Vector3(defaultColor.g, 0, 1), m_precision);
                                    c.b = _RoundColorFixed(c.r, new Vector3(defaultColor.b, 0, 1), m_precision);
                                    c.a = _RoundColorFixed(c.r, new Vector3(defaultColor.a, 0, 1), m_precision);
                                }
                            }
                        }
                    }
                    break;
                }
            } finally {
                GUI.enabled = gui_enabled;
            }
            m_MaterialEditor.SetDefaultGUIWidths();
        }
    static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
    {
        foreach (string asset in importedAssets)
        {
            Debug.Log("Reimported Asset: " + asset);

            //if (System.IO.Path.GetExtension(asset) == ".fbx")
            //{
            //    Debug.Log("Building a bundle for " + asset);
            //    // Create the array of bundle build details.
            //    AssetBundleBuild[] buildMap = new AssetBundleBuild[1];

            //    buildMap[0].assetBundleName = System.IO.Path.GetFileNameWithoutExtension(asset);//"spaceball";

            //    string[] ballAssets = new string[1];
            //    ballAssets[0] = asset;//"Assets/_Spaces/Stuff/SpacesLogo.prefab";

            //    buildMap[0].assetNames = ballAssets;

            //    if (!System.IO.Directory.Exists("Bundle"))
            //        System.IO.Directory.CreateDirectory("Bundle");

            //    BuildPipeline.BuildAssetBundles("Bundle", buildMap, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
            //}

            if (System.IO.Path.GetExtension(asset) == ".shader")
            {
                var myShader = AssetDatabase.LoadAssetAtPath <Shader>(asset);
                var widget   = Spaces.Core.ShaderInterface.CreateInterface(myShader);
                AssetDatabase.CreateAsset(widget, asset.Replace(".shader", ".asset"));

                int count = ShaderUtil.GetPropertyCount(myShader);
                for (int i = 0; i < count; i++)
                {
                    var prop = new Spaces.Core.ShaderInterface.ShaderProperty()
                    {
                        name   = ShaderUtil.GetPropertyName(myShader, i),
                        type   = (Spaces.Core.ShaderInterface.ShaderPropertyType)ShaderUtil.GetPropertyType(myShader, i),
                        hidden = ShaderUtil.IsShaderPropertyHidden(myShader, i),
                        texDim = ShaderUtil.GetTexDim(myShader, i),
                        range  = new Spaces.Core.ShaderInterface.ShaderRangeProperty()
                        {
                            def = ShaderUtil.GetRangeLimits(myShader, i, 0),
                            min = ShaderUtil.GetRangeLimits(myShader, i, 1),
                            max = ShaderUtil.GetRangeLimits(myShader, i, 2)
                        }
                    };

                    widget.properties.Add(prop);
                }
            }
        }

        foreach (string str in deletedAssets)
        {
            Debug.Log("Deleted Asset: " + str);
        }

        for (int i = 0; i < movedAssets.Length; i++)
        {
            Debug.Log("Moved Asset: " + movedAssets[i] + " from: " + movedFromAssetPaths[i]);
        }
    }
Example #21
0
        private static void _Create(Shader shader, string bundleName, string variantName)
        {
            if (shader == null)
            {
                throw new System.ArgumentNullException("shader");
            }

            int propertyCount = ShaderUtil.GetPropertyCount(shader);

            RuntimeShaderInfo shaderInfo = new RuntimeShaderInfo();

            shaderInfo.Name = shader.name;
            if (!shader.HasMappedInstanceID())
            {
                //bool create = EditorUtility.DisplayDialog("RuntimeShaderInfo Generator", "Unable to create RuntimeShaderInfo. Please Create or Update ResourceMap", "Create", "Cancel");
                //if (create)
                //{
                //    ResourceMapGen.CreateResourceMap(true);
                //}

                return;
            }

            shaderInfo.InstanceId           = shader.GetMappedInstanceID();
            shaderInfo.PropertyCount        = propertyCount;
            shaderInfo.PropertyDescriptions = new string[propertyCount];
            shaderInfo.PropertyNames        = new string[propertyCount];
            shaderInfo.PropertyRangeLimits  = new RuntimeShaderInfo.RangeLimits[propertyCount];
            shaderInfo.PropertyTexDims      = new TextureDimension[propertyCount];
            shaderInfo.PropertyTypes        = new RTShaderPropertyType[propertyCount];
            shaderInfo.IsHidden             = new bool[propertyCount];

            for (int i = 0; i < propertyCount; ++i)
            {
                shaderInfo.PropertyDescriptions[i] = ShaderUtil.GetPropertyDescription(shader, i);
                shaderInfo.PropertyNames[i]        = ShaderUtil.GetPropertyName(shader, i);
                shaderInfo.PropertyRangeLimits[i]  = new RuntimeShaderInfo.RangeLimits(
                    ShaderUtil.GetRangeLimits(shader, i, 0),
                    ShaderUtil.GetRangeLimits(shader, i, 1),
                    ShaderUtil.GetRangeLimits(shader, i, 2));
                shaderInfo.PropertyTexDims[i] = ShaderUtil.GetTexDim(shader, i);

                RTShaderPropertyType          rtType = RTShaderPropertyType.Unknown;
                ShaderUtil.ShaderPropertyType type   = ShaderUtil.GetPropertyType(shader, i);
                if (m_typeToType.ContainsKey(type))
                {
                    rtType = m_typeToType[type];
                }

                shaderInfo.PropertyTypes[i] = rtType;
                shaderInfo.IsHidden[i]      = ShaderUtil.IsShaderPropertyHidden(shader, i);
            }

            string fullPath = Application.dataPath + RuntimeShaderUtil.GetPath(true);

            Directory.CreateDirectory(fullPath);

            string fileName = RuntimeShaderUtil.GetShaderInfoFileName(shader);

            string path = Path.Combine(fullPath, fileName);

            bool refresh = !File.Exists(path);

            File.WriteAllText(path, JsonUtility.ToJson(shaderInfo));

            if (refresh)
            {
                AssetDatabase.Refresh();
            }
        }
Example #22
0
        public static void DRAW_PANEL()
        {
            bool GUI_TEMP  = GUI.enabled;
            int  CART_temp = KP.MAT_CART_INDEX;
            int  FAM_temp  = KP.MAT_FAM_INDEX;
            int  TYP_temp  = KP.MAT_TYPE_INDEX;

            if (ME_LIST == null)
            {
                ME_LIST = new List <MaterialEditor>(4);
                Material       m = new Material(Shader.Find("Diffuse"));
                MaterialEditor me;
                for (int i = 0, n = 5; i < n; i++)
                {
                    me = Editor.CreateEditor(m) as MaterialEditor;

                    me.SetTexture("_mainTexture", kLibary.LoadBitmap("create", 25, 25));
                    ME_LIST.Add(me);
                }
            }
            //GUI.enabled = (_selection != null);
            // GUILayoutOption glo = {  };
            EditorGUILayout.BeginVertical(); //----------------------------------------------------------> Begin Vertical
            EditorGUI.BeginChangeCheck();
            GUILayout.Space(2);
            // Material operation and selection slots
            KP.FOLD_mSele = EditorGUILayout.Foldout(KP.FOLD_mSele, "Material Operation ");
            if (KP.FOLD_mSele)
            {
                KP.MAT_SELE_INDEX = GUILayout.Toolbar(KP.MAT_SELE_INDEX, new string[] { "Get", "Set", "2file", "2data" });
                //KP.MAT_SELE_INDEX = GUILayout.Toolbar(KP.MAT_SELE_INDEX, new string[] { "MAT I", "MAT II", "MAT III" });
                EditorGUILayout.BeginHorizontal();

                for (int i = 0, n = 4; i < n; i++)
                {
                    GUILayout.BeginVertical();
                    GUILayout.Box(new GUIContent("Slot " + i), GUILayout.ExpandWidth(true), GUILayout.Height(22));
                    // Debug.Log(ME_LIST[i]);
                    MaterialEditor med = ME_LIST[i];

                    if (med && Event.current.type == EventType.layout)
                    {
                        med.OnPreviewGUI(GUILayoutUtility.GetRect(45, 45), EditorStyles.whiteLabel);
                    }
                    GUILayout.EndVertical();
                    GUILayout.Space(2);
                }

                EditorGUILayout.EndHorizontal();
            }
            KP.FOLD_object = EditorGUILayout.Foldout(KP.FOLD_object, "Shader Family ");
            if (KP.FOLD_object)
            {
                // Material category
                KP.MAT_CART_INDEX = EditorGUILayout.Popup(KP.MAT_CART_INDEX, kShaderLab.CATEGORY);
                GUILayout.Space(2);
                // Material family
                KP.MAT_FAM_INDEX = GUILayout.SelectionGrid(KP.MAT_FAM_INDEX, kShaderLab.FAMILY, 2, KP_Style.grid(), GUILayout.MinWidth(100));
            }
            // Material type
            KP.FOLD_type = EditorGUILayout.Foldout(KP.FOLD_type, "Shader Type ");
            if (KP.FOLD_type)
            {
                //sc1 = EditorGUILayout.BeginScrollView(sc1, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MaxHeight(250), GUILayout.MinHeight(20));
                KP.MAT_TYPE_INDEX = GUILayout.SelectionGrid(KP.MAT_TYPE_INDEX, kShaderLab.GetShaderList(KP.MAT_FAM_INDEX), 1, KP_Style.grid());
                //EditorGUILayout.EndScrollView();
            }
            // Material NAME
            KP.FOLD_name = EditorGUILayout.Foldout(KP.FOLD_name, "Material Name");
            if (KP.FOLD_name)
            {
                KP._meshName = EditorGUILayout.TextField(KP._meshName, KP_Style.tf_input_center());
            }
            // Material shader properties
            KP.FOLD_para = EditorGUILayout.Foldout(KP.FOLD_para, "Material Parameters");
            if (KP.FOLD_para)
            {
                Shader s = (KP._sMaterial != null) ? kShaderLab.GetShader(KP.MAT_CART_INDEX, KP.MAT_FAM_INDEX, KP.MAT_TYPE_INDEX) : null;
                if (s != null)
                {
                    //Debug.Log(s.name);
                    //EditorGUILayout.LabelField("sName : " + s.name);
                    int n = ShaderUtil.GetPropertyCount(s);
                    for (int i = 0; i < n; i++)
                    {
                        // foreach property in current selected

                        string label        = ShaderUtil.GetPropertyDescription(s, i);
                        string propertyName = ShaderUtil.GetPropertyName(s, i);

                        //Debug.Log(ShaderUtil.GetPropertyType(s, i));
                        switch (ShaderUtil.GetPropertyType(s, i))
                        {
                        case ShaderUtil.ShaderPropertyType.Range:     // float ranges
                        {
                            //GUILayout.BeginHorizontal();
                            float v2 = ShaderUtil.GetRangeLimits(s, i, 1);
                            float v3 = ShaderUtil.GetRangeLimits(s, i, 2);

                            RangeProperty(propertyName, label, v2, v3);

                            //GUILayout.EndHorizontal();
                            break;
                        }

                        case ShaderUtil.ShaderPropertyType.Float:     // floats
                            Debug.Log(label);
                            FloatProperty(propertyName, label);
                            break;

                        case ShaderUtil.ShaderPropertyType.Color:     // colors
                        {
                            ColorProperty(propertyName, label);
                            break;
                        }

                        case ShaderUtil.ShaderPropertyType.TexEnv:     // textures
                        {
                            ShaderUtil.ShaderPropertyTexDim desiredTexdim = ShaderUtil.GetTexDim(s, i);
                            TextureProperty(propertyName, label, desiredTexdim);
                            //GUILayout.Space(6);
                            break;
                        }

                        case ShaderUtil.ShaderPropertyType.Vector:     // vectors
                        {
                            Debug.Log(label);
                            //VectorProperty(propertyName, label);
                            break;
                        }

                        default:
                        {
                            GUILayout.Label("ARGH" + label + " : " + ShaderUtil.GetPropertyType(s, i));
                            break;
                        }
                        }
                    }
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                Debug.Log("REPAINT GUI");
                if (CART_temp != KP.MAT_CART_INDEX ||
                    FAM_temp != KP.MAT_FAM_INDEX ||
                    TYP_temp != KP.MAT_TYPE_INDEX)
                {
                    if (KP.MAT_SELE_INDEX != -1)
                    {
                        KP.Reset_material();
                    }
                }
                if (KP.MAT_SELE_INDEX != -1)
                {
                    switch (KP.MAT_SELE_INDEX)
                    {
                    case 0: KP._sMaterial = kSelect.MATERIAL; break;

                    case 1: kSelect.MATERIAL = KP._sMaterial; break;

                    case 2: break;

                    case 3: break;
                    }
                    KP.MAT_SELE_INDEX = -1;
                }
                kPoly2Tool.instance.Repaint();
            }
            EditorGUILayout.EndVertical(); //------------------------------------------------------------> End Vertical
            //GUILayout.Space(10);
            //GUILayout.EndHorizontal();
            GUI.enabled = GUI_TEMP;
        }
Example #23
0
        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI ();

            ChangeMaterialProperty t = target as ChangeMaterialProperty;

            EditorGUI.BeginChangeCheck();
            Undo.RecordObject(t, "Change value");

            Shader        s            = t.GetComponent <Renderer>().sharedMaterial.shader;
            List <string> descriptions = new List <string>();
            List <int>    indices      = new List <int>();

            for (int i = 0; i < ShaderUtil.GetPropertyCount(s); i++)
            {
                ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(s, i);
                if (type == ShaderUtil.ShaderPropertyType.Color || type == ShaderUtil.ShaderPropertyType.Float || type == ShaderUtil.ShaderPropertyType.Range)
                {
                    descriptions.Add(ShaderUtil.GetPropertyDescription(s, i));
                    indices.Add(i);
                }
            }
            int descriptionsIndex = EditorGUILayout.Popup("Property", indices.IndexOf(t.propertyIndex), descriptions.ToArray());

            if (descriptionsIndex > 0)
            {
                t.propertyIndex       = indices[descriptionsIndex];
                t.stored_propertyName = ShaderUtil.GetPropertyName(s, t.propertyIndex);
                switch (ShaderUtil.GetPropertyType(s, t.propertyIndex))
                {
                case ShaderUtil.ShaderPropertyType.Float:
                case ShaderUtil.ShaderPropertyType.Range:
                    t.stored_propertyType = typeof(float).ToString();
                    break;

                case ShaderUtil.ShaderPropertyType.Color:
                    t.stored_propertyType = typeof(Color).ToString();
                    break;
                }
            }
            else
            {
                t.propertyIndex = 0;
            }

            if (t.propertyIndex >= 0)
            {
                ShaderUtil.ShaderPropertyType type = ShaderUtil.GetPropertyType(s, t.propertyIndex);
                if (type == ShaderUtil.ShaderPropertyType.Float)
                {
                    t.value_float = EditorGUILayout.FloatField("Value", t.value_float);
                }
                else if (type == ShaderUtil.ShaderPropertyType.Range)
                {
                    t.value_float = EditorGUILayout.Slider("Value", t.value_float, ShaderUtil.GetRangeLimits(s, t.propertyIndex, 1), ShaderUtil.GetRangeLimits(s, t.propertyIndex, 2));
                }
                else if (type == ShaderUtil.ShaderPropertyType.Color)
                {
                    t.value_color = EditorGUILayout.ColorField("Color", t.value_color);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(t);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, 15f, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
            position = EditorGUI.PrefixLabel(position, label);


            //START DRAW WITH NO INDENTS
            EditorHelper.SuppressIndentLevel();


            var r0 = new Rect(position.xMin, position.yMin, position.width / 2f, position.height);
            var r1 = new Rect(r0.xMax, r0.yMin, position.width - r0.width, r0.height);

            var matProp      = property.FindPropertyRelative(PROP_MATERIAL);
            var valTypeProp  = property.FindPropertyRelative(PROP_VALUETYPE);
            var memberProp   = property.FindPropertyRelative(PROP_VALUEMEMBER);
            var propNameProp = property.FindPropertyRelative(PROP_PROPERTYNAME);


            EditorGUI.BeginChangeCheck();
            matProp.objectReferenceValue = EditorGUI.ObjectField(r1, matProp.objectReferenceValue, typeof(UnityEngine.Object), true);
            if (EditorGUI.EndChangeCheck())
            {
                if (!MaterialUtil.IsMaterialSource(matProp.objectReferenceValue))
                {
                    var go = GameObjectUtil.GetGameObjectFromSource(matProp.objectReferenceValue);
                    matProp.objectReferenceValue = (go != null) ? go.GetComponent <Renderer>() : null;
                }
            }

            var mat = MaterialUtil.GetMaterialFromSource(matProp.objectReferenceValue);

            if (mat != null && mat.shader != null)
            {
                int cnt = ShaderUtil.GetPropertyCount(mat.shader);
                using (var infoLst = TempCollection.GetList <PropInfo>(cnt))
                    using (var contentLst = TempCollection.GetList <GUIContent>(cnt))
                    {
                        int index = -1;

                        for (int i = 0; i < cnt; i++)
                        {
                            var nm = ShaderUtil.GetPropertyName(mat.shader, i);
                            var tp = ShaderUtil.GetPropertyType(mat.shader, i);

                            switch (tp)
                            {
                            case ShaderUtil.ShaderPropertyType.Float:
                            {
                                if (propNameProp.stringValue == nm)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Float));
                                contentLst.Add(EditorHelper.TempContent(nm + " (float)"));
                            }
                            break;

                            case ShaderUtil.ShaderPropertyType.Range:
                            {
                                if (propNameProp.stringValue == nm)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Float));
                                var min = ShaderUtil.GetRangeLimits(mat.shader, i, 1);
                                var max = ShaderUtil.GetRangeLimits(mat.shader, i, 2);
                                contentLst.Add(EditorHelper.TempContent(string.Format("{0} (Range [{1}, {2}]])", nm, min, max)));
                            }
                            break;

                            case ShaderUtil.ShaderPropertyType.Color:
                            {
                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.None)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color));
                                contentLst.Add(EditorHelper.TempContent(nm + " (color)"));

                                //sub members
                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.X)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color, MaterialPropertyValueTypeMember.X));
                                contentLst.Add(EditorHelper.TempContent(nm + ".r (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.Y)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color, MaterialPropertyValueTypeMember.Y));
                                contentLst.Add(EditorHelper.TempContent(nm + ".g (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.Z)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color, MaterialPropertyValueTypeMember.Z));
                                contentLst.Add(EditorHelper.TempContent(nm + ".b (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.W)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color, MaterialPropertyValueTypeMember.W));
                                contentLst.Add(EditorHelper.TempContent(nm + ".a (float)"));
                            }
                            break;

                            case ShaderUtil.ShaderPropertyType.Vector:
                            {
                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.None)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector));
                                contentLst.Add(EditorHelper.TempContent(nm + " (vector)"));

                                //sub members
                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.X)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector, MaterialPropertyValueTypeMember.X));
                                contentLst.Add(EditorHelper.TempContent(nm + ".x (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.Y)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector, MaterialPropertyValueTypeMember.Y));
                                contentLst.Add(EditorHelper.TempContent(nm + ".y (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.Z)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector, MaterialPropertyValueTypeMember.Z));
                                contentLst.Add(EditorHelper.TempContent(nm + ".z (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.W)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector, MaterialPropertyValueTypeMember.W));
                                contentLst.Add(EditorHelper.TempContent(nm + ".w (float)"));
                            }
                            break;
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        index = EditorGUI.Popup(r0, index, contentLst.ToArray());

                        if (EditorGUI.EndChangeCheck())
                        {
                            if (index < 0)
                            {
                                valTypeProp.SetEnumValue(MaterialPropertyValueType.Float);
                                memberProp.SetEnumValue(MaterialPropertyValueTypeMember.None);
                                propNameProp.stringValue = string.Empty;
                            }
                            else
                            {
                                var info = infoLst[index];
                                valTypeProp.SetEnumValue(info.ValueType);
                                memberProp.SetEnumValue(info.MemberType);
                                propNameProp.stringValue = info.Name;
                            }
                        }
                    }
            }


            //SET INDENT BACK
            EditorHelper.ResumeIndentLevel();
        }
Example #25
0
        private void ShowShaderPropertys(Shader s, Material m)
        {
            string propertyName = string.Empty;

            EditorGUI.BeginChangeCheck();

            for (int i = 0; i < ShaderUtil.GetPropertyCount(s); i++)
            {
                if (!ShaderUtil.IsShaderPropertyHidden(s, i))
                {
                    EditorGUILayout.BeginHorizontal();

                    propertyName = ShaderUtil.GetPropertyName(s, i);
                    MaterialProperty materialProperty = MaterialEditor.GetMaterialProperty(new UnityEngine.Object[] { m }, propertyName);

                    EditorGUILayout.LabelField(ShaderUtil.GetPropertyDescription(s, i), GUILayout.Width(150));


                    switch (ShaderUtil.GetPropertyType(s, i))
                    {
                    case ShaderUtil.ShaderPropertyType.Color:

                        Color c = EditorGUILayout.ColorField(m.GetColor(propertyName));
                        m.SetColor(propertyName, c);
                        break;

                    case ShaderUtil.ShaderPropertyType.Float:
                        float f = EditorGUILayout.FloatField(m.GetFloat(propertyName));
                        m.SetFloat(propertyName, f);
                        break;

                    case ShaderUtil.ShaderPropertyType.Range:
                        float min = ShaderUtil.GetRangeLimits(s, i, 1);
                        float max = ShaderUtil.GetRangeLimits(s, i, 2);
                        float r   = EditorGUILayout.Slider(m.GetFloat(propertyName), min, max);
                        m.SetFloat(propertyName, r);
                        break;

                    case ShaderUtil.ShaderPropertyType.TexEnv:
                        EditorGUILayout.BeginVertical();
                        Texture2D tex       = (Texture2D)EditorGUILayout.ObjectField(m.GetTexture(propertyName), typeof(Texture2D), false);
                        Vector2   texOffset = EditorGUILayout.Vector2Field("TextureOffset", m.GetTextureOffset(propertyName));
                        Vector2   texScale  = EditorGUILayout.Vector2Field("TextureOffset", m.GetTextureScale(propertyName));
                        EditorGUILayout.EndVertical();
                        m.SetTexture(propertyName, tex);
                        m.SetTextureOffset(propertyName, texOffset);
                        m.SetTextureScale(propertyName, texScale);
                        break;

                    case ShaderUtil.ShaderPropertyType.Vector:
                        Vector4 v = EditorGUILayout.Vector4Field("", m.GetVector(propertyName));
                        m.SetVector(propertyName, v);
                        break;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
Example #26
0
    public static void InspectorGUI(BuildrEditMode _editMode, BuildrData _data)
    {
        data = _data;
        BuildrTexture[] textures         = data.textures.ToArray();
        int             numberOfTextures = textures.Length;

        selectedTexture = Mathf.Clamp(selectedTexture, 0, numberOfTextures - 1);
        int currentSelectedTexture = selectedTexture;//keep tack of what we had selected to reset fields if changed

        Undo.RecordObject(data, "Texture Modified");

        if (numberOfTextures == 0)
        {
            EditorGUILayout.HelpBox("There are no textures to show", MessageType.Info);
            if (GUILayout.Button("Add New"))
            {
                data.textures.Add(new BuildrTexture("new texture " + numberOfTextures));
                numberOfTextures++;
                selectedTexture = numberOfTextures - 1;
            }
            return;
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Texture", GUILayout.Width(75));
        string[] textureNames = new string[numberOfTextures];
        for (int t = 0; t < numberOfTextures; t++)
        {
            textureNames[t] = textures[t].name;
        }
        selectedTexture = EditorGUILayout.Popup(selectedTexture, textureNames);
        EditorGUILayout.EndHorizontal();

        BuildrTexture bTexture = textures[selectedTexture];

        EditorGUILayout.BeginHorizontal();

        EditorGUILayout.Space();

        if (GUILayout.Button("Add New", GUILayout.Width(81)))
        {
            data.textures.Add(new BuildrTexture("new texture " + numberOfTextures));
            numberOfTextures++;
            selectedTexture = numberOfTextures - 1;
        }


        if (GUILayout.Button("Duplicate", GUILayout.Width(90)))
        {
            data.textures.Add(bTexture.Duplicate());
            numberOfTextures++;
            selectedTexture = numberOfTextures - 1;
        }

        if (GUILayout.Button("Delete", GUILayout.Width(71)))
        {
            if (EditorUtility.DisplayDialog("Deleting Texture Entry", "Are you sure you want to delete this texture?", "Delete", "Cancel"))
            {
                data.RemoveTexture(bTexture);
                selectedTexture = 0;
                GUI.changed     = true;

                return;
            }
        }

        if (GUILayout.Button("Import", GUILayout.Width(71)))
        {
            string xmlPath = EditorUtility.OpenFilePanel("Select the XML file...", "Assets/BuildR/Exported/", "xml");
            if (xmlPath == "")
            {
                return;
            }
            BuildrXMLImporter.ImportTextures(xmlPath, _data);
            textures        = data.textures.ToArray();
            selectedTexture = 0;
            GUI.changed     = true;
        }

        if (GUILayout.Button("Export", GUILayout.Width(71)))
        {
            string xmlPath = EditorUtility.SaveFilePanel("Export as...", "Assets/BuildR/Exported/", _data.name + "_textureLibrary", "xml");
            if (xmlPath == "")
            {
                return;
            }
            BuildrXMLExporter.ExportTextures(xmlPath, _data);
            GUI.changed = true;
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        textures     = data.textures.ToArray();
        textureNames = new string[numberOfTextures];
        for (int t = 0; t < numberOfTextures; t++)
        {
            textureNames[t] = textures[t].name;
        }
        bTexture = textures[selectedTexture];//reassign

        string   textureName = bTexture.name;
        GUIStyle redText     = new GUIStyle(GUI.skin.textField);

        if (textureName.Contains(" "))
        {
            redText.focused.textColor = Color.red;
            textureName = EditorGUILayout.TextField("Name", textureName, redText);
        }
        else
        {
            redText.focused.textColor = defaultCol;
            textureName = EditorGUILayout.TextField("Name", textureName, redText);
        }
        bTexture.name = textureName;

        bool conflictingName = false;

        for (int i = 0; i < textureNames.Length; i++)
        {
            if (selectedTexture != i)
            {
                if (textureNames[i] == bTexture.name)
                {
                    conflictingName = true;
                }
            }
        }

        if (conflictingName)
        {
            EditorGUILayout.HelpBox("You have named this texture the same as another.", MessageType.Warning);
        }


        if (currentSelectedTexture != selectedTexture)
        {
            GUIUtility.hotControl      = 0;
            GUIUtility.keyboardControl = 0;
        }

        bTexture.type = (BuildrTexture.Types)EditorGUILayout.EnumPopup("Type", bTexture.type);

        switch (bTexture.type)
        {
        case BuildrTexture.Types.Basic:

            if (bTexture.texture != null)
            {
                string          texturePath     = AssetDatabase.GetAssetPath(bTexture.texture);
                TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(texturePath);

                if (!textureImporter.isReadable)
                {
                    EditorGUILayout.HelpBox("The texture you have selected is not readable." + "\nPlease select the readable checkbox under advanced texture settings." + "\nOr move this texture to the BuildR texture folder and reimport.", MessageType.Error);
                }
            }

            //Shader Time
            Shader[]      tempshaders = (Shader[])Resources.FindObjectsOfTypeAll(typeof(Shader));
            List <string> shaderNames = new List <string>(ShaderProperties.NAMES);
            foreach (Shader shader in tempshaders)
            {
                if (!string.IsNullOrEmpty(shader.name) && !shader.name.StartsWith("__") && !shader.name.Contains("hidden"))
                {
                    shaderNames.Add(shader.name);
                }
            }
            int selectedShaderIndex    = shaderNames.IndexOf(bTexture.material.shader.name);
            int newSelectedShaderIndex = EditorGUILayout.Popup("Shader", selectedShaderIndex, shaderNames.ToArray());
            if (selectedShaderIndex != newSelectedShaderIndex)
            {
                bTexture.material.shader = Shader.Find(shaderNames[newSelectedShaderIndex]);
            }

            Shader selectedShader = bTexture.material.shader;
            int    propertyCount  = ShaderUtil.GetPropertyCount(selectedShader);

            for (int s = 0; s < propertyCount; s++)
            {
                ShaderUtil.ShaderPropertyType propertyTpe = ShaderUtil.GetPropertyType(selectedShader, s);
                string shaderPropertyName = ShaderUtil.GetPropertyName(selectedShader, s);
                switch (propertyTpe)
                {
                case ShaderUtil.ShaderPropertyType.TexEnv:
                    Texture shaderTexture    = bTexture.material.GetTexture(shaderPropertyName);
                    Texture newShaderTexture = (Texture)EditorGUILayout.ObjectField(shaderPropertyName, shaderTexture, typeof(Texture), false);
                    if (shaderTexture != newShaderTexture)
                    {
                        bTexture.material.SetTexture(shaderPropertyName, newShaderTexture);
                    }
                    break;

                case ShaderUtil.ShaderPropertyType.Color:
                    Color shaderColor    = bTexture.material.GetColor(shaderPropertyName);
                    Color newShaderColor = EditorGUILayout.ColorField(shaderPropertyName, shaderColor);
                    if (shaderColor != newShaderColor)
                    {
                        bTexture.material.SetColor(shaderPropertyName, newShaderColor);
                    }
                    break;

                case ShaderUtil.ShaderPropertyType.Float:
                    float shaderFloat    = bTexture.material.GetFloat(shaderPropertyName);
                    float newShaderFloat = EditorGUILayout.FloatField(shaderPropertyName, shaderFloat);
                    if (shaderFloat != newShaderFloat)
                    {
                        bTexture.material.SetFloat(shaderPropertyName, newShaderFloat);
                    }
                    break;

                case ShaderUtil.ShaderPropertyType.Range:
                    float shaderRange    = bTexture.material.GetFloat(shaderPropertyName);
                    float rangeMin       = ShaderUtil.GetRangeLimits(selectedShader, s, 1);
                    float rangeMax       = ShaderUtil.GetRangeLimits(selectedShader, s, 2);
                    float newShaderRange = EditorGUILayout.Slider(shaderPropertyName, shaderRange, rangeMin, rangeMax);
                    if (shaderRange != newShaderRange)
                    {
                        bTexture.material.SetFloat(shaderPropertyName, newShaderRange);
                    }
                    break;

                case ShaderUtil.ShaderPropertyType.Vector:
                    Vector3 shaderVector    = bTexture.material.GetVector(shaderPropertyName);
                    Vector3 newShaderVector = EditorGUILayout.Vector3Field(shaderPropertyName, shaderVector);
                    if (shaderVector != newShaderVector)
                    {
                        bTexture.material.SetVector(shaderPropertyName, newShaderVector);
                    }
                    break;
                }
            }

            bool tiled = EditorGUILayout.Toggle("Is Tiled", bTexture.tiled);
            if (tiled != bTexture.tiled)
            {
                bTexture.tiled = tiled;
            }
            if (bTexture.tiled)
            {
                bool patterned = EditorGUILayout.Toggle("Has Pattern", bTexture.patterned);
                if (patterned != bTexture.patterned)
                {
                    bTexture.patterned = patterned;
                }
            }
            else
            {
                bTexture.patterned = false;
            }

            if (bTexture.texture == null)
            {
                return;
            }

            Vector2 textureUnitSize = bTexture.textureUnitSize;
            if (bTexture.tiled)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("texture width", GUILayout.Width(75)); //, GUILayout.Width(42));
                textureUnitSize.x = EditorGUILayout.FloatField(bTexture.textureUnitSize.x, GUILayout.Width(25));
                EditorGUILayout.LabelField("metres", GUILayout.Width(40));        //, GUILayout.Width(42));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("texture height", GUILayout.Width(75));//, GUILayout.Width(42));
                textureUnitSize.y = EditorGUILayout.FloatField(bTexture.textureUnitSize.y, GUILayout.Width(25));
                EditorGUILayout.LabelField("metres", GUILayout.Width(40));
                EditorGUILayout.EndHorizontal();
                if (bTexture.textureUnitSize != textureUnitSize)
                {
                    bTexture.textureUnitSize = textureUnitSize;
                }
            }

            Vector2 tileUnitSize = bTexture.tileUnitUV;
            if (bTexture.patterned)
            {
                float minWidth  = 2 / bTexture.texture.width;
                float minHeight = 2 / bTexture.texture.height;

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("unit width", GUILayout.Width(75));
                float tileUnitSizex = EditorGUILayout.Slider(tileUnitSize.x, minWidth, 1.0f);
                if (tileUnitSizex != tileUnitSize.x)
                {
                    tileUnitSize.x = tileUnitSizex;
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("unit height", GUILayout.Width(75));
                float tileUnitSizey = EditorGUILayout.Slider(tileUnitSize.y, minHeight, 1.0f);
                if (tileUnitSizey != tileUnitSize.y)
                {
                    tileUnitSize.y = tileUnitSizey;
                }
                EditorGUILayout.EndHorizontal();
                bTexture.tileUnitUV = tileUnitSize;

                EditorGUILayout.Space();
            }

            const int previewTextureUnitSize = 120;
            const int previewTileUnitSize    = 59;
            const int previewTileUnitPadding = 2;
            const int previewPadding         = 25;

            EditorGUILayout.BeginHorizontal();
            if (bTexture.tiled)
            {
                EditorGUILayout.LabelField("1 Metre Squared", GUILayout.Width(previewTextureUnitSize));
            }
            GUILayout.Space(previewPadding);
            if (bTexture.patterned)
            {
                EditorGUILayout.LabelField("Texture Pattern Units", GUILayout.Width(previewTileUnitSize * 2));
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();


            if (Event.current.type == EventType.Repaint)
            {
                texturePreviewPostion = GUILayoutUtility.GetLastRect();
            }

            if (bTexture.tiled)
            {
                Rect previewRect = new Rect(texturePreviewPostion.x, texturePreviewPostion.y, previewTextureUnitSize, previewTextureUnitSize);
                Rect sourceRect  = new Rect(0, 0, (1.0f / textureUnitSize.x), (1.0f / textureUnitSize.y));

                Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0);
            }

            if (bTexture.patterned)
            {
                Rect previewRect = new Rect(previewTextureUnitSize + previewPadding, 0, previewTileUnitSize, previewTileUnitSize);
                Rect sourceRect  = new Rect(0, tileUnitSize.y, tileUnitSize.x, tileUnitSize.y);

                previewRect.x += texturePreviewPostion.x;
                previewRect.y += texturePreviewPostion.y;

                Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0);

                sourceRect.x  += tileUnitSize.x;
                previewRect.x += previewTileUnitSize + previewTileUnitPadding;

                Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0);

                sourceRect.x  += -tileUnitSize.x;
                sourceRect.y  += -tileUnitSize.y;
                previewRect.x += -(previewTileUnitSize + previewTileUnitPadding);
                previewRect.y += previewTileUnitSize + previewTileUnitPadding;

                Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0);

                sourceRect.x  += tileUnitSize.x;
                previewRect.x += previewTileUnitSize + previewTileUnitPadding;

                Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0);
            }

            if (!bTexture.tiled)
            {
                EditorGUILayout.LabelField("Tile texture");

                EditorGUILayout.BeginHorizontal();
                int currentXTiles = bTexture.tiledX;
                GUILayout.Label("tile x", GUILayout.Width(38));
                currentXTiles = EditorGUILayout.IntField(currentXTiles, GUILayout.Width(20));
                if (GUILayout.Button("+", GUILayout.Width(25)))
                {
                    currentXTiles++;
                }
                EditorGUI.BeginDisabledGroup(currentXTiles < 2);
                if (GUILayout.Button("-", GUILayout.Width(25)))
                {
                    currentXTiles--;
                }
                EditorGUI.EndDisabledGroup();
                bTexture.tiledX = currentXTiles;

                int currentYTiles = bTexture.tiledY;
                GUILayout.Label("tile y", GUILayout.Width(38));
                currentYTiles = EditorGUILayout.IntField(currentYTiles, GUILayout.Width(20));
                if (GUILayout.Button("+", GUILayout.Width(25)))
                {
                    currentYTiles++;
                }
                EditorGUI.BeginDisabledGroup(currentYTiles < 2);
                if (GUILayout.Button("-", GUILayout.Width(25)))
                {
                    currentYTiles--;
                }
                EditorGUI.EndDisabledGroup();
                bTexture.tiledY = currentYTiles;
                EditorGUILayout.EndHorizontal();

                GUILayout.Space(10);
                EditorGUILayout.Space();
                if (Event.current.type == EventType.Repaint)
                {
                    texturePreviewPostion = GUILayoutUtility.GetLastRect();
                }

                Rect previewRect = new Rect(texturePreviewPostion.x, texturePreviewPostion.y, previewTextureUnitSize, previewTextureUnitSize);
                Rect sourceRect  = new Rect(0, 0, currentXTiles, currentYTiles);

                Graphics.DrawTexture(previewRect, bTexture.texture, sourceRect, 0, 0, 0, 0);
            }

            GUILayout.Space(previewTextureUnitSize);

            break;

        case BuildrTexture.Types.Substance:

            bTexture.proceduralMaterial = (ProceduralMaterial)EditorGUILayout.ObjectField("Procedural Material", bTexture.proceduralMaterial, typeof(ProceduralMaterial), false);

            if (bTexture.proceduralMaterial != null)
            {
                ProceduralMaterial pMat = bTexture.proceduralMaterial;
                GUILayout.Label(pMat.GetGeneratedTexture(pMat.mainTexture.name), GUILayout.Width(400));
            }
            else
            {
                EditorGUILayout.HelpBox("There is no substance material set.", MessageType.Error);
            }
            break;

        case BuildrTexture.Types.User:
            bTexture.userMaterial = (Material)EditorGUILayout.ObjectField("User Material", bTexture.userMaterial, typeof(Material), false);

            if (bTexture.userMaterial != null)
            {
                Material mat = bTexture.userMaterial;
                GUILayout.Label(mat.mainTexture, GUILayout.Width(400));
            }
            else
            {
                EditorGUILayout.HelpBox("There is no substance material set.", MessageType.Error);
            }
            break;
        }
    }
    void drawKeywordSection()
    {
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Keyword", new GUIStyle(EditorStyles.boldLabel));

        var meshRenderer = (MeshRenderer)serializedObject.FindProperty("meshRenderer").objectReferenceValue;
        var image        = (Image)serializedObject.FindProperty("image").objectReferenceValue;

        Shader shader;

        if (meshRenderer != null)
        {
            var materialIndex = serializedObject.FindProperty("materialIndex").intValue;
            if (materialIndex < 0 || materialIndex >= meshRenderer.sharedMaterials.Length)
            {
                return;
            }

            shader = meshRenderer.sharedMaterials[materialIndex].shader;
        }
        else if (image != null)
        {
            shader = image.material.shader;
        }
        else
        {
            return;
        }

        var propertyCount = ShaderUtil.GetPropertyCount(shader);

        if (propertyCount == 0)
        {
            EditorGUILayout.HelpBox("This material has no shader properties defined", MessageType.Warning);
            return;
        }

        var propertyNames        = new string[propertyCount];
        var selectedPropertyName = serializedObject.FindProperty("keyword").stringValue;

        var selectedIndex = -1;

        for (var i = 0; i < propertyCount; i++)
        {
            propertyNames[i] = ShaderUtil.GetPropertyName(shader, i);
            if (propertyNames[i] == selectedPropertyName)
            {
                selectedIndex = i;
            }
        }

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Material keyword");
        var newSelectionIndex = EditorGUILayout.Popup(selectedIndex == -1 ? 0 : selectedIndex, propertyNames);

        EditorGUILayout.EndHorizontal();

        if (newSelectionIndex != selectedIndex)
        {
            selectedIndex = newSelectionIndex;
            serializedObject.FindProperty("keyword").stringValue = propertyNames[newSelectionIndex];
        }

        var propertyType = ShaderUtil.GetPropertyType(shader, selectedIndex);

        switch (propertyType)
        {
        case ShaderUtil.ShaderPropertyType.Float:
            setAnimationTypes(animateFloat: true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("floatFromValue"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("floatToValue"));
            break;

        case ShaderUtil.ShaderPropertyType.Range:
            setAnimationTypes(animateFloat: true);
            var min = ShaderUtil.GetRangeLimits(shader, selectedIndex, 1);
            var max = ShaderUtil.GetRangeLimits(shader, selectedIndex, 2);
            drawRangeProperty("From value", "floatFromValue", min, max);
            drawRangeProperty("To value", "floatToValue", min, max);
            break;

        case ShaderUtil.ShaderPropertyType.Color:
            setAnimationTypes(animateColor: true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("colorFromValue"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("colorToValue"));
            break;

        case ShaderUtil.ShaderPropertyType.Vector:
            setAnimationTypes(animateVector: true);
            drawVectorProperty("From value", "vectorFromValue");
            drawVectorProperty("To value", "vectorToValue");
            break;

        default:
            EditorGUILayout.HelpBox("This property type can't be animated", MessageType.Warning);
            break;
        }
    }