Ejemplo n.º 1
0
    IList <StateTransitionsTreeElement> GetData()
    {
        PersoBehaviour pb = (PersoBehaviour)target;
        List <StateTransitionsTreeElement> tr = new List <StateTransitionsTreeElement>();

        tr.Add(new StateTransitionsTreeElement("Hidden root", -1, -1));
        BasePersoBehaviour.StateTransition[] transitions = pb.GetStateTransitions(pb.currentState);
        if (transitions != null)
        {
            int id = 0;
            foreach (var t in transitions)
            {
                tr.Add(new StateTransitionsTreeElement("State transition " + t.TargetStateName, 0, id)
                {
                    stateToGoName    = t.StateToGoName,
                    stateToGoIndex   = t.StateToGoIndex,
                    targetStateName  = t.TargetStateName,
                    targetStateIndex = t.TargetStateIndex,
                    linkingType      = t.LinkingType
                });
                id++;
            }
        }
        return(tr);
    }
Ejemplo n.º 2
0
        public void Write(Writer writer)
        {
            PersoBehaviour persoBehaviour = gao.GetComponent <PersoBehaviour>();

            if (p3dData != null && persoBehaviour != null && persoBehaviour.state != null && persoBehaviour.state.offset != null)
            {
                if (persoBehaviour.state.offset != p3dData.off_stateCurrent)
                {
                    p3dData.off_stateCurrent = persoBehaviour.state.offset;
                    Pointer.Goto(ref writer, p3dData.offset);
                    p3dData.Write(writer);
                } /*else {
                   * MapLoader.Loader.print("do not write state for perso " + fullName);
                   * }*/
            }

            if (persoBehaviour.clearTheBrain)
            {
                Pointer.Goto(ref writer, this.offset + 0xC); // perso + 0xC = Brain *
                Pointer.Write(writer, null);
                persoBehaviour.clearTheBrain = false;
            }

            CustomBitsComponent customBits = gao.GetComponent <CustomBitsComponent>();

            if (customBits != null && customBits.modified && stdGame != null)
            {
                Pointer.Goto(ref writer, stdGame.offset);
                stdGame.Write(writer);
            }
        }
Ejemplo n.º 3
0
    public void SetCinematic(int index)
    {
        if (index < 0 || index > cinematicsManager.cinematics.Count)
        {
            return;
        }
        cinematicIndex   = index;
        currentCinematic = index;
        index--;

        actors = new PersoBehaviour[0];
        if (cinematic != null)
        {
            foreach (CinematicActor actor in cinematic.actors)
            {
                PersoBehaviour pb = actor.perso.Gao.GetComponent <PersoBehaviour>();
                actor.cineState.anim_ref = MapLoader.Loader.FromOffset <AnimationReference>(actor.cineState.off_anim_ref);
                pb.SetState(actor.waitState.index);
            }
            cinematic = null;
        }
        if (index != -1)
        {
            cinematic = cinematicsManager.cinematics[index];
            actors    = cinematic.actors.Select(a => a.perso.Gao.GetComponent <PersoBehaviour>()).ToArray();
            foreach (CinematicActor actor in cinematic.actors)
            {
                PersoBehaviour pb = actor.perso.Gao.GetComponent <PersoBehaviour>();
                actor.cineState.anim_ref = actor.anim_ref;
                actor.cineState.speed    = actor.cineStateSpeed;
                pb.SetState(actor.cineState.index);
            }
        }
    }
Ejemplo n.º 4
0
    private JSONObject GetPersoJSON(Perso perso)
    {
        JSONObject     persoJSON = new JSONObject();
        PersoBehaviour pb        = perso.Gao.GetComponent <PersoBehaviour>();

        persoJSON["offset"]       = perso.offset.ToString();
        persoJSON["nameFamily"]   = perso.nameFamily;
        persoJSON["nameModel"]    = perso.nameModel;
        persoJSON["nameInstance"] = perso.namePerso;
        if (perso.p3dData.family != null)
        {
            persoJSON["family"] = perso.p3dData.family.family_index;
        }
        if (pb != null)
        {
            persoJSON["enabled"] = pb.IsEnabled;
            persoJSON["state"]   = pb.stateIndex;
            if (perso.p3dData.objectList != null)
            {
                persoJSON["objectList"] = pb.poListIndex;
            }
            persoJSON["playAnimation"]  = pb.playAnimation;
            persoJSON["animationSpeed"] = pb.animationSpeed;
            persoJSON["autoNextState"]  = pb.autoNextState;
        }
        return(persoJSON);
    }
Ejemplo n.º 5
0
    void ExportAnimationsData()
    {
        PersoBehaviour pb = (PersoBehaviour)target;
        PersoAnimationsDataExporter pade = new PersoAnimationsDataExporter(pb);

        pade.ExportPersoStatesAnimations();
    }
Ejemplo n.º 6
0
 public void Update()
 {
     if (controller.LoadState == Controller.State.Finished && !sentHierarchy)
     {
         SendHierarchy();
         sentHierarchy = true;
     }
     if (controller.LoadState == Controller.State.Finished)
     {
         if (highlightedPerso_ != selector.highlightedPerso)
         {
             highlightedPerso_ = selector.highlightedPerso;
             Send(GetHighlightJSON());
         }
         if (selectedPerso_ != selector.selectedPerso)
         {
             selectedPerso_ = selector.selectedPerso;
             if (selectedPerso_ != null)
             {
                 selectedPersoStateIndex_ = selectedPerso_.stateIndex;
                 Send(GetSelectionJSON());
             }
         }
         if (selectedPerso_ != null && selectedPersoStateIndex_ != selectedPerso_.stateIndex)
         {
             selectedPersoStateIndex_ = selectedPerso_.stateIndex;
             Send(GetSelectionJSON());
         }
     }
 }
