Ejemplo n.º 1
0
        private void SetLabel(SpriteResolver spriteResolver, string label)
        {
            var category = spriteResolver.GetCategory();

            label = DoesLabelExistInCategory(label, category) ? label : NoneLabel;
            spriteResolver.SetCategoryAndLabel(category, label);
        }
Ejemplo n.º 2
0
 private void InitSpriteResolve()
 {
     string[] toDefault =
     {
         "arm.l",
         "arm.r",
         "leg.l",
         "leg.r",
         "torso",
         "head",
         "head.face",
     };
     foreach (Transform child in transform)
     {
         Debug.Log(child.name);
         SpriteResolver spriteResolver = child.GetComponent <SpriteResolver>();
         if (spriteResolver)
         {
             if (Array.IndexOf(toDefault, child.name) >= 0)
             {
                 spriteResolver.SetCategoryAndLabel(child.name, "default");
             }
             else
             {
                 spriteResolver.SetCategoryAndLabel(child.name, "empty");
             }
         }
     }
 }
Ejemplo n.º 3
0
    void Start() // Start is called before the first frame update
    {
        base.Start();
        sprite         = GetComponent <SpriteRenderer>();
        spriteResolver = GetComponent <SpriteResolver>();

        arrow       = arrowObj.GetComponent <Arrow>();
        orientation = new Vector3(0, -arrowOffset, 1);
    }
        public void OnEnable()
        {
            m_SpriteCategoryHash = serializedObject.FindProperty("m_CategoryHash");
            m_SpritelabelHash    = serializedObject.FindProperty("m_labelHash");
            m_SpriteSkin         = (target as SpriteResolver).GetComponent <SpriteSkin>();

            m_PreviousCategoryHash = SpriteResolver.ConvertFloatToInt(m_SpriteCategoryHash.floatValue);
            m_PreviouslabelHash    = SpriteResolver.ConvertFloatToInt(m_SpritelabelHash.floatValue);
            UpdateSpriteLibrary();
        }
 /**
  * @Description: Add all equipments resolvers into the list
  * @version: 1.0.0
  * @Author: Zilin Zhang
  * @Date: 2020-11-27 03:29:45
  * @LastEditors: Zilin Zhang
  * @LastEditTime: 2020-11-27 03:29:45
  */
 private void AddResolverIntoList()
 {
     foreach (var resolover in FindObjectsOfType <SpriteResolver>())
     {
         spriteResolvers.Add(resolover);
         if (resolover.GetCategory().Equals("LeftItem"))
         {
             leftHandResolve = resolover;
         }
         if (resolover.GetCategory().Equals("RightItem"))
         {
             rightHandResolve = resolover;
         }
     }
 }
Ejemplo n.º 6
0
 //Get resolver
 public void getResolver(int getwhich)
 {
     foreach (SpriteResolver resolver in Resources.FindObjectsOfTypeAll <SpriteResolver>())
     {
         if (resolver.transform.parent.parent.gameObject.GetComponent <PlayerData>().whichplayer == getwhich)
         {
             if (resolver.GetCategory() == "haira")
             {
                 hairaResolver = resolver;
             }
             else if (resolver.GetCategory() == "hairb")
             {
                 hairbResolver = resolver;
             }
             else if (resolver.GetCategory() == "hairc")
             {
                 haircResolver = resolver;
             }
             else if (resolver.GetCategory() == "eye")
             {
                 eyeResolver = resolver;
             }
             else if (resolver.GetCategory() == "sunglasses")
             {
                 sunglassesResolver = resolver;
             }
             else if (resolver.GetCategory() == "eyebrow")
             {
                 eyebrowResolver = resolver;
             }
             else if (resolver.GetCategory() == "cat")
             {
                 catResolver = resolver;
             }
             else if (resolver.GetCategory() == "wheelchair")
             {
                 wheelchairResolver = resolver;
             }
             else if (resolver.GetCategory() == "mouth")
             {
                 mouthResolver = resolver;
             }
         }
     }
 }
