private void UpdateSearchBoxSizeForAll(PartiallyVisibleObject script)
 {
     EditorGUI.BeginChangeCheck();
     script.pillarSearchBoxSize = EditorGUILayout.Vector3Field("Search box size: ", script.pillarSearchBoxSize);
     if (EditorGUI.EndChangeCheck())
     {
         foreach (Object obj in targets)
         {
             ((PartiallyVisibleObject)obj).pillarSearchBoxSize = script.pillarSearchBoxSize;
         }
     }
 }
 private void UpdateSearchRadiusForAll(PartiallyVisibleObject script)
 {
     EditorGUI.BeginChangeCheck();
     script.pillarSearchRadius = EditorGUILayout.FloatField("Search radius: ", script.pillarSearchRadius);
     if (EditorGUI.EndChangeCheck())
     {
         foreach (Object obj in targets)
         {
             ((PartiallyVisibleObject)obj).pillarSearchRadius = script.pillarSearchRadius;
         }
     }
 }
        private void OnEnable()
        {
            InitializeDictEntry();

            OnActivePillarChanged += HandleActivePillarChanged;

            thisPartiallyVisibleObject = GetComponent <PartiallyVisibleObject>();
            if (thisPartiallyVisibleObject != null)
            {
                thisPartiallyVisibleObject.OnVisibilityStateChange += HandlePillarVisibilityChange;
            }
        }
        public override void OnInspectorGUI()
        {
            PartiallyVisibleObject script = target as PartiallyVisibleObject;
            float defaultWidth            = EditorGUIUtility.labelWidth;

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            script.DEBUG = EditorGUILayout.Toggle("Debug mode: ", script.DEBUG);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).DEBUG = script.DEBUG;
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            script.findPillarsTechnique = (PartiallyVisibleObject.FindPillarsTechnique)EditorGUILayout.EnumPopup("Technique for finding pillars", script.findPillarsTechnique);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).findPillarsTechnique = script.findPillarsTechnique;
                }
            }

            EditorGUILayout.Space();

            switch (script.findPillarsTechnique)
            {
            case PartiallyVisibleObject.FindPillarsTechnique.whitelist:
                SerializedProperty whitelist = serializedObject.FindProperty("whitelist");
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(whitelist, new GUIContent("Whitelist: "), true);
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
                break;

            case PartiallyVisibleObject.FindPillarsTechnique.automaticSphere:
                UpdateSearchRadiusForAll(script);
                break;

            case PartiallyVisibleObject.FindPillarsTechnique.automaticSphereWithBlacklist: {
                UpdateSearchRadiusForAll(script);
                SerializedProperty blacklist = serializedObject.FindProperty("blacklist");
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(blacklist, new GUIContent("Blacklist: "), true);
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            }
            break;

            case PartiallyVisibleObject.FindPillarsTechnique.automaticBox:
                UpdateSearchBoxSizeForAll(script);
                break;

            case PartiallyVisibleObject.FindPillarsTechnique.automaticBoxWithBlacklist: {
                UpdateSearchBoxSizeForAll(script);
                SerializedProperty blacklist = serializedObject.FindProperty("blacklist");
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(blacklist, new GUIContent("Blacklist: "), true);
                if (EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
            }
            break;
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            script.setLayerRecursively = EditorGUILayout.Toggle("Set layer recursively? ", script.setLayerRecursively);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).setLayerRecursively = script.setLayerRecursively;
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            script.setMaterialColorOnStateChange = EditorGUILayout.Toggle("Set color on state change? ", script.setMaterialColorOnStateChange);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).setMaterialColorOnStateChange = script.setMaterialColorOnStateChange;
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            script.setMaterialColorOnStart = EditorGUILayout.Toggle("Set material color on start? ", script.setMaterialColorOnStart);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).setMaterialColorOnStart = script.setMaterialColorOnStart;
                }
            }
            if (script.setMaterialColorOnStart)
            {
                EditorGUI.BeginChangeCheck();
                script.materialColor = EditorGUILayout.ColorField("Material color: ", script.materialColor);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (Object obj in targets)
                    {
                        ((PartiallyVisibleObject)obj).materialColor = script.materialColor;
                    }
                }
                EditorGUI.BeginChangeCheck();
                script.emissiveColor = EditorGUILayout.ColorField("Material emission color: ", script.emissiveColor);
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (Object obj in targets)
                    {
                        ((PartiallyVisibleObject)obj).emissiveColor = script.emissiveColor;
                    }
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            script.startingVisibilityState = (VisibilityState_old)EditorGUILayout.EnumPopup("Starting visibility state: ", script.startingVisibilityState);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).startingVisibilityState = script.startingVisibilityState;
                }
            }
            string s = script.visibilityState.ToString();

            EditorGUILayout.LabelField("Current visibility state: ", char.ToUpper(s[0]) + s.Substring(1));

            EditorGUILayout.Space();

            ///////////////
            // Materials //
            ///////////////
            EditorGUI.BeginChangeCheck();
            bool allowSceneObjects = !EditorUtility.IsPersistent(target);

            script.visibleMaterial = (Material)EditorGUILayout.ObjectField("Fully Visible Material: ", script.visibleMaterial, typeof(Material), allowSceneObjects);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).visibleMaterial = script.visibleMaterial;
                }
            }
            EditorGUI.BeginChangeCheck();
            script.partiallyVisibleMaterial = (Material)EditorGUILayout.ObjectField("Partially Visible Material: ", script.partiallyVisibleMaterial, typeof(Material), allowSceneObjects);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).partiallyVisibleMaterial = script.partiallyVisibleMaterial;
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            script.swapRevealDirection = EditorGUILayout.Toggle("Reverse reveal direction? ", script.swapRevealDirection);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).swapRevealDirection = script.swapRevealDirection;
                }
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            script.overrideOnOffAngles = EditorGUILayout.Toggle("Override On/Off Angles?", script.overrideOnOffAngles);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Object obj in targets)
                {
                    ((PartiallyVisibleObject)obj).overrideOnOffAngles = script.overrideOnOffAngles;
                }
            }

            if (script.overrideOnOffAngles)
            {
                EditorGUI.BeginChangeCheck();
                script.onAngle  = Angle.Degrees(EditorGUILayout.FloatField("On Angle Degrees: ", script.onAngle.degrees));
                script.offAngle = Angle.Degrees(EditorGUILayout.FloatField("Off Angle Degrees: ", script.offAngle.degrees));
                if (EditorGUI.EndChangeCheck())
                {
                    foreach (Object obj in targets)
                    {
                        ((PartiallyVisibleObject)obj).onAngle  = Angle.Degrees(EditorGUILayout.FloatField("On Angle Degrees: ", script.onAngle.degrees));
                        ((PartiallyVisibleObject)obj).offAngle = Angle.Degrees(EditorGUILayout.FloatField("Off Angle Degrees: ", script.offAngle.degrees));
                    }
                }
            }
            else
            {
                EditorGUILayout.LabelField("On Angle: ", script.onAngle.ToString());
                EditorGUILayout.LabelField("Off Angle: ", script.offAngle.ToString());
            }
        }