Ejemplo n.º 7
0
    void UpdateTooFarLimit()
    {
        if (tooFarLimitDiamond == null)
        {
            InitTooFarLimit();
        }
        PersoBehaviour pb = selectedPerso == null ? null : selectedPerso as PersoBehaviour;

        if (pb != null && controller.viewCollision && pb.perso != null &&
            pb.perso.stdGame != null && pb.perso.stdGame.tooFarLimit > 0)
        {
            if (!tooFarLimitDiamond.activeSelf)
            {
                tooFarLimitDiamond.SetActive(true);
            }
            tooFarLimitDiamond.transform.localScale    = Vector3.one * pb.perso.stdGame.tooFarLimit;
            tooFarLimitDiamond.transform.localRotation = Quaternion.identity;
            tooFarLimitDiamond.transform.position      = selectedPerso.transform.position;
        }
        else
        {
            if (tooFarLimitDiamond.activeSelf)
            {
                tooFarLimitDiamond.SetActive(false);
            }
        }
    }
Ejemplo n.º 8
0
    void InitTransitionsTreeIfNeeded(Rect transitionsRect, PersoBehaviour target)
    {
        if (treeViewStateTransitions == null || treeviewStateTransitionsState == null || treeViewStateTransitions.perso != target)
        {
            treeviewStateTransitionsState = new TreeViewState();

            bool firstInit   = m_MultiColumnHeaderState == null;
            var  headerState = StateTransitionsTreeView.CreateDefaultMultiColumnHeaderState(transitionsRect.width);
            if (MultiColumnHeaderState.CanOverwriteSerializedFields(m_MultiColumnHeaderState, headerState))
            {
                MultiColumnHeaderState.OverwriteSerializedFields(m_MultiColumnHeaderState, headerState);
            }
            m_MultiColumnHeaderState = headerState;

            var multiColumnHeader = new MultiColumnHeader(headerState);
            if (firstInit)
            {
                multiColumnHeader.ResizeToFit();
            }

            var treeModel = new TreeModel <StateTransitionsTreeElement>(GetData());

            treeViewStateTransitions = new StateTransitionsTreeView(treeviewStateTransitionsState, multiColumnHeader, treeModel)
            {
                perso      = target,
                stateIndex = target.stateIndex,
            };
        }
    }
Ejemplo n.º 9
0
    private void ParseSelectionJSON(JSONNode msg)
    {
        MapLoader   l     = MapLoader.Loader;
        Perso       perso = null;
        SuperObject so    = null;

        if (msg["offset"] != null && msg["offset"] != "null")
        {
            if (msg["type"] != null && msg["type"] == SuperObject.Type.Perso.ToString())
            {
                perso = l.persos.FirstOrDefault(p => p.offset.ToString() == msg["offset"]);
                if (perso != null)
                {
                    PersoBehaviour pb = perso.Gao.GetComponent <PersoBehaviour>();
                    selector.Select(pb, view: msg["view"] != null);
                }
            }
            else
            {
                so = l.superObjects.FirstOrDefault(s => s.offset.ToString() == msg["offset"]);
                if (so != null)
                {
                    selector.Select(so);
                }
            }
        }
        else
        {
            selector.Deselect();
        }
    }
Ejemplo n.º 10
0
    IList <StateTransitionTreeElement> GetData()
    {
        PersoBehaviour pb = (PersoBehaviour)target;
        List <StateTransitionTreeElement> tr = new List <StateTransitionTreeElement>();

        tr.Add(new StateTransitionTreeElement("Hidden root", -1, -1));
        if (pb.state != null && pb.state.stateTransitions != null && pb.state.stateTransitions.Count > 0)
        {
            int id = 0;
            foreach (State.Transition t in pb.state.stateTransitions)
            {
                if (t != null)
                {
                    State stateToGo   = State.FromOffset(t.off_stateToGo);
                    State targetState = State.FromOffset(t.off_targetState);
                    tr.Add(new StateTransitionTreeElement("State transition " + targetState.ToString(), 0, id)
                    {
                        stateToGoName    = stateToGo.ToString(),
                        stateToGoIndex   = stateToGo.index,
                        targetStateName  = targetState.ToString(),
                        targetStateIndex = targetState.index,
                        linkingType      = t.linkingType
                    });
                    id++;
                }
            }
        }
        return(tr);
    }
Ejemplo n.º 11
0
    public void RecalculateSectorLighting()
    {
        foreach (SectorComponent sc in sectors)
        {
            ApplySectorLighting(sc, sc.Gao, LightInfo.ObjectLightedFlag.Environment);

            /*foreach (Perso p in sc.sector.persos) {
             *      if (p.Gao) {
             *              PersoBehaviour pb = p.Gao.GetComponent<PersoBehaviour>();
             *              if (pb != null) {
             *                      pb.sector = sc;
             *              }
             *      }
             * }*/
        }
        if (loaded)
        {
            foreach (Perso p in MapLoader.Loader.persos)
            {
                PersoBehaviour pb = p.Gao.GetComponent <PersoBehaviour>();
                ApplySectorLighting(pb.sector, p.Gao, LightInfo.ObjectLightedFlag.Perso);
            }
            foreach (ROMPersoBehaviour p in controller.romPersos)
            {
                ApplySectorLighting(p.sector, p.gameObject, LightInfo.ObjectLightedFlag.Perso);
            }
        }
    }
