static object PerformMemberwiseClone(ref object o)
        {
            var ins = new UnityEngine.UI.SpriteState();

            ins = (UnityEngine.UI.SpriteState)o;
            return(ins);
        }
Esempio n. 2
0
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.UI.SpriteState spriteState = (UnityEngine.UI.SpriteState)value;
     writer.WriteProperty("highlightedSprite", spriteState.highlightedSprite);
     writer.WriteProperty("pressedSprite", spriteState.pressedSprite);
     writer.WriteProperty("disabledSprite", spriteState.disabledSprite);
 }
Esempio n. 3
0
        private void SetSpriteSwipe(ImgNode image, UnityEngine.UI.Button button)
        {
            string lowerName = image.Name.ToLower();

            if (lowerName.StartsWith("n_"))
            {
                button.image.sprite = image.sprite;
            }
            else if (lowerName.StartsWith("p_"))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                UnityEngine.UI.SpriteState state = button.spriteState;
                state.pressedSprite = image.sprite;
                button.spriteState  = state;
            }
            else if (lowerName.StartsWith("d_"))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                UnityEngine.UI.SpriteState state = button.spriteState;
                state.disabledSprite = image.sprite;
                button.spriteState   = state;
            }
            else if (lowerName.StartsWith("h_"))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                UnityEngine.UI.SpriteState state = button.spriteState;
                state.highlightedSprite = image.sprite;
                button.spriteState      = state;
            }
        }
Esempio n. 4
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            UnityEngine.UI.Button button = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Button>(PSDImporterConst.ASSET_PATH_BUTTON, layer.name, parent);

            if (layer.layers != null)
            {
                for (int imageIndex = 0; imageIndex < layer.layers.Length; imageIndex++)
                {
                    PSImage image     = layer.layers[imageIndex].image;
                    string  lowerName = image.name.ToLower();
                    if (image.imageType != ImageType.Label && image.imageType != ImageType.Texture)
                    {
                        if (image.imageSource == ImageSource.Custom || image.imageSource == ImageSource.Common)
                        {
                            string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
                            Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;

                            if (image.name.ToLower().Contains("normal"))
                            {
                                button.image.sprite = sprite;
                                RectTransform rectTransform = button.GetComponent <RectTransform>();
                                rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
                                rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);

                                adjustButtonBG(image.imageType, button);
                            }
                            else if (image.name.ToLower().Contains("pressed"))
                            {
                                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                                UnityEngine.UI.SpriteState state = button.spriteState;
                                state.pressedSprite = sprite;
                                button.spriteState  = state;
                            }
                            else if (image.name.ToLower().Contains("disabled"))
                            {
                                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                                UnityEngine.UI.SpriteState state = button.spriteState;
                                state.disabledSprite = sprite;
                                button.spriteState   = state;
                            }
                            else if (image.name.ToLower().Contains("highlighted"))
                            {
                                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                                UnityEngine.UI.SpriteState state = button.spriteState;
                                state.highlightedSprite = sprite;
                                button.spriteState      = state;
                            }
                        }
                    }
                    else
                    {
                        //ctrl.DrawImage(image, button.gameObject);
                        ctrl.DrawLayer(layer.layers[imageIndex], button.gameObject);
                    }
                }
            }
        }
Esempio n. 5
0
 public override void ReadFrom(object obj)
 {
     base.ReadFrom(obj);
     if (obj == null)
     {
         return;
     }
     UnityEngine.UI.SpriteState o = (UnityEngine.UI.SpriteState)obj;
     highlightedSprite = o.highlightedSprite.GetMappedInstanceID();
     pressedSprite     = o.pressedSprite.GetMappedInstanceID();
     disabledSprite    = o.disabledSprite.GetMappedInstanceID();
 }
