Initial commit: Unity WordConnect project
This commit is contained in:
@ -0,0 +1,86 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using WordsToolkit.Scripts.GUI.Buttons;
|
||||
|
||||
namespace WordsToolkit.Scripts.Editor.GUI
|
||||
{
|
||||
[CustomEditor(typeof(CustomButton), true)]
|
||||
internal class CustomButtonDrawer : UnityEditor.Editor
|
||||
{
|
||||
private CustomButtonEditor customButtonEditor;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
customButtonEditor = new CustomButtonEditor();
|
||||
}
|
||||
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
var root = new VisualElement();
|
||||
|
||||
root.Add(new PropertyField(serializedObject.FindProperty("noSound")));
|
||||
root.Add(new PropertyField(serializedObject.FindProperty("overrideClickSound")));
|
||||
root.Add(new PropertyField(serializedObject.FindProperty("overrideAnimatorController")));
|
||||
|
||||
var foldout = new Foldout { text = "Custom Button Settings", value = false };
|
||||
foldout.Add(customButtonEditor.CreateInspectorGUI(serializedObject));
|
||||
root.Add(foldout);
|
||||
// Draw default inspector for inherited fields
|
||||
var iterator = serializedObject.GetIterator();
|
||||
iterator.NextVisible(true); // Skip Script field
|
||||
var customButtonType = typeof(CustomButton);
|
||||
while (iterator.NextVisible(false))
|
||||
{
|
||||
var field = iterator.serializedObject.targetObject.GetType().GetField(iterator.name);
|
||||
if (field != null)
|
||||
{
|
||||
// Show fields from parent classes AND child classes, but not from CustomButton itself
|
||||
if (field.DeclaringType != customButtonType)
|
||||
{
|
||||
root.Add(new PropertyField(serializedObject.FindProperty(iterator.name)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw fields from derived class if any
|
||||
var targetType = serializedObject.targetObject.GetType();
|
||||
if (targetType != customButtonType)
|
||||
{
|
||||
var derivedFields = targetType.GetFields(BindingFlags.Public |
|
||||
BindingFlags.NonPublic |
|
||||
BindingFlags.Instance |
|
||||
BindingFlags.DeclaredOnly);
|
||||
foreach (var field in derivedFields)
|
||||
{
|
||||
if (field.IsPrivate && !field.IsDefined(typeof(SerializeField), false))
|
||||
continue;
|
||||
|
||||
var property = serializedObject.FindProperty(field.Name);
|
||||
if (property != null)
|
||||
{
|
||||
root.Add(new PropertyField(property));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5ef7a07874d4973a9672a27bb8b024e
|
||||
timeCreated: 1748678361
|
||||
@ -0,0 +1,156 @@
|
||||
// // ©2015 - 2025 Candy Smith
|
||||
// // All rights reserved
|
||||
// // Redistribution of this software is strictly not allowed.
|
||||
// // Copy of this software can be obtained from unity asset store only.
|
||||
// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UIElements;
|
||||
using WordsToolkit.Scripts.GUI;
|
||||
using WordsToolkit.Scripts.Popups.Reward;
|
||||
|
||||
namespace WordsToolkit.Scripts.Editor.GUI
|
||||
{
|
||||
public class CustomButtonEditor
|
||||
{
|
||||
public VisualElement CreateInspectorGUI(SerializedObject serializedObject)
|
||||
{
|
||||
var root = new VisualElement();
|
||||
|
||||
root.Add(new VisualElement { name = "space", style = { height = 10 } });
|
||||
|
||||
// Add the Interactable field
|
||||
root.Add(GetBindPropertyField(serializedObject, "m_Interactable", "Interactable"));
|
||||
|
||||
// Add the Transition field
|
||||
var transition = GetPropertyField(serializedObject, "m_Transition", "Transition");
|
||||
transition.Bind(serializedObject);
|
||||
root.Add(transition);
|
||||
var onClickProperty = GetBindPropertyField(serializedObject, "m_OnClick", "On Click");
|
||||
var spriteProperty = GetPropertyField(serializedObject, "m_SpriteState", "Sprites");
|
||||
var colorProperty = GetPropertyField(serializedObject, "m_Colors", "Colors");
|
||||
var animations = GetPropertyField(serializedObject, "m_AnimationTriggers", "Animations");
|
||||
transition.RegisterValueChangeCallback(evt =>
|
||||
{
|
||||
Transition(serializedObject, root, spriteProperty, animations, colorProperty);
|
||||
root.Remove(onClickProperty);
|
||||
root.Add(onClickProperty);
|
||||
});
|
||||
Transition(serializedObject, root, spriteProperty, animations, colorProperty);
|
||||
|
||||
root.Add(onClickProperty);
|
||||
|
||||
colorProperty.Bind(serializedObject);
|
||||
spriteProperty.Bind(serializedObject);
|
||||
animations.Bind(serializedObject);
|
||||
return root;
|
||||
}
|
||||
|
||||
private static void Transition(SerializedObject serializedObject, VisualElement root, PropertyField spriteProperty, PropertyField animations, PropertyField colorProperty)
|
||||
{
|
||||
var transitionProperty = serializedObject.FindProperty("m_Transition");
|
||||
// Add transition details based on the selected type
|
||||
if (transitionProperty.enumValueIndex == (int)Selectable.Transition.ColorTint)
|
||||
{
|
||||
if (root.Contains(spriteProperty))
|
||||
{
|
||||
root.Remove(spriteProperty);
|
||||
}
|
||||
|
||||
if (root.Contains(animations))
|
||||
{
|
||||
root.Remove(animations);
|
||||
}
|
||||
|
||||
root.Add(colorProperty);
|
||||
}
|
||||
else if (transitionProperty.enumValueIndex == (int)Selectable.Transition.SpriteSwap)
|
||||
{
|
||||
if (root.Contains(colorProperty))
|
||||
{
|
||||
root.Remove(colorProperty);
|
||||
}
|
||||
|
||||
if (root.Contains(animations))
|
||||
{
|
||||
root.Remove(animations);
|
||||
}
|
||||
|
||||
root.Add(spriteProperty);
|
||||
}
|
||||
else if (transitionProperty.enumValueIndex == (int)Selectable.Transition.Animation)
|
||||
{
|
||||
if (root.Contains(colorProperty))
|
||||
{
|
||||
root.Remove(colorProperty);
|
||||
}
|
||||
|
||||
if (root.Contains(spriteProperty))
|
||||
{
|
||||
root.Remove(spriteProperty);
|
||||
}
|
||||
|
||||
root.Add(animations);
|
||||
}
|
||||
else if (transitionProperty.enumValueIndex == (int)Selectable.Transition.None)
|
||||
{
|
||||
if (root.Contains(colorProperty))
|
||||
{
|
||||
root.Remove(colorProperty);
|
||||
}
|
||||
|
||||
if (root.Contains(spriteProperty))
|
||||
{
|
||||
root.Remove(spriteProperty);
|
||||
}
|
||||
|
||||
if (root.Contains(animations))
|
||||
{
|
||||
root.Remove(animations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private VisualElement GetBindPropertyField(SerializedObject serializedObject, string propertyName, string label)
|
||||
{
|
||||
var propertyField = GetPropertyField(serializedObject, propertyName, label);
|
||||
propertyField.Bind(serializedObject);
|
||||
return propertyField;
|
||||
}
|
||||
|
||||
private PropertyField GetPropertyField(SerializedObject serializedObject, string propertyName, string label)
|
||||
{
|
||||
return new PropertyField(serializedObject.FindProperty(propertyName), label);
|
||||
}
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(RewardedButton))]
|
||||
internal class RewardedButtonEditor : UnityEditor.Editor
|
||||
{
|
||||
private CustomButtonEditor customButtonEditor;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
customButtonEditor = new CustomButtonEditor();
|
||||
}
|
||||
|
||||
public override VisualElement CreateInspectorGUI()
|
||||
{
|
||||
var root = new VisualElement();
|
||||
|
||||
// Add a property field for placement
|
||||
var placementField = new PropertyField(serializedObject.FindProperty("placement"), "Placement");
|
||||
root.Add(placementField);
|
||||
root.Add(customButtonEditor.CreateInspectorGUI(serializedObject));
|
||||
return root;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e393e17f265f4314be795dcbc434ac2a
|
||||
timeCreated: 1709550126
|
||||
Reference in New Issue
Block a user