Пример #1
0
    void EndTextEditing()
    {
        if (IsEditing())
        {
            // Erm, do this first, cuz deactivating stuff could cause this to be
            // called again recursively. Like deactivating the inputFieldObject!
            lastActorEdited  = actorBeingEdited;
            actorBeingEdited = null;

            inputFieldObject.SetActive(false);
            cooldownRoutine = StartCoroutine(CooldownRoutine());
            if (inputField.text == EMPTY_TEXT)
            {
                engine.DestroyActor(lastActorEdited);
            }
            else
            {
                editMain.SetTargetActor(lastActorEdited);
                // editMain.SetFocusedTargetActor(lastActorEdited);

                string undoText = actorTextBeforeEditing;

                if (actorWasJustCreated)
                {
                    var engine    = lastActorEdited.GetEngine();
                    var actorData = engine.SaveActor(lastActorEdited);
                    undoStack.PushUndoForCreatingActor(lastActorEdited, $"Create text panel");
                }
                else
                {
                    string currText = lastActorEdited.GetCommentText();
                    if (ActorUndoUtil.GetUnableToEditActorReason(lastActorEdited.GetEngine(), lastActorEdited.GetName()) == null)
                    {
                        undoStack.PushUndoForActor(
                            lastActorEdited,
                            $"Edit text panel",
                            redoActor =>
                        {
                            redoActor.SetCommentText(currText);
                            redoActor.ApplyPropertiesToClones();
                        },
                            undoActor =>
                        {
                            undoActor.SetCommentText(undoText);
                            undoActor.ApplyPropertiesToClones();
                        });
                    }
                }
            }
        }
    }
Пример #2
0
    private void ActorUpdate(VoosActor actor)
    {
        assetUI.header.text = $"{actor.GetDisplayName()} : Move";
        UpdateVec3Input(actor.GetPosition(), assetUI.currentInputs);
        UpdateVec3Input(actor.GetSpawnPosition(), assetUI.spawnInputs);
        UpdateVec3Input(actor.GetRenderableOffset(), assetUI.offsetInputs);
        VoosActor parent = actor.GetEngine().GetActor(actor.GetTransformParent());

        assetUI.currentParentButtonText.text = parent != null?parent.GetDisplayName() : "<none>";

        VoosActor spawnParent = actor.GetEngine().GetActor(actor.GetSpawnTransformParent());

        assetUI.restartParentButtonText.text = spawnParent != null?spawnParent.GetDisplayName() : "<none>";
    }
Пример #3
0
        public void PushTo(VoosActor actor)
        {
            actor.SetSpawnPosition(position);
            actor.SetSpawnRotation(rotation);
            VoosActor parent = actor.GetEngine().GetActor(parentName);

            actor.SetSpawnTransformParent(IsValidSpawnParent(actor, parent) ? parentName : null);
            // NOTE: No need to call ApplyPropertiesToClones because that function
            // doesn't copy this anyway
        }
Пример #4
0
 bool IsValidSpawnParent(VoosActor actor, VoosActor parent)
 {
     // Check for self or cycles
     while (parent != null)
     {
         if (parent == actor)
         {
             Util.Log($"Cycle detected!");
             return(false);
         }
         parent = actor.GetEngine().GetActor(parent.GetSpawnTransformParent());
     }
     return(true);
 }
Пример #5
0
    public static void PushUndoForActor(this UndoStack stack, VoosActor theActor, string label, System.Action <VoosActor> doIt, System.Action <VoosActor> undo)
    {
        // IMPORTANT: Do *NOT* use a reference to the actor! It may be deleted,
        // un-deleted, etc. So use its name, which is stable.
        string actorName = theActor.GetName();

        // Assume the VoosEngine instance is stable.
        VoosEngine engineRef = theActor.GetEngine();

        stack.Push(new UndoStack.Item
        {
            actionLabel           = label,
            getUnableToDoReason   = () => GetUnableToEditActorReason(engineRef, actorName),
            getUnableToUndoReason = () => GetUnableToEditActorReason(engineRef, actorName),
            doIt = () => GetValidActorThen(engineRef, actorName, doIt),
            undo = () => GetValidActorThen(engineRef, actorName, undo)
        });
    }
Пример #6
0
    static IEnumerable <string> GetUsedSojoIds(VoosActor actor)
    {
        string pfxId = actor.GetPfxId();
        string sfxId = actor.GetSfxId();

        if (!pfxId.IsNullOrEmpty())
        {
            yield return(pfxId);
        }
        if (!sfxId.IsNullOrEmpty())
        {
            yield return(sfxId);
        }

        var brain = new ActorBehaviorsEditor(actor.GetName(), actor.GetEngine(), null);

        foreach (var beh in brain.GetAssignedBehaviors())
        {
            foreach (var prop in beh.GetProperties())
            {
                if (prop.propType == BehaviorProperties.PropType.Image ||
                    prop.propType == BehaviorProperties.PropType.ParticleEffect ||
                    prop.propType == BehaviorProperties.PropType.Prefab ||
                    prop.propType == BehaviorProperties.PropType.Sound)
                {
                    if (prop.propType == BehaviorProperties.PropType.Prefab)
                    {
                        throw new System.Exception("Sorry, exporting an actor with prefab ref is not supported yet.");
                    }

                    // Yes, we should crash if the string cast fails.
                    string sojoId = (string)prop.data;
                    if (!sojoId.IsNullOrEmpty())
                    {
                        yield return(sojoId);
                    }
                }
            }
        }
    }
