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); } } }
void CellGUI(Rect cellRect, TreeViewItem <StateTransitionsTreeElement> item, Columns column, ref RowGUIArgs args) { // Center cell rect vertically (makes it easier to place controls, icons etc in the cells) CenterRectUsingSingleLineHeight(ref cellRect); switch (column) { case Columns.TargetState: if (GUI.Button(cellRect, item.data.targetStateName, MiniButton)) { if (perso != null) { perso.SetState(item.data.targetStateIndex); } if (persoROM != null) { persoROM.SetState(item.data.targetStateIndex); } if (persoPS1 != null) { persoPS1.SetState(item.data.targetStateIndex); } } break; case Columns.StateToGo: if (GUI.Button(cellRect, item.data.stateToGoName, MiniButton)) { if (perso != null) { perso.SetState(item.data.stateToGoIndex); } if (persoROM != null) { persoROM.SetState(item.data.stateToGoIndex); } if (persoPS1 != null) { persoPS1.SetState(item.data.stateToGoIndex); } } break; case Columns.LinkingType: GUI.Label(cellRect, item.data.linkingType.ToString(), EditorStyles.centeredGreyMiniLabel); break; } }
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(); } }
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; } } }
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(); } }
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); } }
public static ExportState CreateFromState(State s) { Family fam = s.family; ExportState es = new ExportState(); Perso examplePerso = MapLoader.Loader.persos.Find(p => p.p3dData.family == s.family); if (examplePerso == null) { return(es); } examplePerso.Gao.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity); examplePerso.Gao.transform.localScale = Vector3.one; PersoBehaviour pb = examplePerso.Gao.GetComponent <PersoBehaviour>(); pb.SetState(s); if (pb.a3d == null) { return(es); } es.animationLength = pb.a3d.num_onlyFrames; es.instances = new List <ExportObjectInstance>(); es.channels = new Dictionary <int, ExportChannel>(); for (int c = 0; c < pb.a3d.num_channels; c++) { es.channels.Add(c, new ExportChannel() { positions = new Vector3[es.animationLength], rotations = new Quaternion[es.animationLength], scales = new Vector3[es.animationLength], }); AnimChannel ch = pb.a3d.channels[pb.a3d.start_channels + c]; List <ushort> listOfNTTOforChannel = new List <ushort>(); for (int j = 0; j < pb.a3d.num_onlyFrames; j++) { AnimOnlyFrame of = pb.a3d.onlyFrames[pb.a3d.start_onlyFrames + j]; //print(ch.numOfNTTO + " - " + of.numOfNTTO + " - " + a3d.numOfNTTO.Length); AnimNumOfNTTO numOfNTTO = pb.a3d.numOfNTTO[ch.numOfNTTO + of.numOfNTTO]; if (!listOfNTTOforChannel.Contains(numOfNTTO.numOfNTTO)) { listOfNTTOforChannel.Add(numOfNTTO.numOfNTTO); } } for (int k = 0; k < listOfNTTOforChannel.Count; k++) { int j = listOfNTTOforChannel[k] - pb.a3d.start_NTTO; AnimNTTO ntto = pb.a3d.ntto[pb.a3d.start_NTTO + j]; if (ntto.IsInvisibleNTTO) { } else { es.instances.Add(new ExportObjectInstance() { channelId = c, familyObjectIndex = ntto.object_index, visibilities = new bool[es.animationLength] }); } } } for (uint i = 0; i < es.animationLength; i++) { pb.currentFrame = i; pb.UpdateAnimation(); for (int c = 0; c < pb.a3d.num_channels; c++) { if (pb.channelObjects[c].transform.childCount == 0) { Debug.LogWarning("ChannelObject " + pb.channelObjects[c] + " has no children :("); continue; } Vector3 position = pb.channelObjects[c].transform.GetChild(0).position; Quaternion rotation = pb.channelObjects[c].transform.GetChild(0).rotation; Vector3 scale = pb.channelObjects[c].transform.GetChild(0).lossyScale; bool visible = pb.channelObjects[c].transform.GetChild(0).gameObject.activeSelf; //Vector3 exportRotation = AngleUtil.quaternion2Euler(rotation, AngleUtil.RotSeq.) //Quaternion swappedRotation = Quaternion.Euler(rotation.eulerAngles.x, rotation.eulerAngles.y, rotation.eulerAngles.z); es.channels[c].positions[i] = position; es.channels[c].rotations[i] = rotation; es.channels[c].scales[i] = scale; //es.channels[c].visibilities[i][objectIndex] = visible ? true : false; foreach (var instance in es.instances.Where(instance => instance.channelId == c)) { AnimChannel ch = pb.a3d.channels[pb.a3d.start_channels + c]; AnimOnlyFrame of = pb.a3d.onlyFrames[pb.a3d.start_onlyFrames + i]; AnimNumOfNTTO numOfNTTO = pb.a3d.numOfNTTO[ch.numOfNTTO + of.numOfNTTO]; AnimNTTO ntto = pb.a3d.ntto[numOfNTTO.numOfNTTO]; if (ntto.object_index != instance.familyObjectIndex) { continue; } //if (ntto.IsBoneNTTO) continue; int poNum = numOfNTTO.numOfNTTO - pb.a3d.start_NTTO; PhysicalObject physicalObject = pb.subObjects[c][poNum]; instance.visibilities[i] = physicalObject == null ? false : true; //instance.familyObjectIndex; } } } return(es); }