﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class PVPSetupWindow : EditorWindow
{
    // Add menu named "My Window" to the Window menu
    [MenuItem("Avatar PVP/Setup Layers")]
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        PVPSetupWindow window = EditorWindow.GetWindow<PVPSetupWindow>();
        window.Show();
    }

    void OnGUI()
    {
        if(GUILayout.Button("Setup layers for PVP (Will override layers 22 through 31)"))
        {
            //Based on https://forum.unity.com/threads/create-tags-and-layers-in-the-editor-using-script-both-edit-and-runtime-modes.732119/
            SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
            SerializedProperty layersProp = tagManager.FindProperty("layers");
            SerializedProperty iceLayer = layersProp.GetArrayElementAtIndex(22);
            iceLayer.stringValue = "Ice";
            SerializedProperty NewDOTLayer = layersProp.GetArrayElementAtIndex(23);
            NewDOTLayer.stringValue = "DOT";
            SerializedProperty StunLayer = layersProp.GetArrayElementAtIndex(24);
            StunLayer.stringValue = "Stun";
            SerializedProperty PoisonLayer = layersProp.GetArrayElementAtIndex(25);
            PoisonLayer.stringValue = "Poison";
            SerializedProperty SpeedLayer = layersProp.GetArrayElementAtIndex(26);
            SpeedLayer.stringValue = "Speed";
            SerializedProperty RadLayer = layersProp.GetArrayElementAtIndex(27);
            RadLayer.stringValue = "RAD";
            SerializedProperty ShieldLayer = layersProp.GetArrayElementAtIndex(28);
            ShieldLayer.stringValue = "Shield";
            SerializedProperty HOTLayer = layersProp.GetArrayElementAtIndex(29);
            HOTLayer.stringValue = "HOT";
            SerializedProperty RepairLayer = layersProp.GetArrayElementAtIndex(30);
            RepairLayer.stringValue = "Repair";
            SerializedProperty FireLayer = layersProp.GetArrayElementAtIndex(31);
            FireLayer.stringValue = "Fire";
            tagManager.ApplyModifiedProperties();
        }
        EditorGUILayout.Space();
        if (GUILayout.Button("Setup Layer Collision matrix for PVP"))
        {
            for(int i = 22; i <= 31; i++)
            {
                for (int i2 = 0; i2 <= 31; i2++)
                {
                    Physics.IgnoreLayerCollision(i2, i, true);
                }
            }
        }
        /*
        EditorGUILayout.Space();
        if (!Physics.GetIgnoreLayerCollision(10, 29))
        {
            EditorGUILayout.LabelField("Warning! Layer Collision Matrix not setup for HOT layer!");
        }

        EditorGUILayout.Space();
        if (!Physics.GetIgnoreLayerCollision(10, 30))
        {
            EditorGUILayout.LabelField("Warning! Layer Collision Matrix not setup for Heal layer!");

        }
        EditorGUILayout.Space();
        if (!Physics.GetIgnoreLayerCollision(10, 31))
        {
            EditorGUILayout.LabelField("Warning! Layer Collision Matrix not setup for DOT layer!");

        }

        if (GUILayout.Button("Setup Layer Collision matrix"))
        {
            Physics.IgnoreLayerCollision(10, 29, true);
            Physics.IgnoreLayerCollision(10, 30, true);
            Physics.IgnoreLayerCollision(10, 31, true);
        }*/
    }
}
