private WebJSON.SuperObject GetSuperObjectJSON(SuperObjectComponent so, bool includeChildren = true) { if (so == null) { return(null); } WebJSON.SuperObject soJSON = new WebJSON.SuperObject() { Type = so.Type, Offset = so.Offset }; soJSON.Name = so.gameObject.name; soJSON.Position = so.gameObject.transform.localPosition; soJSON.Rotation = so.gameObject.transform.localEulerAngles; soJSON.Scale = so.gameObject.transform.localScale; if (soJSON.Type == SuperObject.Type.Perso) { BasePersoBehaviour pb = GetPersoFromSuperObjectOffset(soJSON.Offset); if (pb != null) { soJSON.Perso = GetPersoJSON(pb); } } if (includeChildren) { soJSON.Children = so.Children.Select(s => GetSuperObjectJSON(s, includeChildren: includeChildren)).ToArray(); } return(soJSON); }
private void ParseSelectionJSON(WebJSON.Selection msg) { MapLoader l = MapLoader.Loader; if (msg.Perso != null && msg.Perso.Offset != null) { BasePersoBehaviour bpb = GetPersoFromOffset(msg.Perso.Offset); if (bpb != null) { selector.Select(bpb, view: msg.View); } } else if (msg.SuperObject != null && msg.SuperObject != null && msg.SuperObject.Offset != null) { SuperObjectComponent so = controller.superObjects.FirstOrDefault(s => s.Offset == msg.SuperObject.Offset); if (so != null) { selector.Select(so); } } else { selector.Deselect(); } }
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; } }
private void ParsePersoJSON(WebJSON.Perso msg) { MapLoader l = MapLoader.Loader; BasePersoBehaviour perso = null; if (msg.Offset != null) { perso = GetPersoFromOffset(msg.Offset); } if (perso != null) { BasePersoBehaviour pb = perso; if (msg.IsEnabled.HasValue) { pb.IsEnabled = msg.IsEnabled.Value; } if (msg.State.HasValue) { pb.stateIndex = msg.State.Value; /*if (pb == selectedPerso_) { * selectedPersoStateIndex_ = msg.State.Value; * }*/ } if (msg.ObjectList.HasValue) { pb.poListIndex = msg.ObjectList.Value; } if (msg.PlayAnimation.HasValue) { pb.playAnimation = msg.PlayAnimation.Value; } if (msg.AnimationSpeed.HasValue) { pb.animationSpeed = msg.AnimationSpeed.Value; } if (msg.AutoNextState.HasValue) { pb.autoNextState = msg.AutoNextState.Value; } if (msg.Position.HasValue) { pb.transform.localPosition = msg.Position.Value; } if (msg.Rotation.HasValue) { pb.transform.localEulerAngles = msg.Rotation.Value; } if (msg.Scale.HasValue) { pb.transform.localScale = msg.Scale.Value; } } }
private WebJSON.DsgVar[] GetDsgVarsJSON(BasePersoBehaviour perso) { DsgVarComponent dsgComponent = perso?.brain?.dsgVars; if (dsgComponent != null && dsgComponent.editableEntries != null && dsgComponent.editableEntries.Length > 0) { return(dsgComponent.editableEntries.Select(e => GetDsgVarJSON(e)).ToArray()); } return(null); }
private WebJSON.Perso GetPersoJSON(BasePersoBehaviour pb, bool includeDetails = true, bool includeLists = false, bool includeBrain = false) { if (pb == null) { return(null); } WebJSON.Perso persoJSON = new WebJSON.Perso(); persoJSON.Offset = pb.Offset; persoJSON.NameFamily = pb.NameFamily; persoJSON.NameModel = pb.NameModel; persoJSON.NameInstance = pb.NameInstance; if (includeDetails) { persoJSON.IsEnabled = pb.IsEnabled; persoJSON.State = pb.currentState; persoJSON.ObjectList = pb.poListIndex; persoJSON.PlayAnimation = pb.playAnimation; persoJSON.AnimationSpeed = pb.animationSpeed; persoJSON.AutoNextState = pb.autoNextState; } persoJSON.Type = pb.IsAlways ? WebJSON.PersoType.Always : WebJSON.PersoType.Instance; persoJSON.Name = pb.gameObject.name; persoJSON.Position = pb.transform.localPosition; persoJSON.Rotation = pb.transform.localEulerAngles; persoJSON.Scale = pb.transform.localScale; if (includeLists) { if (pb.stateNames != null) { persoJSON.States = Enumerable.Range(0, pb.stateNames.Length).Select(i => new WebJSON.State() { Name = pb.stateNames[i], Transitions = pb.GetStateTransitions(i)?.Select(t => new WebJSON.State.Transition() { LinkingType = t.LinkingType, StateToGo = t.StateToGoIndex, TargetState = t.TargetStateIndex }).ToArray(), }).ToArray(); } persoJSON.ObjectLists = pb.poListNames; } if (includeBrain) { persoJSON.Brain = GetBrainJSON(selector.selectedPerso); persoJSON.BehaviorTransitionExportAvailable = selector.selectedPerso is PersoBehaviour && (persoJSON.Brain?.Intelligence?.Length > 0 || persoJSON.Brain?.Reflex?.Length > 0 || persoJSON.Brain?.Macros?.Length > 0); } return(persoJSON); }
private WebJSON.Brain GetBrainJSON(BasePersoBehaviour perso, bool includeScriptContents = false) { WebJSON.Brain brainJSON = new WebJSON.Brain(); if (perso.brain != null) { brainJSON.Intelligence = perso.brain.Intelligence.Select(i => GetComportJSON(i, includeScriptContents: includeScriptContents)).ToArray(); brainJSON.Reflex = perso.brain.Reflex.Select(i => GetComportJSON(i, includeScriptContents: includeScriptContents)).ToArray(); brainJSON.Macros = perso.brain.Macros.Select(i => GetMacroJSON(i, includeScriptContents: includeScriptContents)).ToArray(); brainJSON.DsgVars = GetDsgVarsJSON(perso); } return(brainJSON); }
public void Select(BasePersoBehaviour pb, bool view = false) { //print(pb.name); if (selectedPerso != pb || view) { #if UNITY_EDITOR if (pb?.gameObject != null) { UnityEditor.Selection.activeGameObject = pb.gameObject; } #endif selectedPerso = pb; if (controller.CinematicSwitcher == null || !controller.CinematicSwitcher.HasControlOfCamera) { cam.JumpTo(pb.gameObject); } } }
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()); } } }
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; * } * } * }*/ }
public void Deselect() { selectedPerso = null; }
public void JumpTo(GameObject gao) { if (UnitySettings.IsRaymapGame) { return; } Vector3? center = null, size = null; BasePersoBehaviour bpb = gao.GetComponent <BasePersoBehaviour>(); if (bpb != null) { switch (bpb) { case PersoBehaviour pb: //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; break; case ROMPersoBehaviour rpb: center = rpb.transform.position; size = rpb.transform.lossyScale; break; case PS1PersoBehaviour ppb: center = ppb.transform.position; size = ppb.transform.lossyScale; break; } } else { SuperObjectComponent sc = gao.GetComponent <SuperObjectComponent>(); if (sc != null) { if (sc.so != null) { center = (gao.transform.position + sc.so.boundingVolume.Center); size = Vector3.Scale(sc.so.boundingVolume.Size, gao.transform.lossyScale); } else { center = gao.transform.position; size = gao.transform.lossyScale; } } } if (center.HasValue) { float objectSize = Mathf.Min(5f, Mathf.Max(size.Value.x, size.Value.y, size.Value.z)); bool orthographic = cam.orthographic; if (orthographic) { targetOrthoSize = objectSize * 2f * 1.5f; Vector3 target = cam.transform.InverseTransformPoint(center.Value); targetPos = cam.transform.TransformPoint(new Vector3(target.x, target.y, 0f)); } else { float cameraDistance = 4.0f; // Constant factor 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); } } } }