Ejemplo n.º 12
0
    private JSONObject GetBrainJSON(Perso perso, bool includeScriptContents = false)
    {
        JSONObject     brainJSON = new JSONObject();
        PersoBehaviour pb        = perso.Gao.GetComponent <PersoBehaviour>();

        if (perso.brain != null && perso.brain.mind != null && perso.brain.mind.AI_model != null)
        {
            if (perso.brain.mind.AI_model.behaviors_normal != null && perso.brain.mind.AI_model.behaviors_normal.Length > 0)
            {
                JSONArray  ruleBehaviorsJSON = new JSONArray();
                Behavior[] ruleBehaviors     = perso.brain.mind.AI_model.behaviors_normal;
                int        iter = 0;
                foreach (Behavior behavior in ruleBehaviors)
                {
                    ruleBehaviorsJSON.Add(GetBehaviorJSON(perso, behavior,
                                                          perso.brain.mind.AI_model, Behavior.BehaviorType.Intelligence, iter,
                                                          includeScriptContents));
                    iter++;
                }
                brainJSON["ruleBehaviors"] = ruleBehaviorsJSON;
            }
            if (perso.brain.mind.AI_model.behaviors_reflex != null && perso.brain.mind.AI_model.behaviors_reflex.Length > 0)
            {
                JSONArray  reflexBehaviorsJSON = new JSONArray();
                Behavior[] reflexBehaviors     = perso.brain.mind.AI_model.behaviors_reflex;
                int        iter = 0;
                foreach (Behavior behavior in reflexBehaviors)
                {
                    reflexBehaviorsJSON.Add(GetBehaviorJSON(perso, behavior,
                                                            perso.brain.mind.AI_model, Behavior.BehaviorType.Reflex, iter,
                                                            includeScriptContents));
                    iter++;
                }
                brainJSON["reflexBehaviors"] = reflexBehaviorsJSON;
            }
            if (perso.brain.mind.AI_model.macros != null && perso.brain.mind.AI_model.macros.Length > 0)
            {
                JSONArray macrosJSON = new JSONArray();
                Macro[]   macros     = perso.brain.mind.AI_model.macros;
                int       iter       = 0;
                foreach (Macro macro in macros)
                {
                    macrosJSON.Add(GetBehaviorJSON(perso, macro,
                                                   perso.brain.mind.AI_model, null, iter,
                                                   includeScriptContents));
                    iter++;
                }
                brainJSON["macros"] = macrosJSON;
            }
        }
        JSONArray dsgVars = GetDsgVarsJSON(perso);

        if (dsgVars != null && dsgVars.Count > 0)
        {
            brainJSON["dsgVars"] = dsgVars;
        }

        return(brainJSON);
    }
Ejemplo n.º 13
0
 public void Select(PersoBehaviour pb, bool view = false)
 {
     //print(pb.name);
     if (selectedPerso != pb || view)
     {
         selectedPerso = pb;
         cam.JumpTo(pb.gameObject);
     }
 }
Ejemplo n.º 14
0
    private JSONObject GetDsgVarValueJSON(DsgVarComponent.DsgVarEditableEntry.Value value)
    {
        if (value == null)
        {
            return(null);
        }
        JSONObject dsgObj = new JSONObject();

        dsgObj["string"] = value.ToString();
        switch (value.type)
        {
        case DsgVarInfoEntry.DsgVarType.Perso:
            PersoBehaviour pb = value.AsPerso;
            if (pb != null)
            {
                Perso p = pb.perso;
                if (p != null)
                {
                    JSONObject persoJSON = new JSONObject();
                    persoJSON["offset"]       = p.offset.ToString();
                    persoJSON["nameFamily"]   = p.nameFamily;
                    persoJSON["nameModel"]    = p.nameModel;
                    persoJSON["nameInstance"] = p.namePerso;
                    dsgObj["perso"]           = persoJSON;
                }
            }
            break;

        case DsgVarInfoEntry.DsgVarType.SuperObject:
            SuperObjectComponent soc = value.AsSuperObject;
            if (soc != null)
            {
                SuperObject spo    = soc.so;
                JSONObject  soJSON = new JSONObject();
                soJSON["offset"] = spo.offset.ToString();
                soJSON["type"]   = spo.type.ToString();
                soJSON["offset"] = spo.offset.ToString();
                if (spo.type == SuperObject.Type.Perso && spo.data != null)
                {
                    Perso p = spo.data as Perso;
                    if (p != null)
                    {
                        JSONObject persoJSON = new JSONObject();
                        persoJSON["offset"]       = p.offset.ToString();
                        persoJSON["nameFamily"]   = p.nameFamily;
                        persoJSON["nameModel"]    = p.nameModel;
                        persoJSON["nameInstance"] = p.namePerso;
                        soJSON["perso"]           = persoJSON;
                    }
                }
                dsgObj["value"] = soJSON;
            }
            break;
        }
        return(dsgObj);
    }
Ejemplo n.º 15
0
    private void HandleCollision()
    {
        int layerMask = 0;

        if (controller.viewCollision)
        {
            layerMask |= 1 << LayerMask.NameToLayer("Collide");
        }
        else
        {
            layerMask |= 1 << LayerMask.NameToLayer("Visual");
        }
        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)));
            for (int i = 0; i < hits.Length; i++)
            {
                // the object identified by hit.transform was clicked
                PersoBehaviour pb = hits[i].transform.GetComponentInParent <PersoBehaviour>();
                if (pb != null)
                {
                    highlightedPerso = pb;
                    if (Input.GetMouseButtonDown(0))
                    {
                        Select(pb, view: true);
                    }
                    return;
                }
            }

            /*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;
         *      }
         *  }
         * }*/
    }
Ejemplo n.º 16
0
        public static void CreatePersoScript(PersoBehaviour pb, string description, string author, string rank)
        {
            string baseName = "";
            string newName  = "";
            string newDir   = "";

            switch (rank)
            {
            case "Family":
                newName = pb.perso.nameFamily;
                newDir  = $"{persoPath}/{pb.perso.nameFamily}";
                break;

            case "Model":
                baseName = pb.perso.nameFamily;
                newName  = pb.perso.nameModel;
                newDir   = $"{persoPath}/{pb.perso.nameFamily}/Models";
                break;

            case "Instance":
                baseName = pb.perso.nameModel;
                newName  = pb.perso.namePerso;
                newDir   = $"{persoLvlPath}";
                break;
            }

            if (!Directory.Exists(newDir))
            {
                Directory.CreateDirectory(newDir);
            }
            string newPath = $"{newDir}/{newName}.cs";

            if (File.Exists(newPath))
            {
                return;
            }

            var scr  = new StreamReader($"Assets/Scripts/RaymapGame/PersoEditor/Objects/NewScript_{rank}.txt");
            var outs = scr.ReadToEnd()
                       .Replace("Author", author)
                       .Replace("NewScript", newName)
                       .Replace("DerivedScript", baseName)
                       .Replace("Description", description).Split(new string[] { "~~" }, System.StringSplitOptions.RemoveEmptyEntries);

            var newScr = new StreamWriter(newPath);

            if (author != "")
            {
                newScr.Write(outs[0]);
            }
            newScr.Write(outs[1]);

            scr.Close();
            newScr.Close();
        }
