Example #1
0
        /// <summary>
        /// Sets the CommNetNetwork object to be CommNetManager if CommNetManager is installed.
        /// </summary>
        /// <param name="scenario">Your instance of CommNetScenario.</param>
        /// <param name="CustomCommNetNetwork">The handle of the CommNetNetwork object that is being implemented.</param>
        /// <returns>True if CommNetManager or the supplied Net was instantiated, False if not.</returns>
        public static bool SetCommNetManagerIfAvailable(this CommNetScenario scenario, out CommNetNetwork CustomCommNetNetwork)
        {
            CustomCommNetNetwork = null;
            //Replace the CommNet network
            CommNetNetwork stockNet = UnityEngine.Object.FindObjectOfType <CommNetNetwork>();

            if (CommNetManagerInstalled)
            {
                if (stockNet.GetType() == CommNetManager)
                {
                    CustomCommNetNetwork = stockNet;
                    return(true);
                }
                CustomCommNetNetwork = (CommNetNetwork)scenario.gameObject.AddComponent(CommNetManager);
            }
            else
            {
                return(false);
            }

            if (!(CustomCommNetNetwork == null))
            {
                UnityEngine.Object.Destroy(stockNet);
                _commNetwork = CustomCommNetNetwork;
                //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work
                return(true);
            }
            else
            {
                CustomCommNetNetwork = stockNet;
                _commNetwork         = stockNet;
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Sets the CommNetNetwork object to be CommNetManager if CommNetManager is installed or a supplied type if it is not.
        /// </summary>
        /// <param name="scenario">Your instance of CommNetScenario.</param>
        /// <param name="derivativeOfCommNetNetwork">Type of your network to instantiate if CommNetManager is not installed.</param>
        /// <param name="CustomCommNetNetwork">The handle of the CommNetNetwork object that is being implemented.</param>
        /// <returns>True if CommNetManager or the supplied Net was instantiated, false if not.</returns>
        public static bool SetCommNetManagerIfAvailable(this CommNetScenario scenario, Type derivativeOfCommNetNetwork, out CommNetNetwork CustomCommNetNetwork)
        {
            CustomCommNetNetwork = null;
            //Replace the CommNet network
            CommNetNetwork stockNet = CommNetScenario.FindObjectOfType <CommNetNetwork>();

            if (CommNetManagerInstalled)
            {
                if (stockNet.GetType() == CommNetManager)
                {
                    CustomCommNetNetwork = stockNet;
                    return(true);
                }
                CustomCommNetNetwork = (CommNetNetwork)scenario.gameObject.AddComponent(CommNetManager);
            }
            else
            {
                if (!typeof(CommNetNetwork).IsAssignableFrom(derivativeOfCommNetNetwork))
                {
                    UnityEngine.Debug.LogError("The supplied Type in SetCommNetManagerIfAvailable is not a derivative of CommNetNetwork.");
                    return(false);
                }
                CustomCommNetNetwork = (CommNetNetwork)scenario.gameObject.AddComponent(derivativeOfCommNetNetwork);
            }

            if (CustomCommNetNetwork != null)
            {
                UnityEngine.Object.Destroy(stockNet);
                _commNetwork = CustomCommNetNetwork;
                //CommNetNetwork.Instance.GetType().GetMethod("set_Instance").Invoke(CustomCommNetNetwork, null); // reflection to bypass Instance's protected set // don't seem to work
                return(true);
            }
            else
            {
                CustomCommNetNetwork = stockNet;
                _commNetwork         = stockNet;
                return(false);
            }
        }
Example #3
0
 /// <summary>
 /// Sets the CommNetNetwork object to be CommNetManager if CommNetManager is installed.
 /// </summary>
 /// <param name="scenario">Your instance of CommNetScenario.</param>
 /// <returns>True if CommNetManager or the supplied Net was instantiated, False if not.</returns>
 public static bool SetCommNetManagerIfAvailable(this CommNetScenario scenario)
 {
     return(SetCommNetManagerIfAvailable(scenario, out _));
 }
Example #4
0
 /// <summary>
 /// Sets the CommNetNetwork object to be CommNetManager if CommNetManager is installed or a supplied type if it is not.
 /// </summary>
 /// <param name="scenario">Your instance of CommNetScenario.</param>
 /// <param name="derivativeOfCommNetNetwork">Type of your network to instantiate if CommNetManager is not installed.</param>
 /// <returns>True if CommNetManager or the supplied Net was instantiated, False if not.</returns>
 public static bool SetCommNetManagerIfAvailable(this CommNetScenario scenario, Type derivativeOfCommNetNetwork)
 {
     return(SetCommNetManagerIfAvailable(scenario, derivativeOfCommNetNetwork, out _));
 }
Example #5
0
        /// <summary>
        /// Sets the CommNetNetwork object to be CommNetManager if CommNetManager is installed.
        /// </summary>
        /// <param name="scenario">Your instance of CommNetScenario.</param>
        /// <returns>True if CommNetManager or the supplied Net was instantiated, False if not.</returns>
        public static bool SetCommNetManagerIfAvailable(this CommNetScenario scenario)
        {
            CommNetNetwork throwaway;

            return(SetCommNetManagerIfAvailable(scenario, out throwaway));
        }