Пример #7
0
    void PrepareInputForScript(ControllerInput input)
    {
        if (input == null)
        {
            return;
        }

        if (userMain == null)
        {
            // Not ready yet.
            return;
        }

        inputStateForScript = new InputStateForScript();

        if (input.GetKeyDown(PlayerBody.VKEY_JUMP))
        {
            // V1 name:
            voosActor.EnqueueMessage("JumpTriggered");
            // V2 name:
            voosActor.EnqueueMessage("Jump");
        }

        if (input.GetKeyDown(PlayerBody.VKEY_PRIMARY_ACTION))
        {
            // V1 name:
            voosActor.EnqueueMessage("Action1Triggered");
            // V2 name:
            voosActor.EnqueueMessage("PrimaryAction");
        }

        if (input.GetKeyDown(PlayerBody.VKEY_SECONDARY_ACTION))
        {
            // V1 name:
            voosActor.EnqueueMessage("Action2Triggered");
            // V2 name:
            voosActor.EnqueueMessage("SecondaryAction");
        }

        List <string> keysHeld         = new List <string>();
        List <string> keysJustPressed  = new List <string>();
        List <string> keysJustReleased = new List <string>();

        foreach (string key in ScriptableKeyNames)
        {
            bool isDown = input.GetKeyDown(key) && !keysHeldAsReportedToScript.Contains(key);
            bool isUp   = !input.GetKeyHeld(key) && keysHeldAsReportedToScript.Contains(key);
            bool isHeld = input.GetKeyHeld(key);

            if (isHeld)
            {
                keysHeldAsReportedToScript.Add(key);
            }
            else
            {
                keysHeldAsReportedToScript.Remove(key);
            }

            if (isDown)
            {
                voosActor.EnqueueMessage("KeyDown", $"{{\"keyName\": \"{key}\"}}");
                keysJustPressed.Add(key);
            }
            if (isHeld)
            {
                voosActor.EnqueueMessage("KeyHeld", $"{{\"keyName\": \"{key}\"}}");
                keysHeld.Add(key);
            }
            if (isUp)
            {
                voosActor.EnqueueMessage("KeyUp", $"{{\"keyName\": \"{key}\"}}");
                keysJustReleased.Add(key);
            }
        }

        bool mouseIsDown = Input.GetMouseButton(0) && !userMain.CursorOverUI() && !userMain.InEditMode();

        if (mouseIsDown && !reportedMouseDown)
        {
            voosActor.EnqueueMessage("MouseDown");
            reportedMouseDown = true;
            inputStateForScript.mouseButtonJustPressed = true;
        }
        if (reportedMouseDown)
        {
            voosActor.EnqueueMessage("MouseHeld");
            inputStateForScript.mouseButtonIsPressed = true;
        }
        if (!mouseIsDown && reportedMouseDown)
        {
            voosActor.EnqueueMessage("MouseUp");
            reportedMouseDown = false;
            inputStateForScript.mouseButtonJustReleased = true;
        }

        Vector2 mousePosUiCoords;
        Vector3 mousePosRaw = Input.mousePosition;

        mousePosUiCoords = gameUiMain.UnityScreenPointToGameUiPoint(mousePosRaw);

        inputStateForScript.mouseX           = mousePosUiCoords.x;
        inputStateForScript.mouseY           = mousePosUiCoords.y;
        inputStateForScript.keysHeld         = keysHeld.ToArray();
        inputStateForScript.keysJustPressed  = keysJustPressed.ToArray();
        inputStateForScript.keysJustReleased = keysJustReleased.ToArray();

        Ray mouseRay = userMain.GetCamera().ScreenPointToRay(mousePosRaw);

        inputStateForScript.mouseRayOrigin    = mouseRay.origin;
        inputStateForScript.mouseRayDirection = mouseRay.direction;

        if (inputStateForScript.mouseButtonJustPressed)
        {
            RaycastHit hit;
            if (Physics.Raycast(mouseRay.origin, mouseRay.direction, out hit, 1000, VoosActor.LayerMaskValue, QueryTriggerInteraction.Collide))
            {
                VoosActor clickedActor = hit.collider.GetComponentInParent <VoosActor>();
                if (clickedActor != null)
                {
                    clickedActor.GetEngine().EnqueueMessage(new VoosEngine.ActorMessage
                    {
                        name        = "ActorClicked",
                        targetActor = clickedActor.GetName(),
                        argsJson    = "{}"
                    });
                }
            }
        }

        inputStateForScript.mouseWheelRaw = Input.GetAxis("Mouse ScrollWheel");
        inputStateForScript.mouseWheel    = inputStateForScript.mouseWheelRaw * MOUSEWHEEL_FACTOR;
    }
Пример #8
0
 void OnEnable()
 {
     voosActor.GetEngine().onBeforeVoosUpdate += OnBeforeVoosUpdate;
 }
 public static ActorBehaviorsEditor FromActor(VoosActor actor)
 {
     return(new ActorBehaviorsEditor(actor.GetName(), actor.GetEngine(), null));
 }