Ejemplo n.º 17
0
 public void UpdateViewCollision()
 {
     if (loader != null)
     {
         viewCollision_ = viewCollision;
         foreach (PhysicalObject po in loader.physicalObjects)
         {
             if (po != null)
             {
                 po.UpdateViewCollision(viewCollision);
             }
         }
         foreach (Perso perso in loader.persos)
         {
             if (perso != null && perso.Gao != null)
             {
                 PersoBehaviour pb = perso.Gao.GetComponent <PersoBehaviour>();
                 pb.UpdateViewCollision(viewCollision);
             }
         }
         foreach (ROMPersoBehaviour perso in romPersos)
         {
             if (perso != null)
             {
                 perso.UpdateViewCollision(viewCollision);
             }
         }
         foreach (SuperObject so in loader.superObjects)
         {
             if (so.Gao != null)
             {
                 if (so.flags.HasFlag(OpenSpace.Object.Properties.SuperObjectFlags.Flags.Invisible))
                 {
                     if (so.type == SuperObject.Type.Perso)
                     {
                         UpdatePersoActive(so.data as Perso);
                     }
                     else
                     {
                         so.Gao.SetActive(viewCollision || viewInvisible);
                     }
                 }
             }
         }
         if (loader is OpenSpace.Loader.R2ROMLoader)
         {
             PhysicalObjectComponent[] pos = FindObjectsOfType <PhysicalObjectComponent>();
             foreach (PhysicalObjectComponent po in pos)
             {
                 po.UpdateViewCollision(viewCollision);
             }
         }
     }
 }
Ejemplo n.º 18
0
 public void InitPersos()
 {
     if (loader != null)
     {
         for (int i = 0; i < loader.persos.Count; i++)
         {
             PersoBehaviour unityBehaviour = loader.persos[i].Gao.AddComponent <PersoBehaviour>();
             unityBehaviour.perso = loader.persos[i];
             unityBehaviour.Init();
         }
     }
 }
Ejemplo n.º 19
0
 public void UpdatePersoActive(Perso perso)
 {
     if (perso != null && perso.Gao != null)
     {
         PersoBehaviour pb = perso.Gao.GetComponent <PersoBehaviour>();
         if (pb != null)
         {
             bool isVisible = true;
             if (perso.SuperObject != null)
             {
                 isVisible = !perso.SuperObject.flags.HasFlag(OpenSpace.Object.Properties.SuperObjectFlags.Flags.Invisible);
             }
             perso.Gao.SetActive(showPersos && pb.IsEnabled && (isVisible || (viewCollision || viewInvisible)));
         }
     }
 }
Ejemplo n.º 20
0
    void Update()
    {
        highlightedPerso = null;
        Rect screenRect = new Rect(0, 0, Screen.width, Screen.height);

        if (!cam.mouseLookEnabled &&
            controller.LoadState == Controller.State.Finished &&
            screenRect.Contains(Input.mousePosition))
        {
            HandleCollision();
        }
        if (controller.LoadState == Controller.State.Finished)
        {
            UpdateTooFarLimit();
        }
    }
Ejemplo n.º 21
0
    void ExportMeshesData()
    {
        PersoBehaviour pb     = (PersoBehaviour)target;
        var            meshes = pb.gameObject.GetComponentsInChildren <ExportableModel>();

        foreach (var m in meshes)
        {
            if (m.gameObject.activeInHierarchy)
            {
                if (m != m.gameObject.transform.parent.GetComponentsInChildren <ExportableModel>()[0])                  // Ignore any ExportableModel that's not the first of its siblinngs
                {
                    continue;
                }
                m.AddToExportObjectsLibrary();
            }
        }
    }
Ejemplo n.º 22
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        PersoBehaviour pb = (PersoBehaviour)target;

        pb.stateIndex = EditorGUILayout.Popup(pb.stateIndex, pb.stateNames);

        GUILayout.BeginHorizontal();
        GUI.enabled = pb.stateIndex > 0;
        if (GUILayout.Button("Previous state"))
        {
            pb.SetState(pb.stateIndex - 1);
        }
        GUI.enabled = (pb.stateNames != null && pb.stateIndex < pb.stateNames.Length - 1);
        if (GUILayout.Button("Next state"))
        {
            pb.SetState(pb.stateIndex + 1);
        }
        GUI.enabled = true;
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Print scripts"))
        {
            pb.PrintScripts();
        }
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Print DsgVar"))
        {
            pb.PrintDsgVar();
        }
        if (GUILayout.Button("Print DsgVar from Mind->DsgMem"))
        {
            pb.PrintDsgVarFromMindMem();
        }
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Print Animation Debug Info"))
        {
            pb.PrintAnimationDebugInfo();
        }
    }
Ejemplo n.º 23
0
    private void ParsePersoJSON(JSONNode msg)
    {
        MapLoader l     = MapLoader.Loader;
        Perso     perso = null;

        if (msg["offset"] != null)
        {
            perso = l.persos.FirstOrDefault(p => p.offset.ToString() == msg["offset"]);
        }
        if (perso != null)
        {
            PersoBehaviour pb = perso.Gao.GetComponent <PersoBehaviour>();
            if (msg["enabled"] != null)
            {
                pb.IsEnabled = (msg["enabled"].AsBool);
            }
            if (msg["state"] != null)
            {
                pb.SetState(msg["state"].AsInt);
                if (pb == selectedPerso_)
                {
                    selectedPersoStateIndex_ = msg["state"].AsInt;
                }
            }
            if (msg["objectList"] != null)
            {
                pb.poListIndex = msg["objectList"].AsInt;
            }
            if (msg["playAnimation"] != null)
            {
                pb.playAnimation = msg["playAnimation"].AsBool;
            }
            if (msg["animationSpeed"] != null)
            {
                pb.animationSpeed = msg["animationSpeed"].AsFloat;
            }
            if (msg["autoNextState"] != null)
            {
                pb.autoNextState = msg["autoNextState"].AsBool;
            }
        }
    }