Esempio n. 6
0
 public override object WriteTo(object obj, System.Collections.Generic.Dictionary <long, UnityEngine.Object> objects)
 {
     obj = base.WriteTo(obj, objects);
     if (obj == null)
     {
         return(null);
     }
     UnityEngine.UI.SpriteState o = (UnityEngine.UI.SpriteState)obj;
     o.highlightedSprite = (UnityEngine.Sprite)objects.Get(highlightedSprite);
     o.pressedSprite     = (UnityEngine.Sprite)objects.Get(pressedSprite);
     o.disabledSprite    = (UnityEngine.Sprite)objects.Get(disabledSprite);
     return(o);
 }
        static void WriteBackInstance(CSHotFix.Runtime.Enviorment.AppDomain __domain, StackObject *ptr_of_this_method, IList <object> __mStack, ref UnityEngine.UI.SpriteState instance_of_this_method)
        {
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            switch (ptr_of_this_method->ObjectType)
            {
            case ObjectTypes.Object:
            {
                __mStack[ptr_of_this_method->Value] = instance_of_this_method;
            }
            break;

            case ObjectTypes.FieldReference:
            {
                var ___obj = __mStack[ptr_of_this_method->Value];
                if (___obj is ILTypeInstance)
                {
                    ((ILTypeInstance)___obj)[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    var t = __domain.GetType(___obj.GetType()) as CLRType;
                    t.SetFieldValue(ptr_of_this_method->ValueLow, ref ___obj, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.StaticFieldReference:
            {
                var t = __domain.GetType(ptr_of_this_method->Value);
                if (t is ILType)
                {
                    ((ILType)t).StaticInstance[ptr_of_this_method->ValueLow] = instance_of_this_method;
                }
                else
                {
                    ((CLRType)t).SetStaticFieldValue(ptr_of_this_method->ValueLow, instance_of_this_method);
                }
            }
            break;

            case ObjectTypes.ArrayReference:
            {
                var instance_of_arrayReference = __mStack[ptr_of_this_method->Value] as UnityEngine.UI.SpriteState[];
                instance_of_arrayReference[ptr_of_this_method->ValueLow] = instance_of_this_method;
            }
            break;
            }
        }
        static StackObject *set_spriteState_8(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.UI.SpriteState value = (UnityEngine.UI.SpriteState) typeof(UnityEngine.UI.SpriteState).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            UnityEngine.UI.Selectable instance_of_this_method;
            instance_of_this_method = (UnityEngine.UI.Selectable) typeof(UnityEngine.UI.Selectable).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.spriteState = value;

            return(__ret);
        }
Esempio n. 9
0
        static StackObject *get_disabledSprite_6(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            UnityEngine.UI.SpriteState instance_of_this_method = (UnityEngine.UI.SpriteState) typeof(UnityEngine.UI.SpriteState).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            var result_of_this_method = instance_of_this_method.disabledSprite;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __intp.Free(ptr_of_this_method);
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Esempio n. 10
0
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.UI.SpriteState spriteState = new UnityEngine.UI.SpriteState();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "highlightedSprite":
                    if (spriteState.highlightedSprite == null)
                    {
                        spriteState.highlightedSprite = reader.ReadProperty <UnityEngine.Sprite> ();
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.Sprite> (spriteState.highlightedSprite);
                    }
                    break;

                case "pressedSprite":
                    if (spriteState.pressedSprite == null)
                    {
                        spriteState.pressedSprite = reader.ReadProperty <UnityEngine.Sprite> ();
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.Sprite> (spriteState.pressedSprite);
                    }
                    break;

                case "disabledSprite":
                    if (spriteState.disabledSprite == null)
                    {
                        spriteState.disabledSprite = reader.ReadProperty <UnityEngine.Sprite> ();
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.Sprite> (spriteState.disabledSprite);
                    }
                    break;
                }
            }
            return(spriteState);
        }
        static StackObject *Equals_6(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.UI.SpriteState other = (UnityEngine.UI.SpriteState) typeof(UnityEngine.UI.SpriteState).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);
            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            UnityEngine.UI.SpriteState instance_of_this_method;
            instance_of_this_method = (UnityEngine.UI.SpriteState) typeof(UnityEngine.UI.SpriteState).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            var result_of_this_method = instance_of_this_method.Equals(other);

            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __ret->ObjectType = ObjectTypes.Integer;
            __ret->Value      = result_of_this_method ? 1 : 0;
            return(__ret + 1);
        }
Esempio n. 12
0
        static StackObject *set_highlightedSprite_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            UnityEngine.Sprite @value = (UnityEngine.Sprite) typeof(UnityEngine.Sprite).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            ptr_of_this_method = ILIntepreter.GetObjectAndResolveReference(ptr_of_this_method);
            UnityEngine.UI.SpriteState instance_of_this_method = (UnityEngine.UI.SpriteState) typeof(UnityEngine.UI.SpriteState).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));

            instance_of_this_method.highlightedSprite = value;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            WriteBackInstance(__domain, ptr_of_this_method, __mStack, ref instance_of_this_method);

            __intp.Free(ptr_of_this_method);
            return(__ret);
        }
