Add more docs.

This commit is contained in:
excitedneon 2017-05-08 22:59:35 +03:00
parent 461705d1e3
commit fad6c0fc0c
8 changed files with 107 additions and 4 deletions

View File

@ -2,14 +2,23 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary>
/// A syncable component that all characters have. Controls the character's subsystems.
/// </summary>
public class Character : SyncBase { public class Character : SyncBase {
/// <summary>
/// How fast the player should move in Unity's spatial units per second.
/// </summary>
public float MovementSpeed = 5.0f; public float MovementSpeed = 5.0f;
/// <summary>
/// The character controller, used to move the character. Handles collisions.
/// </summary>
public CharacterController CharacterController; public CharacterController CharacterController;
private Vector3 MovementDirection = new Vector3(); private Vector3 MovementDirection = new Vector3();
/// <summary> /// <summary>
/// Moves the character in the wanted direction. /// Moves the character in the given direction.
/// </summary> /// </summary>
/// <param name="Direction">Movement direction.</param> /// <param name="Direction">Movement direction.</param>
public void Move(Vector3 Direction) { public void Move(Vector3 Direction) {
@ -27,6 +36,9 @@ public class Character : SyncBase {
} }
} }
/// <summary>
/// Whether the player is moving or not.
/// </summary>
public bool Moving() { public bool Moving() {
return MovementDirection.sqrMagnitude != 0; return MovementDirection.sqrMagnitude != 0;
} }

View File

@ -6,8 +6,8 @@ using UnityEngine.UI;
/// <summary> /// <summary>
/// Controls an input and an output to implement a console interface to call /// Controls an input and an output to implement a console interface to call
/// arbitrary commands which can be set from anywhere in the program. /// arbitrary commands which can be set from anywhere in the program through
/// <seealso cref="Term"/> /// <see cref="Term"/>.
/// </summary> /// </summary>
public class DebugConsole : MonoBehaviour { public class DebugConsole : MonoBehaviour {
private static readonly Regex CommandPartRegex = new Regex("([^ \"]+ )|(\"[^\"]+\")"); private static readonly Regex CommandPartRegex = new Regex("([^ \"]+ )|(\"[^\"]+\")");
@ -68,7 +68,7 @@ public class DebugConsole : MonoBehaviour {
/// Adds a command to be used in the console. /// Adds a command to be used in the console.
/// </summary> /// </summary>
/// <param name="command">The command template that should be used. /// <param name="command">The command template that should be used.
/// eg. "print (text)" or "add (number) (number)"</param> /// eg. "print (text)" or "add (number) (number)".</param>
/// <param name="description">Description.</param> /// <param name="description">Description.</param>
/// <param name="action">Action.</param> /// <param name="action">Action.</param>
public void AddCommand(string command, string description, DebugConsoleAction.Action action) { public void AddCommand(string command, string description, DebugConsoleAction.Action action) {

View File

@ -1,11 +1,26 @@
using System.Collections.Generic; using System.Collections.Generic;
/// <summary>
/// Class that defines an action that commands in the
/// <see cref="DebugConsole"/> might use.
/// </summary>
public class DebugConsoleAction { public class DebugConsoleAction {
/// <summary>
/// A delegate for all of the actions that commands do.
/// </summary>
public delegate void Action(List<string> command); public delegate void Action(List<string> command);
/// <summary>
/// A description that will be shown when using the "help (command)" command in the console.
/// </summary>
public readonly string Description; public readonly string Description;
private Action ActionFunc; private Action ActionFunc;
/// <summary>
/// Initializes a new instance of the <see cref="DebugConsoleAction"/> class.
/// </summary>
/// <param name="description">Description.</param>
/// <param name="actionFunc">Action func.</param>
public DebugConsoleAction(string description, Action actionFunc) { public DebugConsoleAction(string description, Action actionFunc) {
this.Description = description; this.Description = description;
this.ActionFunc = actionFunc; this.ActionFunc = actionFunc;

View File

@ -2,7 +2,17 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary>
/// Types of entities. Every entity type has its own prefab, see
/// <see cref="Spawner"/>.
/// </summary>
public enum EntityType { public enum EntityType {
/// <summary>
/// Player character.
/// </summary>
PC, PC,
/// <summary>
/// Non player character.
/// </summary>
NPC NPC
} }

View File

@ -2,7 +2,14 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary>
/// Controls the player character. Shouldn't exist on the server, and only one
/// should exist per client (the character that client is controlling).
/// </summary>
public class PlayerController : MonoBehaviour { public class PlayerController : MonoBehaviour {
/// <summary>
/// The character this controller should control.
/// </summary>
public Character Character; public Character Character;
private void Update() { private void Update() {

View File

@ -2,9 +2,23 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary>
/// A utility class to spawn entities into the world based on
/// their <see cref="EntityType"/> and .
/// </summary>
public class Spawner : MonoBehaviour { public class Spawner : MonoBehaviour {
/// <summary>
/// The <see cref="SyncDB"/> this <see cref="Spawner"/> should be using to
/// set entities' IDs.
/// </summary>
public SyncDB SyncDB; public SyncDB SyncDB;
/// <summary>
/// The <see cref="EntityType.PC"/> prefab.
/// </summary>
public GameObject PCEntityPrefab; public GameObject PCEntityPrefab;
/// <summary>
/// The <see cref="EntityType.NPC"/> prefab.
/// </summary>
public GameObject NPCEntityPrefab; public GameObject NPCEntityPrefab;
/// <summary> /// <summary>
@ -12,6 +26,10 @@ public class Spawner : MonoBehaviour {
/// </summary> /// </summary>
/// <param name="type">Type.</param> /// <param name="type">Type.</param>
/// <param name="position">Position.</param> /// <param name="position">Position.</param>
/// <param name="ids">The ids of the entity's synced components. Should be
/// set if they exist already (eg. the server has sent them over). These
/// ids should be from <see cref="SyncDB.GetEntityIDs"/>. To create new
/// ids, leave as the default (null).</param>
public GameObject Spawn(EntityType type, Vector3 position, uint[] ids = null) { public GameObject Spawn(EntityType type, Vector3 position, uint[] ids = null) {
GameObject Spawned = null; GameObject Spawned = null;
switch (type) { switch (type) {

View File

@ -2,6 +2,14 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
/// <summary>
/// A base class for all syncable components. An instance of
/// <see cref="SyncDB"/> will contain all of the game's synced components.
/// </summary>
public class SyncBase : MonoBehaviour { public class SyncBase : MonoBehaviour {
/// <summary>
/// The ID this syncable component can be found with from its parent
/// <see cref="SyncDB"/>.
/// </summary>
public uint ID; public uint ID;
} }

View File

@ -3,6 +3,10 @@ using System.Collections.Generic;
using System; using System;
using UnityEngine; using UnityEngine;
/// <summary>
/// A database of the game's all syncable components. Syncable components are
/// the instances of the subclasses of <see cref="SyncBase"/>.
/// </summary>
public class SyncDB : MonoBehaviour { public class SyncDB : MonoBehaviour {
private static readonly Type[] SyncableClasses = new Type[]{ private static readonly Type[] SyncableClasses = new Type[]{
typeof(Character) typeof(Character)
@ -11,6 +15,12 @@ public class SyncDB : MonoBehaviour {
private uint IDCounter = 0; private uint IDCounter = 0;
private Dictionary<uint, SyncBase> Database = new Dictionary<uint, SyncBase>(); private Dictionary<uint, SyncBase> Database = new Dictionary<uint, SyncBase>();
/// <summary>
/// Add an entity to the database with the given IDs.
/// </summary>
/// <param name="gameObject">Game object.</param>
/// <param name="ids">The IDs. Should be from <see cref="GetEntityIDs"/> or
/// <see cref="GetNewEntityIDs"/>, since the order is important.</param>
public void AddEntity(GameObject gameObject, uint[] ids) { public void AddEntity(GameObject gameObject, uint[] ids) {
int Index = 0; int Index = 0;
for (int i = 0; i < SyncableClasses.Length; i++) { for (int i = 0; i < SyncableClasses.Length; i++) {
@ -22,6 +32,15 @@ public class SyncDB : MonoBehaviour {
} }
} }
/// <summary>
/// Makes an ordered list of the given gameobject's syncable components'
/// IDs.
/// </summary>
/// <returns>The IDs.</returns>
/// <param name="gameObject">Game object.</param>
/// <param name="newIDs">Whether or not new IDs are created.
/// <see cref="GetNewEntityIDs"/> is a shorthand for this function with
/// this parameter set to true.</param>
public uint[] GetEntityIDs(GameObject gameObject, bool newIDs = false) { public uint[] GetEntityIDs(GameObject gameObject, bool newIDs = false) {
List<uint> IDs = new List<uint>(); List<uint> IDs = new List<uint>();
for (int i = 0; i < SyncableClasses.Length; i++) { for (int i = 0; i < SyncableClasses.Length; i++) {
@ -40,14 +59,28 @@ public class SyncDB : MonoBehaviour {
return IDArray; return IDArray;
} }
/// <summary>
/// Creates an ordered list of the given gameobject's syncable components'
/// IDs. See <see cref="GetEntityIDs"/> for more information.
/// </summary>
/// <returns>The new IDs.</returns>
/// <param name="gameObject">Game object.</param>
public uint[] GetNewEntityIDs(GameObject gameObject) { public uint[] GetNewEntityIDs(GameObject gameObject) {
return GetEntityIDs(gameObject, true); return GetEntityIDs(gameObject, true);
} }
/// <summary>
/// Get a synced component by its ID.
/// </summary>
/// <param name="id">The ID.</param>
public SyncBase Get(uint id) { public SyncBase Get(uint id) {
return Database[id]; return Database[id];
} }
/// <summary>
/// Creates a new ID which isn't in use yet.
/// </summary>
/// <returns>A new, free ID.</returns>
public uint CreateID() { public uint CreateID() {
uint ID; uint ID;
try { try {