Ejemplo n.º 24
0
    public void JumpTo(GameObject gao)
    {
        Vector3?       center = null, size = null;
        PersoBehaviour pb = gao.GetComponent <PersoBehaviour>();

        if (pb != null)
        {
            //print(pb.perso.SuperObject.boundingVolume.Center + " - " + pb.perso.SuperObject.boundingVolume.Size);
            center = (pb.perso.SuperObject != null && pb.perso.SuperObject.boundingVolume != null) ? (pb.transform.position + pb.perso.SuperObject.boundingVolume.Center) : pb.transform.position;
            size   = (pb.perso.SuperObject != null && pb.perso.SuperObject.boundingVolume != null) ? Vector3.Scale(pb.perso.SuperObject.boundingVolume.Size, pb.transform.lossyScale) : pb.transform.lossyScale;
        }
        else
        {
            SuperObjectComponent sc = gao.GetComponent <SuperObjectComponent>();
            if (sc != null)
            {
                center = (gao.transform.position + sc.so.boundingVolume.Center);
                size   = Vector3.Scale(sc.so.boundingVolume.Size, gao.transform.lossyScale);
            }
        }
        if (center.HasValue)
        {
            float cameraDistance = 4.0f;                                                     // Constant factor
            float objectSize     = Mathf.Min(5f, Mathf.Max(size.Value.x, size.Value.y, size.Value.z));
            float cameraView     = 2.0f * Mathf.Tan(0.5f * Mathf.Deg2Rad * cam.fieldOfView); // Visible height 1 meter in front
            float distance       = cameraDistance * objectSize / cameraView;                 // Combined wanted distance from the object
            distance += objectSize;                                                          // Estimated offset from the center to the outside of the object * 2

            /*transform.position = center.Value + -transform.right * distance;
             * transform.LookAt(center.Value, Vector3.up);*/
            //transform.LookAt(center.Value, Vector3.up);
            //transform.position = center.Value + Vector3.Normalize(transform.position - center.Value) * distance;
            targetPos = center.Value + Vector3.Normalize(transform.position - center.Value) * distance;
            if (center.Value - transform.position != Vector3.zero)
            {
                targetRot = Quaternion.LookRotation(center.Value - transform.position, Vector3.up);
            }
        }
    }
Ejemplo n.º 25
0
        public void Write(Writer writer)
        {
            PersoBehaviour persoBehaviour = gao.GetComponent <PersoBehaviour>();

            if (p3dData != null && persoBehaviour != null && persoBehaviour.state != null && persoBehaviour.state.offset != null)
            {
                if (persoBehaviour.state.offset != p3dData.off_stateCurrent)
                {
                    p3dData.off_stateCurrent = persoBehaviour.state.offset;
                    p3dData.Write(writer);
                } /*else {
                   * MapLoader.Loader.print("do not write state for perso " + fullName);
                   * }*/
            }

            if (persoBehaviour.clearTheBrain)
            {
                if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                {
                    Pointer.Goto(ref writer, offset + 0x10);
                }
                else
                {
                    Pointer.Goto(ref writer, offset + 0xC);
                }
                Pointer.Write(writer, null);
                persoBehaviour.clearTheBrain = false;
            }

            CustomBitsComponent customBits = gao.GetComponent <CustomBitsComponent>();

            if (customBits != null && customBits.modified && stdGame != null)
            {
                stdGame.Write(writer);
            }
        }
Ejemplo n.º 26
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        PersoBehaviour pb = (PersoBehaviour)target;

        pb.poListIndex = EditorGUILayout.Popup("Objects List", pb.poListIndex, pb.poListNames);
        pb.stateIndex  = EditorGUILayout.Popup(pb.stateIndex, pb.stateNames);

        /*if (pb.perso != null && pb.perso.p3dData != null) {
         *  GUILayout.Label("S0: " + pb.perso.p3dData.off_stateInitial);
         *  GUILayout.Label("S1: " + pb.perso.p3dData.off_stateCurrent);
         *  GUILayout.Label("S2: " + pb.perso.p3dData.off_state2);
         * }*/

        GUILayout.BeginVertical();
        byte updateCheckByte = pb.perso.stdGame.miscFlags;

        GUILayout.Label("StdGame: " + pb.perso.stdGame.offset.ToString());
        GUILayout.Label("StdGame.UpdateByte: " + Convert.ToString(updateCheckByte, 2).PadLeft(8, '0'));
        bool consideredOnScreen   = (updateCheckByte & (1 << 5)) != 0;
        bool consideredTooFarAway = (updateCheckByte & (1 << 7)) != 0;

        GUILayout.Label("Considered on screen (bit 5): " + consideredOnScreen);
        GUILayout.Label("Considered too far away (bit 7): " + consideredTooFarAway);
        GUILayout.Label("State custom bits: " + Convert.ToString(pb.state != null ? pb.state.customStateBits : 0, 2).PadLeft(8, '0'));

        /* // Only enable when working on morph data, it prevents from using the buttons properly otherwise
         * if (pb.a3d != null && pb.morphDataArray != null) {
         * for (int i = 0; i < pb.a3d.num_channels; i++) {
         * AnimMorphData currentMorphData = pb.morphDataArray[i, pb.currentFrame];
         *
         * if (currentMorphData != null) {
         *  GUILayout.Label("MorphData[" + i + "," + pb.currentFrame + "]: Morph to " + currentMorphData.objectIndexTo + ", progress " + currentMorphData.morphProgress);
         * }
         * }
         * }*/
        GUILayout.EndVertical();

        GUILayout.BeginHorizontal();
        GUI.enabled = pb.currentState > 0;
        if (GUILayout.Button("Previous state"))
        {
            pb.SetState(pb.currentState - 1);
        }
        GUI.enabled = (pb.stateNames != null && pb.currentState < pb.stateNames.Length - 1);
        if (GUILayout.Button("Next state"))
        {
            pb.SetState(pb.currentState + 1);
        }
        GUI.enabled = true;
        GUILayout.EndHorizontal();

        if (pb.IsLoaded)
        {
            Rect rect = GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth, 100f);
            InitTransitionsTreeIfNeeded(rect, pb);
            if (treeViewStateTransitions.stateIndex != pb.currentState ||
                treeViewStateTransitions.perso != pb)
            {
                treeViewStateTransitions.perso      = pb;
                treeViewStateTransitions.stateIndex = pb.currentState;
                treeViewStateTransitions.treeModel.SetData(GetData());
                treeViewStateTransitions.Reload();
            }
            treeViewStateTransitions.OnGUI(rect);
        }

        /*if (pb.state != null && pb.state.stateTransitions != null && pb.state.stateTransitions.Count > 0) {
         *      GUILayout.Label("State transition");
         *      GUILayout.BeginHorizontal();
         *      GUILayout.Label("Target State");
         *      GUILayout.Label("State To Go");
         *      GUILayout.EndHorizontal();
         *      foreach (State.Transition t in pb.state.stateTransitions) {
         *              if (t != null) {
         *                      State stateToGo = State.FromOffset(t.off_stateToGo);
         *                      State targetState = State.FromOffset(t.off_targetState);
         *                      if (stateToGo != null && targetState != null) {
         *                              GUILayout.BeginHorizontal();
         *                              if (GUILayout.Button(targetState.ToString())) pb.SetState(targetState);
         *                              if (GUILayout.Button(stateToGo.ToString())) pb.SetState(stateToGo);
         *                              GUILayout.EndHorizontal();
         *                      }
         *              }
         *      }
         * }*/

        if (GUILayout.Button("Print scripts"))
        {
            pb.PrintScripts();
        }
        if (GUILayout.Button("Print translated scripts"))
        {
            pb.PrintTranslatedScripts();
        }

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Print DsgVar"))
        {
            pb.PrintDsgVar();
        }
        if (GUILayout.Button("Print DsgVar from Mind->DsgMem"))
        {
            pb.PrintDsgVarFromMindMem();
        }
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Print Animation Debug Info"))
        {
            pb.PrintAnimationDebugInfo();
        }
        if (GUILayout.Button("Export Meshes and Animations Data (including cleanup)"))
        {
            ExportMeshesAndAnimationsData();
        }
        if (GUILayout.Button("Export Meshes Data"))
        {
            ExportMeshesData();
        }
        if (GUILayout.Button("Export Animations Data"))
        {
            ExportAnimationsData();
        }
    }
