//--------------------------------------------------------------------------------------------/ // Methods //--------------------------------------------------------------------------------------------/ /// <summary> /// Shows/hides this window /// </summary> /// <param name="show"></param> /// <param name="onFinished"></param> public void Transition(bool show, System.Action onFinished = null) { if (debug) { StratusDebug.Log(show, this); } if (!show) { eventSystem.SetSelectedGameObject(null); } canvas.blocksRaycasts = show; canvas.interactable = show; pollingInput = show; currentSeq?.Cancel(); currentSeq = StratusActions.Sequence(this); // Fade the canvas StratusActions.Property(currentSeq, () => canvas.alpha, show ? 1f : 0f, transitionSpeed, Ease.Linear); StratusActions.Call(currentSeq, () => { visible = false; }); // Optionally, select the default button if (defaultSelected) { //Trace.Script($"Selecting {defaultSelected.name}", this); if (show) { StratusActions.Call(currentSeq, () => eventSystem.SetSelectedGameObject(defaultSelected.gameObject)); } } // Optionally, reset the state of all other selectables if (controlSelectables) { foreach (var selectable in selectables) { if (selectable == defaultSelected) { continue; } selectable.OnDeselect(null); } } // Now invoke any callbacks if (onFinished != null) { StratusActions.Call(currentSeq, () => { onFinished(); }); } }
public InputLayer Pop() { InputLayer layer = null; // If there's layers remaining, remove the topmost if (hasActiveLayers) { layer = _layers.Pop(); layer.active = false; layer.pushed = false; } bool queue = hasQueuedLayers && (!hasActiveLayers || (hasActiveLayers && !activeLayer.blocking)); StratusDebug.Log($"Popped {layer}. Check queue? {queue}"); // If there's still layers left if (queue) { // If there are queud layers // and the topmost is not blocking if (hasQueuedLayers) { while (_queuedLayers.NotEmpty()) { layer = _queuedLayers.Dequeue(); bool blocking = layer.blocking; StratusDebug.Log($"Popped layer {layer}, blocking ? {blocking}"); Push(layer, !blocking); if (blocking) { StratusDebug.Log($"Breaking"); break; } } } } // Update the current layer if its active if (hasActiveLayers) { if (activeLayer.pushed) { ActivateInputLayer(activeLayer); } else { StratusDebug.LogError("Layer not enabled???"); } } return(layer); }
private void OnMouseOver(ObjectNote note, UnityEngine.Event e) { StratusDebug.Log("Moused over " + note.name); if (e.isMouse && e.button == 0) { StratusDebug.Log("Clicked on " + note.name); highlightedNote = note; //e.Use(); } }
//------------------------------------------------------------------------/ // Methods //------------------------------------------------------------------------/ /// <summary> /// Submits a command to be executed /// </summary> /// <param name="command"></param> /// <returns></returns> public static bool Submit(string command) { RecordCommand(command); string[] commandSplit = command.Split(delimiter); int length = command.Length; if (length < 1) { return(false); } string commandName = null; Action <string> commandAction = null; string args = null; // Compose the command by working backwards for (int i = length; i >= 0; i--) { commandName = commandSplit.Take(i).Join(delimiterStr); StratusDebug.Log($"Searching command: {commandName}"); commandAction = commandActions.GetValueOrNull(commandName); if (commandAction != null) { StratusDebug.Log($"Found command: {commandName}"); if (i > 0) { args = commandSplit.Skip(i).Join(delimiterStr); } break; } } if (commandAction != null) { try { StratusDebug.Log($"Executing command {commandName} with args: {args}"); commandAction.Invoke(args); } catch (Exception e) { string msg = $"Error executing the command '{commandName}':\n{e}"; RecordEntry(new History.Entry(msg, History.EntryType.Error)); } return(true); } else { RecordEntry(new History.Entry($"No command matching '{command}' could be found!", History.EntryType.Warning)); } return(false); }
/// <summary> /// Sets the current value for the property. /// </summary> public virtual void SetCurrent() { float easeVal = this.easeType.Evaluate(this.elapsed / this.duration); T currentValue = this.ComputeCurrentValue((easeVal)); if (logging) { StratusDebug.Log("CurrentValue = '" + currentValue + "'"); } this.Set(currentValue); }
public override float Update(float dt) { StratusDebug.Log(message, this.target); this.isFinished = true; if (StratusActions.debug) { Debug.Log("#" + this.id + ": Finished!"); } return(0.0f); }
public void DestroyAndClear() { foreach (var layer in map.Values) { foreach (var behaviour in layer) { StratusDebug.Log($"Destroying {behaviour.Value.gameObject}"); behaviour.Value.DestroyGameObject(); } } map.Clear(); }
void OnSelectingNotePosition() { var e = UnityEngine.Event.current; if (e.type == EventType.MouseUp && e.button == 0) { OnMouseReleased(); e.Use(); isAddingNoteOnSceneView = false; StratusDebug.Log("Now releasing mouse"); } }
private static void CenterOnAnother(MenuCommand command) { var transform = Selection.activeTransform; //Undo.RecordObject(transform, transform.name); var selectionMenu = new GenericMenu(); foreach (var go in Scene.activeScene.gameObjects) { selectionMenu.AddItem(new GUIContent(go.name), true, () => { StratusDebug.Log("Centering on " + go.name); }); } selectionMenu.ShowAsContext(); }
private static void AddResourcesOfType <T>() where T : UnityEngine.Object { Type type = typeof(T); loadedResources.Add(type, new Dictionary <string, UnityEngine.Object>()); T[] resources = Resources.FindObjectsOfTypeAll <T>(); foreach (var resource in resources) { StratusDebug.Log($"Loading {resource.name}"); loadedResources[type].Add(resource.name, resource); } }
public static void OnPostProcessScene() { if (UnityEditor.BuildPipeline.isBuildingPlayer) { StratusDebug.Log($"Removing all instances of:"); GameObjectBookmark.RemoveAll(); } else { //Trace.Script($"In Editor. Not removing!"); } }
public static T CreateScriptableObject <T>(string path) where T : ScriptableObject { #if UNITY_EDITOR StratusDebug.Log(path + " has not been saved, creating it!"); T data = ScriptableObject.CreateInstance <T>(); CreateAssetAndDirectories(data, path); UnityEditor.AssetDatabase.SaveAssets(); return(data); #else return(null); #endif }
/// <summary> /// If a GUI control was changed, saves the state of the object /// </summary> /// <param name="procedure"></param> /// <param name="obj"></param> public static void SaveOnControlChange(UnityEngine.Object obj, System.Action procedure) { EditorGUI.BeginChangeCheck(); procedure(); if (EditorGUI.EndChangeCheck()) { SerializedObject serializedObject = new SerializedObject(obj); serializedObject.UpdateIfRequiredOrScript(); serializedObject.ApplyModifiedProperties(); UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty(); StratusDebug.Log($"Saving change on {obj.name}"); } }
/// <summary> /// Applies the given scales to the transformation in sequence over a given duration /// </summary> /// <param name="transform"></param> /// <param name="scalingCurves"></param> /// <param name="totalDuration"></param> /// <param name="repeat"></param> /// <param name="timeScale"></param> /// <returns></returns> public static IEnumerator Scale(Transform transform, AnimationCurve[] scalingCurves, float totalDuration, bool repeat = false, TimeScale timeScale = TimeScale.FixedDelta) { Vector3 originalScale = transform.localScale; float durationForEach = totalDuration / scalingCurves.Length; do { foreach (var scale in scalingCurves) { StratusDebug.Log("Scaling to " + scale); yield return(Scale(transform, scale, durationForEach, timeScale)); } } while (repeat); }
/// <summary> /// Activates this triggerable /// </summary> public void Activate() { if (!enabled) { return; } if (debug) { StratusDebug.Log($"<i>{description}</i> has been triggered!", this); } this.RunTriggerSequence(); activated = true; }
public static void ScrollToChildIfNotVisible(this ScrollRect scrollRect, RectTransform contentChild) { if (scrollRect.content != contentChild.parent) { StratusDebug.LogError($"Can only scroll to children of scrollRect's content {scrollRect.content}"); return; } int childIndex = contentChild.transform.GetSiblingIndex(); float targetValue = 1f - ((float)childIndex / (float)scrollRect.content.transform.childCount); float currentValue = scrollRect.verticalNormalizedPosition; StratusDebug.Log($"Scrolling to {targetValue}"); scrollRect.verticalNormalizedPosition = targetValue; }
/// <summary> /// Saves the current save data /// </summary> public bool SaveCurrent() { if (latestSave != null) { if (latestSave.serialized) { if (debug) { StratusDebug.Log($"Saved latest save..."); } Save(latestSave); } } return(false); }
//------------------------------------------------------------------------/ // Methods //------------------------------------------------------------------------/ /// <summary> /// Triggers the event /// </summary> protected void Activate() { if (!enabled) { return; } if (debug) { StratusDebug.Log($"<i>{description}</i> has been activated!", this); } // Dispatch the trigger event onto a given target if one is provided foreach (var target in targets) { if (target == null) { continue; } if (scope == Scope.GameObject) { target.gameObject.Dispatch <TriggerEvent>(triggerEvent); if (this.recursive) { foreach (var child in target.gameObject.Children()) { child.Dispatch <TriggerEvent>(triggerEvent); } } } else if (scope == Scope.Component) { target.Activate(); } } // If not persistent, disable if (!persistent) { this.enabled = false; } // Announce this trigger was activated activated = true; this.onActivate(this); }
protected override bool HandleCommand(string commandName, int itemIndex, IReorderableListAdaptor adaptor) { if (base.HandleCommand(commandName, itemIndex, adaptor)) { return(true); } switch (commandName) { case "Boop": StratusDebug.Log("Boop"); return(true); } return(false); }
//------------------------------------------------------------------------/ // Static Functions //------------------------------------------------------------------------/ /// <summary> /// Finds the neighbors of this node /// </summary> /// <param name="node"></param> /// <returns></returns> private static Node[] FindNeighbors(Node node, SearchBase arguments) { List <Node> neighbors = new List <Node>(); if (arguments.debug) { StratusDebug.Log("Looking for neighboring nodes for the node: " + node.description); } // Check for actions that satisfy the preconditions of this node ElementType[] neighborElements = arguments.neighborFunction(node.element); foreach (ElementType element in neighborElements) { // Don't add the parent if (node.parent != null && node.parent.element.Equals(element)) { if (arguments.debug) { StratusDebug.Log($"Skipping neighbor node {element} since it's the parent {node.parent.element}"); } continue; } // Optionally, check if the element is traversable if (arguments.traversableFunction != null && !arguments.traversableFunction(element)) { continue; } float distance = arguments.distanceFunction(node.element, element); float givenCost = node.givenCost + distance; Node neighborNode = new Node(node, element, givenCost); neighbors.Add(neighborNode); if (arguments.debug) { StratusDebug.Log($"Added neighbor node {neighborNode} with given cost: {givenCost}. (Distance = {distance})"); } } if (arguments.debug) { StratusDebug.Log($"Found {neighbors.Count} neighbors"); } return(neighbors.ToArray()); }
/// <summary> /// Unregisters the GameObject from the event system. /// </summary> /// <param name="obj"></param> public static void Disconnect(GameObject obj) { // Is this truly necessary, though? if (isQuitting || StratusEvents.instance.dispatchMap == null) { return; } // Remove this GameObject from the event dispatch map if (StratusEvents.instance.dispatchMap.ContainsKey(obj)) { if (logging.register) { StratusDebug.Log(obj.name + " has been disconnected from the event system"); } StratusEvents.instance.dispatchMap.Remove(obj); } }
/// <summary> /// Unsubscribe this gameobject from the action system /// </summary> /// <param name="gameObject"></param> private void UnsubscribeFromActions(GameObject gameObject) { // @TODO: Why is this an issue? if (gameObject == null) { return; } if (StratusActions.debug) { StratusDebug.Log("'" + gameObject.name + "'"); } ActionsContainer container = this.actionsOwnerMap[gameObject]; this.activeActions.Remove(container); this.actionsOwnerMap.Remove(gameObject); }
/// <summary> /// Unloads multiple scenes in sequence asynchronously /// </summary> /// <param name="scenes"></param> public static void Unload(SceneField[] scenes, SceneCallback onScenesUnloaded = null) { // Editor mode #if UNITY_EDITOR if (isEditMode) { foreach (var scene in scenes) { StratusDebug.Log($"Closing {scene.name}"); EditorSceneManager.CloseScene(scene.runtime, true); } return; } #endif // Play mode instance.StartCoroutine(instance.UnloadAsync(scenes, onScenesUnloaded)); }
///// <summary> ///// Loads save data from the given file, generates if not present ///// </summary> ///// <param name="fileName"></param> ///// <param name="folderName"></param> ///// <returns></returns> //public SaveType LoadOrCreate(string fileName, string folderName = null) //{ // string filePath = ComposePath(fileName, folderName); // if (StratusIO.FileExists(filePath)) // { // return Load(fileName, folderName); // } // if (debug) // { // StratusDebug.Log($"Creating data at path {filePath}"); // } // return CreateSave(null, fileName); //} /// <summary> /// Deletes the save file at the default folder /// </summary> /// <param name="fileName"></param> /// <param name="folderName"></param> public bool Delete(string fileName, string folderName = null) { if (!Exists(fileName, saveDirectoryPath)) { return(false); } var fileNameExt = fileName + saveExtension; var filePath = saveDirectoryPath + fileNameExt; StratusIO.DeleteFile(ComposePath(fileName, folderName)); File.Delete(filePath); if (debug) { StratusDebug.Log($"Deleted data at path {filePath}"); } return(true); }
/// <summary> /// Informs the handler of state changes /// </summary> /// <param name="state"></param> internal void Inform(State state) { //if (Tracing) // Trace.Script("Goal = " + Goal + ", State = " + state, Parent); // If the state has been changed to the goal state and we are not there currently... if (Compare(state, goal) && !isAtGoalState) { if (logging) { StratusDebug.Log("Now at goal state '" + goal.ToString() + "'", parent); } isAtGoalState = true; if (onEnterState != null) { onEnterState(); } else if (onStateChange != null) { onStateChange(isAtGoalState); } } // If we were at the goal state and the state has been changed to another... else if (!Compare(state, goal) && isAtGoalState) { isAtGoalState = false; if (onExitState != null) { if (logging) { StratusDebug.Log("Now exiting state '" + state.ToString() + "'", parent); } onExitState(); } else if (onStateChange != null) { if (logging) { StratusDebug.Log("Not at goal state '" + goal.ToString() + "', flipping state to " + isAtGoalState, parent); } onStateChange(isAtGoalState); } } }
private void ProcessEvents(UnityEngine.Event e) { switch (e.type) { case EventType.MouseDown: if (e.button == 0) { StratusDebug.Log("Left mouse down"); } break; case EventType.MouseUp: if (e.button == 0) { StratusDebug.Log("Left mouse up!"); } break; } }
private Dictionary <Node, Node> GetMap() { bool IsWithinRange(Node x) { if (x.givenCost <= range) { return(true); } if (debug) { StratusDebug.Log($"{x} Is out of range {x.givenCost} < ({range}) from {startElement}"); } return(false); } Dictionary <Node, Node> map = BuildDjkstraMap(this, null, IsWithinRange); return(map); }
//------------------------------------------------------------------------/ // Methods: Replacement //------------------------------------------------------------------------/ private static void ReplaceSelected(GameObject[] originals, GameObject prefab, bool keepNames, bool respectHierarchy, bool verbose = false) { if (verbose) { StratusDebug.Log("Now replacing " + originals.Length + " objects!"); } Undo.IncrementCurrentGroup(); Undo.SetCurrentGroupName(typeof(GameObjectReplaceWizard).Name); var undoIndex = Undo.GetCurrentGroup(); { for (var index = 0; index < originals.Length; index++) { Replace(originals[index], prefab, keepNames, mantainHierarchy); } } Undo.CollapseUndoOperations(undoIndex); }
private static void BookmarkAsset() { UnityEngine.Object activeObject = Selection.activeObject; // Special case for scenes if (activeObject.GetType() == typeof(SceneAsset)) { StratusDebug.Log("That's a scene!"); SceneAsset scene = activeObject as SceneAsset; if (!bookmarkedScenes.Contains(scene)) { bookmarkedScenes.Add(scene); } } else { StratusPreferences.instance.objectBookmarks.projectBookmarks.Add(activeObject); } StratusPreferences.Save(); }
private void AddExtension(int extensionTypeIndex) { Type extensionType = extensionTypes[extensionTypeIndex]; IExtensionBehaviour extension = target.gameObject.AddComponent(extensionType) as IExtensionBehaviour; if (extension == null) { StratusDebug.Error($"Failed to construct extension of type {extensionType.Name}"); return; } StratusDebug.Log($"Adding extension {extensionType.Name}"); target.Add(extension); Undo.RecordObject(target, extensionType.Name); serializedObject.ApplyModifiedProperties(); this.SetExtensionIndex(); this.RefreshExtensions(); }