From fad6c0fc0cd97c98576fc4c6af0cf057d883d580 Mon Sep 17 00:00:00 2001 From: excitedneon Date: Mon, 8 May 2017 22:59:35 +0300 Subject: [PATCH] Add more docs. --- Assets/Scripts/Character.cs | 14 ++++++++- Assets/Scripts/Console/DebugConsole.cs | 6 ++-- Assets/Scripts/Console/DebugConsoleAction.cs | 15 +++++++++ Assets/Scripts/EntityType.cs | 10 ++++++ Assets/Scripts/PlayerController.cs | 7 +++++ Assets/Scripts/Spawner.cs | 18 +++++++++++ Assets/Scripts/SyncBase.cs | 8 +++++ Assets/Scripts/SyncDB.cs | 33 ++++++++++++++++++++ 8 files changed, 107 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Character.cs b/Assets/Scripts/Character.cs index 26f9a73..b593c6c 100644 --- a/Assets/Scripts/Character.cs +++ b/Assets/Scripts/Character.cs @@ -2,14 +2,23 @@ using System.Collections.Generic; using UnityEngine; +/// +/// A syncable component that all characters have. Controls the character's subsystems. +/// public class Character : SyncBase { + /// + /// How fast the player should move in Unity's spatial units per second. + /// public float MovementSpeed = 5.0f; + /// + /// The character controller, used to move the character. Handles collisions. + /// public CharacterController CharacterController; private Vector3 MovementDirection = new Vector3(); /// - /// Moves the character in the wanted direction. + /// Moves the character in the given direction. /// /// Movement direction. public void Move(Vector3 Direction) { @@ -27,6 +36,9 @@ public class Character : SyncBase { } } + /// + /// Whether the player is moving or not. + /// public bool Moving() { return MovementDirection.sqrMagnitude != 0; } diff --git a/Assets/Scripts/Console/DebugConsole.cs b/Assets/Scripts/Console/DebugConsole.cs index e381719..f0a5b4f 100644 --- a/Assets/Scripts/Console/DebugConsole.cs +++ b/Assets/Scripts/Console/DebugConsole.cs @@ -6,8 +6,8 @@ using UnityEngine.UI; /// /// 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 +/// . /// public class DebugConsole : MonoBehaviour { private static readonly Regex CommandPartRegex = new Regex("([^ \"]+ )|(\"[^\"]+\")"); @@ -68,7 +68,7 @@ public class DebugConsole : MonoBehaviour { /// Adds a command to be used in the console. /// /// The command template that should be used. - /// eg. "print (text)" or "add (number) (number)" + /// eg. "print (text)" or "add (number) (number)". /// Description. /// Action. public void AddCommand(string command, string description, DebugConsoleAction.Action action) { diff --git a/Assets/Scripts/Console/DebugConsoleAction.cs b/Assets/Scripts/Console/DebugConsoleAction.cs index 24986ff..08e5716 100644 --- a/Assets/Scripts/Console/DebugConsoleAction.cs +++ b/Assets/Scripts/Console/DebugConsoleAction.cs @@ -1,11 +1,26 @@ using System.Collections.Generic; +/// +/// Class that defines an action that commands in the +/// might use. +/// public class DebugConsoleAction { + /// + /// A delegate for all of the actions that commands do. + /// public delegate void Action(List command); + /// + /// A description that will be shown when using the "help (command)" command in the console. + /// public readonly string Description; private Action ActionFunc; + /// + /// Initializes a new instance of the class. + /// + /// Description. + /// Action func. public DebugConsoleAction(string description, Action actionFunc) { this.Description = description; this.ActionFunc = actionFunc; diff --git a/Assets/Scripts/EntityType.cs b/Assets/Scripts/EntityType.cs index 3aededc..068a31a 100644 --- a/Assets/Scripts/EntityType.cs +++ b/Assets/Scripts/EntityType.cs @@ -2,7 +2,17 @@ using System.Collections.Generic; using UnityEngine; +/// +/// Types of entities. Every entity type has its own prefab, see +/// . +/// public enum EntityType { + /// + /// Player character. + /// PC, + /// + /// Non player character. + /// NPC } diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index b801513..1127e33 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -2,7 +2,14 @@ using System.Collections.Generic; using UnityEngine; +/// +/// Controls the player character. Shouldn't exist on the server, and only one +/// should exist per client (the character that client is controlling). +/// public class PlayerController : MonoBehaviour { + /// + /// The character this controller should control. + /// public Character Character; private void Update() { diff --git a/Assets/Scripts/Spawner.cs b/Assets/Scripts/Spawner.cs index 09441c0..154cd6a 100644 --- a/Assets/Scripts/Spawner.cs +++ b/Assets/Scripts/Spawner.cs @@ -2,9 +2,23 @@ using System.Collections.Generic; using UnityEngine; +/// +/// A utility class to spawn entities into the world based on +/// their and . +/// public class Spawner : MonoBehaviour { + /// + /// The this should be using to + /// set entities' IDs. + /// public SyncDB SyncDB; + /// + /// The prefab. + /// public GameObject PCEntityPrefab; + /// + /// The prefab. + /// public GameObject NPCEntityPrefab; /// @@ -12,6 +26,10 @@ public class Spawner : MonoBehaviour { /// /// Type. /// Position. + /// 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 . To create new + /// ids, leave as the default (null). public GameObject Spawn(EntityType type, Vector3 position, uint[] ids = null) { GameObject Spawned = null; switch (type) { diff --git a/Assets/Scripts/SyncBase.cs b/Assets/Scripts/SyncBase.cs index b0e424d..b18bea7 100644 --- a/Assets/Scripts/SyncBase.cs +++ b/Assets/Scripts/SyncBase.cs @@ -2,6 +2,14 @@ using System.Collections.Generic; using UnityEngine; +/// +/// A base class for all syncable components. An instance of +/// will contain all of the game's synced components. +/// public class SyncBase : MonoBehaviour { + /// + /// The ID this syncable component can be found with from its parent + /// . + /// public uint ID; } diff --git a/Assets/Scripts/SyncDB.cs b/Assets/Scripts/SyncDB.cs index 152f008..8223878 100644 --- a/Assets/Scripts/SyncDB.cs +++ b/Assets/Scripts/SyncDB.cs @@ -3,6 +3,10 @@ using System.Collections.Generic; using System; using UnityEngine; +/// +/// A database of the game's all syncable components. Syncable components are +/// the instances of the subclasses of . +/// public class SyncDB : MonoBehaviour { private static readonly Type[] SyncableClasses = new Type[]{ typeof(Character) @@ -11,6 +15,12 @@ public class SyncDB : MonoBehaviour { private uint IDCounter = 0; private Dictionary Database = new Dictionary(); + /// + /// Add an entity to the database with the given IDs. + /// + /// Game object. + /// The IDs. Should be from or + /// , since the order is important. public void AddEntity(GameObject gameObject, uint[] ids) { int Index = 0; for (int i = 0; i < SyncableClasses.Length; i++) { @@ -22,6 +32,15 @@ public class SyncDB : MonoBehaviour { } } + /// + /// Makes an ordered list of the given gameobject's syncable components' + /// IDs. + /// + /// The IDs. + /// Game object. + /// Whether or not new IDs are created. + /// is a shorthand for this function with + /// this parameter set to true. public uint[] GetEntityIDs(GameObject gameObject, bool newIDs = false) { List IDs = new List(); for (int i = 0; i < SyncableClasses.Length; i++) { @@ -40,14 +59,28 @@ public class SyncDB : MonoBehaviour { return IDArray; } + /// + /// Creates an ordered list of the given gameobject's syncable components' + /// IDs. See for more information. + /// + /// The new IDs. + /// Game object. public uint[] GetNewEntityIDs(GameObject gameObject) { return GetEntityIDs(gameObject, true); } + /// + /// Get a synced component by its ID. + /// + /// The ID. public SyncBase Get(uint id) { return Database[id]; } + /// + /// Creates a new ID which isn't in use yet. + /// + /// A new, free ID. public uint CreateID() { uint ID; try {