Esempio n. 13
0
        private void SetSpriteSwipe(Image image, UnityEngine.UI.Button button)
        {
            string lowerName = image.name.ToLower();
            string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
            Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;

            if (lowerName.StartsWith("n_"))
            {
                button.image.sprite = sprite;

                RectTransform rectTransform = button.GetComponent <RectTransform>();
                rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
                rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
            }
            else if (lowerName.StartsWith("p_"))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                UnityEngine.UI.SpriteState state = button.spriteState;
                state.pressedSprite = sprite;
                button.spriteState  = state;
            }
            else if (lowerName.StartsWith("d_"))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                UnityEngine.UI.SpriteState state = button.spriteState;
                state.disabledSprite = sprite;
                button.spriteState   = state;
            }
            else if (lowerName.StartsWith("h_"))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                UnityEngine.UI.SpriteState state = button.spriteState;
                state.highlightedSprite = sprite;
                button.spriteState      = state;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Replaces all the references in the supplied array (does not work with internal properties).
        /// </summary>
        /// <param name="find">Find.</param>
        /// <param name="replaceWith">Replace with.</param>
        /// <param name="spriteRenderersOnly">If set to <c>true</c> sprite renderers only.</param>
        /// <returns>The replaced references count.</returns>
        public static int ReplaceReferences(Component[] components, Sprite find, Sprite replaceWith, bool spriteRenderersOnly)
        {
            if (components == null || components.Length == 0)
            {
                return(0);
            }

            int count = 0;

            foreach (Object comp in components)
            {
                // Handle sprite renderers differently
                if (comp is SpriteRenderer)
                {
                    if ((comp as SpriteRenderer).sprite == find)
                    {
                        (comp as SpriteRenderer).sprite = replaceWith;
                        count++;
                    }
                }
                else if (comp is UnityEngine.UI.Image)
                {
                    // If this component is not a sprite renderer
                    if (spriteRenderersOnly)
                    {
                        continue;
                    }

                    if ((comp as UnityEngine.UI.Image).sprite == find)
                    {
                        (comp as UnityEngine.UI.Image).sprite = replaceWith;
                        count++;
                    }
                }
                else if (comp is UnityEngine.UI.Selectable)
                {
                    // If this component is not a sprite renderer
                    if (spriteRenderersOnly)
                    {
                        continue;
                    }

                    UnityEngine.UI.Selectable  selectable = (comp as UnityEngine.UI.Selectable);
                    UnityEngine.UI.SpriteState ss         = selectable.spriteState;

                    if (ss.highlightedSprite == find)
                    {
                        ss.highlightedSprite = replaceWith;
                        count++;
                    }
                    if (ss.pressedSprite == find)
                    {
                        ss.pressedSprite = replaceWith;
                        count++;
                    }
                    if (ss.disabledSprite == find)
                    {
                        ss.disabledSprite = replaceWith;
                        count++;
                    }

                    selectable.spriteState = ss;
                }
                else
                {
                    // If this component is not a sprite renderer
                    if (spriteRenderersOnly)
                    {
                        continue;
                    }

                    // Get the fileds info
                    FieldInfo[] fields = comp.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);

                    foreach (FieldInfo fieldInfo in fields)
                    {
                        if (fieldInfo == null)
                        {
                            continue;
                        }

                        object fieldValue = fieldInfo.GetValue(comp);

                        // Handle arrays
                        if (fieldInfo.FieldType.IsArray)
                        {
                            var fieldValueArray = fieldValue as System.Array;

                            if (fieldValueArray == null || fieldValueArray.GetType() != typeof(Sprite[]))
                            {
                                continue;
                            }

                            bool         changed  = false;
                            System.Array newArray = new System.Array[fieldValueArray.Length];
                            fieldValueArray.CopyTo(newArray, 0);

                            for (int i = 0; i < newArray.Length; i++)
                            {
                                object element = newArray.GetValue(i);

                                if (element != null && element.GetType() == typeof(Sprite))
                                {
                                    Sprite o = element as Sprite;

                                    // Check if the value is what we are looking for
                                    if (o == find)
                                    {
                                        newArray.SetValue((replaceWith as object), i);
                                        changed = true;
                                        count++;
                                    }
                                }
                            }

                            // Repalce the array
                            if (changed)
                            {
                                fieldInfo.SetValue(comp, newArray);
                            }
                        }
                        // Handle structs
                        else if (fieldInfo.FieldType.IsValueType && !fieldInfo.FieldType.IsEnum && !fieldInfo.IsLiteral)
                        {
                            FieldInfo[] structFields = fieldInfo.FieldType.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

                            foreach (FieldInfo structFieldInfo in structFields)
                            {
                                if (structFieldInfo == null)
                                {
                                    continue;
                                }

                                if (structFieldInfo.FieldType == typeof(Sprite))
                                {
                                    Sprite structFieldValue = structFieldInfo.GetValue(fieldValue) as Sprite;

                                    // Check if the value is what we are looking for
                                    if (structFieldValue == find)
                                    {
                                        // Replace
                                        structFieldInfo.SetValue(fieldValue, (replaceWith as object));
                                        count++;
                                    }
                                }
                            }

                            fieldInfo.SetValue(comp, fieldValue);
                        }
                        // Handle direct sprites
                        else if (fieldInfo.FieldType == typeof(Sprite))
                        {
                            // Check if the value is what we are looking for
                            if ((fieldValue as Sprite) == find)
                            {
                                // Replace
                                fieldInfo.SetValue(comp, (replaceWith as object));
                                count++;
                            }
                        }
                    }
                }

                if (PrefabUtility.GetPrefabType((comp as Component).gameObject) != PrefabType.None)
                {
                    EditorUtility.SetDirty((comp as Component));
                }
            }

            return(count);
        }