Ejemplo n.º 27
0
    public void UpdateLivePreview()
    {
        Reader reader = MapLoader.Loader.livePreviewReader;

        foreach (SuperObject so in MapLoader.Loader.superObjects)
        {
            if (!(so.data is Perso))
            {
                continue;
            }

            if (so.off_matrix == null)
            {
                continue;
            }
            Pointer.Goto(ref reader, so.off_matrix);
            so.matrix = Matrix.Read(MapLoader.Loader.livePreviewReader, so.off_matrix);
            if (so.data != null && so.data.Gao != null)
            {
                so.data.Gao.transform.localPosition = so.matrix.GetPosition(convertAxes: true);
                so.data.Gao.transform.localRotation = so.matrix.GetRotation(convertAxes: true);
                so.data.Gao.transform.localScale    = so.matrix.GetScale(convertAxes: true);

                if (so.data is Perso)
                {
                    Perso perso = (Perso)so.data;

                    PersoBehaviour pb = perso.Gao.GetComponent <PersoBehaviour>();
                    if (pb != null)
                    {
                        Pointer.Goto(ref reader, perso.p3dData.offset);
                        perso.p3dData.UpdateCurrentState(reader);

                        // State offset changed?
                        if (perso.p3dData.stateCurrent != null)
                        {
                            pb.SetState(perso.p3dData.stateCurrent.index);
                            pb.autoNextState = true;
                        }
                    }

                    MindComponent mc = perso.Gao.GetComponent <MindComponent>();
                    if (mc != null)
                    {
                        Mind mind = mc.mind;
                        Pointer.DoAt(ref reader, mind.Offset, () => {
                            mind.UpdateCurrentBehaviors(reader);
                        });
                    }

                    DsgVarComponent dsgVarComponent = perso.Gao.GetComponent <DsgVarComponent>();
                    if (dsgVarComponent != null)
                    {
                        dsgVarComponent.SetPerso(perso);
                    }

                    CustomBitsComponent customBitsComponent = perso.Gao.GetComponent <CustomBitsComponent>();
                    if (customBitsComponent != null)
                    {
                        Pointer.Goto(ref reader, perso.off_stdGame);
                        perso.stdGame = StandardGame.Read(reader, perso.off_stdGame);
                        customBitsComponent.stdGame = perso.stdGame;
                        customBitsComponent.Init();
                    }

                    DynamicsMechanicsComponent dnComponent = perso.Gao.GetComponent <DynamicsMechanicsComponent>();
                    if (dnComponent != null)
                    {
                        Pointer.DoAt(ref reader, perso.off_dynam, () => {
                            perso.dynam = Dynam.Read(reader, perso.off_dynam);
                        });

                        dnComponent.SetDynamics(perso.dynam.dynamics);
                    }
                }
            }
        }

        Perso camera = loader.persos.FirstOrDefault(p => p != null && p.namePerso.Equals("StdCamer"));

        if (camera != null)
        {
            SuperObject cameraSO = camera.SuperObject;
            Pointer.Goto(ref reader, cameraSO.off_matrix);
            cameraSO.matrix = Matrix.Read(reader, cameraSO.off_matrix);
            camera.Gao.transform.localPosition = cameraSO.matrix.GetPosition(convertAxes: true);
            camera.Gao.transform.localRotation = cameraSO.matrix.GetRotation(convertAxes: true);
            camera.Gao.transform.localScale    = cameraSO.matrix.GetScale(convertAxes: true);

            Camera.main.transform.position = camera.Gao.transform.position;
            Camera.main.transform.rotation = camera.Gao.transform.rotation * Quaternion.Euler(0, 180, 0);
        }
    }
