Skip to content

Commit

Permalink
Simple Blackboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ZorPastaman committed Jul 15, 2020
1 parent 511bbec commit e328559
Show file tree
Hide file tree
Showing 353 changed files with 7,981 additions and 1 deletion.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Changelog

All notable changes to this package will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.0.0] - 2020-07-15

### Added

- Blackboard and other core functionality.
- Blackboard serialization.
- Unity components support.
- Unity editor support.
- Tests.

[unreleased]: https://github.com/ZorPastaman/Simple-Blackboard/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/ZorPastaman/Simple-Blackboard/releases/tag/v1.0.0
7 changes: 7 additions & 0 deletions CHANGELOG.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/AddPopups.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions Editor/AddPopups/AddPopup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright (c) 2020 Vladimir Popov zor1994@gmail.com https://github.com/ZorPastaman/Simple-Blackboard

using UnityEditor;
using UnityEngine;
using Zor.SimpleBlackboard.Core;

namespace Zor.SimpleBlackboard.BlackboardTableEditors
{
/// <summary>
/// Popup used for adding new properties to <see cref="Zor.SimpleBlackboard.Core.Blackboard"/> in the editor.
/// </summary>
internal sealed class AddPopup : EditorWindow
{
private GUIContent m_closeButtonIcon;
private GUILayoutOption[] m_closeButtonOptions;

private Blackboard m_blackboard;
private string m_key;
private IAddPopupValue m_addPopupValue;

private Vector2 m_scrollPos;

/// <summary>
/// Sets necessary parameters to <see cref="AddPopup"/>. Call this before first <see cref="OnGUI"/>.
/// </summary>
/// <param name="blackboard">New property is added to this.</param>
/// <param name="key">Initial key. It can be changed in <see cref="OnGUI"/>.</param>
/// <param name="addPopupValue">Value wrapper.</param>
/// <param name="popupPosition">Position of the popup in the editor space.</param>
public void Setup(Blackboard blackboard, string key, IAddPopupValue addPopupValue, Vector2 popupPosition)
{
m_blackboard = blackboard;
m_key = key;
m_addPopupValue = addPopupValue;
var size = new Vector2(450f, EditorGUIUtility.singleLineHeight * 8f
+ EditorGUIUtility.standardVerticalSpacing * 6f);

ShowAsDropDown(new Rect(popupPosition, size), size);
}

private void OnEnable()
{
m_closeButtonIcon = EditorGUIUtility.IconContent("LookDevClose");
m_closeButtonOptions = new[] { GUILayout.Width(32f) };
}

private void OnGUI()
{
EditorGUILayout.BeginHorizontal();

EditorGUILayout.LabelField(m_addPopupValue.valueType.Name, EditorStyles.toolbarButton);

if (GUILayout.Button(m_closeButtonIcon, EditorStyles.toolbarButton, m_closeButtonOptions))
{
Close();
return;
}

EditorGUILayout.EndHorizontal();

m_key = EditorGUILayout.TextField("Key", m_key);

m_scrollPos = EditorGUILayout.BeginScrollView(m_scrollPos);

m_addPopupValue.DrawValue("Value");

EditorGUILayout.EndScrollView();

if (GUILayout.Button("OK"))
{
m_addPopupValue.Set(m_key, m_blackboard);
Close();
}
}
}
}
11 changes: 11 additions & 0 deletions Editor/AddPopups/AddPopup.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Editor/AddPopups/AddPopupValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2020 Vladimir Popov zor1994@gmail.com https://github.com/ZorPastaman/Simple-Blackboard

using System;
using Zor.SimpleBlackboard.BlackboardValueViews;
using Zor.SimpleBlackboard.Core;

namespace Zor.SimpleBlackboard.BlackboardTableEditors
{
/// <summary>
/// Value wrapper used in <see cref="AddPopup"/>.
/// </summary>
/// <typeparam name="T">Value type.</typeparam>
internal sealed class AddPopupValue<T> : IAddPopupValue
{
private readonly BlackboardValueView<T> m_valueView;
private T m_value;

/// <summary>
/// Creates a wrapper over <paramref name="valueView"/>.
/// </summary>
/// <param name="valueView">Value view of <typeparamref name="T"/> used in this wrapper.</param>
public AddPopupValue(BlackboardValueView<T> valueView)
{
m_valueView = valueView;
}

/// <inheritdoc/>
public Type valueType => typeof(T);

/// <inheritdoc/>
public void DrawValue(string label)
{
m_value = m_valueView.DrawValue(label, m_value);
}

/// <inheritdoc/>
public void Set(string key, Blackboard blackboard)
{
blackboard.SetObjectValue(typeof(T), new BlackboardPropertyName(key), m_value);
}
}
}
11 changes: 11 additions & 0 deletions Editor/AddPopups/AddPopupValue.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions Editor/AddPopups/IAddPopupValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2020 Vladimir Popov zor1994@gmail.com https://github.com/ZorPastaman/Simple-Blackboard

using System;
using Zor.SimpleBlackboard.Core;

namespace Zor.SimpleBlackboard.BlackboardTableEditors
{
/// <summary>
/// Interface for a value wrapper used in <see cref="AddPopup"/>.
/// </summary>
internal interface IAddPopupValue
{
/// <summary>
/// Type of the value.
/// </summary>
Type valueType { get; }

/// <summary>
/// Draws an editor for the value.
/// </summary>
/// <param name="label">Property label.</param>
void DrawValue(string label);

/// <summary>
/// Sets the current value into <paramref name="blackboard"/> using <paramref name="key"/> as a property name.
/// </summary>
/// <param name="key">Property name.</param>
/// <param name="blackboard">Sets current value into this.</param>
void Set(string key, Blackboard blackboard);
}
}
11 changes: 11 additions & 0 deletions Editor/AddPopups/IAddPopupValue.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Editor/CustomEditors.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions Editor/CustomEditors/BlackboardContainerComponentCustomEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2020 Vladimir Popov zor1994@gmail.com https://github.com/ZorPastaman/Simple-Blackboard

using UnityEditor;
using Zor.SimpleBlackboard.EditorTools;

namespace Zor.SimpleBlackboard.Components
{
[CustomEditor(typeof(BlackboardContainer))]
public sealed class BlackboardContainerComponentCustomEditor : Editor
{
private bool m_constantRepaint;

public override void OnInspectorGUI()
{
base.OnInspectorGUI();

if (!EditorApplication.isPlaying)
{
return;
}

EditorGUILayout.Separator();
m_constantRepaint = EditorGUILayout.Toggle("Require Constant Repaint", m_constantRepaint);

var blackboardContainer = (BlackboardContainer)target;
BlackboardEditor.DrawBlackboard(blackboardContainer.blackboard);
}

public override bool RequiresConstantRepaint()
{
return m_constantRepaint;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e328559

Please sign in to comment.