Beispiel #1
0
    public static void loadMaterial(this MyMaterial m)
    {
        MaterialSetting ms = m.getSetting();

        if (ms.material == null)
        {
            if (File.Exists(Application.dataPath + "/Resources/Material/" + m + ".mat") == false)
            {
                File.Copy(Application.dataPath + "/Resources/Material/DEFAULT.mat", Application.dataPath + "/Resources/Material/" + m + ".mat");
            }
            ms.material = Resources.Load <Material>("Material\\" + m);
        }
        bool found = false;

        foreach (TextureType type in Enum.GetValues(typeof(TextureType)))
        {
            if (ms.getTexture(type) != null)
            {
                Material mat = new Material(ms.material);
                mat.mainTexture = ms.getTexture(type);
                ChunkMeshCreator.materials.Add(m + "_" + type, mat);
                found = true;
            }
        }
        if (found == false)
        {
            Material mat = new Material(GameManager.getGameManager().itemMaterial);
            ChunkMeshCreator.materials.Add(m + "_" + TextureType.NORMAL, mat);
            //GameManager.getGameManager().webHandler.giveRandomTexture(mat, name.Replace("_", " "));
        }
    }
    void AssignParams(MaterialSetting setting)
    {
        var mat = setting.material;
        var keywords = setting.keyworkds;
        var fparams = setting.fparams;

        for (int i = 0; i < keywords.Count; ++i)
        {
            if (keywords[i].value)
            {
                mat.EnableKeyword(keywords[i].key);
            }
            else
            {
                mat.DisableKeyword(keywords[i].key);
                
            }
            //Debug.Log(mat.name + " " + keywords[i].key + " " + mat.IsKeywordEnabled(keywords[i].key));
        }

        for (int i = 0; i < fparams.Count; ++i)
        {
            mat.SetFloat(fparams[i].key, fparams[i].value);
        }
    }
        void OnWizardCreate()
        {
            SkinnedMeshRenderer[] skinnedMeshRenderers
                = targetModel.GetComponentsInChildren <SkinnedMeshRenderer>();

            for (int j = 0; j < skinnedMeshRenderers.Length; j++)
            {
                MaterialSetting exportData
                    = ScriptableObject.CreateInstance <MaterialSetting>();

                exportData.targetName
                    = m_Utility.GetHierarchyPath(skinnedMeshRenderers[j].gameObject.transform);

                Material[] materials = skinnedMeshRenderers[j].sharedMaterials;

                exportData.mat = new Material[materials.Length];

                for (int i = 0; i < materials.Length; i++)
                {
                    exportData.mat[i] = materials[i];
                }

                AssetDatabase.CreateAsset(
                    exportData, "Assets/Models/Resources/MaterialData/MaterialSetting_" + j + ".asset");
            }
        }
 void OnWizardUpdate()
 {
     if (MaterialName == null)
     {
         MaterialName = new string[objects.Length];
         for (int i = 0; i < objects.Length; i++)
         {
             MaterialSetting materialSetting = (MaterialSetting)objects[i];
             MaterialName[i] = materialSetting.targetName;
         }
     }
 }
Beispiel #5
0
    public MaterialSetting getMaterialSetting(MyMaterial material)
    {
        foreach (MaterialSetting matSetting in materialSetting)
        {
            if (matSetting.myMaterial == material)
            {
                return(matSetting);
            }
        }
        MaterialSetting ms = new MaterialSetting(material);

        materialSetting.Add(ms);
        return(ms);
    }
        void OnWizardCreate()
        {
            for (int i = 0; i < objects.Length; i++)
            {
                setting = (MaterialSetting)objects[i];
                GameObject targetObject = GameObject.Find(setting.targetName);
                materials = targetObject.GetComponent <SkinnedMeshRenderer>().sharedMaterials;

                for (int j = 0; j < materials.Length; j++)
                {
                    materials[j] = setting.mat[j];
                }

                targetObject.GetComponent <SkinnedMeshRenderer>().materials = materials;
            }
        }
Beispiel #7
0
        void OnWizardCreate()
        {
            for (int i = 0; i < objects.Length; i++)
            {
                setting = (MaterialSetting)objects[i];

                //設定されたパスをターゲット対象に変更する
                //m_Utility.ChangeRootPath

                GameObject targetObject
                    = GameObject.Find(m_Utility.ChangeRootPath(setting.targetName, parentObject.name));

                materials = targetObject.GetComponent <SkinnedMeshRenderer>().sharedMaterials;

                for (int j = 0; j < materials.Length; j++)
                {
                    materials[j] = setting.mat[j];
                }

                targetObject.GetComponent <SkinnedMeshRenderer>().materials = materials;
            }
        }
 public static void init()
 {
     foreach (MyMaterial m in Enum.GetValues(typeof(MyMaterial)))
     {
         MaterialSetting ms = m.getSetting();
         if (ms != null && ms.itemRenderStyle == ItemRenderStyle.ITEM)
         {
             if (ms.texture != null)
             {
                 ItemMeshCreator imc = new ItemMeshCreator(ms.texture);
                 ms.itemPrefab = imc.getGameObject();
             }
             else
             {
                 throw new Exception(m + " does not have a texture attached!");
             }
         }
         else if (ms != null && ms.isPlaceable)
         {
             ms.itemPrefab = CubeMeshCreator.getGameObject(m);
         }
     }
 }