Ejemplo n.º 7
0
        private void Awake()
        {
            _asset = Assets.SpriteLibraryAsset;
            GetComponent <SpriteLibrary>().spriteLibraryAsset = _asset;
            _face      = transform.Find(BodyPartTag.Face.ToString()).GetComponent <SpriteResolver>();
            _bodyParts = new List <SpriteResolver>();

            foreach (BodyPartTag bodyPartTag in typeof(BodyPartTag).GetEnumValues())
            {
                _bodyParts.Add(transform.Find(bodyPartTag.ToString()).GetComponent <SpriteResolver>());
            }

            _accessories = new List <SpriteResolver>();

            foreach (AccessoryCategory category in typeof(AccessoryCategory).GetEnumValues())
            {
                _accessories.Add(transform.Find(category.ToString()).GetComponent <SpriteResolver>());
            }
        }
        void GetCategoryAndLabelStringValue(out string categoryName, out string labelName)
        {
            categoryName = null;
            labelName    = null;
            var spriteLib = spriteResolver.spriteLibrary;

            if (spriteLib != null)
            {
                int entryHash = SpriteResolver.ConvertFloatToInt(m_SpriteKey.floatValue);
                spriteLib.GetCategoryAndEntryNameFromHash(entryHash, out categoryName, out labelName);
                if (string.IsNullOrEmpty(categoryName) || string.IsNullOrEmpty(labelName))
                {
                    int labelHash    = SpriteResolver.ConvertFloatToInt(m_LabelHash.floatValue);
                    int categoryHash = SpriteResolver.ConvertFloatToInt(m_CategoryHash.floatValue);
                    m_SpriteKey.floatValue = SpriteResolver.ConvertCategoryLabelHashToSpriteKey(spriteLib, categoryHash, labelHash);
                    entryHash = SpriteResolver.ConvertFloatToInt(m_SpriteKey.floatValue);
                    spriteLib.GetCategoryAndEntryNameFromHash(entryHash, out categoryName, out labelName);
                }
            }
        }
Ejemplo n.º 9
0
 // Start is called before the first frame update
 void Start()
 {
     sr = GetComponent <SpriteResolver>();
 }
