Exemplo n.º 1
0
    void Update()
    {
        if (UnitySettings.IsRaymapGame)
        {
            return;
        }
        highlightedPerso = null;
        UpdateHighlight();
        highlightedCollision = null;
        highlightedWayPoint  = null;
        Rect screenRect = new Rect(0, 0, Screen.width, Screen.height);

        if (!cam.MouseLookEnabled && !cam.MouseLookRMBEnabled &&
            controller.LoadState == Controller.State.Finished &&
            screenRect.Contains(Input.mousePosition))
        {
            HandleCollision();
        }
        if (controller.LoadState == Controller.State.Finished)
        {
            UpdateTooFarLimit();
        }
        if (IsSelecting && (!Input.GetMouseButton(0) || highlightedPerso == null))
        {
            IsSelecting = false;
        }
    }
Exemplo n.º 2
0
        public WayPointBehaviour GetGameObject()
        {
            GameObject gao = new GameObject("WayPoint (" + Offset + ")");

            if (perso.Value != null)
            {
                gao.name += " - Perso: " + perso.Value.Offset;
            }
            float   factor      = 32f;
            Vector3 pos         = Position;
            float   radius_conv = radius / factor;

            gao.transform.position = pos;
            WayPointBehaviour wpBehaviour = gao.AddComponent <WayPointBehaviour>();

            wpBehaviour.wpROM = this;
            if (radius_conv > 1)
            {
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                sphere.transform.localScale    = new Vector3(radius_conv * 2, radius_conv * 2, radius_conv * 2);
                sphere.transform.parent        = gao.transform;
                sphere.transform.localPosition = Vector3.zero;
                // No collider necessary
                GameObject.Destroy(sphere.GetComponent <SphereCollider>());
                MeshRenderer sphereRenderer = sphere.GetComponent <MeshRenderer>();
                sphereRenderer.material       = MapLoader.Loader.collideTransparentMaterial;
                sphereRenderer.material.color = new Color(0.7f, 0f, 0.7f, 0.5f);
            }
            return(wpBehaviour);
        }
Exemplo n.º 3
0
        private void InitGameObject()
        {
            gao = new GameObject("WayPoint (" + this.offset + ")");
            gao.transform.position = new Vector3(position.x, position.z, position.y);
            WayPointBehaviour wpBehaviour = gao.AddComponent <WayPointBehaviour>();

            gao.layer          = LayerMask.NameToLayer("Graph");
            wpBehaviour.wp     = this;
            wpBehaviour.radius = radius;
        }
Exemplo n.º 4
0
 private WebJSON.WayPoint GetWayPointJSON(WayPointBehaviour wp, bool includeGraphs)
 {
     if (wp == null)
     {
         return(null);
     }
     return(new WebJSON.WayPoint()
     {
         Name = wp.gameObject.name,
         Graphs = includeGraphs ? wp.graphs.Select(g => GetGraphJSON(g)).ToArray() : null
     });
 }
Exemplo n.º 5
0
        public WayPointBehaviour GetGameObject()
        {
            GameObject gao = new GameObject("WayPoint (" + Offset + ")");
            //if (perso.Value != null) gao.name += " - Perso: " + perso.Value.Offset;
            float   factor      = 100f;
            Vector3 pos         = Position;
            float   radius_conv = radius / factor;

            gao.transform.position = pos;
            WayPointBehaviour wpBehaviour = gao.AddComponent <WayPointBehaviour>();

            gao.layer          = LayerMask.NameToLayer("Graph");
            wpBehaviour.wpPS1  = this;
            wpBehaviour.radius = radius_conv;
            return(wpBehaviour);
        }
Exemplo n.º 6
0
        public WayPointBehaviour GetGameObject()
        {
            GameObject gao = new GameObject("WayPoint (" + Offset + ")");
            //if (perso.Value != null) gao.name += " - Perso: " + perso.Value.Offset;
            Vector3 pos = Position;
            //UnityEngine.Debug.Log(Offset + " - " + radius + " - " + short_0C + " - " + short_0E + " - " + short_12);
            float radius_conv = radius / 100f * (256f / R2PS1Loader.CoordinateFactor);           // Radius is usually 100, matching PC's default value of 1

            gao.transform.position = pos;
            WayPointBehaviour wpBehaviour = gao.AddComponent <WayPointBehaviour>();

            gao.layer          = LayerMask.NameToLayer("Graph");
            wpBehaviour.wpPS1  = this;
            wpBehaviour.radius = radius_conv;
            return(wpBehaviour);
        }