Beispiel #9
0
    void AssignParams(MaterialSetting setting)
    {
        var mat      = setting.material;
        var keywords = setting.keyworkds;
        var fparams  = setting.fparams;

        for (int i = 0; i < keywords.Count; ++i)
        {
            if (keywords[i].value)
            {
                mat.EnableKeyword(keywords[i].key);
            }
            else
            {
                mat.DisableKeyword(keywords[i].key);
            }
            //Debug.Log(mat.name + " " + keywords[i].key + " " + mat.IsKeywordEnabled(keywords[i].key));
        }

        for (int i = 0; i < fparams.Count; ++i)
        {
            mat.SetFloat(fparams[i].key, fparams[i].value);
        }
    }
    public static void init()
    {
        GameObject    set           = GameManager.getGameManager().iconRederSet;
        Camera        camera        = set.GetComponent <Camera>();
        RenderTexture renderTexture = new RenderTexture(64, 64, 64);

        camera.targetTexture = renderTexture;
        GameObject   itemModel        = set.transform.FindChild("ItemModel").gameObject;
        GameObject   cubeModel        = set.transform.FindChild("CubeModel").gameObject;
        MeshRenderer CubeMeshRenderer = cubeModel.GetComponent <MeshRenderer>();

        foreach (MyMaterial m in Enum.GetValues(typeof(MyMaterial)))
        {
            if (m == MyMaterial.AIR)
            {
                continue;
            }
            MaterialSetting ms = m.getSetting();
            if (ms.iconSprite == null)
            {
                GameObject tempObject = null;
                if (ms.itemRenderStyle == ItemRenderStyle.BLOCK)
                {
                    CubeMeshRenderer.enabled  = true;
                    CubeMeshRenderer.material = m.getMaterial(Direction.UP);
                    //int x = 0;
                    //int i = 13 / x;
                }
                else if (ms.itemRenderStyle == ItemRenderStyle.ITEM)
                {
                    tempObject = Instantiate <GameObject>(ms.itemPrefab);
                    tempObject.transform.SetParent(itemModel.transform, false);
                }


                camera.Render();
                CubeMeshRenderer.enabled = false;
                if (tempObject != null)
                {
                    for (int i = 0; i < tempObject.transform.childCount; i++)
                    {
                        GameObject o = tempObject.transform.GetChild(i).gameObject;
                        GameObject.DestroyImmediate(o);
                    }
                    GameObject.DestroyImmediate(tempObject);
                }
                RenderTexture.active = renderTexture;
                Texture2D imageOverview = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.ARGB32, false);
                imageOverview.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
                RenderTexture.active = null;
                //Replacing Black;
                for (int x = 0; x < renderTexture.width; x++)
                {
                    for (int y = 0; y < renderTexture.height; y++)
                    {
                        Color c = imageOverview.GetPixel(x, y);
                        if (c.b == 0 && c.r == 0 && c.b == 0)
                        {
                            imageOverview.SetPixel(x, y, new Color(0, 0, 0, 0));
                        }
                    }
                }
                imageOverview.Apply();
                Sprite sprite = Sprite.Create(imageOverview, new Rect(0, 0, renderTexture.width, renderTexture.height), Vector2.zero);
                ms.iconSprite = sprite;
            }
        }
        Destroy(set);
    }
