public void RequestOptionExecution(Unit[] units, UnitOption option, UnitOptionParams param) { if (isServer) { RequestOption_Server(units, option, param); } else { // Make game object array from unit array. // Validate units at the same time. GameObject[] gos = new GameObject[units.Length]; for (int i = 0; i < units.Length; i++) { var unit = units[i]; if (unit != null) { if (unit.Faction == Player.Faction) { gos[i] = unit.gameObject; } } } string json = param == null ? null : param.ToJson(); // Send command request to the server. CmdRequestExec(gos, option, json); } }
public static void ExecuteOptions(Unit[] units, UnitOption option, UnitOptionParams[] param) { if (units == null || units.Length == 0) { return; } if (param != null && param.Length != units.Length) { Debug.LogError("Not enough parameters for the number of units supplied! (Total {0} units, {1} params). Pass a null array to not execute without options.".Form(units.Length, param.Length)); return; } for (int i = 0; i < units.Length; i++) { var unit = units[i]; if (units != null) { UnitOptionParams p = null; if (param != null) { p = param[i]; } ExecuteOption(unit, option, p); } } }
private void RequestOption_Server(Unit[] units, UnitOption option, UnitOptionParams param) { if (units == null || units.Length == 0) { return; } // No need for validation, server side and already done. Unit.ExecuteOptions(units, option, param); }
public static void ExecuteOption(Unit unit, UnitOption option, UnitOptionParams param) { if (unit == null) { return; } unit.ExecOption(new OptionAndParams() { Option = option, Params = param }); }
public static void ExecuteOptions(Unit[] units, UnitOption option, UnitOptionParams param) { if (units == null || units.Length == 0) { return; } foreach (var unit in units) { if (unit != null) { ExecuteOption(unit, option, param); } } }
public void Update() { if (NoOptions.activeSelf && !Active) { NoOptions.SetActive(false); } Parent.gameObject.SetActive(Active); openState = Mathf.Clamp01(openState + (1f / OpenTime) * (Active ? 1f : -1f) * Time.unscaledDeltaTime); float p = OpenCurve.Evaluate(openState); Group.alpha = p; if (GatheringInput) { if (workingIndex != gathered) { // We have gathered more input! Move on to the next or terminate. if (gathered == totalToGather) { // Done! GatheringInput = false; inputs = null; // Execute the option with collected params. UnitOptionParams param = new UnitOptionParams(); for (byte i = 0; i < values.Count; i++) { param.Update(i, values[i]); } var array = Unit.CurrentlySelected.ToArray(); Player.Local.UnitOptionExecution.RequestOptionExecution(array, option, param); values.Clear(); } else { // Move on to the next! workingIndex++; var current = inputs[workingIndex]; RunInputCollection(current); } } } }
private void CmdRequestExecUniqueParams(GameObject[] gos, UnitOption option, string[] param) { if (gos == null || gos.Length == 0) { return; } // Turn gameobjects into units. // Validate units too. Unit[] units = new Unit[gos.Length]; for (int i = 0; i < gos.Length; i++) { var go = gos[i]; if (go != null) { var unit = go.GetComponent <Unit>(); if (unit != null) { if (unit.Faction == Player.Faction) { units[i] = unit; } } } } // Make the params object from the json. Works even if the json is null or blank. // May return null, which is fine. UnitOptionParams[] p = null; if (param != null) { p = new UnitOptionParams[param.Length]; for (int i = 0; i < param.Length; i++) { Debug.Log("Received {0}".Form(param[i])); p[i] = UnitOptionParams.TryDeserialize(param[i]); } } // Run the server version. RequestOption_Server(units, option, p); }