Ejemplo n.º 10
0
 public static int get_label_as_number(
     this SpriteResolver in_resolver
     )
 {
     return(Int32.Parse(in_resolver.GetLabel()));
 }
        void UpdateSpriteLibrary()
        {
            m_SpriteLibSelection.Clear();
            int categoryHash = SpriteResolver.ConvertFloatToInt(m_SpriteCategoryHash.floatValue);
            int labelHash    = SpriteResolver.ConvertFloatToInt(m_SpritelabelHash.floatValue);
            var spriteLib    = spriteResolver.GetComponentInParent <SpriteLibrary>();

            if (spriteLib != null)
            {
                foreach (var labels in spriteLib.labels)
                {
                    if (!m_SpriteLibSelection.ContainsKey(labels.hash))
                    {
                        var nameHash = labels.categoryList.Select(x => x.hash).Distinct().ToArray();
                        if (nameHash.Length > 0)
                        {
                            var selectionList = new SpriteCategorySelectionList()
                            {
                                names = nameHash.Select(x =>
                                {
                                    var v = labels.categoryList.FirstOrDefault(y => y.hash == x);
                                    return(v.name);
                                }).ToArray(),
                                nameHash = nameHash,
                                sprites  = nameHash.Select(x =>
                                {
                                    var v = labels.categoryList.FirstOrDefault(y => y.hash == x);
                                    return(v.sprite);
                                }).ToArray(),
                                categoryName     = labels.name,
                                categoryNameHash = labels.hash
                            };

                            m_SpriteLibSelection.Add(labels.hash, selectionList);
                        }
                    }
                }
            }
            m_CategorySelection        = new string[1 + m_SpriteLibSelection.Keys.Count];
            m_CategorySelection[0]     = TextContent.none;
            m_CategorySelectionHash    = new int[1 + m_SpriteLibSelection.Keys.Count];
            m_CategorySelectionHash[0] = SpriteLibraryAsset.GetStringHash(TextContent.none);
            for (int i = 0; i < m_SpriteLibSelection.Keys.Count; ++i)
            {
                var selection = m_SpriteLibSelection[m_SpriteLibSelection.Keys.ElementAt(i)];
                m_CategorySelection[i + 1]     = selection.categoryName;
                m_CategorySelectionHash[i + 1] = selection.categoryNameHash;
                if (selection.categoryNameHash == categoryHash)
                {
                    m_CategorySelectionIndex = i + 1;
                }
            }
            ValidateCategorySelectionIndexValue();
            if (m_CategorySelectionIndex > 0)
            {
                m_SpriteSelectorWidget.UpdateContents(m_SpriteLibSelection[m_CategorySelectionHash[m_CategorySelectionIndex]].sprites);
                if (m_SpriteLibSelection.ContainsKey(categoryHash))
                {
                    m_labelSelectionIndex = Array.FindIndex(m_SpriteLibSelection[categoryHash].nameHash, x => x == labelHash);
                }
            }
            spriteResolver.spriteLibChanged = false;
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            if (spriteResolver.spriteLibChanged)
            {
                UpdateSpriteLibrary();
            }

            var currentlabelHashValue    = SpriteResolver.ConvertFloatToInt(m_SpritelabelHash.floatValue);
            var currentCategoryHashValue = SpriteResolver.ConvertFloatToInt(m_SpriteCategoryHash.floatValue);

            m_CategorySelectionIndex = Array.FindIndex(m_CategorySelectionHash, x => x == currentCategoryHashValue);
            ValidateCategorySelectionIndexValue();

            if (m_CategorySelection.Length == 1)
            {
                EditorGUILayout.LabelField(Style.noSpriteLibContainer);
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                m_CategorySelectionIndex = EditorGUILayout.Popup(Style.categoryLabel, m_CategorySelectionIndex, m_CategorySelection);
                if (m_CategorySelectionIndex != 0)
                {
                    var selection = m_SpriteLibSelection[m_CategorySelectionHash[m_CategorySelectionIndex]];
                    if (selection.names.Length <= 0)
                    {
                        EditorGUILayout.LabelField(Style.categoryIsEmptyLabel);
                    }
                    else
                    {
                        if (m_labelSelectionIndex < 0 || m_labelSelectionIndex >= selection.names.Length)
                        {
                            m_labelSelectionIndex = 0;
                        }
                        m_labelSelectionIndex = EditorGUILayout.Popup(Style.labelLabel, m_labelSelectionIndex, selection.names);
                        m_labelSelectionIndex = m_SpriteSelectorWidget.ShowGUI(m_labelSelectionIndex);
                    }
                }

                if (EditorGUI.EndChangeCheck())
                {
                    currentCategoryHashValue = m_CategorySelectionHash[m_CategorySelectionIndex];
                    if (m_SpriteLibSelection.ContainsKey(currentCategoryHashValue))
                    {
                        var hash = m_SpriteLibSelection[currentCategoryHashValue].nameHash;
                        if (hash.Length > 0)
                        {
                            if (m_labelSelectionIndex < 0 || m_labelSelectionIndex >= hash.Length)
                            {
                                m_labelSelectionIndex = 0;
                            }
                            currentlabelHashValue = m_SpriteLibSelection[currentCategoryHashValue].nameHash[m_labelSelectionIndex];
                        }
                    }

                    m_SpriteCategoryHash.floatValue = SpriteResolver.ConvertIntToFloat(currentCategoryHashValue);
                    m_SpritelabelHash.floatValue    = SpriteResolver.ConvertIntToFloat(currentlabelHashValue);
                    serializedObject.ApplyModifiedProperties();

                    var sf = target as SpriteResolver;
                    if (m_SpriteSkin != null)
                    {
                        m_SpriteSkin.ignoreNextSpriteChange = true;
                    }
                    sf.ResolveSpriteToSpriteRenderer();
                }

                if (m_PreviousCategoryHash != currentCategoryHashValue)
                {
                    if (m_SpriteLibSelection.ContainsKey(currentCategoryHashValue))
                    {
                        m_SpriteSelectorWidget.UpdateContents(m_SpriteLibSelection[currentCategoryHashValue].sprites);
                    }
                    m_PreviousCategoryHash = currentCategoryHashValue;
                }

                if (m_PreviouslabelHash != currentlabelHashValue)
                {
                    if (m_SpriteLibSelection.ContainsKey(currentCategoryHashValue))
                    {
                        m_labelSelectionIndex = Array.FindIndex(m_SpriteLibSelection[currentCategoryHashValue].nameHash, x => x == currentlabelHashValue);
                    }
                    m_PreviouslabelHash = currentlabelHashValue;
                }

                serializedObject.ApplyModifiedProperties();
                if (m_SpriteSelectorWidget.NeedUpdatePreview())
                {
                    this.Repaint();
                }
            }
        }
