Exemplo n.º 1
0
    public void OnGUI()
    {
        string fileName = "Assets/ScriptableData.asset";

        if (GUILayout.Button("Save asset"))
        {
            ScriptableData scriptableObject = CreateTestScriptableObject();
            AssetDatabase.CreateAsset(scriptableObject, fileName);
        }
    }
Exemplo n.º 2
0
 public virtual void SendData()
 {
     using (Packet packet = new Packet())
     {
         ScriptableData skillData = new ScriptableData();
         skillData.DataType = typeof(ScriptableData).ToString();
         skillData.Prefix   = "PREFIX: SKILL";
         skillData.ScriptId = Id;
         packet.Write(JsonUtility.ToJson(skillData));
         NetManager.Instance.SendData(packet);
     }
 }
Exemplo n.º 3
0
 public void DecodeJson(string json)
 {
     //TODO: Strategy Pattern
     try
     {
         PacketData jsonData = JsonUtility.FromJson <PacketData>(json);
         if (jsonData.DataType == typeof(CharacterData).ToString())
         {
             CharacterData charData = JsonUtility.FromJson <CharacterData>(json);
             otherPlayerLastData = charData;
             NetUpdate();
         }
         else
         {
             if (jsonData.DataType == typeof(ScriptableData).ToString())
             {
                 ScriptableData scriptData = JsonUtility.FromJson <ScriptableData>(json);
                 ScriptInfo     info       = ScriptDatabase.GetInstance().GetScript(scriptData.ScriptId);
                 SkillBehaviour skill      = ScriptableObject.CreateInstance(info.Script.GetClass()) as SkillBehaviour;
                 skill.Caster = otherPlayer;
                 skill.Initialize();
                 if (skill.OnCast != null)
                 {
                     Debug.Log("Cast");
                     skill.OnCast.RunContext();
                 }
             }
             else if (jsonData.DataType == typeof(ProjectileSpawnData).ToString())
             {
                 ProjectileSpawnData projData = JsonUtility.FromJson <ProjectileSpawnData>(json);
                 UnityMainThreadDispatcher.Instance().Enqueue(() =>
                 {
                     spawner.SpawnProjectile(projData.PrefabResourcePath, projData);
                 });
             }
             else
             {
                 SpawnData objSpawnData = JsonUtility.FromJson <SpawnData>(json);
                 UnityMainThreadDispatcher.Instance().Enqueue(() =>
                 {
                     spawner.SpawnObject(objSpawnData.PrefabResourcePath, objSpawnData);
                 });
             }
         }
     }
     catch
     {
         return;
     }
 }
Exemplo n.º 4
0
    private static ScriptableData CreateTestScriptableObject()
    {
        ScriptableData scriptableObject = ScriptableObject.CreateInstance <ScriptableData>();

        scriptableObject.stringProperty = "Test String";
        scriptableObject.intProperty    = 1234;
        if (scriptableObject.dictionaryProperty != null)
        {
            scriptableObject.dictionaryProperty.Clear();
            scriptableObject.dictionaryProperty["key1"] = 111;
            scriptableObject.dictionaryProperty["key2"] = 222;
            scriptableObject.dictionaryProperty["key3"] = 333;
        }
        return(scriptableObject);
    }
    protected void UpdateInitialPair(ScriptableData target)
    {
        _initialPair.serializedObject = new SerializedObject(_initialPair.serializableTemplate);
        SerializedProperty keyProperty   = _initialPair.serializedObject.FindProperty("key");
        SerializedProperty valueProperty = _initialPair.serializedObject.FindProperty("value");
        float viewWidth = EditorGUIUtility.currentViewWidth * 0.5f - 40;

        GUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(keyProperty, GUIContent.none, GUILayout.Width(viewWidth));
        EditorGUILayout.PropertyField(valueProperty, GUIContent.none, GUILayout.Width(viewWidth));
        if (GUILayout.Button("Add", GUILayout.Width(50)))
        {
            _initialPair.serializedObject.ApplyModifiedProperties();
            if (_initialPair.serializableTemplate.key != null && _initialPair.serializableTemplate.key.Length > 0)
            {
                target.dictionaryProperty[_initialPair.serializableTemplate.key] = _initialPair.serializableTemplate.value;
                _addKey = (string)_initialPair.serializableTemplate.key.Clone();
                _initialPair.serializableTemplate.key   = "";
                _initialPair.serializableTemplate.value = 0;
            }
        }
        GUILayout.EndHorizontal();
    }