Exemplo n.º 7
0
        private void InitGameObject()
        {
            gao = new GameObject("WayPoint (" + this.offset + ")");
            gao.transform.position = new Vector3(position.x, position.z, position.y);
            WayPointBehaviour wpBehaviour = gao.AddComponent <WayPointBehaviour>();

            wpBehaviour.wp = this;

            if (radius > 1)
            {
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                sphere.transform.position   = new Vector3(position.x, position.z, position.y);
                sphere.transform.localScale = new Vector3(radius * 2, radius * 2, radius * 2);
                sphere.transform.parent     = gao.transform;
                // No collider necessary
                GameObject.Destroy(sphere.GetComponent <SphereCollider>());
                MeshRenderer sphereRenderer = sphere.GetComponent <MeshRenderer>();
                sphereRenderer.material       = MapLoader.Loader.collideTransparentMaterial;
                sphereRenderer.material.color = new Color(0.7f, 0f, 0.7f, 0.5f);
            }
        }
Exemplo n.º 8
0
 public void Update()
 {
     if (controller.LoadState == Controller.State.Finished && !sentHierarchy)
     {
         SendHierarchy();
         sentHierarchy = true;
     }
     if ((Application.platform == RuntimePlatform.WebGLPlayer || testMessages) && controller.LoadState == Controller.State.Finished)
     {
         if (highlightedPerso_ != selector.highlightedPerso ||
             highlightedCollision_ != selector.highlightedCollision ||
             highlightedWayPoint_ != selector.highlightedWayPoint)
         {
             highlightedPerso_     = selector.highlightedPerso;
             highlightedCollision_ = selector.highlightedCollision;
             highlightedWayPoint_  = selector.highlightedWayPoint;
             Send(GetHighlightMessageJSON());
         }
         if (selectedPerso_ != selector.selectedPerso)
         {
             selectedPerso_ = selector.selectedPerso;
             if (selectedPerso_ != null)
             {
                 selectedPersoStateIndex_ = selectedPerso_.currentState;
                 Send(GetSelectionMessageJSON(true, true));
             }
         }
         if (selectedPerso_ != null && selectedPersoStateIndex_ != selectedPerso_.currentState)
         {
             selectedPersoStateIndex_ = selectedPerso_.currentState;
             Send(GetSelectionMessageJSON(false, false));
         }
         if (controller.CinematicSwitcher != null && cinematicIndex_ != controller.CinematicSwitcher.currentCinematic)
         {
             cinematicIndex_ = controller.CinematicSwitcher.currentCinematic;
             Send(GetCineDataMessageJSON());
         }
     }
 }
Exemplo n.º 9
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        WayPointBehaviour wpBehaviour = (WayPointBehaviour)target;
        var nodes = wpBehaviour.nodes;

        foreach (var node in nodes)
        {
            GUILayout.Label("List of arcs offsets:");
            int i = 0;
            if (node?.arcList?.list != null)
            {
                foreach (var arc in node.arcList.list)
                {
                    //arc.
                    GUILayout.Label("Arc #" + i + ", caps @" + (arc.offset + 0x10).ToString() + ", points to " +
                                    arc.graphNode.offset.ToString());
                    i++;
                }
            }
        }
    }