Ejemplo n.º 13
0
 public ModelPart(SpriteResolver resolver)
 {
     _resolver = resolver;
     _category = _resolver.GetCategory();
     _renderer = _resolver.GetComponent <SpriteRenderer>();
 }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            if (m_ReInitOnNextGUI)
            {
                m_ReInitOnNextGUI = false;
                UpdateSpriteLibrary();
            }

            if (spriteResolver.spriteLibChanged)
            {
                UpdateSpriteLibrary();
            }

            GetCategoryAndLabelStringValue(out var currentCategoryValue, out var currentLabelValue);
            var catIndex = Array.FindIndex(m_CategorySelection, x => x == currentCategoryValue);

            if (catIndex >= 0)
            {
                m_CategorySelectionIndex = catIndex;
            }
            ValidateCategorySelectionIndexValue();

            EditorGUI.BeginChangeCheck();
            using (new EditorGUI.DisabledScope(m_CategorySelection.Length <= 1))
                m_CategorySelectionIndex = EditorGUILayout.Popup(Style.categoryLabel, m_CategorySelectionIndex, m_CategorySelection);

            SpriteCategorySelectionList selection;

            m_SpriteLibSelection.TryGetValue(m_CategorySelection[m_CategorySelectionIndex], out selection);

            var entryNames = Style.emptyCategoryDropDownOption;

            if (selection.entryNames != null)
            {
                entryNames = selection.entryNames;
            }
            if (m_LabelSelectionIndex < 0 || m_LabelSelectionIndex >= entryNames.Length)
            {
                m_LabelSelectionIndex = 0;
            }
            using (new EditorGUI.DisabledScope(m_CategorySelectionIndex == 0 || entryNames.Length == 0))
            {
                if (entryNames.Length == 0)
                {
                    m_LabelSelectionIndex = EditorGUILayout.Popup(Style.labelLabel, 0, new [] { Style.categoryIsEmptyLabel });
                }
                else
                {
                    m_LabelSelectionIndex = EditorGUILayout.Popup(Style.labelLabel, m_LabelSelectionIndex, entryNames);
                }
            }

            m_LabelSelectionIndex = m_SpriteSelectorWidget.ShowGUI(m_LabelSelectionIndex);


            if (EditorGUI.EndChangeCheck())
            {
                currentCategoryValue = m_CategorySelection[m_CategorySelectionIndex];
                if (m_SpriteLibSelection.ContainsKey(currentCategoryValue))
                {
                    var hash = m_SpriteLibSelection[currentCategoryValue].entryNames;
                    if (hash.Length > 0)
                    {
                        if (m_LabelSelectionIndex < 0 || m_LabelSelectionIndex >= hash.Length)
                        {
                            m_LabelSelectionIndex = 0;
                        }
                        currentLabelValue = m_SpriteLibSelection[currentCategoryValue].entryNames[m_LabelSelectionIndex];
                    }
                }

                m_SpriteKey.floatValue = SpriteResolver.ConvertIntToFloat(SpriteLibrary.GetHashForCategoryAndEntry(currentCategoryValue, currentLabelValue));
                ApplyModifiedProperty();

                var sf = target as SpriteResolver;
                if (m_SpriteSkin != null)
                {
                    m_SpriteSkin.ignoreNextSpriteChange = true;
                }
                sf.ResolveSpriteToSpriteRenderer();
            }

            if (m_PreviousCategoryValue != currentCategoryValue)
            {
                if (!string.IsNullOrEmpty(currentCategoryValue))
                {
                    if (m_SpriteLibSelection.ContainsKey(currentCategoryValue))
                    {
                        m_SpriteSelectorWidget.UpdateContents(m_SpriteLibSelection[currentCategoryValue].sprites);
                    }
                    else
                    {
                        m_SpriteSelectorWidget.UpdateContents(new Sprite[0]);
                    }

                    this.Repaint();
                }

                m_PreviousCategoryValue = currentCategoryValue;
            }

            if (!string.IsNullOrEmpty(currentLabelValue) && m_PreviousLabelValue != currentLabelValue)
            {
                if (m_SpriteLibSelection.ContainsKey(currentCategoryValue))
                {
                    m_LabelSelectionIndex = Array.FindIndex(m_SpriteLibSelection[currentCategoryValue].entryNames, x => x == currentLabelValue);
                }
                m_PreviousLabelValue = currentLabelValue;
            }

            ApplyModifiedProperty();
            if (m_SpriteSelectorWidget.NeedUpdatePreview())
            {
                this.Repaint();
            }
        }
