Exemplo n.º 1
0
    private static void RestoreSerializedData()
    {
        string path = Path.Combine(Application.dataPath, "paths.bytes");

        if (File.Exists(path))
        {
            UnityEngine.Debug.Log("Attempting to restore path data..." +
                                  "");
            List <ProtoBuf.PathData> pathList = Serialization.Deserialize <List <ProtoBuf.PathData> >(File.ReadAllBytes(path));
            if (pathList != null)
            {
                Transform[] children = Parent.GetDirectChildren();
                for (int i = 0; i < pathList.Count; i++)
                {
                    ProtoBuf.PathData pathData = pathList[i];

                    for (int y = 0; y < children.Length; y++)
                    {
                        Transform child = children[y];
                        if (child.gameObject.name == pathData?.name)
                        {
                            child.GetComponent <PathData>().serializedData = pathData;
                            break;
                        }
                    }
                }
            }

            File.Delete(path);
            UnityEngine.Debug.Log("Restored Path Data");
        }
    }
Exemplo n.º 2
0
    internal void Set(ProtoBuf.PathData serializedData)
    {
        this.serializedData = serializedData;

        pathType = GetTypeFromName();

        gameObject.name = this.serializedData.name = string.Concat(pathType, " ", transform.parent.GetDirectChildren().Where(x => x.GetComponent <PathData>().pathType == pathType).Count());

        foreach (ProtoBuf.VectorData point in serializedData.nodes)
        {
            AddNode(point, -1);
        }
    }
Exemplo n.º 3
0
    public ProtoBuf.PathData GetPathData()
    {
        if (serializedData == null)
        {
            serializedData = PathManager.CreateEmptyPathData(GetTypeFromName());
        }

        serializedData.nodes = new ProtoBuf.VectorData[transform.childCount];

        for (int i = 0; i < transform.childCount; i++)
        {
            serializedData.nodes[i] = transform.GetChild(i).transform.position;
        }

        return(serializedData);
    }
Exemplo n.º 4
0
    public static void CreatePath(PathType pathType, Vector3 position)
    {
        if (Parent == null)
        {
            FindOrCreateParent();
        }

        ProtoBuf.PathData serializedData = CreateEmptyPathData(pathType);
        PathData          pathData       = new GameObject(serializedData.name).AddComponent <PathData>();

        pathData.transform.SetParent(Parent);

        pathData.Set(serializedData);

        pathData.AddNode(position + (Vector3.forward * 2));
        pathData.AddNode(position + -(Vector3.forward * 2));
    }
Exemplo n.º 5
0
    public IEnumerator Load(World.Data world)
    {
        ActionProgressBar.UpdateProgress("Loading Map Prefabs", 0f);
        yield return(null);

        yield return(null);

        Stopwatch sw = Stopwatch.StartNew();

        if (Parent == null)
        {
            FindOrCreateParent();
        }

        for (int i = 0; i < world.pathData.Count; i++)
        {
            if (sw.Elapsed.TotalSeconds > 1f || i == 0 || i == world.pathData.Count - 1)
            {
                ActionProgressBar.UpdateProgress("Loading Map Paths", (float)world.pathData.Count / (float)i);
                yield return(null);

                yield return(null);

                sw.Reset();
            }

            ProtoBuf.PathData serializedData = world.pathData[i];

            PathData pathData = new GameObject(serializedData.name).AddComponent <PathData>();

            pathData.transform.SetParent(Parent);

            pathData.Set(serializedData);
        }

        sw.Stop();
    }