Beispiel #11
0
    private void displayEditItem()
    {
        GUILayout.BeginHorizontal();
        if (selectedItemIndex > 0)
        {
            if (GUILayout.Button("Privious"))
            {
                selectedItemIndex--;
            }
        }
        if (selectedItemIndex < Enum.GetValues(typeof(MyMaterial)).Length - 1)
        {
            if (GUILayout.Button("Next"))
            {
                selectedItemIndex++;
            }
        }
        if (GUILayout.Button("Last"))
        {
            selectedItemIndex = Enum.GetValues(typeof(MyMaterial)).Length - 1;
        }
        mat = (MyMaterial)EditorGUILayout.EnumPopup("Item: ", mat);
        MaterialSetting ms = database.getMaterialSetting(mat);

        GUILayout.EndHorizontal();

        ms.isPlaceable = GUILayout.Toggle(ms.isPlaceable, "Is placeable: ");
        if (ms.isPlaceable)
        {
            //IF IS BLOCK
            ms.useCustomeBlockModel = GUILayout.Toggle(ms.useCustomeBlockModel, "Use Custome Block Model");
            if (ms.useCustomeBlockModel == false)
            {
                textureType = (TextureType)EditorGUILayout.EnumPopup("Texture Type", textureType);
                switch (textureType)
                {
                case (TextureType.NORMAL): {
                    ms.texture = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.texture, typeof(Texture2D), false);
                    break;
                }

                case (TextureType.SIDE): {
                    ms.textureSIDE = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.textureSIDE, typeof(Texture2D), false);
                    break;
                }

                case (TextureType.UP): {
                    ms.textureUP = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.textureUP, typeof(Texture2D), false);
                    break;
                }

                case (TextureType.DOWN): {
                    ms.textureDOWN = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.textureDOWN, typeof(Texture2D), false);
                    break;
                }

                case (TextureType.NORTH): {
                    ms.textureNORTH = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.textureNORTH, typeof(Texture2D), false);
                    break;
                }

                case (TextureType.SOUTH): {
                    ms.textureSOUTH = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.textureSOUTH, typeof(Texture2D), false);
                    break;
                }

                case (TextureType.WEST): {
                    ms.textureWEST = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.textureWEST, typeof(Texture2D), false);
                    break;
                }

                case (TextureType.EAST): {
                    ms.textureEAST = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.textureEAST, typeof(Texture2D), false);
                    break;
                }

                default: {
                    ms.texture = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.texture, typeof(Texture2D), false);
                    break;
                }
                }

                //Search
                GUILayout.Space(10f);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Auto Fill"))
                {
                    searchKeyword = mat.ToString().Replace("_", " ").ToLower();
                }
                searchKeyword = GUILayout.TextField(searchKeyword);
                if (GUILayout.Button("Search Image"))
                {
                    WebHandler.getTextures(webSearchTexture, searchKeyword);
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                webSearchSelected = GUILayout.SelectionGrid(webSearchSelected, webSearchTexture.ToArray(), 8);
                GUILayout.EndHorizontal();
                if (GUILayout.Button("Use This Image As Texture"))
                {
                    if (File.Exists("Assets/Resources/Texture/" + mat + "_" + textureType + ".png"))
                    {
                        File.Delete("Assets/Resources/Texture/" + mat + "_" + textureType + ".png");
                    }
                    File.WriteAllBytes("Assets/Resources/Texture/" + mat + "_" + textureType + ".png", ((Texture2D)webSearchTexture[webSearchSelected]).EncodeToPNG());
                    AssetDatabase.Refresh();
                    Texture2D t = Resources.Load <Texture2D>("Texture\\" + mat + "_" + textureType);
                    t.filterMode = FilterMode.Point;
                    ms.setTexture(textureType, t);
                    if (ms.material == null)
                    {
                        Material material = Resources.Load <Material>("Material\\" + mat);
                        if (material == null)
                        {
                            File.Copy(Application.dataPath + "/Resources/Material/DEFAULT.mat", Application.dataPath + "/Resources/Material/" + mat + ".mat");
                            material = Resources.Load <Material>("Material\\" + mat);
                        }
                        ms.material = material;
                    }
                    AssetDatabase.Refresh();
                }
                editDropTable(ms.dropTable);
            }
            else
            {
                ms.customeBlockModel = (GameObject)EditorGUILayout.ObjectField("Custome Block Model", ms.customeBlockModel, typeof(GameObject), false);
            }
        }
        else
        {
            //IF IS ITEM
            ms.texture = (Texture2D)EditorGUILayout.ObjectField("Texture", ms.texture, typeof(Texture2D), false);
            //Search
            GUILayout.Space(10f);
            GUILayout.BeginHorizontal();
            searchKeyword = GUILayout.TextField(searchKeyword);
            if (GUILayout.Button("Auto Fill"))
            {
                searchKeyword = mat.ToString().Replace("_", " ").ToLower();
            }
            if (GUILayout.Button("Search Image"))
            {
                WebHandler.getTextures(webSearchTexture, searchKeyword, transparent: true);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            webSearchSelected = GUILayout.SelectionGrid(webSearchSelected, webSearchTexture.ToArray(), 8);
            GUILayout.EndHorizontal();
            if (GUILayout.Button("Use This Image As Texture"))
            {
                if (File.Exists("Assets/Resources/Texture/" + mat + "_" + textureType + ".png"))
                {
                    File.Delete("Assets/Resources/Texture/" + mat + "_" + textureType + ".png");
                }
                File.WriteAllBytes("Assets/Resources/Texture/" + mat + "_" + textureType + ".png", ((Texture2D)webSearchTexture[webSearchSelected]).EncodeToPNG());
                AssetDatabase.Refresh();
                Texture2D t = Resources.Load <Texture2D>("Texture\\" + mat + "_" + textureType);
                t.filterMode = FilterMode.Point;
                ms.setTexture(textureType, t);
                if (ms.material == null)
                {
                    Material material = Resources.Load <Material>("Material\\" + mat);
                    if (material == null)
                    {
                        File.Copy(Application.dataPath + "/Resources/Material/DEFAULT.mat", Application.dataPath + "/Resources/Material/" + mat + ".mat");
                        material = Resources.Load <Material>("Material\\" + mat);
                    }
                    ms.material = material;
                }
                AssetDatabase.Refresh();
            }
        }
        //Name
        ms.desplayName = EditorGUILayout.TextField("Display Name: ", ms.desplayName);
        //DESCRIPTION
        ms.description = EditorGUILayout.TextField("Description: ", ms.description);

        GUILayout.Space(10f);
    }