Example #1
0
    private void SaveAsset()
    {
        string          fullPath = string.Concat(filePath, stageName, ".asset");
        ScriptableStage newStage = ScriptableObject.CreateInstance(typeof(ScriptableStage)) as ScriptableStage;

        newStage.SetDimension(stageWidth, stageHeight);

        for (int i = 0; i < stageHeight; i++)
        {
            for (int j = 0; j < stageWidth; j++)
            {
                newStage.SetMatrixValue(i, j, stage[i, j]);
            }
        }

        string[] names = AssetDatabase.FindAssets(stageName);

        if (names.Length > 0)
        {
            newStage.Name = string.Concat(stageName, names.Length + 1);
            string newPath = string.Concat(filePath, newStage.Name, ".asset");
            AssetDatabase.CreateAsset(newStage, newPath);
        }
        else
        {
            AssetDatabase.CreateAsset(newStage, fullPath);
        }

        if (!usePreviousSetup)
        {
            ClearWindowMatrixAndName();
        }
    }
    private void DrawInspector()
    {
        SerializedProperty col = serializedObject.FindProperty("stageMatrix").FindPropertyRelative("cols");

        Debug.Log("col.arraySize: " + col.arraySize);
        for (int i = 0; i < col.arraySize; i++)
        {
            SerializedProperty row = col.GetArrayElementAtIndex(i).FindPropertyRelative("rows");

            Debug.Log("for row.arraySize: " + i + " | " + row.arraySize);

            //            if (col.arraySize != row.arraySize)
            //                col.arraySize = row.arraySize;

            //Get the selected object
            ScriptableStage obj = (ScriptableStage)target;

            EditorGUILayout.BeginHorizontal();
            for (int j = 0; j < row.arraySize; j++)
            {
                GUIContent btn;
                int        value = row.GetArrayElementAtIndex(j).intValue;
                switch (value)
                {
                case 1:
                    btn = new GUIContent(greenTexture);
                    break;

                case 2:
                    btn = new GUIContent(pinkTexture);
                    break;

                case 3:
                    btn = new GUIContent(redTexture);
                    break;

                default:
                    btn = new GUIContent(blueTexture);
                    break;
                }

                if (GUILayout.Button(btn, buttonLayoutOptions))
                {
                    value++;
                    if (value > 3)
                    {
                        value = 0;
                    }
                    obj.SetMatrixValue(i, j, value);
                }
            }
            EditorGUILayout.EndHorizontal();
        }
    }