Ejemplo n.º 15
0
        /*
         * public void UpdateFace()
         * {
         *  if (Math.Abs( velocity.x) > Math. Abs(velocity.y))
         *  {
         *      eyes.SetCategoryAndLabel(velocity.x > 0 ? "eyes_right" : "eyes_left", "default");
         *  }
         *  else
         *  {
         *      eyes.SetCategoryAndLabel(velocity.y < 0 ? "eyes_front" : "eyes_back", "default");
         *  }
         * }
         */


        public void GetAnimComponents()
        {
            body = transform.Find("body").GetComponent <SpriteResolver>();
            head = transform.Find("head").GetComponent <SpriteResolver>();
            eyes = head.transform.Find("eyes").GetComponent <SpriteResolver>();
        }
Ejemplo n.º 16
0
        public void StartGame()
        {
            networkmanager = GetComponent <CharactorCreatorNetworkManager>();
            networkmanager.OnGame_Started();

            //setActivePlayer();
            foreach (var resolver in FindObjectsOfType <SpriteResolver>())
            {
                spriteResolvers.Add(resolver);
                if (resolver.GetCategory() == "haira")
                {
                    hairaResolver = resolver;
                }
                else if (resolver.GetCategory() == "hairb")
                {
                    hairbResolver = resolver;
                }
                else if (resolver.GetCategory() == "hairc")
                {
                    haircResolver = resolver;
                }
                else if (resolver.GetCategory() == "eye")
                {
                    eyeResolver = resolver;
                }
                else if (resolver.GetCategory() == "sunglasses")
                {
                    sunglassesResolver = resolver;
                }
                else if (resolver.GetCategory() == "eyebrow")
                {
                    eyebrowResolver = resolver;
                }
                else if (resolver.GetCategory() == "cat")
                {
                    catResolver = resolver;
                }
                else if (resolver.GetCategory() == "wheelchair")
                {
                    wheelchairResolver = resolver;
                }
                else if (resolver.GetCategory() == "mouth")
                {
                    mouthResolver = resolver;
                }

                if (PlayerNetwork.Instance.myCharacter == 0)
                {
                    //blind.SetActive(true);
                    eye.SetActive(false);
                    wheelchair.SetActive(false);
                }
                else
                {
                    //deaf.SetActive(true);
                    sunglasses.SetActive(false);
                }
            }

            defaultbody_pressed_selected();
        }