Exemplo n.º 10
0
    public static void DrawDsgVarValue(Rect rect, DsgVarComponent.DsgVarEditableEntry dsgVarEntry, DsgVarComponent.DsgVarEditableEntry.Value value, int?arrayIndex)
    {
        string stringVal;

        switch (value.type)
        {
        case DsgVarInfoEntry.DsgVarType.Boolean:
            value.AsBoolean = EditorGUI.Toggle(rect, value.AsBoolean);
            break;

        case DsgVarInfoEntry.DsgVarType.Int:
            value.AsInt = EditorGUI.IntField(rect, value.AsInt);
            break;

        case DsgVarInfoEntry.DsgVarType.UInt:
            stringVal = EditorGUI.TextField(rect, value.AsUInt.ToString());
            if (UInt32.TryParse(stringVal, out uint r_uint))
            {
                value.AsUInt = r_uint;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.Caps:
            stringVal = EditorGUI.TextField(rect, value.AsCaps.ToString());
            if (UInt32.TryParse(stringVal, out uint r_caps))
            {
                value.AsCaps = r_caps;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.Short:
            stringVal = EditorGUI.TextField(rect, value.AsShort.ToString());
            if (Int16.TryParse(stringVal, out short r_short))
            {
                value.AsShort = r_short;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.UShort:
            stringVal = EditorGUI.TextField(rect, value.AsUShort.ToString());
            if (UInt16.TryParse(stringVal, out ushort r_ushort))
            {
                value.AsUShort = r_ushort;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.Byte:
            stringVal = EditorGUI.TextField(rect, value.AsByte.ToString());
            if (SByte.TryParse(stringVal, out sbyte r_sbyte))
            {
                value.AsByte = r_sbyte;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.UByte:
            stringVal = EditorGUI.TextField(rect, value.AsUByte.ToString());
            if (Byte.TryParse(stringVal, out byte r_byte))
            {
                value.AsUByte = r_byte;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.Float:
            value.AsFloat = EditorGUI.FloatField(rect, value.AsFloat);
            break;

        case DsgVarInfoEntry.DsgVarType.Text:
            int?newTextID = DrawText(rect, value.AsText);
            if (newTextID.HasValue)
            {
                value.AsText = newTextID.Value;
            }
            //GUILayout.Label(MapLoader.Loader.localization.GetTextForHandleAndLanguageID((int)value.AsUInt, 0));
            break;

        case DsgVarInfoEntry.DsgVarType.Vector:
            value.AsVector = EditorGUI.Vector3Field(rect, "", value.AsVector);
            break;

        case DsgVarInfoEntry.DsgVarType.Perso:
            if (MapLoader.Loader is OpenSpace.Loader.R2ROMLoader)
            {
                ROMPersoBehaviour currentPersoBehaviour  = value.AsPersoROM != null ? value.AsPersoROM : null;
                ROMPersoBehaviour selectedPersoBehaviour = ((ROMPersoBehaviour)EditorGUI.ObjectField(rect, currentPersoBehaviour, typeof(ROMPersoBehaviour), true));

                if (selectedPersoBehaviour != null && selectedPersoBehaviour.gameObject != null)
                {
                    value.AsPersoROM = selectedPersoBehaviour;
                }
            }
            else
            {
                PersoBehaviour currentPersoBehaviour  = value.AsPerso != null ? value.AsPerso : null;
                PersoBehaviour selectedPersoBehaviour = ((PersoBehaviour)EditorGUI.ObjectField(rect, currentPersoBehaviour, typeof(PersoBehaviour), true));

                if (selectedPersoBehaviour != null && selectedPersoBehaviour.gameObject != null)
                {
                    value.AsPerso = selectedPersoBehaviour;
                }
            }
            break;

        case DsgVarInfoEntry.DsgVarType.SuperObject:
            SuperObjectComponent currentGao  = value.AsSuperObject != null ? value.AsSuperObject : null;
            SuperObjectComponent selectedGao = ((SuperObjectComponent)EditorGUI.ObjectField(rect, currentGao, typeof(SuperObjectComponent), true));

            if (selectedGao != null && selectedGao.gameObject != null)
            {
                value.AsSuperObject = selectedGao;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.WayPoint:
            WayPointBehaviour currentWaypointGao  = value.AsWayPoint != null ? value.AsWayPoint : null;
            WayPointBehaviour selectedWaypointGao = ((WayPointBehaviour)EditorGUI.ObjectField(rect, currentWaypointGao, typeof(WayPointBehaviour), true));

            if (selectedWaypointGao != null && selectedWaypointGao.gameObject != null)
            {
                value.AsWayPoint = selectedWaypointGao;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.Graph:
            GraphBehaviour currentGraphGao  = value.AsGraph != null ? value.AsGraph : null;
            GraphBehaviour selectedGraphGao = ((GraphBehaviour)EditorGUI.ObjectField(rect, currentGraphGao, typeof(GraphBehaviour), true));

            if (selectedGraphGao != null && selectedGraphGao.gameObject != null)
            {
                value.AsGraph = selectedGraphGao;
            }
            break;

        case DsgVarInfoEntry.DsgVarType.ActionArray:
        case DsgVarInfoEntry.DsgVarType.FloatArray:
        case DsgVarInfoEntry.DsgVarType.Array11:
        case DsgVarInfoEntry.DsgVarType.GraphArray:
        case DsgVarInfoEntry.DsgVarType.Array9:
        case DsgVarInfoEntry.DsgVarType.IntegerArray:
        case DsgVarInfoEntry.DsgVarType.PersoArray:
        case DsgVarInfoEntry.DsgVarType.SoundEventArray:
        case DsgVarInfoEntry.DsgVarType.SuperObjectArray:
        case DsgVarInfoEntry.DsgVarType.TextArray:
        case DsgVarInfoEntry.DsgVarType.TextRefArray:
        case DsgVarInfoEntry.DsgVarType.VectorArray:
        case DsgVarInfoEntry.DsgVarType.WayPointArray:
            if (value.AsArray != null)
            {
                if (arrayIndex.HasValue)
                {
                    if (value.AsArray[arrayIndex.Value] != null)
                    {
                        DrawDsgVarValue(rect, dsgVarEntry, value.AsArray[arrayIndex.Value], arrayIndex);
                    }
                }
                else
                {
                    EditorGUI.LabelField(rect, "Length: " + value.AsArray.Length);
                }
            }
            break;
        }
    }
Exemplo n.º 11
0
    public void Init()
    {
        if (MapLoader.Loader is OpenSpace.Loader.R2ROMLoader)
        {
            OpenSpace.Loader.R2ROMLoader l = MapLoader.Loader as OpenSpace.Loader.R2ROMLoader;
            foreach (OpenSpace.ROM.WayPoint wp in l.waypointsROM)
            {
                AddWaypoint(wp.GetGameObject());
            }
            if (graphRoot == null && l.graphsROM.Count > 0)
            {
                graphRoot = new GameObject("Graphs");
                graphRoot.transform.SetParent(transform);
                graphRoot.SetActive(false);
            }
            foreach (OpenSpace.ROM.Graph graph in l.graphsROM)
            {
                GameObject go_graph = new GameObject("Graph " + graph.Offset);
                go_graph.transform.SetParent(graphRoot.transform);
                GraphBehaviour gb = go_graph.AddComponent <GraphBehaviour>();
                gb.graphROM         = graph;
                graphROMDict[graph] = gb;

                for (int i = 0; i < graph.num_nodes; i++)
                {
                    OpenSpace.ROM.GraphNode node = graph.nodes.Value.nodes[i].Value;
                    if (node.waypoint.Value != null)
                    {
                        WayPointBehaviour wp = waypoints.FirstOrDefault(w => w.wpROM == node.waypoint.Value);
                        if (wp != null)
                        {
                            gb.nodes.Add(wp);
                            wp.nodesROM.Add(node);
                            wp.name = "GraphNode[" + i + "].WayPoint (" + wp.wpROM.Offset + ")";
                            if (i == 0)
                            {
                                go_graph.transform.position = wp.transform.position;
                            }
                            wp.transform.SetParent(go_graph.transform);
                        }
                    }
                }
            }
        }
        else
        {
            MapLoader l = MapLoader.Loader;
            foreach (WayPoint wp in l.waypoints)
            {
                AddWaypoint(wp.Gao.GetComponent <WayPointBehaviour>());
            }
            if (graphRoot == null && l.graphs.Count > 0)
            {
                graphRoot = new GameObject("Graphs");
                graphRoot.transform.SetParent(transform);
                graphRoot.SetActive(false);
            }
            foreach (Graph graph in l.graphs)
            {
                GameObject go_graph = new GameObject(graph.name ?? "Graph " + graph.offset.ToString());
                go_graph.transform.SetParent(graphRoot.transform);
                GraphBehaviour gb = go_graph.AddComponent <GraphBehaviour>();
                gb.graph         = graph;
                graphDict[graph] = gb;

                for (int i = 0; i < graph.nodes.Count; i++)
                {
                    GraphNode node = graph.nodes[i];
                    if (node == null)
                    {
                        continue;
                    }
                    if (node.wayPoint != null)
                    {
                        WayPointBehaviour wp = waypoints.FirstOrDefault(w => w.wp == node.wayPoint);
                        if (wp != null)
                        {
                            gb.nodes.Add(wp);
                            wp.nodes.Add(node);
                            wp.name = "GraphNode[" + i + "].WayPoint (" + wp.wp.offset + ")";
                            if (i == 0)
                            {
                                go_graph.transform.position = wp.transform.position;
                            }
                            wp.transform.SetParent(go_graph.transform);
                        }
                    }
                }
            }
        }

        List <WayPointBehaviour> isolateWaypoints = waypoints.Where(w => w.nodes.Count == 0 && w.nodesROM.Count == 0).ToList();

        if (isolateWaypointRoot == null && isolateWaypoints.Count > 0)
        {
            isolateWaypointRoot = new GameObject("Isolate WayPoints");
            isolateWaypointRoot.transform.SetParent(transform);
            isolateWaypointRoot.SetActive(false);
        }
        foreach (WayPointBehaviour wp in isolateWaypoints)
        {
            wp.name = "Isolate WayPoint @" + (wp.wpROM != null ? wp.wpROM.Offset : wp.wp.offset);
            wp.transform.SetParent(isolateWaypointRoot.transform);
        }
        foreach (WayPointBehaviour wp in waypoints)
        {
            wp.Init();
        }
        UpdateViewGraphs();
        //loaded = true;
    }
Exemplo n.º 12
0
 public void AddWaypoint(WayPointBehaviour wp)
 {
     waypoints.Add(wp);
     wp.manager = this;
 }
Exemplo n.º 13
0
    private void HandleCollision()
    {
        int layerMask = 0;

        if (controller.viewCollision)
        {
            layerMask |= 1 << LayerMask.NameToLayer("Collide");
        }
        else
        {
            layerMask |= 1 << LayerMask.NameToLayer("Visual");
        }
        if (controller.viewGraphs)
        {
            layerMask |= 1 << LayerMask.NameToLayer("Graph");
        }
        Ray ray = cam.cam.ScreenPointToRay(Input.mousePosition);

        RaycastHit[] hits = Physics.RaycastAll(ray, Mathf.Infinity, layerMask, QueryTriggerInteraction.Ignore);
        if (hits != null && hits.Length > 0)
        {
            System.Array.Sort(hits, (x, y) => (x.distance.CompareTo(y.distance)));
            if (controller.showPersos)
            {
                for (int i = 0; i < hits.Length; i++)
                {
                    // the object identified by hit.transform was clicked
                    BasePersoBehaviour pb = hits[i].transform.GetComponentInParent <BasePersoBehaviour>();
                    if (pb != null)
                    {
                        highlightedPerso = pb;
                        if (Input.GetMouseButtonDown(0))
                        {
                            IsSelecting = true;
                        }
                        UpdateHighlight();
                        if (IsSelecting)
                        {
                            if (cam.IsPanningWithThreshold())
                            {
                                IsSelecting = false;
                            }
                            else if (Input.GetMouseButtonUp(0))
                            {
                                Select(pb, view: true);
                            }
                        }
                        break;
                    }
                }
            }
            if (controller.viewCollision)
            {
                for (int i = 0; i < hits.Length; i++)
                {
                    CollideComponent cc = hits[i].transform.GetComponent <CollideComponent>();
                    if (cc != null)
                    {
                        highlightedCollision = cc;
                        break;
                    }
                }
            }
            if (controller.viewGraphs)
            {
                for (int i = 0; i < hits.Length; i++)
                {
                    WayPointBehaviour wp = hits[i].transform.GetComponent <WayPointBehaviour>();
                    if (wp != null)
                    {
                        highlightedWayPoint = wp;
                        break;
                    }
                }
            }

            /*SectorComponent sector = hit.transform.GetComponentInParent<SectorComponent>();
             * if (sector != null) {
             *  JumpTo(sector.gameObject);
             *  return;
             * }*/
        }

        /*if (Input.GetMouseButtonDown(0)) { // if left button pressed...
         *  if (Physics.Raycast(ray, out hit)) {
         *      // the object identified by hit.transform was clicked
         *      PersoBehaviour pb = hit.transform.GetComponentInParent<PersoBehaviour>();
         *      if (pb != null) {
         *          JumpTo(pb.gameObject);
         *          return;
         *      }
         *      SectorComponent sector = hit.transform.GetComponentInParent<SectorComponent>();
         *      if (sector != null) {
         *          JumpTo(sector.gameObject);
         *          return;
         *      }
         *  }
         * }*/
    }
Exemplo n.º 14
0
 public void Init()
 {
     if (nodes.Count > 0)
     {
         foreach (GraphNode node in nodes)
         {
             for (int i = 0; i < node.arcList.list.Count; i++)
             {
                 Arc   arc   = node.arcList.list[i];
                 Color color = Color.white;
                 if (arc.weight == -1)
                 {
                     color = Color.white;
                 }
                 else
                 {
                     Random.InitState((int)arc.capabilities * 33);
                     color = Random.ColorHSV(0, 1, 0.2f, 1f, 0.4f, 1.0f);
                 }
                 LineRenderer lr = new GameObject("Arc").AddComponent <LineRenderer>();
                 lr.transform.SetParent(transform);
                 lr.material              = new Material(Shader.Find("Custom/Line"));
                 lr.gameObject.hideFlags |= HideFlags.HideInHierarchy;
                 lr.material.color        = color;
                 lr.positionCount         = 2;
                 lr.useWorldSpace         = true;
                 WayPointBehaviour tar = manager.waypoints.FirstOrDefault(w => w.nodes.Contains(arc.graphNode));
                 lr.SetPositions(new Vector3[] { transform.position, tar.transform.position });
                 lr.widthMultiplier = (arc.weight > 0 ? arc.weight : 30f) / 30f;
                 lines.Add(lr);
                 targets.Add(tar);
                 //DrawLineThickness(transform.position, arc.graphNode.Gao.transform.position, arc.weight > 0 ? arc.weight : 100);
             }
         }
     }
     else if (nodesROM.Count > 0)
     {
         foreach (OpenSpace.ROM.GraphNode node in nodesROM)
         {
             for (int i = 0; i < node.num_arcs; i++)
             {
                 Color color  = Color.white;
                 int   weight = -1;
                 if (node.arcs_weights.Value != null && node.arcs_weights.Value.weights[i] != 0xFFFF)
                 {
                     weight = node.arcs_weights.Value.weights[i];
                 }
                 if (weight == -1)
                 {
                     color = Color.white;
                 }
                 else
                 {
                     uint caps = 0;
                     if (node.arcs_caps.Value != null)
                     {
                         caps = node.arcs_caps.Value.caps[i];
                     }
                     Random.InitState((int)caps * 33);
                     color = Random.ColorHSV(0, 1, 0.2f, 1f, 0.4f, 1.0f);
                 }
                 LineRenderer lr = new GameObject("Arc").AddComponent <LineRenderer>();
                 lr.transform.SetParent(transform);
                 lr.material              = new Material(Shader.Find("Custom/Line"));
                 lr.gameObject.hideFlags |= HideFlags.HideInHierarchy;
                 lr.material.color        = color;
                 lr.positionCount         = 2;
                 lr.useWorldSpace         = true;
                 WayPointBehaviour tar = manager.waypoints.FirstOrDefault(w => w.nodesROM.Contains(node.arcs_nodes.Value.nodes[i].Value));
                 lr.SetPositions(new Vector3[] { transform.position, tar.transform.position });
                 lr.widthMultiplier = (weight > 0 ? weight : 30f) / 30f;
                 lines.Add(lr);
                 targets.Add(tar);
                 //DrawLineThickness(transform.position, arc.graphNode.Gao.transform.position, arc.weight > 0 ? arc.weight : 100);
             }
         }
     }
     CreateMesh();
 }