Ejemplo n.º 28
0
    async Task InitPersos()
    {
        if (loader != null)
        {
            for (int i = 0; i < loader.persos.Count; i++)
            {
                detailedState = "Initializing persos: " + i + "/" + loader.persos.Count;
                await WaitIfNecessary();

                Perso          p = loader.persos[i];
                PersoBehaviour unityBehaviour = p.Gao.AddComponent <PersoBehaviour>();
                unityBehaviour.controller = this;
                if (loader.globals != null && loader.globals.spawnablePersos != null)
                {
                    if (loader.globals.spawnablePersos.IndexOf(p) > -1)
                    {
                        unityBehaviour.IsAlways           = true;
                        unityBehaviour.transform.position = new Vector3(i * 10, -1000, 0);
                    }
                }
                if (!unityBehaviour.IsAlways)
                {
                    if (p.sectInfo != null && p.sectInfo.off_sector != null)
                    {
                        unityBehaviour.sector = sectorManager.sectors.FirstOrDefault(s => s.sector != null && s.sector.SuperObject.offset == p.sectInfo.off_sector);
                    }
                    else
                    {
                        SectorComponent sc = sectorManager.GetActiveSectorWrapper(p.Gao.transform.position);
                        unityBehaviour.sector = sc;
                    }
                }
                else
                {
                    unityBehaviour.sector = null;
                }
                unityBehaviour.perso = p;
                unityBehaviour.Init();

                // Scripts
                if (p.Gao)
                {
                    if (p.brain != null && p.brain.mind != null && p.brain.mind.AI_model != null)
                    {
                        if (p.brain.mind.AI_model.behaviors_normal != null)
                        {
                            GameObject intelParent = new GameObject("Rule behaviours");
                            intelParent.transform.parent = p.Gao.transform;
                            Behavior[] normalBehaviors = p.brain.mind.AI_model.behaviors_normal;
                            int        iter            = 0;
                            foreach (Behavior behavior in normalBehaviors)
                            {
                                string     shortName   = behavior.GetShortName(p.brain.mind.AI_model, Behavior.BehaviorType.Intelligence, iter);
                                GameObject behaviorGao = new GameObject(shortName);
                                behaviorGao.transform.parent = intelParent.transform;
                                foreach (Script script in behavior.scripts)
                                {
                                    GameObject scriptGao = new GameObject("Script");
                                    scriptGao.transform.parent = behaviorGao.transform;
                                    ScriptComponent scriptComponent = scriptGao.AddComponent <ScriptComponent>();
                                    scriptComponent.SetScript(script, p);
                                }
                                if (behavior.firstScript != null)
                                {
                                    ScriptComponent scriptComponent = behaviorGao.AddComponent <ScriptComponent>();
                                    scriptComponent.SetScript(behavior.firstScript, p);
                                }
                                if (iter == 0)
                                {
                                    behaviorGao.name += " (Init)";
                                }
                                if ((behavior.scripts == null || behavior.scripts.Length == 0) && behavior.firstScript == null)
                                {
                                    behaviorGao.name += " (Empty)";
                                }
                                iter++;
                            }
                        }
                        if (p.brain.mind.AI_model.behaviors_reflex != null)
                        {
                            GameObject reflexParent = new GameObject("Reflex behaviours");
                            reflexParent.transform.parent = p.Gao.transform;
                            Behavior[] reflexBehaviors = p.brain.mind.AI_model.behaviors_reflex;
                            int        iter            = 0;
                            foreach (Behavior behavior in reflexBehaviors)
                            {
                                string     shortName   = behavior.GetShortName(p.brain.mind.AI_model, Behavior.BehaviorType.Reflex, iter);
                                GameObject behaviorGao = new GameObject(shortName);
                                behaviorGao.transform.parent = reflexParent.transform;
                                foreach (Script script in behavior.scripts)
                                {
                                    GameObject scriptGao = new GameObject("Script");
                                    scriptGao.transform.parent = behaviorGao.transform;
                                    ScriptComponent scriptComponent = scriptGao.AddComponent <ScriptComponent>();
                                    scriptComponent.SetScript(script, p);
                                }
                                if (behavior.firstScript != null)
                                {
                                    ScriptComponent scriptComponent = behaviorGao.AddComponent <ScriptComponent>();
                                    scriptComponent.SetScript(behavior.firstScript, p);
                                }
                                if ((behavior.scripts == null || behavior.scripts.Length == 0) && behavior.firstScript == null)
                                {
                                    behaviorGao.name += " (Empty)";
                                }
                                iter++;
                            }
                        }
                        if (p.brain.mind.AI_model.macros != null)
                        {
                            GameObject macroParent = new GameObject("Macros");
                            macroParent.transform.parent = p.Gao.transform;
                            Macro[] macros = p.brain.mind.AI_model.macros;
                            int     iter   = 0;

                            foreach (Macro macro in macros)
                            {
                                GameObject behaviorGao = new GameObject(macro.GetShortName(p.brain.mind.AI_model, iter));
                                behaviorGao.transform.parent = macroParent.transform;
                                ScriptComponent scriptComponent = behaviorGao.AddComponent <ScriptComponent>();
                                scriptComponent.SetScript(macro.script, p);
                                iter++;
                            }
                        }
                    }
                }
            }
            // Initialize DSGVars after all persos have their perso behaviours
            for (int i = 0; i < loader.persos.Count; i++)
            {
                Perso    p   = loader.persos[i];
                Moddable mod = null;
                if (p.SuperObject != null && p.SuperObject.Gao != null)
                {
                    mod = p.SuperObject.Gao.GetComponent <Moddable>();
                    if (mod != null)
                    {
                        mod.persoBehaviour = p.Gao.GetComponent <PersoBehaviour>();
                    }
                }
                if (p.Gao && p.brain != null && p.brain.mind != null && p.brain.mind.AI_model != null)
                {
                    // DsgVars
                    if (p.brain.mind.dsgMem != null || p.brain.mind.AI_model.dsgVar != null)
                    {
                        DsgVarComponent dsgVarComponent = p.Gao.AddComponent <DsgVarComponent>();
                        dsgVarComponent.SetPerso(p);
                        if (mod != null)
                        {
                            mod.dsgVarComponent = dsgVarComponent;
                        }
                    }
                    // Dynam
                    if (p.dynam != null && p.dynam.dynamics != null)
                    {
                        DynamicsMechanicsComponent dynamicsBehaviour = p.Gao.AddComponent <DynamicsMechanicsComponent>();
                        dynamicsBehaviour.SetDynamics(p.dynam.dynamics);
                    }
                    // Mind
                    if (p.brain != null && p.brain.mind != null)
                    {
                        MindComponent mindComponent = p.Gao.AddComponent <MindComponent>();
                        mindComponent.Init(p, p.brain.mind);
                        if (mod != null)
                        {
                            mod.mindComponent = mindComponent;
                        }
                    }
                    // Custom Bits
                    if (p.stdGame != null)
                    {
                        CustomBitsComponent c = p.Gao.AddComponent <CustomBitsComponent>();
                        c.stdGame = p.stdGame;
                        if (Settings.s.engineVersion == Settings.EngineVersion.R3)
                        {
                            c.hasAiCustomBits = true;
                        }
                        c.Init();
                    }
                }
            }
        }
        if (loader is OpenSpace.Loader.R2ROMLoader)
        {
            OpenSpace.Loader.R2ROMLoader romLoader = loader as OpenSpace.Loader.R2ROMLoader;
            if (romPersos.Count > 0)
            {
                for (int i = 0; i < romPersos.Count; i++)
                {
                    detailedState = "Initializing persos: " + i + "/" + romPersos.Count;
                    await WaitIfNecessary();

                    ROMPersoBehaviour unityBehaviour = romPersos[i];
                    unityBehaviour.controller = this;

                    /*if (loader.globals != null && loader.globals.spawnablePersos != null) {
                     *      if (loader.globals.spawnablePersos.IndexOf(p) > -1) {
                     *              unityBehaviour.IsAlways = true;
                     *              unityBehaviour.transform.position = new Vector3(i * 10, -1000, 0);
                     *      }
                     * }*/
                    if (!unityBehaviour.IsAlways)
                    {
                        SectorComponent sc = sectorManager.GetActiveSectorWrapper(unityBehaviour.transform.position);
                        unityBehaviour.sector = sc;
                    }
                    else
                    {
                        unityBehaviour.sector = null;
                    }

                    /*Moddable mod = null;
                     * if (p.SuperObject != null && p.SuperObject.Gao != null) {
                     *      mod = p.SuperObject.Gao.GetComponent<Moddable>();
                     *      if (mod != null) {
                     *              mod.persoBehaviour = unityBehaviour;
                     *      }
                     * }*/
                    unityBehaviour.Init();

                    var iteratorPerso = unityBehaviour.perso;

                    // Of sound brain and AI model?
                    if (iteratorPerso.brain?.Value?.aiModel?.Value != null)
                    {
                        var aiModel = iteratorPerso.brain.Value.aiModel.Value;

                        // DsgVars
                        if (iteratorPerso.brain?.Value?.dsgMem?.Value != null || aiModel.dsgVar?.Value != null)
                        {
                            DsgVarComponent dsgVarComponent = unityBehaviour.gameObject.AddComponent <DsgVarComponent>();
                            dsgVarComponent.SetPerso(iteratorPerso);
                        }

                        // Comports
                        if (aiModel.comportsIntelligence.Value != null)
                        {
                            aiModel.comportsIntelligence.Value.CreateGameObjects("Rule", unityBehaviour.gameObject, iteratorPerso);
                        }
                        if (aiModel.comportsReflex.Value != null)
                        {
                            aiModel.comportsReflex.Value.CreateGameObjects("Reflex", unityBehaviour.gameObject, iteratorPerso);
                        }
                    }
                }
            }
            if (romLoader.level != null && romLoader.level.spawnablePersos.Value != null && romLoader.level.num_spawnablepersos > 0)
            {
                GameObject spawnableParent = new GameObject("Spawnable persos");
                for (int i = 0; i < romLoader.level.num_spawnablepersos; i++)
                {
                    detailedState = "Initializing spawnable persos: " + i + "/" + romLoader.level.num_spawnablepersos;
                    await WaitIfNecessary();

                    OpenSpace.ROM.SuperObjectDynamic sod = romLoader.level.spawnablePersos.Value.superObjects[i];
                    GameObject sodGao = sod.GetGameObject();
                    if (sodGao != null)
                    {
                        ROMPersoBehaviour unityBehaviour = sodGao.GetComponent <ROMPersoBehaviour>();
                        unityBehaviour.controller = this;
                        unityBehaviour.IsAlways   = true;
                        unityBehaviour.transform.SetParent(spawnableParent.transform);
                        unityBehaviour.transform.position   = new Vector3(i * 10, -1000, 0);
                        unityBehaviour.transform.rotation   = Quaternion.identity;
                        unityBehaviour.transform.localScale = Vector3.one;
                        if (!unityBehaviour.IsAlways)
                        {
                            SectorComponent sc = sectorManager.GetActiveSectorWrapper(unityBehaviour.transform.position);
                            unityBehaviour.sector = sc;
                        }
                        else
                        {
                            unityBehaviour.sector = null;
                        }
                        unityBehaviour.Init();

                        var iteratorPerso = unityBehaviour.perso;

                        // Of sound brain and AI model?
                        if (iteratorPerso.brain?.Value?.aiModel?.Value != null)
                        {
                            var aiModel = iteratorPerso.brain.Value.aiModel.Value;

                            // DsgVars
                            if (iteratorPerso.brain?.Value?.dsgMem?.Value != null || aiModel.dsgVar?.Value != null)
                            {
                                DsgVarComponent dsgVarComponent = unityBehaviour.gameObject.AddComponent <DsgVarComponent>();
                                dsgVarComponent.SetPerso(iteratorPerso);
                            }

                            // Comports
                            if (aiModel.comportsIntelligence.Value != null)
                            {
                                aiModel.comportsIntelligence.Value.CreateGameObjects("Rule", unityBehaviour.gameObject, iteratorPerso);
                            }
                            if (aiModel.comportsReflex.Value != null)
                            {
                                aiModel.comportsReflex.Value.CreateGameObjects("Reflex", unityBehaviour.gameObject, iteratorPerso);
                            }
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 29
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;
        }
    }
Ejemplo n.º 30
0
 public PersoAnimationStatesDataManipulator(PersoBehaviour persoBehaviour)
 {
     this.animationExportInterface = new PersoGeneralAnimationExportInterface(persoBehaviour.perso.p3dData.family);
 }