Example #1
0
		void Start() {

#if UNITY_EDITOR
			if (Application.isPlaying) {
#endif
				if (OnBodyCreatedEvent != null) {
					OnBodyCreatedEvent(this);
				}
				if (simControlRef == null) {
					if (SimulationControl.instance == null) {
						Debug.Log("SpaceGravity2D: Simulation Control not found");
						enabled = false;
						return;
					} 
					simControlRef = SimulationControl.instance;
				}
#if UNITY_EDITOR
			} else {
				if (simControlRef == null) {
					simControlRef = GameObject.FindObjectOfType<SimulationControl>();
				}
				if (simControlRef != null) {
					orbitData.gravConst = simControlRef.gravitationalConstant;
					orbitData.eclipticNormal = simControlRef.eclipticNormal;
					orbitData.eclipticUp = simControlRef.eclipticUp;
				}
			}
#endif
		}
Example #2
0
		void Start() {
			if ( SimControl == null ) {
				SimControl = GameObject.FindObjectOfType<SimulationControl>();
			}
			if ( SimControl == null ) {
				enabled = false;
			}
		}
Example #3
0
 void Start()
 {
     if (SimControl == null)
     {
         SimControl = GameObject.FindObjectOfType <SimulationControl>();
     }
     if (SimControl == null)
     {
         enabled = false;
     }
 }
Example #4
0
		/// <summary>
		/// Get all main references
		/// </summary>
		public void FindReferences() {
			if (!_transform) {
				_transform = transform;
			}
			if (!_rigidbody2D) {
				_rigidbody2D = GetComponent<Rigidbody2D>();
			}
			if (!_simulationControl) {
				_simulationControl = GameObject.FindObjectOfType<SimulationControl>();
			}
		}
 void OnEnable()
 {
     //Singleton:
     if (instance && instance != this)
     {
         Debug.LogWarning("SpaceGravity2D: SimulationControl already exists");
         enabled = false;
         return;
     }
     instance = this;
     SubscribeForEvents();
 }
Example #6
0
		/// <summary>
		/// find components and simControl references
		/// </summary>
		public void FindReferences() {
			if (transformRef == null || simControlRef == null) {
#if UNITY_EDITOR
				if (!Application.isPlaying) {
					Undo.RecordObject(this, "FindReferences");
				}
#endif
				if (transformRef == null) {
					transformRef = transform;
				}
				if (simControlRef == null) {
					simControlRef = SimulationControl.instance ?? GameObject.FindObjectOfType<SimulationControl>();
				}
			}
		}
        void OnEnable()
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return;
            }
#endif
            //Singleton:
            if (instance && instance != this)
            {
                Debug.Log("SpaceGravity2D: SimulationControl already exists");
                enabled = false;
                return;
            }
            instance = this;
            SubscribeForEvents();
        }
        /// <summary>
        /// Editor update subscribed callback.
        /// </summary>
        /// <remarks>
        /// Subscribe OnSceneGUI event if _simControl is not null.
        /// If SimulationControl is not exists on scene, continuously retry untill it's not created.
        /// </remarks>
        private void StartupUpdate()
        {
            if (_waitTime > EditorApplication.timeSinceStartup)
            {
                // Wait for check time.
                return;
            }
            if (_simControl == null)
            {
                if (SimulationControl.Instance != null)
                {
                    _simControl = SimulationControl.Instance;
                }
                else
                {
                    var simControl = GameObject.FindObjectOfType <SimulationControl>();
                    if (simControl != null)
                    {
                        SimulationControl.Instance = simControl;
                        _simControl = simControl;
                    }
                    else
                    {
                        _waitTime = EditorApplication.timeSinceStartup + _waitDuration;
                        // If simulation control is not created, exit and wait for next check time.
                        return;
                    }
                }
            }
            _arrowsBtnImage = Resources.Load("Textures/arrowsBtn") as Texture2D;
            _orbitsBtnImage = Resources.Load("Textures/orbitsBtn") as Texture2D;
            CreateButtonStyle();

            // Subscribe our OnSceneGUI for updates callbacks.
            SceneView.onSceneGUIDelegate += this.OnSceneGUI;
            SceneView.RepaintAll();

            // Don't call this function anymore.
            EditorApplication.update -= StartupUpdate;
        }
Example #9
0
		void Start() {
			LastPosition = _transform.position;
			if (Application.isPlaying) {
				if (OnBodyCreatedEvent != null) {
					OnBodyCreatedEvent(this);
				}
				if (!_simulationControl) {
					if (SimulationControl.instance == null) {
						Debug.LogWarning("SpaceGravity2D: Simulation Control not found");
						enabled = false;
						return;
					}
					else {
						_simulationControl = SimulationControl.instance;
					}
				}
				if (IsFixedPosition) {
					RelativeVelocity = Vector3.zero;
				}
				if (UseRailMotion) {
					CalculateNewOrbitData();
				}
			}
		}
 public SimulationControl()
 {
     Instance = this;
 }
Example #11
0
		/// <summary>
		/// Get all main references
		/// </summary>
		public void FindReferences() {
			if (!_transform) {
				_transform = transform;
			}
			if (!_rigidbody2D) {
				_rigidbody2D = GetComponent<Rigidbody2D>();
			}
			if (!_simulationControl) {
				_simulationControl = GameObject.FindObjectOfType<SimulationControl>();
			}
		}
Example #12
0
		void Start() {
			LastPosition = _transform.position;
			if (Application.isPlaying) {
				if (OnBodyCreatedEvent != null) {
					OnBodyCreatedEvent(this);
				}
				if (!_simulationControl) {
					if (SimulationControl.instance == null) {
						Debug.LogWarning("SpaceGravity2D: Simulation Control not found");
						enabled = false;
						return;
					}
					else {
						_simulationControl = SimulationControl.instance;
					}
				}
				if (IsFixedPosition) {
					RelativeVelocity = Vector3.zero;
				}
				if (UseRailMotion) {
					CalculateNewOrbitData();
				}
			}
		}
Example #13
0
		void OnEnable() {
			//Singleton:
			if (instance && instance != this) {
				Debug.LogWarning("SpaceGravity2D: SimulationControl already exists");
				enabled = false;
				return;
			}
			instance = this;
			SubscribeForEvents();
		}