Exemple #1
0
    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;
            }
        }
    }
Exemple #2
0
    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);
    }