コード例 #1
0
        /*
         *  <summary>
         *  Given an array of string names, the context sets allies if they exist in the CharacterPool instance as prefabs.
         *  Creates a game object based on the previous lookup.
         *  Created characters are then marked as isAlly = true and added to the Allies List
         *  The UI status bars are also added here.
         *  </summary>
         *  <param name="parent">Transform to hold the new game object.</param>
         *  <param name="parentList">List<Character> the list for reference of type of character (allies or enemies)</param>
         *  <param name="characters">string[] Array of character names to lookup in the prefabs characters pool</param>
         *  <param name="isAlly">Boolean to set the character as Ally (true) or Enemey (false)</param>
         */
        private void PrepareCharacters(Transform parent, List <Character> parentList, string[] characters)
        {
            CoordinatesController coordinates = parent.GetComponent <CoordinatesController>();

            for (int i = 0; i < characters.Length; i++)
            {
                //TODO: What if the character does not exist in the pool?
                String     characterKey       = characters[i];
                GameObject characterReference = charactersPool.get(characterKey);
                //Character newCharacter = characterReference.GetComponent<Character>();
                //newCharacter.isAlly = false;//this is not being saved?
                GameObject newInstance = Instantiate(characterReference, parent, false);
                newInstance.transform.localPosition = new Vector2(coordinates.points[i].x, coordinates.points[i].y);
                Character newCharacter = newInstance.GetComponent <Character>();
                newCharacter.CurrentHealth = newCharacter.MaxHealth;
                newCharacter.IsAlive       = true;
                parentList.Add(newCharacter);

                //Setup hp and energy bars.
                newInstance.transform.Find("STATUS_BAR");
                GameObject newUIInstance     = Instantiate(_characterUIBarPrefab, newInstance.transform);
                Transform  statusBarPosition = newInstance.transform.Find("StatusBarPosition");
                newUIInstance.name = Character.STATUS_BAR_NAME;
                if (statusBarPosition != null)
                {
                    newUIInstance.transform.position = statusBarPosition.transform.position;
                }
                newCharacter.HierarchyUpdated();
            }
        }
コード例 #2
0
        private void PrepareCharacters(Transform parent, List <Character> parentList, State[] previousState)
        {
            CoordinatesController coordinates = parent.GetComponent <CoordinatesController>();

            for (int i = 0; i < previousState.Length; i++)
            {
                State state = previousState[i];
                //TODO: What if the character does not exist in the pool?
                String     characterKey       = state.Tag;
                GameObject characterReference = charactersPool.get(characterKey);
                //Character newCharacter = characterReference.GetComponent<Character>();
                //newCharacter.isAlly = false;//this is not being saved?
                GameObject newInstance = Instantiate(characterReference, parent, false);
                newInstance.transform.localPosition = new Vector2(coordinates.points[i].x, coordinates.points[i].y);
                Character newCharacter = newInstance.GetComponent <Character>();
                //Just storing our current GameObjects is not possible, we will need to setup a "State" object instead.
                // Just passing the GameObject/Controller will end up in MissingReferenceException: The object of type 'XXController'
                //Testing with CurrentHealths.
                state.loadTo(newCharacter);

                parentList.Add(newCharacter);

                if (state.IsAlive)
                {
                    //TODO: We still need the dead one reference.
                    //Setup hp and energy bars.
                    newInstance.transform.Find("STATUS_BAR");
                    GameObject newUIInstance = Instantiate(_characterUIBarPrefab, newInstance.transform);
                    newUIInstance.name = Character.STATUS_BAR_NAME;
                    newCharacter.HierarchyUpdated();
                    continue;
                }
            }
        }
コード例 #3
0
        // Use this for initialization
        void Start()
        {
            coordinatesController = GetComponent <CoordinatesController>();
            List <Vector2> points = coordinatesController.points;

            foreach (Vector2 point in points)
            {
                //GameObject newInstance = Instantiate(Resources.Load(""),);
            }
        }