Playtest Tools - Death Points

Over dit spel...

Geïnspireerd door deze video besloot ik mijn eigen makkelijk te gebruiken Unity asset te maken dat precies dat en misschien nog net wat meer doet.

Uiteindelijk is daar dit uit gekomen! Een asset die met redelijk weinig gebruiker input punten waarop de speler dood is gegaan opslaat in een XML bestand en dat met allerlei mooie kleurtjes en een tijdlijn weer kan laten zien in je Unity Editor.

Lijkt het je een interessant plugin? Top! Scroll door naar de downloads om 'm van de Unity Asset Store te downloaden.

Engine: Unity/C#
Platform: Unity Editor

DeathPointLoader.cs

using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

namespace PlaytestTools
{
    [ExecuteInEditMode]
    public class DeathPointLoader : MonoBehaviour
    {
        DeathPointContainer deathPoints;

        [SerializeField]
        bool drawDeathPoints = true;
        [SerializeField]
        [Range(0.1f, 2)]
        float deathPointSize;
        [SerializeField]
        Color[] deathPointColors;
        float maxTime;
        public float GetMaxTime
        {
            get { return maxTime; }
        }
        float currentTime = 11.1f;
        public float CurrentTime
        {
            get { return currentTime; }
            set
            {
                currentTime = value;
                //Update scene to instantly show new/removed Gizmos
                SceneView.RepaintAll();
            }
        }

        float timeLineTime = 0;

        public void Start()
        {
            RefreshList();
        }

        public void RefreshList()
        {
            Debug.Log("Playtest Tools: Updating list...");
            deathPoints = DeathPointContainer.Load(XMLLocation());
            UpdateVars();
        }

        public void AddPoint(DeathPoint newDeathPoint)
        {
            deathPoints = DeathPointContainer.Load(XMLLocation());
            deathPoints.DeathPoints.Add(newDeathPoint);
            deathPoints.Save(XMLLocation());
        }

        public void MergeXMLs(string path2)
        {
            DeathPointContainer.Merge(XMLLocation(), path2);
            Debug.Log("Playtest Tools: Done merging files");
        }

        void UpdateVars()
        {
            maxTime = 0;
            uint highestID = 0;
            foreach (DeathPoint dP in deathPoints.DeathPoints)
            {
                if (dP.id > highestID) highestID = dP.id;

                //Set max time
                if (dP.time - 1 > maxTime) maxTime = dP.time + 1;
            }

            if (highestID + 1 != deathPointColors.Length)
            {
                int prevLength = deathPointColors.Length;
                Array.Resize(ref deathPointColors, Mathf.RoundToInt(highestID) + 1);
                Debug.Log("Playtest Tools: Amount of IDs changed. New amount: " + deathPointColors.Length);
                if (prevLength < deathPointColors.Length)
                {
                    int changeAmount = deathPointColors.Length - prevLength;
                    while (changeAmount > 0)
                    {
                        deathPointColors[deathPointColors.Length - changeAmount] = new Color(UnityEngine.Random.Range(0f, 255f) / 255f, UnityEngine.Random.Range(0f, 255f) / 255f, UnityEngine.Random.Range(0f, 255f) / 255f, 0.5f);
                        changeAmount--;
                    }
                }
            }
        }

        void OnDrawGizmos()
        {
            if (drawDeathPoints)
            {
                try
                {
                    for (int i = 0; i < deathPoints.DeathPoints.Count; i++)
                    {
                        if (deathPoints.DeathPoints[i].time <= currentTime)
                        {
                            Gizmos.color = deathPointColors[deathPoints.DeathPoints[i].id];
                            Vector3 pos = new Vector3(deathPoints.DeathPoints[i].x, deathPoints.DeathPoints[i].y, deathPoints.DeathPoints[i].z);
                            Gizmos.DrawCube(pos, Vector3.one * deathPointSize);
                        }
                    }
                }

                catch
                {
                    RefreshList();
                }
            }
        }

        string XMLLocation()
        {
            return new DirectoryInfo(Application.persistentDataPath + "/DeathPoints.xml").ToString();
        }
    }
}

Downloads

Unity Asset Store
Documentatie