Esempio n. 1
0
        /// <summary>
        /// Attempts to find the static instance of the controller and
        ///  Writes the data about the controller to disk in the streaming assets folder
        /// </summary>
        public static void SaveController()
        {
            var _controller = CrowdController.GetCrowdController();

            if (_controller != null)
            {
                SaveController(_controller);
            }
            else
            {
                Debug.LogError("The static instance of the controller is null, can't save");
            }
        }
Esempio n. 2
0
        /// <summary>
        ///  Writes the data about the controller to disk in the streaming assets folder
        /// </summary>
        /// <param name="controller">The controller being saved </param>
        public static void SaveController(CrowdController controller)
        {
            if (controller == null)
            {
                return;
            }

            var _controllerData = new CrowdData();
            var _sources        = controller.Sources;

            _controllerData._stateNames = controller.GetCrowdStates();

            var _groups = controller.GetGroups();

            if (_groups != null)
            {
                _controllerData._groups = new GroupData[_groups.Length];
                for (int i = 0; i < _groups.Length; i++)
                {
                    _controllerData._groups[i] = _groups[i].GetData(_sources);
                }
            }


            _controllerData._unassignedGroup = controller.GetUnassignedGroup.GetData(_sources);


            if (_sources.Count > 0)
            {
                _controllerData._parents = new TransformData[_sources.Count];

                for (int i = 0; i < _sources.Count; i++)
                {
                    _controllerData._parents[i] = GetTransformData(_sources[i].transform);
                }
            }


            string _path = Application.streamingAssetsPath + @"/CrowdAIData";

            Debug.Log(_path);

            string _fileName = @"/CrowdData - " + SceneManager.GetActiveScene().name + ".data.json";

            Debug.Log(_fileName);
            Directory.CreateDirectory(_path);

            var _serializedData = JsonConvert.SerializeObject(_controllerData);

            File.WriteAllText(_path + _fileName, _serializedData);
        }
Esempio n. 3
0
        /// <summary>
        /// Initialise all the GUI serialised properties
        /// </summary>
        void OnEnable()
        {
            crowdFormation_Prop = serializedObject.FindProperty("_crowdFormation");
            innerRadius_Prop    = serializedObject.FindProperty("_innerRadius");
            rotation_Prop       = serializedObject.FindProperty("_rotDir");
            crowdDensity_Prop   = serializedObject.FindProperty("_density");
            tiltAmount_Prop     = serializedObject.FindProperty("_tiltAmount");
            startHeight_Prop    = serializedObject.FindProperty("_startHeight");
            crowdObject_Prop    = serializedObject.FindProperty("_placeholderPrefab");
            crowdStates_Prop    = serializedObject.FindProperty("_crowdStates");
            models_Prop         = serializedObject.FindProperty("_groupModels");


            script = (CrowdController)target;
        }
Esempio n. 4
0
        /// <summary>
        /// Instantiates classes inside of the controller
        /// This will cause the controller to lose all references to objects
        /// </summary>
        public void SetUp()
        {
            _scene = SceneManager.GetActiveScene().name;


            if (_instance != null)
            {
                if (_instance != this && _instance.ControllerScene == _scene)
                {
                    Debug.LogWarning("Can Only Have one Crowd Controller per scene");
                    Destroy(gameObject);
                    return;
                }
            }
            print("set up");
            _instance = this;

            _crowdGroups     = new List <CrowdGroup>();
            _groupUnassigned = new CrowdGroup("Unassigned");
            _crowdSources    = new List <GameObject>();

            _setUp = true;
        }
Esempio n. 5
0
 // Use this for initialization
 void Start()
 {
     _crowdController = GetComponent <CrowdController>();
     _states          = _crowdController.GetCrowdStates();
     _groupNames      = _crowdController.GetGroupNames();
 }